diff --git a/b_asic/GUI/drag_button.py b/b_asic/GUI/drag_button.py index 40be91785b8a410adc6729906192952420707b7a..80bfcf335ca10c54a820749bdc2225d18cbdd060 100644 --- a/b_asic/GUI/drag_button.py +++ b/b_asic/GUI/drag_button.py @@ -70,7 +70,8 @@ class DragButton(QPushButton): button.move(button.mapToParent(event.pos() - self._mouse_press_pos)) - self._window.update() + self._window.scene.update() + self._window.graphic_view.update() super(DragButton, self).mouseMoveEvent(event) def mouseReleaseEvent(self, event): diff --git a/b_asic/GUI/gui_interface.py b/b_asic/GUI/gui_interface.py index 5b808c66243c6e7db927413e1ea034be7daf4e36..a46a9d7984386daf9398bfe45267dba59a0eea31 100644 --- a/b_asic/GUI/gui_interface.py +++ b/b_asic/GUI/gui_interface.py @@ -64,9 +64,16 @@ class Ui_main_window(object): self.special_operations_page.setGeometry(QtCore.QRect(0, 0, 171, 217)) self.special_operations_page.setObjectName("special_operations_page") self.special_operations_list = QtWidgets.QListWidget(self.special_operations_page) - self.special_operations_list.setGeometry(QtCore.QRect(10, 0, 141, 81)) + self.special_operations_list.setGeometry(QtCore.QRect(10, 0, 141, 211)) self.special_operations_list.setObjectName("special_operations_list") self.operation_list.addItem(self.special_operations_page, "") + self.custom_operations_page = QtWidgets.QWidget() + self.custom_operations_page.setGeometry(QtCore.QRect(0, 0, 171, 217)) + self.custom_operations_page.setObjectName("custom_operations_page") + self.custom_operations_list = QtWidgets.QListWidget(self.custom_operations_page) + self.custom_operations_list.setGeometry(QtCore.QRect(10, 0, 141, 211)) + self.custom_operations_list.setObjectName("custom_operations_list") + self.operation_list.addItem(self.custom_operations_page, "") main_window.setCentralWidget(self.centralwidget) self.menu_bar = QtWidgets.QMenuBar(main_window) self.menu_bar.setGeometry(QtCore.QRect(0, 0, 897, 21)) @@ -235,6 +242,8 @@ class Ui_main_window(object): self.load_menu.setObjectName("load_menu") self.save_menu = QtWidgets.QAction(main_window) self.save_menu.setObjectName("save_menu") + self.load_operations = QtWidgets.QAction(main_window) + self.load_operations.setObjectName("load_operations") self.exit_menu = QtWidgets.QAction(main_window) self.exit_menu.setObjectName("exit_menu") self.actionUndo = QtWidgets.QAction(main_window) @@ -256,6 +265,7 @@ class Ui_main_window(object): self.actionToolbar.setObjectName("actionToolbar") self.file_menu.addAction(self.load_menu) self.file_menu.addAction(self.save_menu) + self.file_menu.addAction(self.load_operations) self.file_menu.addSeparator() self.file_menu.addAction(self.exit_menu) self.edit_menu.addAction(self.actionUndo) @@ -290,6 +300,10 @@ class Ui_main_window(object): self.special_operations_list.setSortingEnabled(False) self.special_operations_list.setSortingEnabled(__sortingEnabled) self.operation_list.setItemText(self.operation_list.indexOf(self.special_operations_page), _translate("main_window", "Special operations")) + __sortingEnabled = self.special_operations_list.isSortingEnabled() + self.custom_operations_list.setSortingEnabled(False) + self.custom_operations_list.setSortingEnabled(__sortingEnabled) + self.operation_list.setItemText(self.operation_list.indexOf(self.custom_operations_page), _translate("main_window", "Custom operation")) self.file_menu.setTitle(_translate("main_window", "File")) self.edit_menu.setTitle(_translate("main_window", "Edit")) self.view_menu.setTitle(_translate("main_window", "View")) @@ -300,8 +314,9 @@ class Ui_main_window(object): self.aboutBASIC.setText(_translate("main_window", "About B-ASIC")) self.faqBASIC.setText(_translate("main_window", "FAQ")) self.keybindsBASIC.setText(_translate("main_window", "Keybinds")) - self.load_menu.setText(_translate("main_window", "Load")) - self.save_menu.setText(_translate("main_window", "Save")) + self.load_menu.setText(_translate("main_window", "Load SFG")) + self.save_menu.setText(_translate("main_window", "Save SFG")) + self.load_operations.setText(_translate("main_window", "Load Operations")) self.exit_menu.setText(_translate("main_window", "Exit")) self.exit_menu.setShortcut(_translate("main_window", "Ctrl+Q")) self.actionUndo.setText(_translate("main_window", "Undo")) diff --git a/b_asic/GUI/main_window.py b/b_asic/GUI/main_window.py index 975c3b7f9b2b4d27f6a9977db06924c15e763cf0..6773bc7c07c0786b4946d32ed058f7677b70c91f 100644 --- a/b_asic/GUI/main_window.py +++ b/b_asic/GUI/main_window.py @@ -33,7 +33,7 @@ QStatusBar, QMenuBar, QLineEdit, QPushButton, QSlider, QScrollArea, QVBoxLayout, QHBoxLayout, QDockWidget, QToolBar, QMenu, QLayout, QSizePolicy, QListWidget,\ QListWidgetItem, QGraphicsView, QGraphicsScene, QShortcut, QGraphicsTextItem,\ QGraphicsProxyWidget, QInputDialog, QTextEdit, QFileDialog -from PySide2.QtCore import Qt, QSize, QUrl +from PySide2.QtCore import Qt, QSize, QFileInfo from PySide2.QtGui import QIcon, QFont, QPainter, QPen, QBrush, QKeySequence from tkinter import Tk @@ -91,8 +91,10 @@ class MainWindow(QMainWindow): self.ui.keybindsBASIC.triggered.connect(self.display_keybinds_page) self.ui.core_operations_list.itemClicked.connect(self.on_list_widget_item_clicked) self.ui.special_operations_list.itemClicked.connect(self.on_list_widget_item_clicked) + 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) @@ -118,6 +120,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("Clear Workspace", self.clear_workspace) def resizeEvent(self, event): self.ui.operation_box.setGeometry(10, 10, self.ui.operation_box.width(), self.height()) @@ -219,6 +222,20 @@ class MainWindow(QMainWindow): self.logger.info("Exiting the application.") QApplication.quit() + def clear_workspace(self): + self.logger.info("Clearing workspace from operations and sfgs.") + self.pressed_operations.clear() + self.pressed_ports.clear() + self.operationItemSceneList.clear() + self.operationDragDict.clear() + self.dragOperationSceneDict.clear() + self.signalList.clear() + self.portDict.clear() + self.signalPortDict.clear() + self.sfg_dict.clear() + self.scene.clear() + self.logger.info("Workspace cleared.") + def create_SFG_from_toolbar(self): inputs = [] outputs = [] @@ -299,6 +316,17 @@ class MainWindow(QMainWindow): self.logger.info(f"Added operations from namespace: {namespace.__name__}.") + def add_namespace(self): + module, accepted = QFileDialog().getOpenFileName() + if not accepted: + return + + spec = importlib.util.spec_from_file_location(f"{QFileInfo(module).fileName()}", module) + namespace = importlib.util.module_from_spec(spec) + spec.loader.exec_module(namespace) + + self.add_operations_from_namespace(namespace, self.ui.custom_operations_list) + def create_operation(self, op, position=None): self.logger.info(f"Creating operation of type: {op.type_name()}.") try: