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

workspace dump

parent de85ead4
No related branches found
No related tags found
1 merge request!78Add scheduler GUI
Pipeline #73245 passed
...@@ -55,7 +55,7 @@ class GraphicsAxisItem(QGraphicsItemGroup): ...@@ -55,7 +55,7 @@ class GraphicsAxisItem(QGraphicsItemGroup):
# self.setFlag(QGraphicsItem.ItemIsSelectable) # self.setFlag(QGraphicsItem.ItemIsSelectable)
# self.setAcceptHoverEvents(True) # self.setAcceptHoverEvents(True)
self.update_(width, height, x_indent) self.update_(width*10.0 + 6, height, x_indent)
@property @property
......
...@@ -24,7 +24,7 @@ from qtpy.QtWidgets import ( ...@@ -24,7 +24,7 @@ from qtpy.QtWidgets import (
QGraphicsView, QGraphicsScene, QGraphicsWidget, QGraphicsView, QGraphicsScene, QGraphicsWidget,
QGraphicsLayout, QGraphicsLinearLayout, QGraphicsGridLayout, QGraphicsLayoutItem, QGraphicsAnchorLayout, QGraphicsLayout, QGraphicsLinearLayout, QGraphicsGridLayout, QGraphicsLayoutItem, QGraphicsAnchorLayout,
QGraphicsItem, QGraphicsItemGroup, QGraphicsPathItem, QGraphicsRectItem, QGraphicsItem, QGraphicsItemGroup, QGraphicsPathItem, QGraphicsRectItem,
QStyleOptionGraphicsItem, QWidget, QGraphicsObject, QGraphicsSceneMouseEvent) QStyleOptionGraphicsItem, QWidget, QGraphicsObject, QGraphicsSceneMouseEvent, QGraphicsSimpleTextItem)
from qtpy.QtCore import ( from qtpy.QtCore import (
QPoint, QPointF) QPoint, QPointF)
...@@ -37,15 +37,18 @@ from graphics_component_event import GraphicsComponentEvent ...@@ -37,15 +37,18 @@ from graphics_component_event import GraphicsComponentEvent
class GraphicsComponentItem(QGraphicsItemGroup): class GraphicsComponentItem(QGraphicsItemGroup):
_scale: float = 1.0 # static, changed from MainWindow _scale: float = 1.0 # static, changed from MainWindow
_op_id: str
_height: float _height: float
_component_item: QGraphicsPathItem _component_item: QGraphicsPathItem
_execution_time_item: QGraphicsPathItem _execution_time_item: QGraphicsPathItem
_text_item: QGraphicsSimpleTextItem
_item_group: QGraphicsItemGroup _item_group: QGraphicsItemGroup
def __init__(self, height: float = 10.0, parent: QGraphicsItem = None): def __init__(self, op_id: str, height: float = 10.0, parent: QGraphicsItem = None):
super().__init__(parent) super().__init__(parent)
self._op_id = op_id
self._height = height self._height = height
self._component_item = QGraphicsPathItem() self._component_item = QGraphicsPathItem()
self._item_group = QGraphicsItemGroup() self._item_group = QGraphicsItemGroup()
...@@ -93,6 +96,13 @@ class GraphicsComponentItem(QGraphicsItemGroup): ...@@ -93,6 +96,13 @@ class GraphicsComponentItem(QGraphicsItemGroup):
self._component_item.setPen(pen) self._component_item.setPen(pen)
self._component_item.setBrush(brush) self._component_item.setBrush(brush)
self._component_item.setPos(10, 0) # in parent (i.e. self) coordinates self._component_item.setPos(10, 0) # in parent (i.e. self) coordinates
# op-id/label
label = QGraphicsSimpleTextItem(self._op_id)
label.setScale(label.scale() / self._scale)
center = self._component_item.boundingRect().center()
center -= label.boundingRect().center() / self._scale
label.setPos(self._component_item.pos() + center)
# execution time square # execution time square
execution_time_path = QPainterPath(QPoint(0,0)) execution_time_path = QPainterPath(QPoint(0,0))
...@@ -107,6 +117,7 @@ class GraphicsComponentItem(QGraphicsItemGroup): ...@@ -107,6 +117,7 @@ class GraphicsComponentItem(QGraphicsItemGroup):
# item group, consist of time_item and component_item # item group, consist of time_item and component_item
self.addToGroup(self._component_item) self.addToGroup(self._component_item)
self.addToGroup(label)
self.addToGroup(self._execution_time_item) self.addToGroup(self._execution_time_item)
# move: https://evileg.com/en/post/86/ # move: https://evileg.com/en/post/86/
......
...@@ -34,6 +34,8 @@ from qtpy.QtCore import ( ...@@ -34,6 +34,8 @@ from qtpy.QtCore import (
# B-ASIC # B-ASIC
import logger import logger
from b_asic.schedule import Schedule from b_asic.schedule import Schedule
from b_asic.graph_component import GraphComponent
from b_asic.special_operations import Input, Output
from graphics_component_item import GraphicsComponentItem from graphics_component_item import GraphicsComponentItem
from graphics_axis_item import GraphicsAxisItem from graphics_axis_item import GraphicsAxisItem
from graphics_graph_event import GraphicsGraphEvent from graphics_graph_event import GraphicsGraphEvent
...@@ -72,21 +74,33 @@ class GraphicsGraphItem(QGraphicsItemGroup, GraphicsGraphEvent): ...@@ -72,21 +74,33 @@ class GraphicsGraphItem(QGraphicsItemGroup, GraphicsGraphEvent):
self._components_height = 0.0 self._components_height = 0.0
self._x_axis_indent = 2.0 self._x_axis_indent = 2.0
# build components # build components
spacing = 2.0 spacing = 2.0
for i in range(5): # print('Start times:')
self._components_height += spacing for op_id, op_start_time in self._schedule._start_times.items():
component = GraphicsComponentItem() op = self._schedule._sfg.find_by_id(op_id)
component.setPos(self._x_axis_indent, self._components_height) print(f'type: {type(op).__name__:<24}', end='\t')
self._components.append(component) print(op)
# self._components.addToGroup(component) # slacks = self._schedule.slacks(op_id)
self._components_height += component.height # print(f'{op_id:<5} {slacks}')
# self._components.setPos(self._x_axis_indent, spacing) # op.latency_offsets -> [[int]]
# op.latency() -> int (max of all ports)
latency = op.latency_offsets
print(f'latency: {latency}')
if not isinstance(op, (Input, Output)):
self._components_height += spacing
component = GraphicsComponentItem(op_id)
component.setPos(self._x_axis_indent + op_start_time*10, self._components_height)
self._components.append(component)
self._components_height += component.height
self._components_height += spacing self._components_height += spacing
# build axis # build axis
self._axis = GraphicsAxisItem(50 + 6, self._components_height, self._x_axis_indent) schedule_time: int = 0
schedule_time = self._schedule.schedule_time
self._axis = GraphicsAxisItem(schedule_time, self._components_height, self._x_axis_indent)
# add axis and components # add axis and components
self.addToGroup(self._axis) self.addToGroup(self._axis)
for component in self._components: for component in self._components:
......
...@@ -117,7 +117,6 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -117,7 +117,6 @@ class MainWindow(QMainWindow, Ui_MainWindow):
"""Schedule of an SFG with scheduled Operations.""" """Schedule of an SFG with scheduled Operations."""
_scene: QGraphicsScene _scene: QGraphicsScene
_graph: GraphicsGraphItem _graph: GraphicsGraphItem
_open_file_dialog_opened: bool
_scale: float _scale: float
_debug_rects: QGraphicsItemGroup _debug_rects: QGraphicsItemGroup
...@@ -127,7 +126,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -127,7 +126,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
super().__init__() super().__init__()
self._graph = None self._graph = None
self._open_file_dialog_opened = False self._open_file_dialog_opened = False
self._scale = 10.0 self._scale = 7.5
self._debug_rects = None self._debug_rects = None
QIcon.setThemeName('breeze') QIcon.setThemeName('breeze')
...@@ -151,7 +150,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -151,7 +150,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.menu_node_info .triggered .connect(self.toggle_component_info) self.menu_node_info .triggered .connect(self.toggle_component_info)
self.menu_exit_dialog .triggered .connect(self.toggle_exit_dialog) self.menu_exit_dialog .triggered .connect(self.toggle_exit_dialog)
self.actionT .triggered .connect(self.actionTbtn) self.actionT .triggered .connect(self.actionTbtn)
self.splitter_center .splitterMoved .connect(self._splitter_center_moved) self.splitter .splitterMoved .connect(self._splitter_moved)
# Setup event member functions # Setup event member functions
self.closeEvent = self._close_event self.closeEvent = self._close_event
...@@ -168,17 +167,16 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -168,17 +167,16 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.info_table.setItem(i,1,item) self.info_table.setItem(i,1,item)
# Init central-widget splitter # Init central-widget splitter
self.splitter_center.setStretchFactor(0, 1) self.splitter.setStretchFactor(0, 1)
self.splitter_center.setStretchFactor(1, 0) self.splitter.setStretchFactor(1, 0)
self.splitter_center.setCollapsible(0, False) self.splitter.setCollapsible(0, False)
self.splitter_center.setCollapsible(1, True) self.splitter.setCollapsible(1, True)
def _init_graphics(self) -> None: def _init_graphics(self) -> None:
"""Initialize the QGraphics framework""" """Initialize the QGraphics framework"""
self._scene = QGraphicsScene() self._scene = QGraphicsScene()
self.view.setScene(self._scene) self.view.setScene(self._scene)
self.view.scale(self._scale, self._scale) self.view.scale(self._scale, self._scale)
# self.setMouseTracking(True)
GraphicsComponentItem._scale = self._scale GraphicsComponentItem._scale = self._scale
GraphicsAxisItem._scale = self._scale GraphicsAxisItem._scale = self._scale
self._scene.changed.connect(self.shrink_scene_to_min_size) self._scene.changed.connect(self.shrink_scene_to_min_size)
...@@ -196,13 +194,19 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -196,13 +194,19 @@ class MainWindow(QMainWindow, Ui_MainWindow):
@Slot() @Slot()
def _load_schedule_from_pyfile(self) -> None: def _load_schedule_from_pyfile(self) -> None:
open_dir = QStandardPaths.standardLocations(QStandardPaths.HomeLocation)[0] if not self._open_file_dialog_opened else '' settings = QSettings()
abs_path_filename = QFileDialog.getOpenFileName(self, # open_dir = QStandardPaths.standardLocations(QStandardPaths.HomeLocation)[0] if not self._open_file_dialog_opened else ''
last_file = settings.value('mainwindow/last_opened_file', QStandardPaths.standardLocations(QStandardPaths.HomeLocation)[0], str)
if not os.path.exists(last_file): # if filename does not exist
last_file = os.path.dirname(last_file) + '/'
if not os.path.exists(last_file): # if path does not exist
last_file = QStandardPaths.standardLocations(QStandardPaths.HomeLocation)[0]
abs_path_filename, _ = QFileDialog.getOpenFileName(self,
self.tr("Open python file"), self.tr("Open python file"),
open_dir, last_file,
self.tr("Python Files (*.py *.py3)")) 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) if not abs_path_filename: # return if empty filename (QFileDialog was canceled)
return return
log.debug('abs_path_filename = {}.'.format(abs_path_filename)) log.debug('abs_path_filename = {}.'.format(abs_path_filename))
...@@ -244,6 +248,8 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -244,6 +248,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.open(schedule_obj_list[ret_tuple[0]]) self.open(schedule_obj_list[ret_tuple[0]])
del module del module
settings.setValue("mainwindow/last_opened_file", abs_path_filename)
#@Slot() #@Slot()
...@@ -298,14 +304,14 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -298,14 +304,14 @@ class MainWindow(QMainWindow, Ui_MainWindow):
"""This method toggles the right hand side info window.""" """This method toggles the right hand side info window."""
# Note: splitter handler index 0 is a hidden splitter handle far most left, use index 1 # Note: splitter handler index 0 is a hidden splitter handle far most left, use index 1
settings = QSettings() settings = QSettings()
range = self.splitter_center.getRange(1) # tuple(min, max) range = self.splitter.getRange(1) # tuple(min, max)
if checked: if checked:
self.splitter_center.restoreState(settings.value("mainwindow/splitter_center/last_state")) self.splitter.restoreState(settings.value("mainwindow/splitter/last_state"))
# self.splitter_center.restoreState(settings.value("splitterSizes")) # self.splitter.restoreState(settings.value("splitterSizes"))
else: else:
settings.setValue("mainwindow/splitter_center/last_state", self.splitter_center.saveState()) settings.setValue("mainwindow/splitter/last_state", self.splitter.saveState())
self.splitter_center.moveSplitter(range[1], 1) self.splitter.moveSplitter(range[1], 1)
@Slot(bool) @Slot(bool)
def toggle_exit_dialog(self, checked: bool) -> None: def toggle_exit_dialog(self, checked: bool) -> None:
...@@ -313,18 +319,18 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -313,18 +319,18 @@ class MainWindow(QMainWindow, Ui_MainWindow):
s.setValue("mainwindow/hide_exit_dialog", checked) s.setValue("mainwindow/hide_exit_dialog", checked)
@Slot(int, int) @Slot(int, int)
def _splitter_center_moved(self, pos: int, index: int) -> None: def _splitter_moved(self, pos: int, index: int) -> None:
"""Callback method used to check if the right widget (info window) """Callback method used to check if the right widget (info window)
has collapsed. Update the checkbutton accordingly.""" has collapsed. Update the checkbutton accordingly."""
# TODO: Custom move handler, save state on click-release? # TODO: Custom move handler, save state on click-release?
widths: list[int, int] = list(self.splitter_center.sizes()) widths: list[int, int] = list(self.splitter.sizes())
if widths[1] == 0: if widths[1] == 0:
self.menu_node_info.setChecked(False) self.menu_node_info.setChecked(False)
else: else:
self.menu_node_info.setChecked(True) self.menu_node_info.setChecked(True)
@Slot(list) @Slot('QList<QRectF>')
def shrink_scene_to_min_size(self, region: list[QRectF]) -> None: def shrink_scene_to_min_size(self, region: list[QRectF]) -> None:
self._scene.setSceneRect(self._scene.itemsBoundingRect()) self._scene.setSceneRect(self._scene.itemsBoundingRect())
...@@ -387,7 +393,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -387,7 +393,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
s.setValue('mainwindow/size', self.size()) # window: size s.setValue('mainwindow/size', self.size()) # window: size
s.setValue('mainwindow/state', self.saveState()) # toolbars, dockwidgets: pos, size s.setValue('mainwindow/state', self.saveState()) # toolbars, dockwidgets: pos, size
s.setValue('mainwindow/menu/node_info', self.menu_node_info.isChecked()) s.setValue('mainwindow/menu/node_info', self.menu_node_info.isChecked())
s.setValue('mainwindow/splitter/state', self.splitter_center.saveState()) s.setValue('mainwindow/splitter/state', self.splitter.saveState())
if s.isWritable(): if s.isWritable():
log.debug('Settings written to \'{}\'.'.format(s.fileName())) log.debug('Settings written to \'{}\'.'.format(s.fileName()))
...@@ -404,8 +410,8 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -404,8 +410,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.resize( s.value('mainwindow/size', self.size())) self.resize( s.value('mainwindow/size', self.size()))
self.restoreState( s.value('mainwindow/state', QByteArray())) self.restoreState( s.value('mainwindow/state', QByteArray()))
self.menu_node_info.setChecked( s.value('mainwindow/menu/node_info', True, bool)) self.menu_node_info.setChecked( s.value('mainwindow/menu/node_info', True, bool))
self.splitter_center.restoreState( s.value('mainwindow/splitter/state', QByteArray())) self.splitter.restoreState( s.value('mainwindow/splitter/state', QByteArray()))
self.menu_exit_dialog.setChecked(s.value('mainwindow/hide_exit_dialog', False, bool)) self.menu_exit_dialog.setChecked( s.value('mainwindow/hide_exit_dialog', False, bool))
log.debug('Settings read from \'{}\'.'.format(s.fileName())) log.debug('Settings read from \'{}\'.'.format(s.fileName()))
......
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<widget class="QSplitter" name="splitter_center"> <widget class="QSplitter" name="splitter">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
...@@ -95,7 +95,7 @@ ...@@ -95,7 +95,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>800</width> <width>800</width>
<height>20</height> <height>22</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuFile"> <widget class="QMenu" name="menuFile">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment