Skip to content
Snippets Groups Projects
Commit da36f66e authored by Jacob Wahlman's avatar Jacob Wahlman :ok_hand:
Browse files

added load operation from custom namespace and fixed artifacts when dragging

parent 9dd40c97
No related branches found
No related tags found
1 merge request!57Resolve "Load/Save SFG to file"
Pipeline #15939 failed
......@@ -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):
......
......@@ -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"))
......
......@@ -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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment