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

workspace dump

parent f2f7d332
No related branches found
No related tags found
1 merge request!78Add scheduler GUI
Pipeline #73104 passed
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from operator import contains from operator import contains
import os import os
import sys import sys
...@@ -48,9 +51,9 @@ class GraphicsAxisItem(QGraphicsItemGroup, GraphicsGraphEvent): ...@@ -48,9 +51,9 @@ class GraphicsAxisItem(QGraphicsItemGroup, GraphicsGraphEvent):
self._dy_height = 5/self._scale self._dy_height = 5/self._scale
self._axis = {} self._axis = {}
self.setFlag(QGraphicsItem.ItemIsMovable) # self.setFlag(QGraphicsItem.ItemIsMovable)
self.setFlag(QGraphicsItem.ItemIsSelectable) # self.setFlag(QGraphicsItem.ItemIsSelectable)
self.setAcceptHoverEvents(True) # self.setAcceptHoverEvents(True)
self.update(width, height, x_indent) self.update(width, height, x_indent)
......
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""TODO""" """TODO"""
import os import os
...@@ -32,28 +35,41 @@ from qtpy.QtCore import ( ...@@ -32,28 +35,41 @@ from qtpy.QtCore import (
class GraphicsComponentEvent(QGraphicsObject): class GraphicsComponentEvent(QGraphicsItem):
"""Event handler for GraphicsComponentItem""" """Event handler for GraphicsComponentItem"""
current_pos: QPointF
# _scale: float
def __init__(self, parent): def __init__(self, parent):
super().__init__() super().__init__()
# self.setAcceptedMouseButtons(Qt.LeftButton) # self.setAcceptedMouseButtons(Qt.LeftButton)
self.setFlag(QGraphicsItem.ItemIsMovable) # self.setAcceptedMouseButtons(Qt.NoButton)
self.setFlag(QGraphicsItem.ItemIsSelectable) # self.setFlag(QGraphicsItem.ItemIsMovable)
self.setAcceptHoverEvents(True) # self.setFlag(QGraphicsItem.ItemIsSelectable)
# self.setAcceptHoverEvents(True)
# self.setFlag(QGraphicsItem.ItemSendsGeometryChanges) # self.setFlag(QGraphicsItem.ItemSendsGeometryChanges)
def mouseMoveEvent(self, event: QGraphicsSceneMouseEvent) -> None: def mouseMoveEvent(self, event: QGraphicsSceneMouseEvent) -> None:
"""Set the position of the graphical element in the graphic scene, """Set the position of the graphical element in the graphic scene,
translate coordinates of the cursor within the graphic element translate coordinates of the cursor within the graphic element
in the coordinate system of the graphic scenes""" in the coordinate system of the parent object"""
print('GraphicsComponentEvent.mouseMoveEvent()')
# Qt.DragMoveCursor # Qt.DragMoveCursor
self.setPos(self.mapToScene(event.pos())) dx = (self.mapToParent(event.pos()) - self.current_pos).x()
if dx > 5.05:
# TODO: send signal
self.setX(self.x() + 10.0)
self.current_pos.setX(self.current_pos.x() + 10.0)
elif dx < -5.05:
# TODO: send signal
self.setX(self.x() - 10-0)
self.current_pos.setX(self.current_pos.x() - 10.0)
def mousePressEvent(self, event: QGraphicsSceneMouseEvent) -> None: def mousePressEvent(self, event: QGraphicsSceneMouseEvent) -> None:
"""Changes the cursor to ClosedHandCursor when grabbing an object""" """Changes the cursor to ClosedHandCursor when grabbing an object"""
print('GraphicsComponentEvent.mousePressEvent()') print('GraphicsComponentEvent.mousePressEvent()')
self.current_pos = self.mapToParent(event.pos())
self.setCursor(QCursor(Qt.ClosedHandCursor)) self.setCursor(QCursor(Qt.ClosedHandCursor))
event.accept() event.accept()
......
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os import os
import sys import sys
from typing import Any, Optional from typing import Any, Optional
...@@ -21,7 +24,7 @@ from qtpy.QtWidgets import ( ...@@ -21,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) QStyleOptionGraphicsItem, QWidget, QGraphicsObject, QGraphicsSceneMouseEvent)
from qtpy.QtCore import ( from qtpy.QtCore import (
QPoint, QPointF) QPoint, QPointF)
...@@ -31,7 +34,7 @@ from b_asic.schedule import Schedule ...@@ -31,7 +34,7 @@ from b_asic.schedule import Schedule
from graphics_component_event import GraphicsComponentEvent from graphics_component_event import GraphicsComponentEvent
class GraphicsComponentItem(QGraphicsItemGroup, GraphicsComponentEvent, QGraphicsObject): class GraphicsComponentItem(QGraphicsItemGroup, GraphicsComponentEvent):
_scale: float = 1.0 # static, changed from MainWindow _scale: float = 1.0 # static, changed from MainWindow
_height: float _height: float
...@@ -46,14 +49,19 @@ class GraphicsComponentItem(QGraphicsItemGroup, GraphicsComponentEvent, QGraphic ...@@ -46,14 +49,19 @@ class GraphicsComponentItem(QGraphicsItemGroup, GraphicsComponentEvent, QGraphic
self._height = height self._height = height
self._component_item = QGraphicsPathItem() self._component_item = QGraphicsPathItem()
self._item_group = QGraphicsItemGroup() self._item_group = QGraphicsItemGroup()
self.setFlag(QGraphicsItem.ItemIsMovable) self.setFlag(QGraphicsItem.ItemIsMovable)
self.setFlag(QGraphicsItem.ItemIsSelectable) # self.setFlag(QGraphicsItem.ItemIsSelectable)
# self.setFlag(QGraphicsItem.ItemSendsGeometryChanges)
self.setAcceptHoverEvents(True) self.setAcceptHoverEvents(True)
# self.setAcceptTouchEvents(True)
# self.setAcceptDrops(True)
self.setAcceptedMouseButtons(Qt.AllButtons)
# self.setAcceptedMouseButtons(Qt.LeftButton)
# self.setAcceptedMouseButtons(Qt.NoButton)
self._populate() self._populate()
@property @property
def height(self) -> float: def height(self) -> float:
return self._height return self._height
......
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""TODO""" """TODO"""
import os import os
...@@ -32,15 +34,15 @@ from qtpy.QtCore import ( ...@@ -32,15 +34,15 @@ from qtpy.QtCore import (
class GraphicsGraphEvent(QGraphicsObject): class GraphicsGraphEvent(QGraphicsItem):
"""Event handler for GraphicsComponentItem""" """Event handler for GraphicsComponentItem"""
def __init__(self, parent): def __init__(self, parent):
super().__init__() super().__init__()
# self.setAcceptedMouseButtons(Qt.LeftButton) # self.setAcceptedMouseButtons(Qt.LeftButton)
self.setFlag(QGraphicsItem.ItemIsMovable) # self.setFlag(QGraphicsItem.ItemIsMovable)
self.setFlag(QGraphicsItem.ItemIsSelectable) # self.setFlag(QGraphicsItem.ItemIsSelectable)
self.setAcceptHoverEvents(True) # self.setAcceptHoverEvents(True)
# self.setFlag(QGraphicsItem.ItemSendsGeometryChanges) # self.setFlag(QGraphicsItem.ItemSendsGeometryChanges)
def mouseMoveEvent(self, event: QGraphicsSceneMouseEvent) -> None: def mouseMoveEvent(self, event: QGraphicsSceneMouseEvent) -> None:
......
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os import os
import sys import sys
from typing import Any, Optional from typing import Any, Optional
...@@ -20,25 +22,27 @@ from qtpy.QtGui import ( ...@@ -20,25 +22,27 @@ from qtpy.QtGui import (
QPaintEvent, QPainter, QPainterPath, QColor, QBrush, QPen, QFont, QPolygon, QIcon, QPixmap, QPaintEvent, QPainter, QPainterPath, QColor, QBrush, QPen, QFont, QPolygon, QIcon, QPixmap,
QLinearGradient, QTransform) QLinearGradient, QTransform)
from qtpy.QtWidgets import ( from qtpy.QtWidgets import (
QApplication,
QGraphicsView, QGraphicsScene, QGraphicsWidget, QGraphicsView, QGraphicsScene, QGraphicsWidget,
QGraphicsLayout, QGraphicsLinearLayout, QGraphicsGridLayout, QGraphicsLayoutItem, QGraphicsAnchorLayout, QGraphicsLayout, QGraphicsLinearLayout, QGraphicsGridLayout, QGraphicsLayoutItem, QGraphicsAnchorLayout,
QGraphicsItem, QGraphicsItemGroup, QGraphicsPathItem, QGraphicsLineItem, QGraphicsRectItem, QGraphicsItem, QGraphicsItemGroup, QGraphicsPathItem, QGraphicsLineItem, QGraphicsRectItem,
QStyleOptionGraphicsItem, QWidget, QGraphicsObject) QStyleOptionGraphicsItem, QWidget, QGraphicsObject)
from qtpy.QtCore import ( from qtpy.QtCore import (
QPoint, QPointF) QPoint, QPointF, QEvent)
# B-ASIC # B-ASIC
import logger import logger
from b_asic.schedule import Schedule from b_asic.schedule import Schedule
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
class GraphicsGraphItem(QGraphicsItemGroup, QGraphicsObject): class GraphicsGraphItem(QGraphicsItemGroup):
_schedule: Schedule _schedule: Schedule
_axis: GraphicsAxisItem _axis: GraphicsAxisItem
_component_group: QGraphicsItemGroup _component_group: list[GraphicsComponentItem]
_components_height: float _components_height: float
_x_axis_indent: float _x_axis_indent: float
...@@ -46,24 +50,32 @@ class GraphicsGraphItem(QGraphicsItemGroup, QGraphicsObject): ...@@ -46,24 +50,32 @@ class GraphicsGraphItem(QGraphicsItemGroup, QGraphicsObject):
def __init__(self, schedule: Schedule, parent: QGraphicsItem = None): def __init__(self, schedule: Schedule, parent: QGraphicsItem = None):
super().__init__(parent) super().__init__(parent)
self.setFlag(QGraphicsItem.ItemIsMovable) # self.setFlag(QGraphicsItem.ItemIsMovable)
self.setFlag(QGraphicsItem.ItemIsSelectable) # self.setFlag(QGraphicsItem.ItemIsSelectable)
self.setAcceptHoverEvents(True) self.setAcceptHoverEvents(True)
self.setHandlesChildEvents(False)
# self.setAcceptedMouseButtons(Qt.NoButton)
self._schedule = deepcopy(schedule) self._schedule = deepcopy(schedule)
self._axis = None self._axis = None
self._component_group = QGraphicsItemGroup() # self._component_group = QGraphicsItemGroup()
self._component_group = []
# self._component_group.setHandlesChildEvents(False)
# self._component_group.setAcceptedMouseButtons(Qt.NoButton)
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): for i in range(5):
self._components_height += spacing
component = GraphicsComponentItem() component = GraphicsComponentItem()
component.setPos(0, self._components_height) component.setPos(self._x_axis_indent, self._components_height)
self._component_group.addToGroup(component) self._component_group.append(component)
self._components_height += component.height + spacing # self._component_group.addToGroup(component)
self._component_group.setPos(self._x_axis_indent, spacing) self._components_height += component.height
# self._component_group.setPos(self._x_axis_indent, spacing)
self._components_height += spacing self._components_height += spacing
# build axis # build axis
...@@ -71,26 +83,52 @@ class GraphicsGraphItem(QGraphicsItemGroup, QGraphicsObject): ...@@ -71,26 +83,52 @@ class GraphicsGraphItem(QGraphicsItemGroup, QGraphicsObject):
# add axis and components # add axis and components
self.addToGroup(self._axis) self.addToGroup(self._axis)
self.addToGroup(self._component_group) for component in self._component_group:
self.addToGroup(component)
# self.addToGroup(self._component_group)
def installSceneEventFilters(self) -> None:
for item in self._component_group:
item.installSceneEventFilter(self)
# for item in self._component_group.childItems():
# item.installSceneEventFilter(self)
self.setFiltersChildEvents(True)
def sceneEventFilter(self, ojb: QGraphicsItem, event: QEvent) -> bool:
"""Returns true if the event was filtered (i.e. stopped), otherwise false"""
type_ = event.type()
if type_ != QEvent.GraphicsSceneHoverMove: print(f'---> Event: {type_}')
if type_ == QEvent.GraphicsSceneHoverEnter: ...
# print('\t\tQEvent.GraphicsSceneHoverEnter')
elif type_ == QEvent.GraphicsSceneHoverLeave: ...
# print('\t\tQEvent.GraphicsSceneHoverLeave')
elif type_ == QEvent.GraphicsSceneContextMenu: ...
# elif type_ == QEvent.mousePressEvent:
# print('\t\tQEvent.mousePressEvent')
# elif type_ == QEvent.mouseReleaseEvent:
# print('\t\tQEvent.mouseReleaseEvent')
else: ... #False
def update(self) -> None: return False
# def sceneEvent(self, event: QEvent) -> bool:
# print(f'sceneEvent() --> {event.type()}')
# # event.accept()
# # QApplication.sendEvent(self.scene(), event)
# return False
def update_(self) -> None:
# self.prepareGeometryChange() # self.prepareGeometryChange()
# self.removeFromGroup(self._axis) # self.removeFromGroup(self._axis)
self._axis.update(40 + 6, self._components_height, self._x_axis_indent) self._axis.update(40 + 6, self._components_height, self._x_axis_indent)
# self.addToGroup(self._axis) # self.addToGroup(self._axis)
# @property @property
# def scale(self) -> float: def schedule(self) -> Schedule:
# return self._scale return self._schedule
# @scale.setter
# def scale(self, scale:float) -> None:
# self._scale = scale
# for component in self._component_group.childItems():
# component.scale = scale
# @staticmethod
@property @property
def axis(self) -> GraphicsAxisItem: def axis(self) -> GraphicsAxisItem:
......
# This Python file uses the following encoding: utf-8 #!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" B-ASIC Scheduler-gui Logger Module. """ B-ASIC Scheduler-gui Logger Module.
Contains a logger that logs to the console and a file using levels. It is based Contains a logger that logs to the console and a file using levels. It is based
......
# This Python file uses the following encoding: utf-8 #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""B-ASIC Scheduler-gui Module. """B-ASIC Scheduler-gui Module.
Contains the scheduler-gui class for scheduling operations in an SFG. Contains the scheduler-gui class for scheduling operations in an SFG.
...@@ -170,14 +171,10 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -170,14 +171,10 @@ class MainWindow(QMainWindow, Ui_MainWindow):
def _init_graphics(self) -> None: def _init_graphics(self) -> None:
"""Initialize the QGraphics framework""" """Initialize the QGraphics framework"""
# 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._scene = QGraphicsScene() self._scene = QGraphicsScene()
self.graphics_view.setDragMode(QGraphicsView.RubberBandDrag)
self.graphics_view.setScene(self._scene) self.graphics_view.setScene(self._scene)
self.graphics_view.scale(self._scale, self._scale) self.graphics_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
...@@ -189,23 +186,24 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -189,23 +186,24 @@ class MainWindow(QMainWindow, Ui_MainWindow):
############### ###############
@Slot() @Slot()
def actionTbtn(self) -> None: def actionTbtn(self) -> None:
sched = self._graph.schedule self._graph.schedule.plot_schedule()
sched.plot_schedule() print(f'filtersChildEvents(): {self._graph.filtersChildEvents()}')
# self.printButtonPressed('callback_pushButton()') # self.printButtonPressed('callback_pushButton()')
@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 '' 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"), abs_path_filename = QFileDialog.getOpenFileName(self,
open_dir, self.tr("Open python file"),
self.tr("Python Files (*.py *.py3)")) open_dir,
self.tr("Python Files (*.py *.py3)"))
abs_path_filename = abs_path_filename[0] 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))
self._open_file_dialog_opened = True self._open_file_dialog_opened = True
module_name = inspect.getmodulename(abs_path_filename) module_name = inspect.getmodulename(abs_path_filename)
if not module_name: # return if empty module name if not module_name: # return if empty module name
log.error('Could not load module from file \'{}\'.'.format(abs_path_filename)) log.error('Could not load module from file \'{}\'.'.format(abs_path_filename))
...@@ -250,6 +248,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -250,6 +248,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self._graph = GraphicsGraphItem(schedule) self._graph = GraphicsGraphItem(schedule)
self._scene.addItem(self._graph) self._scene.addItem(self._graph)
self._graph.installSceneEventFilters()
# graph.prepareGeometryChange() # graph.prepareGeometryChange()
# graph.setPos(200, 20) # graph.setPos(200, 20)
...@@ -362,9 +361,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -362,9 +361,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
#### Helper member functions #### #### Helper member functions ####
################################# #################################
def printButtonPressed(self, func_name: str) -> None: def printButtonPressed(self, func_name: str) -> None:
#TODO: remove #TODO: remove
self.label.setText("hello")
alert = QMessageBox(self) alert = QMessageBox(self)
alert.setText("Called from " + func_name + '!') alert.setText("Called from " + func_name + '!')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment