Skip to content
Snippets Groups Projects
Commit 2a9c4ca9 authored by Andreas Bolin's avatar Andreas Bolin
Browse files

workspace dump

parent 2769576c
Branches
No related tags found
1 merge request!78Add scheduler GUI
Pipeline #73063 passed
This commit is part of merge request !78. Comments created here will be created in the context of that merge request.
......@@ -13,14 +13,14 @@ from qtpy import QtWidgets
# QGraphics and QPainter imports
from qtpy.QtCore import (
Qt, QObject, QRect, QRectF, QPoint, QSize, QSizeF, QByteArray)
Qt, QObject, QRect, QRectF, QPoint, QSize, QSizeF, QByteArray, Slot)
from qtpy.QtGui import (
QPaintEvent, QPainter, QPainterPath, QColor, QBrush, QPen, QFont, QPolygon, QIcon, QPixmap,
QLinearGradient, QTransform)
QLinearGradient, QTransform, QMatrix)
from qtpy.QtWidgets import (
QGraphicsView, QGraphicsScene, QGraphicsWidget,
QGraphicsLayout, QGraphicsLinearLayout, QGraphicsGridLayout, QGraphicsLayoutItem, QGraphicsAnchorLayout,
QGraphicsItem, QGraphicsItemGroup, QGraphicsPathItem,
QGraphicsItem, QGraphicsItemGroup, QGraphicsPathItem, QGraphicsRectItem,
QStyleOptionGraphicsItem, QWidget)
from qtpy.QtCore import (
QPoint, QPointF)
......@@ -30,42 +30,28 @@ import logger
from b_asic.schedule import Schedule
# class ComponentItem(QGraphicsItemGroup, QGraphicsLayoutItem):
class ComponentItem(QGraphicsItemGroup):
# class ComponentItem(QGraphicsLayoutItem, QGraphicsItemGroup):
# class ComponentItem(QGraphicsLayoutItem, QGraphicsItem):
_scale: float
_scale: float = 1.0
_height: float
_component_item: QGraphicsPathItem
_execution_time_item: QGraphicsPathItem
_item_group: QGraphicsItemGroup
def __init__(self, scale: float, height: float = 1.5):
super().__init__()
def __init__(self, height: float = 1.0, parent: QGraphicsItem = None):
super().__init__(parent)
self._scale = scale
self._height = height
self._component_item = QGraphicsPathItem()
print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! A')
self._item_group = QGraphicsItemGroup()
print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! B')
self._populate()
self.setFlag(QGraphicsItem.ItemIsMovable)
self.setFlag(QGraphicsItem.ItemIsSelectable)
# print(self.boundingRect().size())
@property
def scale(self) -> float:
return self._scale
@scale.setter
def scale(self, scale: float) -> None:
self._scale = scale()
self.prepareGeometryChange()
self.update()
self._populate()
@property
def height(self) -> float:
return self._height
......@@ -93,11 +79,11 @@ class ComponentItem(QGraphicsItemGroup):
self._component_item.setPath(component_path)
self._component_item.setPen(pen)
self._component_item.setBrush(brush)
self._component_item.setPos(0.5,0) # in parent (i.e. item_group) coordinates
self._component_item.setPos(1, 0) # in parent (i.e. self) coordinates
# execution time square
execution_time_path = QPainterPath(QPoint(0,0))
execution_time_path.addRect(0, 0, self._height, self._height)
execution_time_path.addRect(0, 0, 2.0, self._height)
# execution time item
green_color = QColor(Qt.magenta)
......@@ -107,41 +93,11 @@ class ComponentItem(QGraphicsItemGroup):
self._execution_time_item.setPen(pen)
# item group, consist of time_item and component_item
# item_group = QGraphicsItemGroup()
# graphics_item = self.graphicsItem()
# print(graphics_item)
# self._item_group = graphics_item.childItems()[0]
# print(self._item_group)
# # item_group.setScale(self._scale)
# print('############################# 1')
# self._item_group.addToGroup(self._component_item)
# print('############################# 2')
# self._item_group.addToGroup(self._execution_time_item)
print('############################# 1')
self.addToGroup(self._component_item)
print('############################# 2')
self.addToGroup(self._execution_time_item)
# self.setGraphicsItem(self)
# QGraphicsItemGroup
# self.setGroup(item_group)
print('Populated!')
# # reimplement QGraphicsItem virtual functions
# def boundingRect(self) -> QRectF:
# print('boundingRect()')
# # return self._item_group.boundingRect()
# return QRectF(QPointF(0,0), self.geometry().size())
# def paint(self, painter: QPainter, option: QStyleOptionGraphicsItem, widget: Optional[QWidget]= None) -> None:
# print(f'paint(painter={painter}, option={option}, widget={widget})')
# painter.drawRoundedRect(-10, -10, 20, 20, 5, 5)
# # self._item_group.paint(painter, option, widget)
# print("MRO:")
# pprint(ComponentItem.__mro__)
\ No newline at end of file
# move: https://evileg.com/en/post/86/
# inherit QObject
# void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
# void mousePressEvent(QGraphicsSceneMouseEvent *event);
# void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
\ No newline at end of file
......@@ -22,8 +22,8 @@ from qtpy.QtGui import (
from qtpy.QtWidgets import (
QGraphicsView, QGraphicsScene, QGraphicsWidget,
QGraphicsLayout, QGraphicsLinearLayout, QGraphicsGridLayout, QGraphicsLayoutItem, QGraphicsAnchorLayout,
QGraphicsItem, QGraphicsItemGroup, QGraphicsPathItem, QGraphicsLineItem, QGraphicsTextItem,
QStyleOptionGraphicsItem, QWidget, QGraphicsObject)
QGraphicsItem, QGraphicsItemGroup, QGraphicsPathItem, QGraphicsLineItem, QGraphicsTextItem, QGraphicsRectItem,
QStyleOptionGraphicsItem, QWidget, QGraphicsObject, QGraphicsSimpleTextItem)
from qtpy.QtCore import (
QPoint, QPointF)
......@@ -34,16 +34,15 @@ import logger
class GraphicsAxis(QGraphicsItemGroup):
_scale: float
_scale: float = 1.0
_width: float
_height: float
_axis: dict[str: Any]
def __init__(self, scale: float, width: float = 0.0, height: float = 0.0):
super().__init__()
def __init__(self, width: float = 1.0, height: float = 1.0, parent: QGraphicsItem = None):
super().__init__(parent)
self._scale = scale
self._width = width
self._height = height
self._axis = {}
......@@ -56,22 +55,22 @@ class GraphicsAxis(QGraphicsItemGroup):
@property
def width(self) -> float:
return self._axis['w']
@width.setter
def width(self, width: float) -> None:
self._axis['w'] = width
self.prepareGeometryChange()
self._axis.clear()
self._make_axis()
# @width.setter
# def width(self, width: float) -> None:
# self._axis['w'] = width
# self.prepareGeometryChange()
# self._axis.clear()
# self._make_axis()
@property
def height(self) -> float:
return self._axis['h']
@height.setter
def height(self, height: float) -> None:
self._axis['h'] = height
self.prepareGeometryChange()
self._axis.clear()
self._make_axis()
# @height.setter
# def height(self, height: float) -> None:
# self._axis['h'] = height
# self.prepareGeometryChange()
# self._axis.clear()
# self._make_axis()
# def _clear(self) -> None:
# for child in self._axis.values():
......@@ -84,37 +83,51 @@ class GraphicsAxis(QGraphicsItemGroup):
# x-axis
self._axis['x'] = QGraphicsItemGroup()
line1 = QGraphicsLineItem(0, 0, self._width, 0)
line1.setPen(pen)
self._axis['x'].addToGroup(line1)
line = QGraphicsLineItem(0, 0, self._width, 0)
line.setPen(pen)
self._axis['x'].addToGroup(line)
# x-axis arrow
line2 = QGraphicsLineItem(0, 0, -5/self._scale, -5/self._scale)
line2.setPen(pen)
line2.setPos(self._width, 0)
self._axis['x'].addToGroup(line2)
line3 = QGraphicsLineItem(0, 0, -5/self._scale, 5/self._scale)
line3.setPen(pen)
line3.setPos(self._width, 0)
self._axis['x'].addToGroup(line3)
self._axis['x'].setPos(0, self._height)
arrow_line1 = QGraphicsLineItem(0, 0, -0.05, -0.05)
arrow_line1.setPen(pen)
arrow_line1.setPos(self._width, 0)
self._axis['x'].addToGroup(arrow_line1)
arrow_line2 = QGraphicsLineItem(0, 0, -0.05, 0.05)
arrow_line2.setPen(pen)
arrow_line2.setPos(self._width, 0)
self._axis['x'].addToGroup(arrow_line2)
# x-axis scale
ticks = [x for x in range(int(self._width) + 1)]
# ticks = [x for x in range(int(self._width) + 1)]
# print(f'{range(int(self._width) + 1)}')
# print('xxxxxxxxxxxxxxxxxxxxxxx', x)
line4 = QGraphicsLineItem(0, -5/self._scale, 0, 5/self._scale)
# for i in range(len(ticks)):
# lines[i] =
x_scale = []
x_scale_labels = []
for i in range(int(self._width) + 1):
# vertical x-scale
x_scale.append(QGraphicsLineItem(0, -0.05, 0, 0.05))
x_scale[i].setPen(pen)
x_scale[i].setPos(0.2 + i, 0)
self._axis['x'].addToGroup(x_scale[i])
# numbers
x_scale_labels.append(QGraphicsSimpleTextItem(str(i)))
x_scale_labels[i].setScale(x_scale_labels[i].scale() / self._scale)
x_scale_labels[i].setPen(pen)
x_scale_labels[i].setPos(0.16 + i, 0.08)
self._axis['x'].addToGroup(x_scale_labels[i])
# x-axis label
label = QGraphicsTextItem('time')
label.setFlag(QGraphicsItem.ItemIgnoresTransformations)
label.setPos(self._width, self._height + 5/self._scale)
label = QGraphicsSimpleTextItem('time')
label.setScale(label.scale() / self._scale)
label.setPos(self._width - 0.18, 0.08)
self._axis['x'].addToGroup(label)
self._axis['x'].boundingRect()
# add x-axis
self._axis['x'].setPos(0, self._height)
self.addToGroup(self._axis['x'])
self.addToGroup(label)
# y-axis
self._axis['y'] = QGraphicsLineItem(0, 0, 0, self._height)
self._axis['y'].setPen(pen)
self._axis['y'].setPos(0, 0)
# add y-axis
self.addToGroup(self._axis['y'])
\ No newline at end of file
self.addToGroup(self._axis['y'])
\ No newline at end of file
......@@ -15,14 +15,14 @@ from qtpy import QtWidgets
# QGraphics and QPainter imports
from qtpy.QtCore import (
Qt, QObject, QRect, QRectF, QPoint, QSize, QSizeF, QByteArray)
Qt, QObject, QRect, QRectF, QPoint, QSize, QSizeF, QByteArray, Slot)
from qtpy.QtGui import (
QPaintEvent, QPainter, QPainterPath, QColor, QBrush, QPen, QFont, QPolygon, QIcon, QPixmap,
QLinearGradient, QTransform)
from qtpy.QtWidgets import (
QGraphicsView, QGraphicsScene, QGraphicsWidget,
QGraphicsLayout, QGraphicsLinearLayout, QGraphicsGridLayout, QGraphicsLayoutItem, QGraphicsAnchorLayout,
QGraphicsItem, QGraphicsItemGroup, QGraphicsPathItem, QGraphicsLineItem,
QGraphicsItem, QGraphicsItemGroup, QGraphicsPathItem, QGraphicsLineItem, QGraphicsRectItem,
QStyleOptionGraphicsItem, QWidget, QGraphicsObject)
from qtpy.QtCore import (
QPoint, QPointF)
......@@ -37,50 +37,56 @@ from graphics_axis import GraphicsAxis
class GraphicsGraph(QGraphicsItemGroup):
_schedule: Schedule
_scale: float
_axis: dict[str, QGraphicsLineItem] # {'x': <x-axis>, 'y': y-axis}
_axis: GraphicsAxis
_component_group: QGraphicsItemGroup
_axis_group: QGraphicsItemGroup
def __init__(self, schedule: Schedule, scale: float = 100.0, *args, **kwargs):
super().__init__(*args, **kwargs)
def __init__(self, schedule: Schedule, parent: QGraphicsItem = None):
super().__init__(parent)
self._schedule = deepcopy(schedule)
self._scale = scale
self._axis = {}
self._axis = None
self._component_group = QGraphicsItemGroup()
self._axis_group = QGraphicsItemGroup()
# add components
y: float = 0.0
for i in range(3):
component = ComponentItem(self._scale)
for i in range(5):
component = ComponentItem()
component.setPos(0, y)
self._component_group.addToGroup(component)
y += component.height + 0.2
self._component_group.setPos(0.2, 0.1)
self.addToGroup(self._component_group)
y += 0.1
# add x-axis
# self._component_group.boundingRect().width()
axis = GraphicsAxis(self._scale, 5, y)
self.addToGroup(axis)
# add axis
self._axis = GraphicsAxis(5 + 0.6, y)
self.addToGroup(self._axis)
# @property
# def scale(self) -> float:
# return self._scale
# @scale.setter
# def scale(self, scale:float) -> None:
# self._scale = scale
# for component in self._component_group.childItems():
# component.scale = scale
# @staticmethod
@property
def scale(self) -> float:
return self._scale
@scale.setter
def scale(self, scale:float) -> None:
self._scale = scale
for component in self._component_group.childItems():
component.scale = scale
def axis(self) -> GraphicsAxis:
return self._axis
@property
def items(self) -> list[ComponentItem]:
return self._component_group.childItems()
\ No newline at end of file
return self._component_group.childItems()
\ No newline at end of file
......@@ -25,7 +25,7 @@ import inspect
# Qt/qtpy
import qtpy
from qtpy import uic, QtCore, QtGui, QtWidgets
from qtpy.QtCore import QCoreApplication, Qt, Slot, QSettings, QStandardPaths
from qtpy.QtCore import QCoreApplication, Qt, Slot, Signal, QSettings, QStandardPaths
from qtpy.QtGui import QCloseEvent
from qtpy.QtWidgets import (
QApplication, QMainWindow, QMessageBox, QFileDialog, QInputDialog, QCheckBox, QAbstractButton,
......@@ -38,14 +38,15 @@ from qtpy.QtGui import (
QPaintEvent, QPainter, QPainterPath, QColor, QBrush, QPen, QFont, QPolygon, QIcon, QPixmap,
QLinearGradient)
from qtpy.QtWidgets import (
QGraphicsView, QGraphicsScene, QGraphicsWidget,
QGraphicsView, QGraphicsScene, QGraphicsWidget, QGraphicsScale,
QGraphicsLayout, QGraphicsLinearLayout, QGraphicsGridLayout, QGraphicsLayoutItem, QGraphicsAnchorLayout,
QGraphicsItem, QGraphicsItemGroup)
# B-ASIC
import logger
from b_asic.schedule import Schedule
from graphics_graph import GraphicsGraph
from graphics_graph import GraphicsGraph
from graphics_axis import GraphicsAxis
from component_item import ComponentItem
......@@ -116,6 +117,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
_scene_count: int
_open_file_dialog_opened: bool
_scale: float
def __init__(self):
"""Initialize Schedule-gui."""
......@@ -125,7 +127,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self._scene_count = 0
self._graph_count = 0
self._open_file_dialog_opened = False
self._scale = 100.0
self._scale = 75.0
QIcon.setThemeName('breeze')
log.debug('themeName: \'{}\''.format(QIcon.themeName()))
......@@ -176,10 +178,12 @@ class MainWindow(QMainWindow, Ui_MainWindow):
# self.graphic_view.setScene(scene)
# self.graphic_view.setRenderHint(QPainter.Antialiasing)
# self.graphic_view.setGeometry(20, 20, self.width(), self.height())
self.graphics_view.setDragMode(QGraphicsView.RubberBandDrag)
self.graphics_view.scale(self._scale, self._scale)
self._scene = QGraphicsScene()
self.graphics_view.setDragMode(QGraphicsView.RubberBandDrag)
self.graphics_view.setScene(self._scene)
self.graphics_view.scale(self._scale, self._scale)
ComponentItem._scale = self._scale
GraphicsAxis._scale = self._scale
......@@ -270,11 +274,28 @@ class MainWindow(QMainWindow, Ui_MainWindow):
# self._scene_count += 1
graph = GraphicsGraph(schedule, self._scale)
graph = GraphicsGraph(schedule)
# graph.setPos(200, 20)
self._scene.addItem(graph)
# Debug rectangles
# if __debug__:
# self._scene.setSceneRect(self._scene.itemsBoundingRect()) # Forces the scene to it's minimum size
# pen = QPen(Qt.red)
# pen.setStyle(Qt.DashLine)
# pen.setCosmetic(True)
# for component in graph.items:
# self._scene.addRect(component.mapRectToScene(component.boundingRect()), pen)
# for axis in graph.axis.childItems():
# self._scene.addRect(axis.mapRectToScene(axis.boundingRect()), pen)
# pen.setColor(Qt.green)
# self._scene.addRect(self._scene.itemsBoundingRect(), pen)
# self._scene.setSceneRect(self._scene.itemsBoundingRect())
print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 4')
self._graphs[self._graph_count] = graph
self._graph_count += 1
self.update_statusbar(self.tr('Schedule loaded successfully'))
......
......@@ -53,6 +53,9 @@
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="renderHints">
<set>QPainter::HighQualityAntialiasing|QPainter::TextAntialiasing</set>
</property>
</widget>
<widget class="QTableWidget" name="info_table">
<property name="editTriggers">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment