From 97dc434e735c63e558482b58164c16eae112bc66 Mon Sep 17 00:00:00 2001 From: Andreas Bolin <2535580+andbo467@users.noreply.github.com> Date: Wed, 13 Jul 2022 02:10:04 +0200 Subject: [PATCH] workspace dump --- b_asic/scheduler-gui/graphics_scene.py | 102 +++++++++++++++++++++++++ b_asic/scheduler-gui/main_window.py | 17 ++--- 2 files changed, 110 insertions(+), 9 deletions(-) create mode 100644 b_asic/scheduler-gui/graphics_scene.py diff --git a/b_asic/scheduler-gui/graphics_scene.py b/b_asic/scheduler-gui/graphics_scene.py new file mode 100644 index 00000000..ea907c75 --- /dev/null +++ b/b_asic/scheduler-gui/graphics_scene.py @@ -0,0 +1,102 @@ +# This Python file uses the following encoding: utf-8 +"""B-ASIC Scheduler-gui GraphicsScene Module. + +Contains the GraphicsScene class for drawing items on. +""" + + +import os +import sys +from typing import Any +from pprint import pprint +from typing import Any, AnyStr, Generic, Protocol, TypeVar, Union, Optional, overload +from typing_extensions import Self, Final, Literal, LiteralString, TypeAlias, final + +import qtpy +from qtpy import QtCore +from qtpy import QtGui +from qtpy import QtWidgets + +# QGraphics and QPainter imports +from qtpy.QtCore import ( + QObject, QRect, QRectF, QPoint, QSize, QByteArray) +from qtpy.QtGui import ( + QPaintEvent, QPainter, QPainterPath, QColor, QBrush, QPen, QFont, QPolygon, QIcon, QPixmap, + QLinearGradient) +from qtpy.QtWidgets import ( + QGraphicsView, QGraphicsScene, QGraphicsWidget, + QGraphicsLayout, QGraphicsLinearLayout, QGraphicsGridLayout, QGraphicsLayoutItem, QGraphicsAnchorLayout, + QGraphicsItem, QGraphicsItemGroup) + +# B-ASIC +import logger +from b_asic.schedule import Schedule + + + +@final +class GraphicsScene(QGraphicsScene): + """GraphicsScene subclass of QGraphicsScene acts as a scene to place items on""" + _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 + + # @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)) + + # def __init__(self, id: int): + # super(GraphicsScene, self).__init__() + # self._id = id + + + @property + def id(self): + return self._id + + @property + def schedule(self): + return self._schedule + + @schedule.setter + def schedule(self, schedule: Schedule): + self._schedule = schedule + +print('GraphicsScene.__mro__:') +pprint(GraphicsScene.__mro__) + diff --git a/b_asic/scheduler-gui/main_window.py b/b_asic/scheduler-gui/main_window.py index f5d9a884..abf49584 100644 --- a/b_asic/scheduler-gui/main_window.py +++ b/b_asic/scheduler-gui/main_window.py @@ -19,31 +19,30 @@ from pprint import pprint #from diagram import * from importlib.machinery import SourceFileLoader import inspect -from numpy import uint # Qt/qtpy import qtpy from qtpy import uic, QtCore, QtGui, QtWidgets from qtpy.QtCore import QCoreApplication, Qt, Slot, QSettings, QStandardPaths -#QtCore QSize, QPoint from qtpy.QtGui import QCloseEvent from qtpy.QtWidgets import ( QApplication, QMainWindow, QMessageBox, QFileDialog, QInputDialog, QCheckBox, QAbstractButton) # QGraphics and QPainter imports +from qtpy.QtCore import ( + QRect, QPoint, QSize, QByteArray) +from qtpy.QtGui import ( + QPaintEvent, QPainter, QPainterPath, QColor, QBrush, QPen, QFont, QPolygon, QIcon, QPixmap, + QLinearGradient) from qtpy.QtWidgets import ( QGraphicsView, QGraphicsScene, QGraphicsWidget, QGraphicsLayout, QGraphicsLinearLayout, QGraphicsGridLayout, QGraphicsLayoutItem, QGraphicsAnchorLayout, QGraphicsItem, QGraphicsItemGroup) -from qtpy.QtGui import ( - QPaintEvent, QPainter, QPainterPath, QColor, QBrush, QPen, QFont, QPolygon, QIcon, QPixmap, - QLinearGradient) -from qtpy.QtCore import ( - QRect, QPoint, QSize, QByteArray) # B-ASIC import logger from b_asic.schedule import Schedule +from graphics_scene import GraphicsScene log = logger.getLogger() @@ -103,7 +102,6 @@ QCoreApplication.setApplicationName('B-ASIC Scheduler') class MainWindow(QMainWindow, Ui_MainWindow): """Schedule of an SFG with scheduled Operations.""" - _schedules: dict _schedule_id: int @@ -151,12 +149,13 @@ class MainWindow(QMainWindow, Ui_MainWindow): def _init_graphics_view(self) -> None: """Initialize the QGraphics framework""" - self.graphic_scene = QGraphicsScene(self) + 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) + ############### -- GitLab