Skip to content
Snippets Groups Projects

Add scheduler GUI

Merged Oscar Gustafsson requested to merge scheduler-gui into master
2 files
+ 130
86
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -44,10 +44,12 @@ from graphics_component_item import GraphicsComponentItem
# class GraphicsGraphEvent(ABC):
class GraphicsGraphEvent(QGraphicsItem):
"""Event filter and handlers for GraphicsGraphItem"""
# _component_group: list[GraphicsComponentItem]
# _components: list[GraphicsComponentItem]
_current_pos: QPointF
def __init__(self, parent: QGraphicsItem = None):
super().__init__(parent)
self._current_pos: QPointF()
# self.setAcceptedMouseButtons(Qt.LeftButton)
# self.setFlag(QGraphicsItem.ItemIsMovable)
# self.setFlag(QGraphicsItem.ItemIsSelectable)
@@ -69,48 +71,53 @@ class GraphicsGraphEvent(QGraphicsItem):
"""Installs an event filter for 'item' on 'self', causing
all events for 'item' to first pass through 'self's
sceneEventFilter() function."""
for item in self._component_group:
for item in self._components:
item.installSceneEventFilter(self)
self.setFiltersChildEvents(True) # default false
def removeSceneEventFilters(self) -> None:
"""Removes an event filter on 'item' from 'self'."""
for item in self._component_group:
for item in self._components:
item.removeSceneEventFilter(self)
self.setFiltersChildEvents(False)
# def sceneEventFilter(self, item: QGraphicsItem, event: QEvent) -> bool:
def sceneEventFilter(self, item: 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'Graph -->\t{type(item).__name__}\t{type_}')
print(__name__)
"""Returns true if the event was filtered (i.e. stopped), otherwise false.
If false is returned, the event is forwarded to the appropriate child in
the event chain."""
# type_ = type(event)
# if type_ != QEvent.GraphicsSceneHoverMove: print(f'Graph -->\t{type(item).__name__}\t{type_}')
# if event.button():
# # print(f'Graph -->\t{type_}\t{item}')
# print(f'-------->\t{event.button()}')
if type(item) == GraphicsComponentItem:
switch = {
QEvent.FocusIn: self.graph_focusInEvent(item, QFocusEvent(event)),
QEvent.GraphicsSceneContextMenu: self.graph_contextMenuEvent(item, QGraphicsSceneContextMenuEvent(event)),
QEvent.GraphicsSceneDragEnter: self.graph_dragEnterEvent(item, QGraphicsSceneDragDropEvent(event)),
QEvent.GraphicsSceneDragMove: self.graph_dragMoveEvent(item, QGraphicsSceneDragDropEvent(event)),
QEvent.GraphicsSceneDragLeave: self.graph_dragLeaveEvent(item, QGraphicsSceneDragDropEvent(event)),
QEvent.GraphicsSceneDrop: self.graph_dropEvent(item, QGraphicsSceneDragDropEvent(event)),
QEvent.GraphicsSceneHoverEnter: self.graph_hoverEnterEvent(item, QGraphicsSceneHoverEvent(event)),
QEvent.GraphicsSceneHoverMove: self.graph_hoverMoveEvent(item, QGraphicsSceneHoverEvent(event)),
QEvent.GraphicsSceneHoverLeave: self.graph_hoverLeaveEvent(item, QGraphicsSceneHoverEvent(event)),
QEvent.GraphicsSceneMouseMove: self.graph_mouseMoveEvent(item, QGraphicsSceneMouseEvent(event)),
QEvent.GraphicsSceneMousePress: self.graph_mousePressEvent(item, QGraphicsSceneMouseEvent(event)),
QEvent.GraphicsSceneMouseRelease: self.graph_mouseReleaseEvent(item, QGraphicsSceneMouseEvent(event)),
QEvent.GraphicsSceneMouseDoubleClick: self.graph_mouseDoubleClickEvent(item, QGraphicsSceneMouseEvent(event)),
QEvent.GraphicsSceneWheel: self.graph_wheelEvent(item, QGraphicsSceneWheelEvent(event))
QEvent.FocusIn: self.comp_focusInEvent(item, event),
QEvent.GraphicsSceneContextMenu: self.comp_contextMenuEvent(item, event),
QEvent.GraphicsSceneDragEnter: self.comp_dragEnterEvent(item, event),
QEvent.GraphicsSceneDragMove: self.comp_dragMoveEvent(item, event),
QEvent.GraphicsSceneDragLeave: self.comp_dragLeaveEvent(item, event),
QEvent.GraphicsSceneDrop: self.comp_dropEvent(item, event),
QEvent.GraphicsSceneHoverEnter: self.comp_hoverEnterEvent(item, event),
QEvent.GraphicsSceneHoverMove: self.comp_hoverMoveEvent(item, event),
QEvent.GraphicsSceneHoverLeave: self.comp_hoverLeaveEvent(item, event),
QEvent.GraphicsSceneMouseMove: self.comp_mouseMoveEvent(item, event),
QEvent.GraphicsSceneMousePress: self.comp_mousePressEvent(item, event),
QEvent.GraphicsSceneMouseRelease: self.comp_mouseReleaseEvent(item, event),
QEvent.GraphicsSceneMouseDoubleClick: self.comp_mouseDoubleClickEvent(item, event),
QEvent.GraphicsSceneWheel: self.comp_wheelEvent(item, event)
}
# return switch.get(event.type(), self.log(item, event); False)
print(event.type())
print(f'{event.type()} contains: {event.type() in switch}')
return switch.get(event.type(), False)
else:
print(f'Graph -->\t{type(item).__name__}\t{type_}')
# else:
# print(f'Graph -->\t{type(item).__name__}\t{type_}')
return False # returns False if event is ignored and pass through event to its child
@@ -124,17 +131,54 @@ class GraphicsGraphEvent(QGraphicsItem):
########################
#### Event Handlers ####
########################
def graph_focusInEvent(self, item: QGraphicsItem, event: QFocusEvent) -> bool: ...
def graph_contextMenuEvent(self, item: QGraphicsItem, event: QGraphicsSceneContextMenuEvent) -> bool: ...
def graph_dragEnterEvent(self, item: QGraphicsItem, event: QGraphicsSceneDragDropEvent) -> bool: ...
def graph_dragMoveEvent(self, item: QGraphicsItem, event: QGraphicsSceneDragDropEvent) -> bool: ...
def graph_dragLeaveEvent(self, item: QGraphicsItem, event: QGraphicsSceneDragDropEvent) -> bool: ...
def graph_dropEvent(self, item: QGraphicsItem, event: QGraphicsSceneDragDropEvent) -> bool: ...
def graph_hoverEnterEvent(self, item: QGraphicsItem, event: QGraphicsSceneHoverEvent) -> bool: ...
def graph_hoverMoveEvent(self, item: QGraphicsItem, event: QGraphicsSceneHoverEvent) -> bool: ...
def graph_hoverLeaveEvent(self, item: QGraphicsItem, event: QGraphicsSceneHoverEvent) -> bool: ...
def graph_mouseMoveEvent(self, item: QGraphicsItem, event: QGraphicsSceneMouseEvent) -> bool: ...
def graph_mousePressEvent(self, item: QGraphicsItem, event: QGraphicsSceneMouseEvent) -> bool: ...
def graph_mouseReleaseEvent(self, item: QGraphicsItem, event: QGraphicsSceneMouseEvent) -> bool: ...
def graph_mouseDoubleClickEvent(self, item: QGraphicsItem, event: QGraphicsSceneMouseEvent) -> bool: ...
def graph_wheelEvent(self, item: QGraphicsItem, event: QGraphicsSceneWheelEvent) -> bool: ...
\ No newline at end of file
def comp_focusInEvent(self, item: QGraphicsItem, event: QFocusEvent) -> bool:
print(f'comp_focusInEvent() -->\t{type(item).__name__}\t{event.type()}')
def comp_contextMenuEvent(self, item: QGraphicsItem, event: QGraphicsSceneContextMenuEvent) -> bool: ...
def comp_dragEnterEvent(self, item: QGraphicsItem, event: QGraphicsSceneDragDropEvent) -> bool: ...
def comp_dragMoveEvent(self, item: QGraphicsItem, event: QGraphicsSceneDragDropEvent) -> bool: ...
def comp_dragLeaveEvent(self, item: QGraphicsItem, event: QGraphicsSceneDragDropEvent) -> bool: ...
def comp_dropEvent(self, item: QGraphicsItem, event: QGraphicsSceneDragDropEvent) -> bool: ...
def comp_hoverEnterEvent(self, item: QGraphicsItem, event: QGraphicsSceneHoverEvent) -> bool: ...
def comp_hoverMoveEvent(self, item: QGraphicsItem, event: QGraphicsSceneHoverEvent) -> bool: ...
def comp_hoverLeaveEvent(self, item: QGraphicsItem, event: QGraphicsSceneHoverEvent) -> bool: ...
def comp_mouseMoveEvent(self, item: QGraphicsItem, event: QGraphicsSceneMouseEvent) -> bool:
"""Set the position of the graphical element in the graphic scene,
translate coordinates of the cursor within the graphic element
in the coordinate system of the parent object"""
print(f'comp_mouseMoveEvent() -->\t{type(item).__name__}\t{event.type()}')
# # Qt.DragMoveCursor
# # button = event.button()
# self
# dx = (item.mapToParent(event.pos()) - self._current_pos).x()
# if dx > 5.05:
# # TODO: send signal
# item.setX(item.x() + 10.0)
# self._current_pos.setX(self._current_pos.x() + 10.0)
# elif dx < -5.05:
# # TODO: send signal
# item.setX(item.x() - 10-0)
# self._current_pos.setX(self._current_pos.x() - 10.0)
return True
def comp_mousePressEvent(self, item: QGraphicsItem, event: QGraphicsSceneMouseEvent) -> bool:
"""Changes the cursor to ClosedHandCursor when grabbing an object"""
print(f'comp_mousePressEvent() -->\t{type(item).__name__}\t{event.type()}')
# print('GraphicsComponentEvent.mousePressEvent()')
# print(f'button: {event.button()}')
# self._current_pos = item.mapToParent(event.pos())
# item.setCursor(QCursor(Qt.ClosedHandCursor))
# event.accept()
return True
def comp_mouseReleaseEvent(self, item: QGraphicsItem, event: QGraphicsSceneMouseEvent) -> bool:
"""Changes the cursor to OpenHandCursor when releasing an object"""
print(f'comp_mouseReleaseEvent() -->\t{type(item).__name__}\t{event.type()}')
# print('GraphicsComponentEvent.mouseReleaseEvent()')
# item.setCursor(QCursor(Qt.OpenHandCursor))
# event.accept()
return True
def comp_mouseDoubleClickEvent(self, item: QGraphicsItem, event: QGraphicsSceneMouseEvent) -> bool: ...
def comp_wheelEvent(self, item: QGraphicsItem, event: QGraphicsSceneWheelEvent) -> bool: ...
\ No newline at end of file
Loading