diff --git a/b_asic/GUI/arrow.py b/b_asic/GUI/arrow.py index ee0443bab33084c21d8b300aa6a31f21e6b805b5..2bca3cf74d908c153ac05df615b715213e832d8d 100644 --- a/b_asic/GUI/arrow.py +++ b/b_asic/GUI/arrow.py @@ -45,25 +45,25 @@ class Arrow(QGraphicsPathItem): """Remove line and connections to signals etc.""" self.signal.remove_destination() self.signal.remove_source() - self._window.scene.removeItem(self) - if self in self._window._arrow_list: - self._window._arrow_list.remove(self) + self._window._scene.removeItem(self) + if self in self._window._arrows: + self._window._arrows.remove(self) - if self in self._window.signalPortDict: - for port1, port2 in self._window.signalPortDict[self]: + if self in self._window._signal_ports: + for port1, port2 in self._window._signal_ports[self]: for ( operation, operation_ports, - ) in self._window.portDict.items(): + ) in self._window._ports.items(): if ( port1 in operation_ports or port2 in operation_ports ) and operation in self._window._operation_to_sfg: - self._window.logger.info( + self._window._logger.info( "Operation detected in existing SFG, removing SFG" " with name:" f" {self._window._operation_to_sfg[operation].name}." ) - del self._window.sfg_dict[ + del self._window._sfg_dict[ self._window._operation_to_sfg[operation].name ] self._window._operation_to_sfg = { @@ -73,7 +73,7 @@ class Arrow(QGraphicsPathItem): is not self._window._operation_to_sfg[operation] } - del self._window.signalPortDict[self] + del self._window._signal_ports[self] def moveLine(self): """ diff --git a/b_asic/GUI/drag_button.py b/b_asic/GUI/drag_button.py index b63ca2fc8a24e9d4f818ac8192c91ca449cd2aca..eeb63255be109379f0273a57664745ed66f91046 100644 --- a/b_asic/GUI/drag_button.py +++ b/b_asic/GUI/drag_button.py @@ -98,15 +98,14 @@ class DragButton(QPushButton): if event.buttons() == Qt.MouseButton.LeftButton and self._m_press: self._m_drag = True self.move(self.mapToParent(event.pos() - self._mouse_press_pos)) - if self in self._window.pressed_operations: - for button in self._window.pressed_operations: + if self in self._window._pressed_operations: + for button in self._window._pressed_operations: if button is self: continue button.move(button.mapToParent(event.pos() - self._mouse_press_pos)) - self._window.scene.update() - self._window.graphic_view.update() + self._window._update() super().mouseMoveEvent(event) def mouseReleaseEvent(self, event): @@ -129,8 +128,7 @@ class DragButton(QPushButton): newx = GRID * round(x / GRID) newy = GRID * round(y / GRID) self.move(newx, newy) - self._window.scene.update() - self._window.graphic_view.update() + self._window._update() super().mouseReleaseEvent(event) def _flip(self, event=None): @@ -144,8 +142,7 @@ class DragButton(QPushButton): pb.move(newx, pb.pos().y()) pb.setText(text) - self._window.scene.update() - self._window.graphic_view.update() + self._window._update() def _toggle_button(self, pressed=False): self.pressed = not pressed @@ -169,36 +166,36 @@ class DragButton(QPushButton): def select_button(self, modifiers=None): if modifiers != Qt.KeyboardModifier.ControlModifier: - for button in self._window.pressed_operations: + for button in self._window._pressed_operations: button._toggle_button(button.pressed) self._toggle_button(self.pressed) - self._window.pressed_operations = [self] + self._window._pressed_operations = [self] else: self._toggle_button(self.pressed) - if self in self._window.pressed_operations: - self._window.pressed_operations.remove(self) + if self in self._window._pressed_operations: + self._window._pressed_operations.remove(self) else: - self._window.pressed_operations.append(self) + self._window._pressed_operations.append(self) - for signal in self._window._arrow_list: + for signal in self._window._arrows: signal.update() def remove(self, event=None): """Remove button/operation from signal flow graph.""" - self._window.logger.info("Removing operation with name " + self.operation.name) - self._window.scene.removeItem(self._window.dragOperationSceneDict[self]) + self._window._logger.info("Removing operation with name " + self.operation.name) + self._window._scene.removeItem(self._window._drag_operation_scenes[self]) _signals = [] - for signal, ports in self._window.signalPortDict.items(): + for signal, ports in self._window._signal_ports.items(): if any( map( lambda port: set(port).intersection(set(self.ports)), ports, ) ): - self._window.logger.info( + self._window._logger.info( "Removed signal with name: %s to/from operation: %s." % (signal.signal.name, self.operation.name) ) @@ -208,11 +205,11 @@ class DragButton(QPushButton): signal.remove() if self in self._window._operation_to_sfg: - self._window.logger.info( + self._window._logger.info( "Operation detected in existing SFG, removing SFG with name: " + self._window._operation_to_sfg[self].name ) - del self._window.sfg_dict[self._window._operation_to_sfg[self].name] + del self._window._sfg_dict[self._window._operation_to_sfg[self].name] self._window._operation_to_sfg = { op: self._window._operation_to_sfg[op] for op in self._window._operation_to_sfg @@ -220,18 +217,18 @@ class DragButton(QPushButton): is not self._window._operation_to_sfg[self] } - for port in self._window.portDict[self]: - if port in self._window.pressed_ports: - self._window.pressed_ports.remove(port) + for port in self._window._ports[self]: + if port in self._window._pressed_ports: + self._window._pressed_ports.remove(port) - if self in self._window.pressed_operations: - self._window.pressed_operations.remove(self) + if self in self._window._pressed_operations: + self._window._pressed_operations.remove(self) - if self in self._window.dragOperationSceneDict: - del self._window.dragOperationSceneDict[self] + if self in self._window._drag_operation_scenes: + del self._window._drag_operation_scenes[self] - if self.operation in self._window._operation_drag_buttons: - del self._window._operation_drag_buttons[self.operation] + if self.operation in self._window._drag_buttons: + del self._window._drag_buttons[self.operation] def add_ports(self): def _determine_port_distance(opheight, ports): diff --git a/b_asic/GUI/main_window.py b/b_asic/GUI/main_window.py index f4a39e0687230aa86dc0c05ba8e6f9a7f756b3dc..d6b05eacf06e0625504cc2742c662c7b460f381c 100644 --- a/b_asic/GUI/main_window.py +++ b/b_asic/GUI/main_window.py @@ -9,7 +9,6 @@ import logging import os import sys from collections import deque -from pprint import pprint from typing import Dict, List, Optional, Tuple, cast from qtpy.QtCore import QCoreApplication, QFileInfo, QSettings, QSize, Qt, QThread @@ -37,8 +36,8 @@ from b_asic.GUI.arrow import Arrow from b_asic.GUI.drag_button import DragButton from b_asic.GUI.gui_interface import Ui_main_window from b_asic.GUI.port_button import PortButton +from b_asic.GUI.precedence_graph_window import PrecedenceGraphWindow from b_asic.GUI.select_sfg_window import SelectSFGWindow -from b_asic.GUI.show_pc_window import ShowPCWindow from b_asic.GUI.simulate_sfg_window import SimulateSFGWindow from b_asic.GUI.simulation_worker import SimulationWorker from b_asic.GUI.util_dialogs import FaqWindow, KeybindingsWindow @@ -65,113 +64,113 @@ QCoreApplication.setApplicationVersion(__version__) class MainWindow(QMainWindow): def __init__(self): super().__init__() - self.ui = Ui_main_window() - self.ui.setupUi(self) + self._ui = Ui_main_window() + self._ui.setupUi(self) self.setWindowIcon(QIcon("small_logo.png")) - self.scene = QGraphicsScene(self) + self._scene = QGraphicsScene(self) self._operations_from_name = {} - self.zoom = 1 - self.sfg_name_i = 0 - self.dragOperationSceneDict = {} - self._operation_drag_buttons: Dict[Operation, DragButton] = {} - self._arrow_list: List[Arrow] = [] - self.mouse_pressed = False - self.mouse_dragging = False - self.starting_port = [] - self.pressed_operations = [] - self.portDict = {} - self.signalPortDict = {} + self._zoom = 1 + self._sfg_name_i = 0 + self._drag_operation_scenes = {} + self._drag_buttons: Dict[Operation, DragButton] = {} + self._arrows: List[Arrow] = [] + self._mouse_pressed = False + self._mouse_dragging = False + self._starting_port = None + self._pressed_operations = [] + self._ports = {} + self._signal_ports = {} self._operation_to_sfg: Dict[DragButton, SFG] = {} - self.pressed_ports = [] - self.sfg_dict = {} + self._pressed_ports = [] + self._sfg_dict = {} self._window = self - self.logger = logging.getLogger(__name__) + self._logger = logging.getLogger(__name__) self._plot: Dict[Simulation, PlotWindow] = dict() # Create Graphics View - self.graphic_view = QGraphicsView(self.scene, self) - self.graphic_view.setRenderHint(QPainter.Antialiasing) - self.graphic_view.setGeometry( - self.ui.operation_box.width(), 20, self.width(), self.height() + self._graphics_view = QGraphicsView(self._scene, self) + self._graphics_view.setRenderHint(QPainter.Antialiasing) + self._graphics_view.setGeometry( + self._ui.operation_box.width(), 20, self.width(), self.height() ) - self.graphic_view.setDragMode(QGraphicsView.RubberBandDrag) + self._graphics_view.setDragMode(QGraphicsView.RubberBandDrag) - # Create toolbar - self.toolbar = self.addToolBar("Toolbar") - self.toolbar.addAction("Create SFG", self.create_sfg_from_toolbar) - self.toolbar.addAction("Clear workspace", self.clear_workspace) + # Create _toolbar + self._toolbar = self.addToolBar("Toolbar") + self._toolbar.addAction("Create SFG", self.create_sfg_from_toolbar) + self._toolbar.addAction("Clear workspace", self._clear_workspace) # Add operations - self.maxFileNr = 4 - self.recentFilesList = [] - self.recentFilePaths = deque(maxlen=self.maxFileNr) + self._max_recent_files = 4 + self._recent_files = [] + self._recent_files_paths = deque(maxlen=self._max_recent_files) self.add_operations_from_namespace( - b_asic.core_operations, self.ui.core_operations_list + b_asic.core_operations, self._ui.core_operations_list ) self.add_operations_from_namespace( - b_asic.special_operations, self.ui.special_operations_list + b_asic.special_operations, self._ui.special_operations_list ) - self.shortcut_core = QShortcut(QKeySequence("Ctrl+R"), self.ui.operation_box) - self.shortcut_core.activated.connect( + self._shortcut_core = QShortcut(QKeySequence("Ctrl+R"), self._ui.operation_box) + self._shortcut_core.activated.connect( self._refresh_operations_list_from_namespace ) - self.scene.selectionChanged.connect(self._select_operations) + self._scene.selectionChanged.connect(self._select_operations) self.move_button_index = 0 self.is_show_names = True - self.check_show_names = QAction("Show operation names") - self.check_show_names.triggered.connect(self.view_operation_names) - self.check_show_names.setCheckable(True) - self.check_show_names.setChecked(1) - self.ui.view_menu.addAction(self.check_show_names) - - self.ui.actionShowPC.triggered.connect(self._show_precedence_graph) - self.ui.actionSimulateSFG.triggered.connect(self.simulate_sfg) - self.ui.faqBASIC.triggered.connect(self.display_faq_page) - self.ui.aboutBASIC.triggered.connect(self.display_about_page) - self.ui.keybindsBASIC.triggered.connect(self.display_keybindings_page) - self.ui.core_operations_list.itemClicked.connect( + self._check_show_names = QAction("Show operation names") + self._check_show_names.triggered.connect(self.view_operation_names) + self._check_show_names.setCheckable(True) + self._check_show_names.setChecked(True) + self._ui.view_menu.addAction(self._check_show_names) + + self._ui.actionShowPC.triggered.connect(self._show_precedence_graph) + self._ui.actionSimulateSFG.triggered.connect(self.simulate_sfg) + self._ui.faqBASIC.triggered.connect(self.display_faq_page) + self._ui.aboutBASIC.triggered.connect(self.display_about_page) + self._ui.keybindsBASIC.triggered.connect(self.display_keybindings_page) + self._ui.core_operations_list.itemClicked.connect( self.on_list_widget_item_clicked ) - self.ui.special_operations_list.itemClicked.connect( + self._ui.special_operations_list.itemClicked.connect( self.on_list_widget_item_clicked ) - self.ui.custom_operations_list.itemClicked.connect( + self._ui.custom_operations_list.itemClicked.connect( self.on_list_widget_item_clicked ) - self.ui.save_menu.triggered.connect(self.save_work) - self.ui.load_menu.triggered.connect(self.load_work) - self.ui.load_operations.triggered.connect(self.add_namespace) - self.ui.exit_menu.triggered.connect(self.exit_app) - self.shortcut_open = QShortcut(QKeySequence("Ctrl+O"), self) - self.shortcut_open.activated.connect(self.load_work) - self.shortcut_save = QShortcut(QKeySequence("Ctrl+S"), self) - self.shortcut_save.activated.connect(self.save_work) - self.shortcut_help = QShortcut(QKeySequence("Ctrl+?"), self) - self.shortcut_help.activated.connect(self.display_faq_page) - self.shortcut_signal = QShortcut(QKeySequence(Qt.Key_Space), self) - self.shortcut_signal.activated.connect(self._connect_callback) - self.createActionsAndMenus() + self._ui.save_menu.triggered.connect(self.save_work) + self._ui.load_menu.triggered.connect(self.load_work) + self._ui.load_operations.triggered.connect(self.add_namespace) + self._ui.exit_menu.triggered.connect(self.exit_app) + self._shortcut_open = QShortcut(QKeySequence("Ctrl+O"), self) + self._shortcut_open.activated.connect(self.load_work) + self._shortcut_save = QShortcut(QKeySequence("Ctrl+S"), self) + self._shortcut_save.activated.connect(self.save_work) + self._shortcut_help = QShortcut(QKeySequence("Ctrl+?"), self) + self._shortcut_help.activated.connect(self.display_faq_page) + self._shortcut_signal = QShortcut(QKeySequence(Qt.Key_Space), self) + self._shortcut_signal.activated.connect(self._connect_callback) + self._create_recent_file_actions_and_menus() self._keybindings_page = None self._about_page = None self._faq_page = None - self.logger.info("Finished setting up GUI") - self.logger.info( + self._logger.info("Finished setting up GUI") + self._logger.info( "For questions please refer to 'Ctrl+?', or visit the 'Help' " - "section on the toolbar." + "section on the _toolbar." ) self.cursor = QCursor() def resizeEvent(self, event) -> None: - ui_width = self.ui.operation_box.width() - self.ui.operation_box.setGeometry(10, 10, ui_width, self.height()) - self.graphic_view.setGeometry( + ui_width = self._ui.operation_box.width() + self._ui.operation_box.setGeometry(10, 10, ui_width, self.height()) + self._graphics_view.setGeometry( ui_width + 20, 60, self.width() - ui_width - 20, @@ -181,18 +180,18 @@ class MainWindow(QMainWindow): def wheelEvent(self, event) -> None: if event.modifiers() == Qt.KeyboardModifier.ControlModifier: - old_zoom = self.zoom - self.zoom += event.angleDelta().y() / 2500 - self.graphic_view.scale(self.zoom, self.zoom) - self.zoom = old_zoom + old_zoom = self._zoom + self._zoom += event.angleDelta().y() / 2500 + self._graphics_view.scale(self._zoom, self._zoom) + self._zoom = old_zoom def view_operation_names(self) -> None: - if self.check_show_names.isChecked(): + if self._check_show_names.isChecked(): self.is_show_names = True else: self.is_show_names = False - for operation in self.dragOperationSceneDict: + for operation in self._drag_operation_scenes: operation.label.setOpacity(self.is_show_names) operation.is_show_name = self.is_show_names @@ -204,9 +203,9 @@ class MainWindow(QMainWindow): if not accepted: return - self.logger.info("Saving SFG to path: " + str(module)) + self._logger.info("Saving SFG to path: " + str(module)) operation_positions = {} - for op_drag, op_scene in self.dragOperationSceneDict.items(): + for op_drag, op_scene in self._drag_operation_scenes.items(): operation_positions[op_drag.operation.graph_id] = ( int(op_scene.x()), int(op_scene.y()), @@ -219,10 +218,12 @@ class MainWindow(QMainWindow): sfg_to_python(sfg, suffix=f"positions = {operation_positions}") ) except Exception as e: - self.logger.error(f"Failed to save SFG to path: {module}, with error: {e}.") + self._logger.error( + f"Failed to save SFG to path: {module}, with error: {e}." + ) return - self.logger.info("Saved SFG to path: " + str(module)) + self._logger.info("Saved SFG to path: " + str(module)) def save_work(self, event=None) -> None: self.sfg_widget = SelectSFGWindow(self) @@ -238,19 +239,19 @@ class MainWindow(QMainWindow): self._load_from_file(module) def _load_from_file(self, module) -> None: - self.logger.info("Loading SFG from path: " + str(module)) + self._logger.info("Loading SFG from path: " + str(module)) try: sfg, positions = python_to_sfg(module) except ImportError as e: - self.logger.error( + self._logger.error( f"Failed to load module: {module} with the following error: {e}." ) return - self.addRecentFile(module) + self._add_recent_file(module) - while sfg.name in self.sfg_dict: - self.logger.warning( + while sfg.name in self._sfg_dict: + self._logger.warning( f"Duplicate SFG with name: {sfg.name} detected. " "Please choose a new name." ) @@ -262,7 +263,7 @@ class MainWindow(QMainWindow): sfg.name = name self._load_sfg(sfg, positions) - self.logger.info("Loaded SFG from path: " + str(module)) + self._logger.info("Loaded SFG from path: " + str(module)) def _load_sfg(self, sfg, positions=None) -> None: if positions is None: @@ -280,15 +281,15 @@ class MainWindow(QMainWindow): for signal in port.signals: source = [ source - for source in self.portDict[ - self._operation_drag_buttons[signal.source.operation] + for source in self._ports[ + self._drag_buttons[signal.source.operation] ] if source.port is signal.source ] destination = [ destination - for destination in self.portDict[ - self._operation_drag_buttons[signal.destination.operation] + for destination in self._ports[ + self._drag_buttons[signal.destination.operation] ] if destination.port is signal.destination ] @@ -296,32 +297,32 @@ class MainWindow(QMainWindow): if source and destination: self._connect_button(source[0], destination[0]) - for port in self.pressed_ports: + for port in self._pressed_ports: port.select_port() for op in sfg.split(): connect_ports(op.inputs) for op in sfg.split(): - self._operation_drag_buttons[op].setToolTip(sfg.name) - self._operation_to_sfg[self._operation_drag_buttons[op]] = sfg + self._drag_buttons[op].setToolTip(sfg.name) + self._operation_to_sfg[self._drag_buttons[op]] = sfg - self.sfg_dict[sfg.name] = sfg + self._sfg_dict[sfg.name] = sfg self.update() - def createActionsAndMenus(self): - for i in range(self.maxFileNr): - recentFileAction = QAction(self.ui.recent_sfg) + def _create_recent_file_actions_and_menus(self): + for i in range(self._max_recent_files): + recentFileAction = QAction(self._ui.recent_sfg) recentFileAction.setVisible(False) recentFileAction.triggered.connect( - lambda b=0, x=recentFileAction: self.openRecent(x) + lambda b=0, x=recentFileAction: self._open_recent_file(x) ) - self.recentFilesList.append(recentFileAction) - self.ui.recent_sfg.addAction(recentFileAction) + self._recent_files.append(recentFileAction) + self._ui.recent_sfg.addAction(recentFileAction) - self.updateRecentActionList() + self._update_recent_file_list() - def updateRecentActionList(self): + def _update_recent_file_list(self): settings = QSettings() rfp = settings.value("SFG/recentFiles") @@ -331,18 +332,18 @@ class MainWindow(QMainWindow): dequelen = len(rfp) if dequelen > 0: for i in range(dequelen): - action = self.recentFilesList[i] + action = self._recent_files[i] action.setText(rfp[i]) action.setData(QFileInfo(rfp[i])) action.setVisible(True) - for i in range(dequelen, self.maxFileNr): - self.recentFilesList[i].setVisible(False) + for i in range(dequelen, self._max_recent_files): + self._recent_files[i].setVisible(False) - def openRecent(self, action): + def _open_recent_file(self, action): self._load_from_file(action.data().filePath()) - def addRecentFile(self, module): + def _add_recent_file(self, module): settings = QSettings() rfp = settings.value("SFG/recentFiles") @@ -351,34 +352,34 @@ class MainWindow(QMainWindow): if module not in rfp: rfp.append(module) else: - rfp = deque(maxlen=self.maxFileNr) + rfp = deque(maxlen=self._max_recent_files) rfp.append(module) settings.setValue("SFG/recentFiles", rfp) - self.updateRecentActionList() + self._update_recent_file_list() def exit_app(self) -> None: - self.logger.info("Exiting the application.") + self._logger.info("Exiting the application.") QApplication.quit() - def clear_workspace(self) -> None: - self.logger.info("Clearing workspace from operations and SFGs.") - self.pressed_operations.clear() - self.pressed_ports.clear() - self._operation_drag_buttons.clear() - self.dragOperationSceneDict.clear() - self._arrow_list.clear() - self.portDict.clear() - self.signalPortDict.clear() - self.sfg_dict.clear() - self.scene.clear() - self.logger.info("Workspace cleared.") + def _clear_workspace(self) -> None: + self._logger.info("Clearing workspace from operations and SFGs.") + self._pressed_operations.clear() + self._pressed_ports.clear() + self._drag_buttons.clear() + self._drag_operation_scenes.clear() + self._arrows.clear() + self._ports.clear() + self._signal_ports.clear() + self._sfg_dict.clear() + self._scene.clear() + self._logger.info("Workspace cleared.") def create_sfg_from_toolbar(self) -> None: inputs = [] outputs = [] - for op in self.pressed_operations: + for op in self._pressed_operations: if isinstance(op.operation, Input): inputs.append(op.operation) elif isinstance(op.operation, Output): @@ -391,13 +392,13 @@ class MainWindow(QMainWindow): return if not name: - self.logger.warning("Failed to initialize SFG with empty name.") + self._logger.warning("Failed to initialize SFG with empty name.") return - self.logger.info("Creating SFG with name: %s from selected operations." % name) + self._logger.info("Creating SFG with name: %s from selected operations." % name) sfg = SFG(inputs=inputs, outputs=outputs, name=name) - self.logger.info("Created SFG with name: %s from selected operations." % name) + self._logger.info("Created SFG with name: %s from selected operations." % name) def check_equality(signal: Signal, signal_2: Signal) -> bool: source = cast(OutputPort, signal.source) @@ -467,11 +468,11 @@ class MainWindow(QMainWindow): and _signal_destination_index == _signal_2_destination_index ) - for _pressed_op in self.pressed_operations: + for _pressed_op in self._pressed_operations: for operation in sfg.operations: for input_ in operation.inputs: for signal in input_.signals: - for line in self.signalPortDict: + for line in self._signal_ports: if check_equality(line.signal, signal): line.source.operation.operation = ( signal.source.operation @@ -482,7 +483,7 @@ class MainWindow(QMainWindow): for output_ in operation.outputs: for signal in output_.signals: - for line in self.signalPortDict: + for line in self._signal_ports: if check_equality(line.signal, signal): line.source.operation.operation = ( signal.source.operation @@ -491,19 +492,19 @@ class MainWindow(QMainWindow): signal.destination.operation ) - for op in self.pressed_operations: + for op in self._pressed_operations: op.setToolTip(sfg.name) self._operation_to_sfg[op] = sfg - self.sfg_dict[sfg.name] = sfg + self._sfg_dict[sfg.name] = sfg def _show_precedence_graph(self, event=None) -> None: - self._precedence_graph_dialog = ShowPCWindow(self) + self._precedence_graph_dialog = PrecedenceGraphWindow(self) self._precedence_graph_dialog.add_sfg_to_dialog() self._precedence_graph_dialog.show() def get_operations_from_namespace(self, namespace) -> List[str]: - self.logger.info( + self._logger.info( "Fetching operations from namespace: " + str(namespace.__name__) ) return [ @@ -523,7 +524,7 @@ class MainWindow(QMainWindow): except NotImplementedError: pass - self.logger.info("Added operations from namespace: " + str(namespace.__name__)) + self._logger.info("Added operations from namespace: " + str(namespace.__name__)) def add_namespace(self, event=None) -> None: module, accepted = QFileDialog().getOpenFileName() @@ -536,7 +537,7 @@ class MainWindow(QMainWindow): namespace = importlib.util.module_from_spec(spec) spec.loader.exec_module(namespace) - self.add_operations_from_namespace(namespace, self.ui.custom_operations_list) + self.add_operations_from_namespace(namespace, self._ui.custom_operations_list) def create_operation( self, @@ -552,8 +553,8 @@ class MainWindow(QMainWindow): is_flipped : bool, default: False """ try: - if op in self._operation_drag_buttons: - self.logger.warning("Multiple instances of operation with same name") + if op in self._drag_buttons: + self._logger.warning("Multiple instances of operation with same name") return attr_button = DragButton(op, True, window=self) @@ -573,7 +574,7 @@ class MainWindow(QMainWindow): "border-color: black; border-width: 2px" ) attr_button.add_ports() - self.portDict[attr_button] = attr_button.ports + self._ports[attr_button] = attr_button.ports icon_path = os.path.join( os.path.dirname(__file__), @@ -593,10 +594,10 @@ class MainWindow(QMainWindow): "QToolTip { background-color: white; color: black }" ) attr_button.setParent(None) - attr_button_scene = self.scene.addWidget(attr_button) + attr_button_scene = self._scene.addWidget(attr_button) if position is None: attr_button_scene.moveBy( - int(self.scene.width() / 4), int(self.scene.height() / 4) + int(self._scene.width() / 4), int(self._scene.height() / 4) ) attr_button_scene.setFlag(QGraphicsItem.ItemIsSelectable, True) operation_label = QGraphicsTextItem(op.name, attr_button_scene) @@ -612,63 +613,63 @@ class MainWindow(QMainWindow): if is_flipped: attr_button._flip() - self._operation_drag_buttons[op] = attr_button - self.dragOperationSceneDict[attr_button] = attr_button_scene + self._drag_buttons[op] = attr_button + self._drag_operation_scenes[attr_button] = attr_button_scene except Exception as e: - self.logger.error( + self._logger.error( "Unexpected error occurred while creating operation: " + str(e) ) def _create_operation_item(self, item) -> None: - self.logger.info("Creating operation of type: %s" % str(item.text())) + self._logger.info("Creating operation of type: %s" % str(item.text())) try: attr_operation = self._operations_from_name[item.text()]() self.create_operation(attr_operation) except Exception as e: - self.logger.error( + self._logger.error( "Unexpected error occurred while creating operation: " + str(e) ) def _refresh_operations_list_from_namespace(self) -> None: - self.logger.info("Refreshing operation list.") - self.ui.core_operations_list.clear() - self.ui.special_operations_list.clear() + self._logger.info("Refreshing operation list.") + self._ui.core_operations_list.clear() + self._ui.special_operations_list.clear() self.add_operations_from_namespace( - b_asic.core_operations, self.ui.core_operations_list + b_asic.core_operations, self._ui.core_operations_list ) self.add_operations_from_namespace( - b_asic.special_operations, self.ui.special_operations_list + b_asic.special_operations, self._ui.special_operations_list ) - self.logger.info("Finished refreshing operation list.") + self._logger.info("Finished refreshing operation list.") def on_list_widget_item_clicked(self, item) -> None: self._create_operation_item(item) def keyPressEvent(self, event) -> None: if event.key() == Qt.Key.Key_Delete: - for pressed_op in self.pressed_operations: + for pressed_op in self._pressed_operations: pressed_op.remove() self.move_button_index -= 1 - self.pressed_operations.clear() + self._pressed_operations.clear() super().keyPressEvent(event) def _connect_callback(self, *event) -> None: - if len(self.pressed_ports) < 2: - self.logger.warning( + if len(self._pressed_ports) < 2: + self._logger.warning( "Cannot connect less than two ports. Please select at least two." ) return pressed_op_inports = [ pressed - for pressed in self.pressed_ports + for pressed in self._pressed_ports if isinstance(pressed.port, InputPort) ] pressed_op_outports = [ pressed - for pressed in self.pressed_ports + for pressed in self._pressed_ports if isinstance(pressed.port, OutputPort) ] @@ -679,7 +680,7 @@ class MainWindow(QMainWindow): for pressed_op_inport in pressed_op_inports: self._connect_button(pressed_op_outport, pressed_op_inport) - for port in self.pressed_ports: + for port in self._pressed_ports: port.select_port() def _connect_button(self, source: PortButton, destination: PortButton) -> None: @@ -703,7 +704,7 @@ class MainWindow(QMainWindow): for signal in source.port.signals if signal.destination is destination.port ) - self.logger.info( + self._logger.info( "Connecting: %s -> %s." % ( source.operation.operation.type_name(), @@ -715,35 +716,35 @@ class MainWindow(QMainWindow): except StopIteration: arrow = Arrow(source, destination, self) - if arrow not in self.signalPortDict: - self.signalPortDict[arrow] = [] + if arrow not in self._signal_ports: + self._signal_ports[arrow] = [] - self.signalPortDict[arrow].append((source, destination)) - self.scene.addItem(arrow) - self._arrow_list.append(arrow) + self._signal_ports[arrow].append((source, destination)) + self._scene.addItem(arrow) + self._arrows.append(arrow) self.update() def paintEvent(self, event) -> None: - for signal in self.signalPortDict.keys(): + for signal in self._signal_ports.keys(): signal.moveLine() def _select_operations(self) -> None: - selected = [button.widget() for button in self.scene.selectedItems()] + selected = [button.widget() for button in self._scene.selectedItems()] for button in selected: button._toggle_button(pressed=False) - for button in self.pressed_operations: + for button in self._pressed_operations: if button not in selected: button._toggle_button(pressed=True) - self.pressed_operations = selected + self._pressed_operations = selected def _simulate_sfg(self) -> None: self._thread = dict() self._sim_worker = dict() - for sfg, properties in self._simulation_dialog.properties.items(): - self.logger.info("Simulating SFG with name: %s" % str(sfg.name)) + for sfg, properties in self._simulation_dialog._properties.items(): + self._logger.info("Simulating SFG with name: %s" % str(sfg.name)) self._sim_worker[sfg] = SimulationWorker(sfg, properties) self._thread[sfg] = QThread() self._sim_worker[sfg].moveToThread(self._thread[sfg]) @@ -755,13 +756,13 @@ class MainWindow(QMainWindow): self._thread[sfg].start() def _show_plot_window(self, sim: Simulation): - self._plot[sim] = PlotWindow(sim.results, sfg_name=sim._sfg.name) + self._plot[sim] = PlotWindow(sim.results, sfg_name=sim.sfg.name) self._plot[sim].show() def simulate_sfg(self, event=None) -> None: self._simulation_dialog = SimulateSFGWindow(self) - for _, sfg in self.sfg_dict.items(): + for _, sfg in self._sfg_dict.items(): self._simulation_dialog.add_sfg_to_dialog(sfg) self._simulation_dialog.show() @@ -773,7 +774,7 @@ class MainWindow(QMainWindow): def display_faq_page(self, event=None) -> None: if self._faq_page is None: self._faq_page = FaqWindow(self) - self._faq_page.scroll_area.show() + self._faq_page._scroll_area.show() def display_about_page(self, event=None) -> None: if self._about_page is None: diff --git a/b_asic/GUI/port_button.py b/b_asic/GUI/port_button.py index 5bb7d1a588e57e35f4de22354cacde4c498e6c52..c743b3a7e9cb7a89d1f9d13b6a6d8eab6f936ec0 100644 --- a/b_asic/GUI/port_button.py +++ b/b_asic/GUI/port_button.py @@ -48,21 +48,21 @@ class PortButton(QPushButton): def mousePressEvent(self, event): if event.button() == Qt.MouseButton.LeftButton: - self._window.mouse_pressed = True + self._window._mouse_pressed = True self.select_port(event.modifiers()) super().mousePressEvent(event) def mouseReleaseEvent(self, event): - if event.button() == Qt.MouseButton.LeftButton and self._window.mouse_pressed: - self._window.mouse_pressed = False - if self._window.mouse_dragging: - self._window.mouse_dragging = False + if event.button() == Qt.MouseButton.LeftButton and self._window._mouse_pressed: + self._window._mouse_pressed = False + if self._window._mouse_dragging: + self._window._mouse_dragging = False super().mouseReleaseEvent(event) def mouseMoveEvent(self, event): - if self._window.mouse_pressed: - self._window.mouse_draggin = True - self._window.starting_port = self + if self._window._mouse_pressed: + self._window._mouse_dragging = True + self._window._starting_port = self data = QMimeData() drag = QDrag(self) drag.setMimeData(data) @@ -84,7 +84,7 @@ class PortButton(QPushButton): def dropEvent(self, event): event.acceptProposedAction() - if self != self._window.starting_port: + if self != self._window._starting_port: self.select_port(Qt.KeyboardModifier.ControlModifier) self._window._connect_callback() self.update() @@ -98,18 +98,18 @@ class PortButton(QPushButton): def select_port(self, modifiers=None): if modifiers != Qt.KeyboardModifier.ControlModifier: - for port in self._window.pressed_ports: + for port in self._window._pressed_ports: port._toggle_port(port.pressed) self._toggle_port(self.pressed) - self._window.pressed_ports = [self] + self._window._pressed_ports = [self] else: self._toggle_port(self.pressed) - if self in self._window.pressed_ports: - self._window.pressed_ports.remove(self) + if self in self._window._pressed_ports: + self._window._pressed_ports.remove(self) else: - self._window.pressed_ports.append(self) + self._window._pressed_ports.append(self) - for signal in self._window._arrow_list: + for signal in self._window._arrows: signal.update() diff --git a/b_asic/GUI/precedence_graph_window.py b/b_asic/GUI/precedence_graph_window.py new file mode 100644 index 0000000000000000000000000000000000000000..500862be07de77cf5638e217337975288fc2d4f5 --- /dev/null +++ b/b_asic/GUI/precedence_graph_window.py @@ -0,0 +1,58 @@ +""" +B-ASIC window to show precedence graph. +""" +from qtpy.QtCore import Qt, Signal +from qtpy.QtWidgets import ( + QCheckBox, + QDialog, + QFormLayout, + QFrame, + QPushButton, + QVBoxLayout, +) + + +class PrecedenceGraphWindow(QDialog): + pc = Signal() + + def __init__(self, window): + super().__init__() + self._window = window + self._check_box_dict = {} + self.setWindowFlags(Qt.WindowTitleHint | Qt.WindowCloseButtonHint) + self.setWindowTitle("Show precedence graph") + + self._dialog_layout = QVBoxLayout() + self._show_precedence_graph_button = QPushButton("Show PG") + self._show_precedence_graph_button.clicked.connect(self.show_precedence_graph) + self._dialog_layout.addWidget(self._show_precedence_graph_button) + self.setLayout(self._dialog_layout) + + def add_sfg_to_dialog(self): + self._sfg_layout = QVBoxLayout() + self._options_layout = QFormLayout() + + for sfg in self._window._sfg_dict: + check_box = QCheckBox() + self._options_layout.addRow(sfg, check_box) + self._check_box_dict[check_box] = sfg + + self._sfg_layout.addLayout(self._options_layout) + + frame = QFrame() + frame.setFrameShape(QFrame.HLine) + frame.setFrameShadow(QFrame.Sunken) + self._dialog_layout.addWidget(frame) + + self._dialog_layout.addLayout(self._sfg_layout) + + def show_precedence_graph(self): + for check_box, sfg in self._check_box_dict.items(): + if check_box.isChecked(): + self._window._logger.info( + f"Creating a precedence graph from SFG with name: {sfg}." + ) + self._window._sfg_dict[sfg].show_precedence_graph() + + self.accept() + self.pc.emit() diff --git a/b_asic/GUI/properties_window.py b/b_asic/GUI/properties_window.py index 3ff586fc05c7d75818adff88e57d84308803bdc1..b3707e8bbf2a5f9988b59de83b6ec7c00585f27b 100644 --- a/b_asic/GUI/properties_window.py +++ b/b_asic/GUI/properties_window.py @@ -20,58 +20,49 @@ class PropertiesWindow(QDialog): self.setWindowFlags(Qt.WindowTitleHint | Qt.WindowCloseButtonHint) self.setWindowTitle("Properties") - self.name_layout = QHBoxLayout() - self.name_layout.setSpacing(50) - self.name_label = QLabel("Name:") - self.edit_name = QLineEdit( - self.operation.name or self.operation.type_name - ) - self.name_layout.addWidget(self.name_label) - self.name_layout.addWidget(self.edit_name) - self.latency_fields = {} + self._name_layout = QHBoxLayout() + self._name_layout.setSpacing(50) + self._name_label = QLabel("Name:") + self._edit_name = QLineEdit(self.operation.name or self.operation.type_name) + self._name_layout.addWidget(self._name_label) + self._name_layout.addWidget(self._edit_name) + self._latency_fields = {} - self.vertical_layout = QVBoxLayout() - self.vertical_layout.addLayout(self.name_layout) + self._vertical_layout = QVBoxLayout() + self._vertical_layout.addLayout(self._name_layout) if hasattr(self.operation.operation, "value") or hasattr( self.operation.operation, "initial_value" ): - self.constant_layout = QHBoxLayout() - self.constant_layout.setSpacing(50) - self.constant_value = QLabel("Value:") - if hasattr(self.operation.operation, "value"): - self.edit_constant = QLineEdit( - str(self.operation.operation.value) - ) - else: - self.edit_constant = QLineEdit( - str(self.operation.operation.initial_value) - ) - - self.only_accept_float = QDoubleValidator() - self.edit_constant.setValidator(self.only_accept_float) - self.constant_layout.addWidget(self.constant_value) - self.constant_layout.addWidget(self.edit_constant) - self.vertical_layout.addLayout(self.constant_layout) - - self.show_name_layout = QHBoxLayout() - self.check_show_name = QCheckBox("Show name?") - if self.operation.is_show_name: - self.check_show_name.setChecked(1) - else: - self.check_show_name.setChecked(0) - self.check_show_name.setLayoutDirection(Qt.RightToLeft) - self.check_show_name.setStyleSheet("spacing: 170px") - self.show_name_layout.addWidget(self.check_show_name) - self.vertical_layout.addLayout(self.show_name_layout) + self._constant_layout = QHBoxLayout() + self._constant_layout.setSpacing(50) + self._constant_value = QLabel("Value:") + constant = ( + self.operation.operation.value + if hasattr(self.operation.operation, "value") + else self.operation.operation.initial_value + ) + self._edit_constant = QLineEdit(str(constant)) + + self._only_accept_float = QDoubleValidator() + self._edit_constant.setValidator(self._only_accept_float) + self._constant_layout.addWidget(self._constant_value) + self._constant_layout.addWidget(self._edit_constant) + self._vertical_layout.addLayout(self._constant_layout) + + self._show_name_layout = QHBoxLayout() + self._check_show_name = QCheckBox("Show name?") + self._check_show_name.setChecked(self.operation.is_show_name) + self._check_show_name.setLayoutDirection(Qt.RightToLeft) + self._check_show_name.setStyleSheet("spacing: 170px") + self._show_name_layout.addWidget(self._check_show_name) + self._vertical_layout.addLayout(self._show_name_layout) if self.operation.operation.input_count > 0: - self.latency_layout = QHBoxLayout() - self.latency_label = QLabel( - "Set latency for input ports (-1 for None):" - ) - self.latency_layout.addWidget(self.latency_label) - self.vertical_layout.addLayout(self.latency_layout) + self._latency_layout = QHBoxLayout() + self._latency_label = QLabel("Set latency for input ports (-1 for None):") + self._latency_layout.addWidget(self._latency_label) + self._vertical_layout.addLayout(self._latency_layout) input_grid = QGridLayout() x, y = 0, 0 @@ -95,22 +86,20 @@ class PropertiesWindow(QDialog): int_valid.setBottom(-1) input_value.setValidator(int_valid) input_value.setFixedWidth(50) - self.latency_fields[f"in{i}"] = input_value + self._latency_fields[f"in{i}"] = input_value input_layout.addWidget(input_value) input_layout.addStretch() input_layout.setSpacing(10) input_grid.addLayout(input_layout, x, y) y += 1 - self.vertical_layout.addLayout(input_grid) + self._vertical_layout.addLayout(input_grid) if self.operation.operation.output_count > 0: - self.latency_layout = QHBoxLayout() - self.latency_label = QLabel( - "Set latency for output ports (-1 for None):" - ) - self.latency_layout.addWidget(self.latency_label) - self.vertical_layout.addLayout(self.latency_layout) + self._latency_layout = QHBoxLayout() + self._latency_label = QLabel("Set latency for output ports (-1 for None):") + self._latency_layout.addWidget(self._latency_label) + self._vertical_layout.addLayout(self._latency_layout) input_grid = QGridLayout() x, y = 0, 0 @@ -134,37 +123,37 @@ class PropertiesWindow(QDialog): int_valid.setBottom(-1) input_value.setValidator(int_valid) input_value.setFixedWidth(50) - self.latency_fields[f"out{i}"] = input_value + self._latency_fields[f"out{i}"] = input_value input_layout.addWidget(input_value) input_layout.addStretch() input_layout.setSpacing(10) input_grid.addLayout(input_layout, x, y) y += 1 - self.vertical_layout.addLayout(input_grid) + self._vertical_layout.addLayout(input_grid) - self.ok = QPushButton("OK") - self.ok.clicked.connect(self.save_properties) - self.vertical_layout.addWidget(self.ok) - self.setLayout(self.vertical_layout) + self._ok_button = QPushButton("OK") + self._ok_button.clicked.connect(self.save_properties) + self._vertical_layout.addWidget(self._ok_button) + self.setLayout(self._vertical_layout) def save_properties(self): - self._window.logger.info( - f"Saving properties of operation: {self.operation.name}." + self._window._logger.info( + f"Saving _properties of operation: {self.operation.name}." ) - self.operation.name = self.edit_name.text() - self.operation.operation.name = self.edit_name.text() + self.operation.name = self._edit_name.text() + self.operation.operation.name = self._edit_name.text() self.operation.label.setPlainText(self.operation.name) if hasattr(self.operation.operation, "value"): self.operation.operation.value = float( - self.edit_constant.text().replace(",", ".") + self._edit_constant.text().replace(",", ".") ) elif hasattr(self.operation.operation, "initial_value"): self.operation.operation.initial_value = float( - self.edit_constant.text().replace(",", ".") + self._edit_constant.text().replace(",", ".") ) - if self.check_show_name.isChecked(): + if self._check_show_name.isChecked(): self.operation.label.setOpacity(1) self.operation.is_show_name = True else: @@ -173,12 +162,11 @@ class PropertiesWindow(QDialog): self.operation.operation.set_latency_offsets( { - port: float(self.latency_fields[port].text().replace(",", ".")) - if self.latency_fields[port].text() - and float(self.latency_fields[port].text().replace(",", ".")) - > 0 + port: float(latency_edit.text().replace(",", ".")) + if latency_edit.text() + and float(latency_edit.text().replace(",", ".")) > 0 else None - for port in self.latency_fields + for port, latency_edit in self._latency_fields.items() } ) diff --git a/b_asic/GUI/select_sfg_window.py b/b_asic/GUI/select_sfg_window.py index 0822d35eb6147751a56a6a67344fa2e80e377449..69647b13bd7c4d9cf77416db4110f2a9a1ffc516 100644 --- a/b_asic/GUI/select_sfg_window.py +++ b/b_asic/GUI/select_sfg_window.py @@ -19,22 +19,22 @@ class SelectSFGWindow(QDialog): self.setWindowFlags(Qt.WindowTitleHint | Qt.WindowCloseButtonHint) self.setWindowTitle("Select SFG") - self.dialog_layout = QVBoxLayout() - self.ok_btn = QPushButton("Ok") - self.ok_btn.clicked.connect(self.save_properties) - self.dialog_layout.addWidget(self.ok_btn) - self.combo_box = QComboBox() + self._dialog_layout = QVBoxLayout() + self._ok_button = QPushButton("Ok") + self._ok_button.clicked.connect(self.save_properties) + self._dialog_layout.addWidget(self._ok_button) + self._sfg_combo_box = QComboBox() self.sfg = None - self.setLayout(self.dialog_layout) + self.setLayout(self._dialog_layout) # Add SFGs to layout - for sfg in self._window.sfg_dict: - self.combo_box.addItem(sfg) + for sfg in self._window._sfg_dict: + self._sfg_combo_box.addItem(sfg) - self.dialog_layout.addWidget(self.combo_box) + self._dialog_layout.addWidget(self._sfg_combo_box) def save_properties(self): - self.sfg = self._window.sfg_dict[self.combo_box.currentText()] + self.sfg = self._window._sfg_dict[self._sfg_combo_box.currentText()] self.accept() self.ok.emit() diff --git a/b_asic/GUI/show_pc_window.py b/b_asic/GUI/show_pc_window.py deleted file mode 100644 index 43ffc5ea99a11b5b2d4d907090c20b485d70eaa8..0000000000000000000000000000000000000000 --- a/b_asic/GUI/show_pc_window.py +++ /dev/null @@ -1,58 +0,0 @@ -""" -B-ASIC window to show precedence graph. -""" -from qtpy.QtCore import Qt, Signal -from qtpy.QtWidgets import ( - QCheckBox, - QDialog, - QFormLayout, - QFrame, - QPushButton, - QVBoxLayout, -) - - -class ShowPCWindow(QDialog): - pc = Signal() - - def __init__(self, window): - super().__init__() - self._window = window - self.check_box_dict = {} - self.setWindowFlags(Qt.WindowTitleHint | Qt.WindowCloseButtonHint) - self.setWindowTitle("Show precedence graph") - - self.dialog_layout = QVBoxLayout() - self.pc_btn = QPushButton("Show PG") - self.pc_btn.clicked.connect(self.show_precedence_graph) - self.dialog_layout.addWidget(self.pc_btn) - self.setLayout(self.dialog_layout) - - def add_sfg_to_dialog(self): - self.sfg_layout = QVBoxLayout() - self.options_layout = QFormLayout() - - for sfg in self._window.sfg_dict: - check_box = QCheckBox() - self.options_layout.addRow(sfg, check_box) - self.check_box_dict[check_box] = sfg - - self.sfg_layout.addLayout(self.options_layout) - - frame = QFrame() - frame.setFrameShape(QFrame.HLine) - frame.setFrameShadow(QFrame.Sunken) - self.dialog_layout.addWidget(frame) - - self.dialog_layout.addLayout(self.sfg_layout) - - def show_precedence_graph(self): - for check_box, sfg in self.check_box_dict.items(): - if check_box.isChecked(): - self._window.logger.info( - f"Creating a precedence graph from SFG with name: {sfg}." - ) - self._window.sfg_dict[sfg].show_precedence_graph() - - self.accept() - self.pc.emit() diff --git a/b_asic/GUI/simulate_sfg_window.py b/b_asic/GUI/simulate_sfg_window.py index de82864334ce6dd5d8da50228fc0bc46055440e0..99b432208b610f4fc5fdb8fdd71a5b1607528c34 100644 --- a/b_asic/GUI/simulate_sfg_window.py +++ b/b_asic/GUI/simulate_sfg_window.py @@ -1,6 +1,8 @@ """ B-ASIC window to simulate an SFG. """ +from typing import Dict + from qtpy.QtCore import Qt, Signal from qtpy.QtWidgets import ( QCheckBox, @@ -25,20 +27,20 @@ class SimulateSFGWindow(QDialog): def __init__(self, window): super().__init__() self._window = window - self.properties = {} - self.sfg_to_layout = {} - self.input_fields = {} + self._properties = {} + self._sfg_to_layout = {} + self._input_fields = {} self.setWindowFlags(Qt.WindowTitleHint | Qt.WindowCloseButtonHint) self.setWindowTitle("Simulate SFG") - self.dialog_layout = QVBoxLayout() - self.dialog_layout.setSizeConstraint(QLayout.SetFixedSize) - self.simulate_btn = QPushButton("Simulate") - self.simulate_btn.clicked.connect(self.save_properties) - self.dialog_layout.addWidget(self.simulate_btn) - self.setLayout(self.dialog_layout) - self.input_grid = QGridLayout() - self.input_files = {} + self._dialog_layout = QVBoxLayout() + self._dialog_layout.setSizeConstraint(QLayout.SetFixedSize) + self._simulate_btn = QPushButton("Simulate") + self._simulate_btn.clicked.connect(self.save_properties) + self._dialog_layout.addWidget(self._simulate_btn) + self.setLayout(self._dialog_layout) + self._input_grid = QGridLayout() + self._input_files = {} def add_sfg_to_dialog(self, sfg) -> None: sfg_layout = QVBoxLayout() @@ -62,7 +64,7 @@ class SimulateSFGWindow(QDialog): sfg_layout.addLayout(options_layout) - self.input_fields[sfg] = { + self._input_fields[sfg] = { "iteration_count": spin_box, "show_plot": check_box_plot, "all_results": check_box_all, @@ -79,59 +81,59 @@ class SimulateSFGWindow(QDialog): y = 0 input_label = QLabel(f"in{i}") - self.input_grid.addWidget(input_label, i, 0) + self._input_grid.addWidget(input_label, i, 0) input_dropdown = QComboBox() input_dropdown.insertItems(0, list(_GENERATOR_MAPPING.keys())) input_dropdown.currentTextChanged.connect( lambda text, i=i: self.change_input_format(i, text) ) - self.input_grid.addWidget(input_dropdown, i, 1, alignment=Qt.AlignLeft) + self._input_grid.addWidget(input_dropdown, i, 1, alignment=Qt.AlignLeft) self.change_input_format(i, "Constant") y += 1 - sfg_layout.addLayout(self.input_grid) + sfg_layout.addLayout(self._input_grid) frame = QFrame() frame.setFrameShape(QFrame.HLine) frame.setFrameShadow(QFrame.Sunken) - self.dialog_layout.addWidget(frame) + self._dialog_layout.addWidget(frame) - self.sfg_to_layout[sfg] = sfg_layout - self.dialog_layout.addLayout(sfg_layout) + self._sfg_to_layout[sfg] = sfg_layout + self._dialog_layout.addLayout(sfg_layout) def change_input_format(self, i: int, text: str) -> None: - grid = self.input_grid.itemAtPosition(i, 2) + grid = self._input_grid.itemAtPosition(i, 2) if grid: for j in reversed(range(grid.count())): item = grid.itemAt(j) widget = item.widget() if widget: widget.hide() - self.input_grid.removeItem(grid) + self._input_grid.removeItem(grid) param_grid = QGridLayout() if text in _GENERATOR_MAPPING: - param_grid = _GENERATOR_MAPPING[text](self._window.logger) + param_grid = _GENERATOR_MAPPING[text](self._window._logger) else: raise ValueError("Input selection is not implemented") - self.input_grid.addLayout(param_grid, i, 2) + self._input_grid.addLayout(param_grid, i, 2) def save_properties(self) -> None: - for sfg, _properties in self.input_fields.items(): - ic_value = self.input_fields[sfg]["iteration_count"].value() + for sfg, _properties in self._input_fields.items(): + ic_value = self._input_fields[sfg]["iteration_count"].value() if ic_value == 0: - self._window.logger.error("Iteration count is set to zero.") + self._window._logger.error("Iteration count is set to zero.") input_values = [] - for i in range(self.input_grid.rowCount()): - in_format = self.input_grid.itemAtPosition(i, 1).widget().currentText() - in_param = self.input_grid.itemAtPosition(i, 2) + for i in range(self._input_grid.rowCount()): + in_format = self._input_grid.itemAtPosition(i, 1).widget().currentText() + in_param = self._input_grid.itemAtPosition(i, 2) if in_format in _GENERATOR_MAPPING: tmp2 = in_param.get_generator() @@ -140,17 +142,21 @@ class SimulateSFGWindow(QDialog): input_values.append(tmp2) - self.properties[sfg] = { + self._properties[sfg] = { "iteration_count": ic_value, - "show_plot": self.input_fields[sfg]["show_plot"].isChecked(), - "all_results": self.input_fields[sfg]["all_results"].isChecked(), + "show_plot": self._input_fields[sfg]["show_plot"].isChecked(), + "all_results": self._input_fields[sfg]["all_results"].isChecked(), "input_values": input_values, } # If we plot we should also print the entire data, # since you cannot really interact with the graph. - if self.properties[sfg]["show_plot"]: - self.properties[sfg]["all_results"] = True + if self._properties[sfg]["show_plot"]: + self._properties[sfg]["all_results"] = True self.accept() self.simulate.emit() + + @property + def properties(self) -> Dict: + return self._properties diff --git a/b_asic/GUI/simulation_worker.py b/b_asic/GUI/simulation_worker.py index 6411a791be0d62d4c7c2e3347276daa110b7f7d8..455580f2b3f7d241b33ad56f6ece44f435fc35a5 100644 --- a/b_asic/GUI/simulation_worker.py +++ b/b_asic/GUI/simulation_worker.py @@ -5,6 +5,17 @@ from b_asic.simulation import Simulation class SimulationWorker(QObject): + """ + Simulation worker to enable running simulation in a separate thread. + + Parameters + ---------- + sfg : SFG + The signal flow graph to simulate. + properties : dict + Dictionary containing information about the simulation. + """ + finished = Signal(Simulation) def __init__(self, sfg: SFG, properties): diff --git a/b_asic/GUI/util_dialogs.py b/b_asic/GUI/util_dialogs.py index f7f148a364a1f468fcca6f68b9fabf1fa38dac1e..5bc74f462711cd4870c58bd9a4f3d3ec91c7a657 100644 --- a/b_asic/GUI/util_dialogs.py +++ b/b_asic/GUI/util_dialogs.py @@ -72,8 +72,8 @@ class KeybindingsWindow(QDialog): self.setWindowFlags(Qt.WindowTitleHint | Qt.WindowCloseButtonHint) self.setWindowTitle("B-ASIC Keybindings") - self.dialog_layout = QVBoxLayout() - self.setLayout(self.dialog_layout) + self._dialog_layout = QVBoxLayout() + self.setLayout(self._dialog_layout) self.add_information_to_layout() @@ -86,7 +86,7 @@ class KeybindingsWindow(QDialog): frame = QFrame() frame.setFrameShape(QFrame.HLine) frame.setFrameShadow(QFrame.Sunken) - self.dialog_layout.addWidget(frame) + self._dialog_layout.addWidget(frame) keybindings_label = QLabel( "'Ctrl+R' - Reload the operation list to add any new operations " @@ -101,10 +101,10 @@ class KeybindingsWindow(QDialog): information_layout.addWidget(title_label) information_layout.addWidget(subtitle_label) - self.dialog_layout.addLayout(information_layout) - self.dialog_layout.addWidget(frame) + self._dialog_layout.addLayout(information_layout) + self._dialog_layout.addWidget(frame) - self.dialog_layout.addWidget(keybindings_label) + self._dialog_layout.addWidget(keybindings_label) class FaqWindow(QDialog): @@ -114,16 +114,16 @@ class FaqWindow(QDialog): self.setWindowFlags(Qt.WindowTitleHint | Qt.WindowCloseButtonHint) self.setWindowTitle("Frequently Asked Questions") - self.dialog_layout = QVBoxLayout() - self.scroll_area = QScrollArea() - self.setLayout(self.dialog_layout) + self._dialog_layout = QVBoxLayout() + self._scroll_area = QScrollArea() + self.setLayout(self._dialog_layout) for question, answer in _QUESTIONS.items(): - self.add_question_to_layout(question, answer) + self._add_question_to_layout(question, answer) - self.scroll_area.setWidget(self) - self.scroll_area.setWidgetResizable(True) + self._scroll_area.setWidget(self) + self._scroll_area.setWidgetResizable(True) - def add_question_to_layout(self, question, answer): + def _add_question_to_layout(self, question, answer): question_layout = QVBoxLayout() answer_layout = QHBoxLayout() @@ -136,7 +136,7 @@ class FaqWindow(QDialog): frame = QFrame() frame.setFrameShape(QFrame.HLine) frame.setFrameShadow(QFrame.Sunken) - self.dialog_layout.addWidget(frame) + self._dialog_layout.addWidget(frame) question_layout.addLayout(answer_layout) - self.dialog_layout.addLayout(question_layout) + self._dialog_layout.addLayout(question_layout) diff --git a/b_asic/gui_utils/about_window.py b/b_asic/gui_utils/about_window.py index 7c203d4fa1bc9a38576df84c5a1046b3d7ce4846..d702a45951acb013dcb4b79f12a87e66146aa600 100644 --- a/b_asic/gui_utils/about_window.py +++ b/b_asic/gui_utils/about_window.py @@ -26,8 +26,8 @@ class AboutWindow(QDialog): self.setWindowFlags(Qt.WindowTitleHint | Qt.WindowCloseButtonHint) self.setWindowTitle("About B-ASIC") - self.dialog_layout = QVBoxLayout() - self.setLayout(self.dialog_layout) + self._dialog_layout = QVBoxLayout() + self.setLayout(self._dialog_layout) self._add_information_to_layout() @@ -104,9 +104,9 @@ class AboutWindow(QDialog): hline.setFrameShape(QFrame.HLine) hline.setFrameShadow(QFrame.Sunken) - self.dialog_layout.addLayout(layout12) - self.dialog_layout.addWidget(hline) - self.dialog_layout.addLayout(layout34) + self._dialog_layout.addLayout(layout12) + self._dialog_layout.addWidget(hline) + self._dialog_layout.addLayout(layout34) # ONLY FOR DEBUG below diff --git a/b_asic/gui_utils/decorators.py b/b_asic/gui_utils/decorators.py index 2606c0ad63e2617e1b31300eac84162b207183bb..1e3ec970d2e7277e96443ca29e99253b56d3632b 100644 --- a/b_asic/gui_utils/decorators.py +++ b/b_asic/gui_utils/decorators.py @@ -8,7 +8,7 @@ def handle_error(fn): try: return fn(self, *args, **kwargs) except Exception: - self._window.logger.error(f"Unexpected error: {format_exc()}") + self._window._logger.error(f"Unexpected error: {format_exc()}") QErrorMessage(self._window).showMessage(f"Unexpected error: {format_exc()}") return wrapper diff --git a/b_asic/gui_utils/plot_window.py b/b_asic/gui_utils/plot_window.py index e2d5dcf19bdf5096c6b490e29ca1e7da015ce6d8..4ea8f254a9f0574efee38467baa8daff0191eb02 100644 --- a/b_asic/gui_utils/plot_window.py +++ b/b_asic/gui_utils/plot_window.py @@ -80,14 +80,14 @@ class PlotWindow(QWidget): # | ... | plot | # | misc | | - self.dialog_layout = QHBoxLayout() - self.setLayout(self.dialog_layout) + self._dialog_layout = QHBoxLayout() + self.setLayout(self._dialog_layout) listlayout = QVBoxLayout() plotlayout = QVBoxLayout() - self.dialog_layout.addLayout(listlayout) - self.dialog_layout.addLayout(plotlayout) + self._dialog_layout.addLayout(listlayout) + self._dialog_layout.addLayout(plotlayout) ########### Plot: ############## # Do this before the list layout, as the list layout will re/set visibility @@ -128,9 +128,9 @@ class PlotWindow(QWidget): listlayout.addLayout(hlayout) # Add the entire list - self.checklist = QListWidget() - self.checklist.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) - self.checklist.itemChanged.connect(self._item_change) + self._checklist = QListWidget() + self._checklist.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) + self._checklist.itemChanged.connect(self._item_change) listitems = {} # Use | when dropping support for Python 3.8 ordered_for_checklist = {} @@ -139,23 +139,23 @@ class PlotWindow(QWidget): ordered_for_checklist.update(sim_res_delays) ordered_for_checklist.update(sim_res_others) for key in ordered_for_checklist: - listitem = QListWidgetItem(key) - listitems[key] = listitem - self.checklist.addItem(listitem) - listitem.setCheckState( + list_item = QListWidgetItem(key) + listitems[key] = list_item + self._checklist.addItem(list_item) + list_item.setCheckState( Qt.CheckState.Unchecked # CheckState: Qt.CheckState.{Unchecked, PartiallyChecked, Checked} ) for key in sim_res_outs: listitems[key].setCheckState(Qt.CheckState.Checked) - # self.checklist.setFixedWidth(150) - listlayout.addWidget(self.checklist) + # self._checklist.setFixedWidth(150) + listlayout.addWidget(self._checklist) # Add additional checkboxes self._legend = self._plot_axes.legend() - self.legend_checkbox = QCheckBox("&Legend") - self.legend_checkbox.stateChanged.connect(self._legend_checkbox_change) - self.legend_checkbox.setCheckState(Qt.CheckState.Checked) - listlayout.addWidget(self.legend_checkbox) + self._legend_checkbox = QCheckBox("&Legend") + self._legend_checkbox.stateChanged.connect(self._legend_checkbox_change) + self._legend_checkbox.setCheckState(Qt.CheckState.Checked) + listlayout.addWidget(self._legend_checkbox) # self.ontop_checkbox = QCheckBox("&On top") # self.ontop_checkbox.stateChanged.connect(self._ontop_checkbox_change) # self.ontop_checkbox.setCheckState(Qt.CheckState.Unchecked) @@ -191,8 +191,8 @@ class PlotWindow(QWidget): def _button_all_click(self, event): self._auto_redraw = False - for x in range(self.checklist.count()): - self.checklist.item(x).setCheckState(Qt.CheckState.Checked) + for x in range(self._checklist.count()): + self._checklist.item(x).setCheckState(Qt.CheckState.Checked) self._auto_redraw = True self._update_legend() @@ -202,8 +202,8 @@ class PlotWindow(QWidget): def _button_none_click(self, event): self._auto_redraw = False - for x in range(self.checklist.count()): - self.checklist.item(x).setCheckState(Qt.CheckState.Unchecked) + for x in range(self._checklist.count()): + self._checklist.item(x).setCheckState(Qt.CheckState.Unchecked) self._auto_redraw = True self._update_legend() diff --git a/b_asic/scheduler_gui/main_window.py b/b_asic/scheduler_gui/main_window.py index bf9ec33b40f601c5631ecf19754f93466d4ded04..60e7c9622cb9f47db2f141798143cfecd8c93342 100644 --- a/b_asic/scheduler_gui/main_window.py +++ b/b_asic/scheduler_gui/main_window.py @@ -153,7 +153,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): self.maxFileNr = 4 self.recentFilesList: List[QAction] = [] self.recentFilePaths = deque(maxlen=self.maxFileNr) - self.createActionsAndMenus() + self._create_recent_file_actions_and_menus() def _init_graphics(self) -> None: """Initialize the QGraphics framework""" @@ -253,7 +253,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): ) return - self.addRecentFile(abs_path_filename) + self._add_recent_file(abs_path_filename) schedule_obj_list = dict( inspect.getmembers(module, (lambda x: isinstance(x, Schedule))) @@ -644,19 +644,19 @@ class MainWindow(QMainWindow, Ui_MainWindow): else: log.error("'Operator' not found in info table. It may have been renamed.") - def createActionsAndMenus(self): + def _create_recent_file_actions_and_menus(self): for i in range(self.maxFileNr): recentFileAction = QAction(self.menu_Recent_Schedule) recentFileAction.setVisible(False) recentFileAction.triggered.connect( - lambda b=0, x=recentFileAction: self.openRecent(x) + lambda b=0, x=recentFileAction: self._open_recent_file(x) ) self.recentFilesList.append(recentFileAction) self.menu_Recent_Schedule.addAction(recentFileAction) - self.updateRecentActionList() + self._update_recent_file_list() - def updateRecentActionList(self): + def _update_recent_file_list(self): settings = QSettings() rfp = settings.value("scheduler/recentFiles") @@ -674,10 +674,10 @@ class MainWindow(QMainWindow, Ui_MainWindow): for i in range(dequelen, self.maxFileNr): self.recentFilesList[i].setVisible(False) - def openRecent(self, action): + def _open_recent_file(self, action): self._load_from_file(action.data().filePath()) - def addRecentFile(self, module): + def _add_recent_file(self, module): settings = QSettings() rfp = settings.value("scheduler/recentFiles") @@ -691,7 +691,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): settings.setValue("scheduler/recentFiles", rfp) - self.updateRecentActionList() + self._update_recent_file_list() def start_scheduler(schedule: Optional[Schedule] = None) -> None: diff --git a/b_asic/scheduler_gui/timeline_item.py b/b_asic/scheduler_gui/timeline_item.py index 96509c253309c7940d0a956bcb939051995523e0..17752b33e383588c79920b7101676e608a5cf9cb 100644 --- a/b_asic/scheduler_gui/timeline_item.py +++ b/b_asic/scheduler_gui/timeline_item.py @@ -78,7 +78,7 @@ class TimelineItem(QGraphicsLineItem): # return self._delta_time_label def set_text(self, number: int) -> None: - """Set the label text to 'number'.""" + """Set the label text to *number*.""" # self.prepareGeometryChange() self._delta_time_label.setPlainText(f"( {number:+} )") self._delta_time_label.setX( diff --git a/b_asic/simulation.py b/b_asic/simulation.py index 7e449eef7daef19c20b4fc7ae4bcf06d27b53c7b..0f00e098d5993cfb98c52f42f1332e1d8529f60e 100644 --- a/b_asic/simulation.py +++ b/b_asic/simulation.py @@ -219,6 +219,11 @@ class Simulation: """ self._delays.clear() + @property + def sfg(self) -> SFG: + """The signal flow graph being simulated.""" + return self._sfg + def show(self) -> None: """Show the simulation results.""" # import here to avoid cyclic imports diff --git a/docs_sphinx/GUI.rst b/docs_sphinx/GUI.rst index a7d210898085bfd48d819fa89671bd98841f10f0..8a3ece67ac75b860209462bede692de6c3718531 100644 --- a/docs_sphinx/GUI.rst +++ b/docs_sphinx/GUI.rst @@ -52,6 +52,14 @@ GUI.port\_button module :undoc-members: :show-inheritance: +GUI.precedence\_graph\_window module +------------------------------------ + +.. automodule:: b_asic.GUI.precedence_graph_window + :members: + :undoc-members: + :show-inheritance: + GUI.properties\_window module ----------------------------- @@ -68,14 +76,6 @@ GUI.select\_sfg\_window module :undoc-members: :show-inheritance: -GUI.show\_pc\_window module ---------------------------- - -.. automodule:: b_asic.GUI.show_pc_window - :members: - :undoc-members: - :show-inheritance: - GUI.signal\_generator\_input module ----------------------------------- @@ -96,6 +96,14 @@ GUI.simulate\_sfg\_window module :undoc-members: :show-inheritance: +GUI.simulation\_worker module +-------------------------------- + +.. automodule:: b_asic.GUI.simulation_worker + :members: + :undoc-members: + :show-inheritance: + GUI.util\_dialogs module ------------------------ diff --git a/test/test_gui.py b/test/test_gui.py index 0e1af8bbc551e6c5f5460b4eecccf45e68cc8934..2b97730f9e4905cd2be426695f7aa44426933bbe 100644 --- a/test/test_gui.py +++ b/test/test_gui.py @@ -22,10 +22,10 @@ def test_load(qtbot, datadir): widget = GUI.MainWindow() qtbot.addWidget(widget) widget._load_from_file(datadir.join('twotapfir.py')) - assert 'twotapfir' in widget.sfg_dict - widget.clear_workspace() - assert 'twotapfir' not in widget.sfg_dict - assert not widget.sfg_dict + assert 'twotapfir' in widget._sfg_dict + widget._clear_workspace() + assert 'twotapfir' not in widget._sfg_dict + assert not widget._sfg_dict widget.exit_app() @@ -34,9 +34,9 @@ def test_flip(qtbot, datadir): widget = GUI.MainWindow() qtbot.addWidget(widget) widget._load_from_file(datadir.join('twotapfir.py')) - sfg = widget.sfg_dict['twotapfir'] + sfg = widget._sfg_dict['twotapfir'] op = sfg.find_by_name("cmul2") - dragbutton = widget._operation_drag_buttons[op[0]] + dragbutton = widget._drag_buttons[op[0]] assert not dragbutton.is_flipped() dragbutton._flip() assert dragbutton.is_flipped() @@ -47,13 +47,13 @@ def test_sfg_invalidated_by_remove_of_operation(qtbot, datadir): widget = GUI.MainWindow() qtbot.addWidget(widget) widget._load_from_file(datadir.join('twotapfir.py')) - sfg = widget.sfg_dict['twotapfir'] - ops_before_remove = len(widget._operation_drag_buttons) + sfg = widget._sfg_dict['twotapfir'] + ops_before_remove = len(widget._drag_buttons) op = sfg.find_by_name("cmul2") - dragbutton = widget._operation_drag_buttons[op[0]] + dragbutton = widget._drag_buttons[op[0]] dragbutton.remove() - assert not widget.sfg_dict - assert ops_before_remove - 1 == len(widget._operation_drag_buttons) + assert not widget._sfg_dict + assert ops_before_remove - 1 == len(widget._drag_buttons) widget.exit_app() @@ -62,15 +62,15 @@ def test_sfg_invalidated_by_deleting_of_operation(qtbot, datadir): widget = GUI.MainWindow() qtbot.addWidget(widget) widget._load_from_file(datadir.join('twotapfir.py')) - sfg = widget.sfg_dict['twotapfir'] - ops_before_remove = len(widget._operation_drag_buttons) + sfg = widget._sfg_dict['twotapfir'] + ops_before_remove = len(widget._drag_buttons) op = sfg.find_by_name("cmul2") - dragbutton = widget._operation_drag_buttons[op[0]] + dragbutton = widget._drag_buttons[op[0]] # Click qtbot.mouseClick(dragbutton, QtCore.Qt.MouseButton.LeftButton) qtbot.keyClick(widget, QtCore.Qt.Key.Key_Delete) - assert not widget.sfg_dict - assert ops_before_remove - 1 == len(widget._operation_drag_buttons) + assert not widget._sfg_dict + assert ops_before_remove - 1 == len(widget._drag_buttons) widget.exit_app() @@ -79,26 +79,26 @@ def test_select_operation(qtbot, datadir): widget = GUI.MainWindow() qtbot.addWidget(widget) widget._load_from_file(datadir.join('twotapfir.py')) - sfg = widget.sfg_dict['twotapfir'] + sfg = widget._sfg_dict['twotapfir'] op = sfg.find_by_name("cmul2")[0] - dragbutton = widget._operation_drag_buttons[op] + dragbutton = widget._drag_buttons[op] assert not dragbutton.pressed - assert not widget.pressed_operations + assert not widget._pressed_operations # Click qtbot.mouseClick(dragbutton, QtCore.Qt.MouseButton.LeftButton) assert dragbutton.pressed - assert len(widget.pressed_operations) == 1 + assert len(widget._pressed_operations) == 1 # Click again, should unselect qtbot.mouseClick(dragbutton, QtCore.Qt.MouseButton.LeftButton) # Currently failing # assert not dragbutton.pressed - # assert not widget.pressed_operations + # assert not widget._pressed_operations # Select another operation op2 = sfg.find_by_name("add1")[0] - dragbutton2 = widget._operation_drag_buttons[op2] + dragbutton2 = widget._drag_buttons[op2] assert not dragbutton2.pressed # Click @@ -106,7 +106,7 @@ def test_select_operation(qtbot, datadir): assert dragbutton2.pressed # Unselect previous assert not dragbutton.pressed - assert len(widget.pressed_operations) == 1 + assert len(widget._pressed_operations) == 1 # Control-click first qtbot.mouseClick( @@ -116,7 +116,7 @@ def test_select_operation(qtbot, datadir): ) assert dragbutton2.pressed assert dragbutton.pressed - assert len(widget.pressed_operations) == 2 + assert len(widget._pressed_operations) == 2 # Control-click second qtbot.mouseClick( @@ -126,7 +126,7 @@ def test_select_operation(qtbot, datadir): ) assert not dragbutton2.pressed assert dragbutton.pressed - assert len(widget.pressed_operations) == 1 + assert len(widget._pressed_operations) == 1 widget.exit_app() @@ -154,7 +154,7 @@ def test_simulate(qtbot, datadir): widget = GUI.MainWindow() qtbot.addWidget(widget) widget._load_from_file(datadir.join('twotapfir.py')) - assert 'twotapfir' in widget.sfg_dict + assert 'twotapfir' in widget._sfg_dict widget.simulate_sfg() qtbot.wait(100) widget._simulation_dialog.save_properties() @@ -165,35 +165,39 @@ def test_simulate(qtbot, datadir): def test_properties_window_smoke_test(qtbot, datadir): - # Smoke test to open up the properties window + # Smoke test to open up the _properties window # Should really check that the contents are correct and changes works etc widget = GUI.MainWindow() qtbot.addWidget(widget) widget._load_from_file(datadir.join('twotapfir.py')) - sfg = widget.sfg_dict['twotapfir'] + sfg = widget._sfg_dict['twotapfir'] op = sfg.find_by_name("cmul2")[0] - dragbutton = widget._operation_drag_buttons[op] + dragbutton = widget._drag_buttons[op] dragbutton.show_properties_window() assert dragbutton._properties_window.operation == dragbutton - qtbot.mouseClick(dragbutton._properties_window.ok, QtCore.Qt.MouseButton.LeftButton) + qtbot.mouseClick( + dragbutton._properties_window._ok_button, QtCore.Qt.MouseButton.LeftButton + ) widget.exit_app() def test_properties_window_change_name(qtbot, datadir): - # Smoke test to open up the properties window + # Smoke test to open up the _properties window # Should really check that the contents are correct and changes works etc widget = GUI.MainWindow() qtbot.addWidget(widget) widget._load_from_file(datadir.join('twotapfir.py')) - sfg = widget.sfg_dict['twotapfir'] + sfg = widget._sfg_dict['twotapfir'] op = sfg.find_by_name("cmul2")[0] - dragbutton = widget._operation_drag_buttons[op] + dragbutton = widget._drag_buttons[op] assert dragbutton.name == "cmul2" assert dragbutton.operation.name == "cmul2" dragbutton.show_properties_window() - assert dragbutton._properties_window.edit_name.text() == "cmul2" - dragbutton._properties_window.edit_name.setText("cmul73") - qtbot.mouseClick(dragbutton._properties_window.ok, QtCore.Qt.MouseButton.LeftButton) + assert dragbutton._properties_window._edit_name.text() == "cmul2" + dragbutton._properties_window._edit_name.setText("cmul73") + qtbot.mouseClick( + dragbutton._properties_window._ok_button, QtCore.Qt.MouseButton.LeftButton + ) dragbutton._properties_window.save_properties() assert dragbutton.name == "cmul73" assert dragbutton.operation.name == "cmul73" @@ -212,45 +216,45 @@ def test_add_operation_and_create_sfg(qtbot, monkeypatch): widget.create_operation(sqrt) widget.create_operation(out1) # Should be three operations - assert len(widget._operation_drag_buttons) == 3 + assert len(widget._drag_buttons) == 3 # These particular three for op in (in1, sqrt, out1): - assert op in widget._operation_drag_buttons + assert op in widget._drag_buttons # No signals - assert not widget._arrow_list + assert not widget._arrows # Click on first port - in1_port = widget.portDict[widget._operation_drag_buttons[in1]][0] + in1_port = widget._ports[widget._drag_buttons[in1]][0] qtbot.mouseClick( in1_port, QtCore.Qt.MouseButton.LeftButton, ) - assert len(widget.pressed_ports) == 1 + assert len(widget._pressed_ports) == 1 # Click on second port - sqrt_in_port = widget.portDict[widget._operation_drag_buttons[sqrt]][0] + sqrt_in_port = widget._ports[widget._drag_buttons[sqrt]][0] qtbot.mouseClick( sqrt_in_port, QtCore.Qt.MouseButton.LeftButton, QtCore.Qt.KeyboardModifier.ControlModifier, ) - assert len(widget.pressed_ports) == 2 + assert len(widget._pressed_ports) == 2 # Connect ports widget._connect_callback() # Not sure why this won't work # qtbot.keyClick(widget, QtCore.Qt.Key.Key_Space, delay=10) # Still one selected!? - assert len(widget._arrow_list) == 1 + assert len(widget._arrows) == 1 # Click on first port - sqrt_out_port = widget.portDict[widget._operation_drag_buttons[sqrt]][1] + sqrt_out_port = widget._ports[widget._drag_buttons[sqrt]][1] qtbot.mouseClick( sqrt_out_port, QtCore.Qt.MouseButton.LeftButton, ) # Click on second port - out1_port = widget.portDict[widget._operation_drag_buttons[out1]][0] + out1_port = widget._ports[widget._drag_buttons[out1]][0] qtbot.mouseClick( out1_port, QtCore.Qt.MouseButton.LeftButton, @@ -258,17 +262,17 @@ def test_add_operation_and_create_sfg(qtbot, monkeypatch): ) # Connect widget._connect_callback() - assert len(widget._arrow_list) == 2 + assert len(widget._arrows) == 2 # Select input op qtbot.mouseClick( - widget._operation_drag_buttons[in1], + widget._drag_buttons[in1], QtCore.Qt.MouseButton.LeftButton, ) # And output op qtbot.mouseClick( - widget._operation_drag_buttons[out1], + widget._drag_buttons[out1], QtCore.Qt.MouseButton.LeftButton, QtCore.Qt.KeyboardModifier.ControlModifier, ) @@ -279,8 +283,8 @@ def test_add_operation_and_create_sfg(qtbot, monkeypatch): # Create SFG widget.create_sfg_from_toolbar() - # Should be in sfg_dict now - assert "foo" in widget.sfg_dict - assert len(widget.sfg_dict) == 1 + # Should be in _sfg_dict now + assert "foo" in widget._sfg_dict + assert len(widget._sfg_dict) == 1 widget.exit_app() diff --git a/test/test_simulation_gui.py b/test/test_simulation_gui.py index 9b2690639723fa386b0c8d4e99fcf68d96a627d4..cd7599e604e9f04a141f04e8c985aadfa822fb6e 100644 --- a/test/test_simulation_gui.py +++ b/test/test_simulation_gui.py @@ -24,7 +24,7 @@ def test_start_with_data(qtbot): widget = PlotWindow(sim_res) qtbot.addWidget(widget) - assert widget.checklist.count() == 6 + assert widget._checklist.count() == 6 assert len(widget._plot_axes.lines) == 1 @@ -40,7 +40,7 @@ def test_click_buttons(qtbot): widget = PlotWindow(sim_res) qtbot.addWidget(widget) - assert widget.checklist.count() == 6 + assert widget._checklist.count() == 6 assert len(widget._plot_axes.lines) == 1 qtbot.mouseClick(widget._button_all, QtCore.Qt.MouseButton.LeftButton)