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