Skip to content
Snippets Groups Projects
Commit 085fe753 authored by Oscar Gustafsson's avatar Oscar Gustafsson :bicyclist:
Browse files

Cleaning up code

parent 1183e1d4
No related branches found
No related tags found
1 merge request!112Cleaning up code
Pipeline #88230 passed
......@@ -26,7 +26,7 @@ QUESTIONS = {
"the selection box will then be selected."
),
"Selecting multiple operations using without dragging": (
"To select mutliple operations using without dragging, \n"
"To select multiple operations using without dragging, \n"
"press 'Ctrl+LMouseButton' on any operation."
),
"Remove operations": (
......@@ -70,7 +70,7 @@ class KeybindsWindow(QDialog):
super().__init__()
self._window = window
self.setWindowFlags(Qt.WindowTitleHint | Qt.WindowCloseButtonHint)
self.setWindowTitle("B-ASIC Keybinds")
self.setWindowTitle("B-ASIC Keybindings")
self.dialog_layout = QVBoxLayout()
self.setLayout(self.dialog_layout)
......@@ -81,7 +81,7 @@ class KeybindsWindow(QDialog):
information_layout = QVBoxLayout()
title_label = QLabel("B-ASIC / Better ASIC Toolbox")
subtitle_label = QLabel("Keybinds in the GUI.")
subtitle_label = QLabel("Keybindings in the GUI.")
frame = QFrame()
frame.setFrameShape(QFrame.HLine)
......
......@@ -78,7 +78,7 @@ class Arrow(QGraphicsPathItem):
def moveLine(self):
"""
Draw a line connecting self.source with self.destination. Used as callback when moving operations.
Draw a line connecting ``self.source`` with ``self.destination``. Used as callback when moving operations.
"""
ORTHOGONAL = True
OFFSET = 2 * PORTWIDTH
......
......@@ -148,7 +148,7 @@ class MainWindow(QMainWindow):
def create_toolbar_view(self):
self.toolbar = self.addToolBar("Toolbar")
self.toolbar.addAction("Create SFG", self.create_SFG_from_toolbar)
self.toolbar.addAction("Create SFG", self.create_sfg_from_toolbar)
self.toolbar.addAction("Clear workspace", self.clear_workspace)
def resizeEvent(self, event):
......@@ -188,7 +188,7 @@ class MainWindow(QMainWindow):
if not accepted:
return
self.logger.info(f"Saving SFG to path: {module}.")
self.logger.info("Saving SFG to path: " + str(module))
operation_positions = {}
for op_drag, op_scene in self.dragOperationSceneDict.items():
operation_positions[op_drag.operation.graph_id] = (
......@@ -209,7 +209,7 @@ class MainWindow(QMainWindow):
)
return
self.logger.info(f"Saved SFG to path: {module}.")
self.logger.info("Saved SFG to path: " + str(module))
def save_work(self, event=None):
self.sfg_widget = SelectSFGWindow(self)
......@@ -225,7 +225,7 @@ class MainWindow(QMainWindow):
self._load_from_file(module)
def _load_from_file(self, module):
self.logger.info(f"Loading SFG from path: {module}.")
self.logger.info("Loading SFG from path: " + str(module))
try:
sfg, positions = python_to_sfg(module)
except ImportError as e:
......@@ -248,7 +248,7 @@ class MainWindow(QMainWindow):
sfg.name = name
self._load_sfg(sfg, positions)
self.logger.info(f"Loaded SFG from path: {module}.")
self.logger.info("Loaded SFG from path: " + str(module))
def _load_sfg(self, sfg, positions=None):
if positions is None:
......@@ -314,7 +314,7 @@ class MainWindow(QMainWindow):
self.scene.clear()
self.logger.info("Workspace cleared.")
def create_SFG_from_toolbar(self):
def create_sfg_from_toolbar(self):
inputs = []
outputs = []
for op in self.pressed_operations:
......@@ -334,12 +334,12 @@ class MainWindow(QMainWindow):
return
self.logger.info(
f"Creating SFG with name: {name} from selected operations."
"Creating SFG with name: %s from selected operations." % name
)
sfg = SFG(inputs=inputs, outputs=outputs, name=name)
self.logger.info(
f"Created SFG with name: {name} from selected operations."
"Created SFG with name: %s from selected operations." % name
)
def check_equality(signal, signal_2):
......@@ -449,7 +449,7 @@ class MainWindow(QMainWindow):
def get_operations_from_namespace(self, namespace):
self.logger.info(
f"Fetching operations from namespace: {namespace.__name__}."
"Fetching operations from namespace: " + str(namespace.__name__)
)
return [
comp
......@@ -469,7 +469,7 @@ class MainWindow(QMainWindow):
pass
self.logger.info(
f"Added operations from namespace: {namespace.__name__}."
"Added operations from namespace: " + str(namespace.__name__)
)
def add_namespace(self, event=None):
......@@ -545,17 +545,17 @@ class MainWindow(QMainWindow):
self.dragOperationSceneDict[attr_button] = attr_button_scene
except Exception as e:
self.logger.error(
f"Unexpected error occurred while creating operation: {e}."
"Unexpected error occurred while creating operation: " + str(e)
)
def _create_operation_item(self, item):
self.logger.info(f"Creating operation of type: {item.text()}.")
self.logger.info("Creating operation of type: " + str(item.text()))
try:
attr_oper = self._operations_from_name[item.text()]()
self.create_operation(attr_oper)
except Exception as e:
self.logger.error(
f"Unexpected error occurred while creating operation: {e}."
"Unexpected error occurred while creating operation: " + str(e)
)
def _refresh_operations_list_from_namespace(self):
......@@ -607,9 +607,11 @@ class MainWindow(QMainWindow):
if type(source.port) == type(destination.port):
self.logger.warning(
"Cannot connect port of type:"
f" {type(source.port).__name__} to port of type:"
f" {type(destination.port).__name__}."
"Cannot connect port of type: %s to port of type: %s."
% (
type(source.port).__name__,
type(destination.port).__name__,
)
)
continue
......@@ -659,7 +661,7 @@ class MainWindow(QMainWindow):
def _simulate_sfg(self):
for sfg, properties in self.dialog.properties.items():
self.logger.info(f"Simulating SFG with name: {sfg.name}.")
self.logger.info(f"Simulating SFG with name: " + str(sfg.name))
simulation = FastSimulation(
sfg, input_providers=properties["input_values"]
)
......@@ -676,7 +678,7 @@ class MainWindow(QMainWindow):
if properties["show_plot"]:
self.logger.info(
f"Opening plot for SFG with name: {sfg.name}."
"Opening plot for SFG with name: " + str(sfg.name)
)
self.logger.info(
"To save the plot press 'Ctrl+S' when the plot is focused."
......
......@@ -8,8 +8,6 @@ from qtpy.QtWidgets import (
QVBoxLayout,
)
from b_asic.signal_flow_graph import SFG
class ShowPCWindow(QDialog):
pc = Signal()
......
......@@ -67,7 +67,6 @@ class SimulateSFGWindow(QDialog):
}
if sfg.input_count > 0:
input_label = QHBoxLayout()
input_label = QLabel("Input values:")
options_layout.addRow(input_label)
......
......@@ -62,18 +62,18 @@ def compile_rc(*filenames: str) -> None:
def compile(filename: str = None) -> None:
outfile = f"{os.path.splitext(filename)[0]}_rc.py"
rcc = shutil.which("pyside2-rcc")
args = f"-g python -o {outfile} {filename}"
arguments = f"-g python -o {outfile} {filename}"
if rcc is None:
rcc = shutil.which("rcc")
if rcc is None:
rcc = shutil.which("pyrcc5")
args = f"-o {outfile} {filename}"
arguments = f"-o {outfile} {filename}"
assert rcc, "PySide2 compiler failed, can't find rcc"
os_ = sys.platform
if os_.startswith("linux"): # Linux
cmd = f"{rcc} {args}"
cmd = f"{rcc} {arguments}"
subprocess.call(cmd.split())
elif os_.startswith("win32"): # Windows
......@@ -126,25 +126,25 @@ def compile_ui(*filenames: str) -> None:
_check_qt_version()
def compile(filename: str) -> None:
dir, file = os.path.split(filename)
directory, file = os.path.split(filename)
file = os.path.splitext(file)[0]
dir = dir if dir else "."
outfile = f"{dir}/ui_{file}.py"
directory = directory if directory else "."
outfile = f"{directory}/ui_{file}.py"
if uic.PYSIDE2:
uic_ = shutil.which("pyside2-uic")
args = f"-g python -o {outfile} {filename}"
arguments = f"-g python -o {outfile} {filename}"
if uic_ is None:
uic_ = shutil.which("uic")
if uic_ is None:
uic_ = shutil.which("pyuic5")
args = f"-o {outfile} {filename}"
arguments = f"-o {outfile} {filename}"
assert uic_, "PySide2 compiler failed, can't find uic"
os_ = sys.platform
if os_.startswith("linux"): # Linux
cmd = f"{uic_} {args}"
cmd = f"{uic_} {arguments}"
subprocess.call(cmd.split())
elif os_.startswith("win32"): # Windows
......
......@@ -20,7 +20,7 @@ from qtpy.QtWidgets import (
)
# B-ASIC
from b_asic.graph_component import GraphComponent
from b_asic.operation import Operation
from b_asic.scheduler_gui._preferences import (
OPERATION_EXECUTION_TIME_INACTIVE,
OPERATION_LATENCY_ACTIVE,
......@@ -33,7 +33,7 @@ class GraphicsComponentItem(QGraphicsItemGroup):
_scale: float = 1.0
"""Static, changed from MainWindow."""
_operation: GraphComponent
_operation: Operation
_height: float
_ports: Dict[
str, Dict[str, Union[float, QPointF]]
......@@ -46,7 +46,7 @@ class GraphicsComponentItem(QGraphicsItemGroup):
def __init__(
self,
operation: GraphComponent,
operation: Operation,
height: float = 0.75,
parent: Optional[QGraphicsItem] = None,
):
......@@ -93,7 +93,7 @@ class GraphicsComponentItem(QGraphicsItemGroup):
return self._operation.graph_id
@property
def operation(self) -> GraphComponent:
def operation(self) -> Operation:
"""Get the operation."""
return self._operation
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment