From 654d8ca4e1d6b61da245a5813dc9bd2593a95f6d Mon Sep 17 00:00:00 2001 From: Andreas Bolin <2535580+andbo467@users.noreply.github.com> Date: Thu, 14 Jul 2022 03:42:17 +0200 Subject: [PATCH] workspace dump --- b_asic/scheduler-gui/__init__.py | 2 +- b_asic/scheduler-gui/graphics_scene.py | 60 +++-------- b_asic/scheduler-gui/icons/misc.qrc | 6 ++ .../icons/misc/right_filled_panel.svg | 1 + .../scheduler-gui/icons/misc/right_panel.svg | 1 + b_asic/scheduler-gui/icons/misc_rc.py | 101 ++++++++++++++++++ b_asic/scheduler-gui/main_window.py | 54 ++++++---- b_asic/scheduler-gui/main_window.ui | 6 +- 8 files changed, 166 insertions(+), 65 deletions(-) create mode 100644 b_asic/scheduler-gui/icons/misc.qrc create mode 100644 b_asic/scheduler-gui/icons/misc/right_filled_panel.svg create mode 100644 b_asic/scheduler-gui/icons/misc/right_panel.svg create mode 100644 b_asic/scheduler-gui/icons/misc_rc.py diff --git a/b_asic/scheduler-gui/__init__.py b/b_asic/scheduler-gui/__init__.py index ed7b11a0..469917bc 100644 --- a/b_asic/scheduler-gui/__init__.py +++ b/b_asic/scheduler-gui/__init__.py @@ -5,7 +5,7 @@ Graphical user interface for B-ASIC scheduler. from logger import * from main_window import * -from scheduler import * +from graphics_scene import * #__all__ = ['main_window', 'scheduler'] __version__ = '0.1' diff --git a/b_asic/scheduler-gui/graphics_scene.py b/b_asic/scheduler-gui/graphics_scene.py index ea907c75..0115f90a 100644 --- a/b_asic/scheduler-gui/graphics_scene.py +++ b/b_asic/scheduler-gui/graphics_scene.py @@ -40,49 +40,22 @@ class GraphicsScene(QGraphicsScene): _id: Final[int] _schedule: Final[Schedule] - # @overload - # def __init__(self, parent:Optional[QObject]=...) -> None: - # ... - # @overload - # def __init__(self, sceneRect:QRectF, parent:Optional[QObject]=...) -> None: - # ... - # @overload - # def __init__(self, x:float, y:float, width:float, height:float, parent:Optional[QObject]=...) -> None: - # ... - - # @overload - # def __init__(self, parent: QObject, id: int, schedule: Optional[Schedule] = None, *args, **kwargs) -> None: ... - # @overload - # def __init__(self, id: int, schedule: Optional[Schedule] = None, *args, **kwargs) -> None: - # super(Self, self).__init__(parent, *args, **kwargs) - # self._id = id + # def __init__(self, id: int, schedule: Optional["Schedule"] = None, *args, **kwargs): + # def __init__(self, id: int, schedule: Optional["Schedule"] = None): + def __init__(self, id: int, schedule: Schedule = None, *args, **kwargs): + # QGraphicsScene.__init__(self) + super().__init__(*args, **kwargs) - # @overload - # def __init__(self, parent: QObject, id: int, *args, **kwargs): - # super(GraphicsScene, self).__init__(parent, *args, **kwargs) - # self.__init__(id, *args, **kwargs) - - # def __init__(self, id: int, schedule: Schedule = None, parent: Optional[QObject]): - # super(GraphicsScene, self).__init__(parent) - # self._id = id - # self._schedule - def __init__(self, id: int, schedule: Optional["Schedule"] = None, parent: Optional["QObject"] = None): - # def __init__(self, id: int[, schedule: Schedule]):# = None, parent: Optional[QObject] = None): - super(GraphicsScene, self).__init__(parent) self._id = id - self._schedule = schedule - print() - print('parent:', parent) - print('type(parent):', type(parent)) - print() - print('schedule:', schedule) - print('type(schedule):', type(schedule)) - print('self._schedule:', self._schedule) - print('type(self._schedule):', type(self._schedule)) + if isinstance(schedule, Schedule): + self._schedule = schedule + print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!') + self._schedule.plot_schedule() + print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!') + print('From GraphicsScene:') + pprint(self._schedule) + print('') - # def __init__(self, id: int): - # super(GraphicsScene, self).__init__() - # self._id = id @property @@ -96,7 +69,8 @@ class GraphicsScene(QGraphicsScene): @schedule.setter def schedule(self, schedule: Schedule): self._schedule = schedule - -print('GraphicsScene.__mro__:') + + +print('\nGraphicsScene.__mro__') pprint(GraphicsScene.__mro__) - +print('') \ No newline at end of file diff --git a/b_asic/scheduler-gui/icons/misc.qrc b/b_asic/scheduler-gui/icons/misc.qrc new file mode 100644 index 00000000..8c10ef99 --- /dev/null +++ b/b_asic/scheduler-gui/icons/misc.qrc @@ -0,0 +1,6 @@ +<RCC> + <qresource prefix="/icons"> + <file>misc/right_filled_panel.svg</file> + <file>misc/right_panel.svg</file> + </qresource> +</RCC> diff --git a/b_asic/scheduler-gui/icons/misc/right_filled_panel.svg b/b_asic/scheduler-gui/icons/misc/right_filled_panel.svg new file mode 100644 index 00000000..a402b3e9 --- /dev/null +++ b/b_asic/scheduler-gui/icons/misc/right_filled_panel.svg @@ -0,0 +1 @@ +<?xml version="1.0" ?><svg id="icon" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg"><defs><style>.cls-1{fill:none;}</style></defs><title/><path d="M28,4H4A2,2,0,0,0,2,6V26a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V6A2,2,0,0,0,28,4ZM4,6H20V26H4Z"/><rect class="cls-1" data-name="<Transparent Rectangle>" height="32" id="_Transparent_Rectangle_" width="32"/></svg> \ No newline at end of file diff --git a/b_asic/scheduler-gui/icons/misc/right_panel.svg b/b_asic/scheduler-gui/icons/misc/right_panel.svg new file mode 100644 index 00000000..11ba906f --- /dev/null +++ b/b_asic/scheduler-gui/icons/misc/right_panel.svg @@ -0,0 +1 @@ +<?xml version="1.0" ?><svg id="icon" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg"><defs><style>.cls-1{fill:none;}</style></defs><title/><path d="M28,4H4A2,2,0,0,0,2,6V26a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V6A2,2,0,0,0,28,4ZM4,6H20V26H4ZM28,26H22V6h6Z"/><rect class="cls-1" data-name="<Transparent Rectangle>" height="32" id="_Transparent_Rectangle_" width="32"/></svg> \ No newline at end of file diff --git a/b_asic/scheduler-gui/icons/misc_rc.py b/b_asic/scheduler-gui/icons/misc_rc.py new file mode 100644 index 00000000..4dab2371 --- /dev/null +++ b/b_asic/scheduler-gui/icons/misc_rc.py @@ -0,0 +1,101 @@ +# Resource object code (Python 3) +# Created by: object code +# Created by: The Resource Compiler for Qt version 5.15.3 +# WARNING! All changes made in this file will be lost! + +from PySide2 import QtCore + +qt_resource_data = b"\ +\x00\x00\x01{\ +<\ +?xml version=\x221.\ +0\x22 ?><svg id=\x22ic\ +on\x22 viewBox=\x220 0\ + 32 32\x22 xmlns=\x22h\ +ttp://www.w3.org\ +/2000/svg\x22><defs\ +><style>.cls-1{f\ +ill:none;}</styl\ +e></defs><title/\ +><path d=\x22M28,4H\ +4A2,2,0,0,0,2,6V\ +26a2,2,0,0,0,2,2\ +H28a2,2,0,0,0,2-\ +2V6A2,2,0,0,0,28\ +,4ZM4,6H20V26H4Z\ +M28,26H22V6h6Z\x22/\ +><rect class=\x22cl\ +s-1\x22 data-name=\x22\ +<Transparent \ +Rectangle>\x22 h\ +eight=\x2232\x22 id=\x22_\ +Transparent_Rect\ +angle_\x22 width=\x223\ +2\x22/></svg>\ +\x00\x00\x01m\ +<\ +?xml version=\x221.\ +0\x22 ?><svg id=\x22ic\ +on\x22 viewBox=\x220 0\ + 32 32\x22 xmlns=\x22h\ +ttp://www.w3.org\ +/2000/svg\x22><defs\ +><style>.cls-1{f\ +ill:none;}</styl\ +e></defs><title/\ +><path d=\x22M28,4H\ +4A2,2,0,0,0,2,6V\ +26a2,2,0,0,0,2,2\ +H28a2,2,0,0,0,2-\ +2V6A2,2,0,0,0,28\ +,4ZM4,6H20V26H4Z\ +\x22/><rect class=\x22\ +cls-1\x22 data-name\ +=\x22<Transparen\ +t Rectangle>\x22\ + height=\x2232\x22 id=\ +\x22_Transparent_Re\ +ctangle_\x22 width=\ +\x2232\x22/></svg>\ +" + +qt_resource_name = b"\ +\x00\x05\ +\x00o\xa6S\ +\x00i\ +\x00c\x00o\x00n\x00s\ +\x00\x04\ +\x00\x07@\x93\ +\x00m\ +\x00i\x00s\x00c\ +\x00\x0f\ +\x0fJu\xa7\ +\x00r\ +\x00i\x00g\x00h\x00t\x00_\x00p\x00a\x00n\x00e\x00l\x00.\x00s\x00v\x00g\ +\x00\x16\ +\x0f`\xd9\xe7\ +\x00r\ +\x00i\x00g\x00h\x00t\x00_\x00f\x00i\x00l\x00l\x00e\x00d\x00_\x00p\x00a\x00n\x00e\ +\x00l\x00.\x00s\x00v\x00g\ +" + +qt_resource_struct = b"\ +\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x01\ +\x00\x00\x00\x00\x00\x00\x00\x00\ +\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x02\ +\x00\x00\x00\x00\x00\x00\x00\x00\ +\x00\x00\x00\x10\x00\x02\x00\x00\x00\x02\x00\x00\x00\x03\ +\x00\x00\x00\x00\x00\x00\x00\x00\ +\x00\x00\x00\x1e\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\ +\x00\x00\x01\x81\xf9{\xbdx\ +\x00\x00\x00B\x00\x00\x00\x00\x00\x01\x00\x00\x01\x7f\ +\x00\x00\x01\x81\xf9|!l\ +" + +def qInitResources(): + QtCore.qRegisterResourceData(0x03, qt_resource_struct, qt_resource_name, qt_resource_data) + +def qCleanupResources(): + QtCore.qUnregisterResourceData(0x03, qt_resource_struct, qt_resource_name, qt_resource_data) + +qInitResources() diff --git a/b_asic/scheduler-gui/main_window.py b/b_asic/scheduler-gui/main_window.py index 39387b72..530dc3c6 100644 --- a/b_asic/scheduler-gui/main_window.py +++ b/b_asic/scheduler-gui/main_window.py @@ -103,14 +103,17 @@ QCoreApplication.setApplicationName('B-ASIC Scheduler') class MainWindow(QMainWindow, Ui_MainWindow): """Schedule of an SFG with scheduled Operations.""" - _schedules: dict - _schedule_id: int + # _schedules: dict + _scenes: dict[str, GraphicsScene] + _scene_count: int + _open_file_dialog_opened: bool def __init__(self): """Initialize Schedule-gui.""" - super(MainWindow, self).__init__() - self._schedules = {} - self._schedule_id = 0 + super().__init__() + self._scenes = {} + self._scene_count = 0 + self._open_file_dialog_opened = False QIcon.setThemeName('breeze') log.debug('themeName: \'{}\''.format(QIcon.themeName())) @@ -151,11 +154,11 @@ class MainWindow(QMainWindow, Ui_MainWindow): def _init_graphics_view(self) -> None: """Initialize the QGraphics framework""" - self.graphic_scene = GraphicsScene(0, parent=self) - self.graphic_view.setScene(self.graphic_scene) - self.graphic_view.setRenderHint(QPainter.Antialiasing) - self.graphic_view.setGeometry(20, 20, self.width(), self.height()) - self.graphic_view.setDragMode(QGraphicsView.RubberBandDrag) + # scene = GraphicsScene(0, parent=self) + # self.graphic_view.setScene(scene) + # self.graphic_view.setRenderHint(QPainter.Antialiasing) + # self.graphic_view.setGeometry(20, 20, self.width(), self.height()) + # self.graphic_view.setDragMode(QGraphicsView.RubberBandDrag) @@ -165,18 +168,24 @@ class MainWindow(QMainWindow, Ui_MainWindow): ############### @Slot() def callback_pushButton(self) -> None: - self.printButtonPressed('callback_pushButton()') + print('_scene_count:', self._scene_count) + print('From MainWindow:') + pprint(self._scenes[self._scene_count - 1].schedule()) + print('') + # self.printButtonPressed('callback_pushButton()') @Slot() def _load_schedule_from_pyfile(self) -> None: + open_dir = QStandardPaths.standardLocations(QStandardPaths.HomeLocation)[0] if not self._open_file_dialog_opened else '' abs_path_filename = QFileDialog.getOpenFileName(self, self.tr("Open python file"), - QStandardPaths.standardLocations(QStandardPaths.HomeLocation)[0], + open_dir, self.tr("Python Files (*.py *.py3)")) abs_path_filename = abs_path_filename[0] if not abs_path_filename: # return if empty filename (QFileDialog was canceled) return log.debug('abs_path_filename = {}.'.format(abs_path_filename)) + self._open_file_dialog_opened = True module_name = inspect.getmodulename(abs_path_filename) if not module_name: # return if empty module name @@ -220,13 +229,19 @@ class MainWindow(QMainWindow, Ui_MainWindow): #TODO: Unique hash keys #TODO: self.open(schedule_obj_list[ret_tuple[0]) - self._schedules[self._schedule_id] = schedule - self._schedule_id += 1 - print(self._schedule_id) - pprint(self._schedules) + + scene = GraphicsScene(self._scene_count, schedule, self) + #scene = QGraphicsScene() + self._scenes[self._scene_count] = scene + # self.graphic_view.setScene(scene) + # self.graphic_view.setRenderHint(QPainter.Antialiasing) + # self.graphic_view.setGeometry(20, 20, self.width(), self.height()) + # self.graphic_view.setDragMode(QGraphicsView.RubberBandDrag) + + + self._scene_count += 1 - self.printButtonPressed('load_sfg()') - self.update_statusbar(self.tr('SFG loaded successfully')) + self.update_statusbar(self.tr('Schedule loaded successfully')) @Slot() def save(self) -> None: @@ -307,6 +322,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): event.accept() else: event.ignore() + ################################# @@ -356,9 +372,9 @@ class MainWindow(QMainWindow, Ui_MainWindow): log.debug('Settings read from \'{}\'.'.format(s.fileName())) + def start_gui(): app = QApplication(sys.argv) - window = MainWindow() window.show() sys.exit(app.exec_()) diff --git a/b_asic/scheduler-gui/main_window.ui b/b_asic/scheduler-gui/main_window.ui index 7d808406..5332ae48 100644 --- a/b_asic/scheduler-gui/main_window.ui +++ b/b_asic/scheduler-gui/main_window.ui @@ -213,8 +213,9 @@ <bool>true</bool> </property> <property name="icon"> - <iconset theme="application-menu"> - <normaloff>.</normaloff>.</iconset> + <iconset resource="icons/misc.qrc"> + <normaloff>:/icons/misc/right_panel.svg</normaloff> + <normalon>:/icons/misc/right_filled_panel.svg</normalon>:/icons/misc/right_panel.svg</iconset> </property> <property name="text"> <string>&Node Info</string> @@ -264,6 +265,7 @@ </widget> <resources> <include location="icons/basic.qrc"/> + <include location="icons/misc.qrc"/> <include location="icons/breeze.qrc"/> <include location="icons/breeze_dark.qrc"/> </resources> -- GitLab