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

workspace dump

parent b4a524e8
No related branches found
No related tags found
1 merge request!78Add scheduler GUI
Pipeline #73174 passed
......@@ -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
......@@ -39,11 +39,11 @@ from graphics_axis_item import GraphicsAxisItem
from graphics_graph_event import GraphicsGraphEvent
class GraphicsGraphItem(QGraphicsItemGroup):
class GraphicsGraphItem(QGraphicsItemGroup, GraphicsGraphEvent):
_schedule: Schedule
_axis: GraphicsAxisItem
_component_group: list[GraphicsComponentItem]
_components: list[GraphicsComponentItem]
_components_height: float
_x_axis_indent: float
......@@ -61,10 +61,10 @@ class GraphicsGraphItem(QGraphicsItemGroup):
self._schedule = deepcopy(schedule)
self._axis = None
# self._component_group = QGraphicsItemGroup()
self._component_group = []
# self._component_group.setHandlesChildEvents(False)
# self._component_group.setAcceptedMouseButtons(Qt.NoButton)
# self._components = QGraphicsItemGroup()
self._components = []
# self._components.setHandlesChildEvents(False)
# self._components.setAcceptedMouseButtons(Qt.NoButton)
self._components_height = 0.0
self._x_axis_indent = 2.0
......@@ -74,10 +74,10 @@ class GraphicsGraphItem(QGraphicsItemGroup):
self._components_height += spacing
component = GraphicsComponentItem()
component.setPos(self._x_axis_indent, self._components_height)
self._component_group.append(component)
# self._component_group.addToGroup(component)
self._components.append(component)
# self._components.addToGroup(component)
self._components_height += component.height
# self._component_group.setPos(self._x_axis_indent, spacing)
# self._components.setPos(self._x_axis_indent, spacing)
self._components_height += spacing
# build axis
......@@ -85,51 +85,51 @@ class GraphicsGraphItem(QGraphicsItemGroup):
# add axis and components
self.addToGroup(self._axis)
for component in self._component_group:
for component in self._components:
self.addToGroup(component)
# self.addToGroup(self._component_group)
# self.addToGroup(self._components)
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) # default false
# def installSceneEventFilters(self) -> None:
# for item in self._components:
# item.installSceneEventFilter(self)
# # for item in self._components.childItems():
# # item.installSceneEventFilter(self)
# self.setFiltersChildEvents(True) # default false
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__)
# if event.button():
# # print(f'Graph -->\t{type_}\t{item}')
# print(f'-------->\t{event.button()}')
# 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__)
# # if event.button():
# # # print(f'Graph -->\t{type_}\t{item}')
# # print(f'-------->\t{event.button()}')
if type(item) == GraphicsComponentItem:
# if type(item) == GraphicsComponentItem:
switch = {
QEvent.FocusIn: self.graph_focusInEvent(item, Qt.QFocusEvent(event)),
QEvent.GraphicsSceneContextMenu: self.graph_contextMenuEvent(item, Qt.QGraphicsSceneContextMenuEvent(event)),
QEvent.GraphicsSceneDragEnter: self.graph_dragEnterEvent(item, Qt.QGraphicsSceneDragDropEvent(event)),
QEvent.GraphicsSceneDragMove: self.graph_dragMoveEvent(item, Qt.QGraphicsSceneDragDropEvent(event)),
QEvent.GraphicsSceneDragLeave: self.graph_dragLeaveEvent(item, Qt.QGraphicsSceneDragDropEvent(event)),
QEvent.GraphicsSceneDrop: self.graph_dropEvent(item, Qt.QGraphicsSceneDragDropEvent(event)),
QEvent.GraphicsSceneHoverEnter: self.graph_hoverEnterEvent(item, Qt.QGraphicsSceneHoverEvent(event)),
QEvent.GraphicsSceneHoverMove: self.graph_hoverMoveEvent(item, Qt.QGraphicsSceneHoverEvent(event)),
QEvent.GraphicsSceneHoverLeave: self.graph_hoverLeaveEvent(item, Qt.QGraphicsSceneHoverEvent(event)),
QEvent.GraphicsSceneMouseMove: self.graph_mouseMoveEvent(item, Qt.QGraphicsSceneMouseEvent(event)),
QEvent.GraphicsSceneMousePress: self.graph_mousePressEvent(item, Qt.QGraphicsSceneMouseEvent(event)),
QEvent.GraphicsSceneMouseRelease: self.graph_mouseReleaseEvent(item, Qt.QGraphicsSceneMouseEvent(event)),
QEvent.GraphicsSceneMouseDoubleClick: self.graph_mouseDoubleClickEvent(item, Qt.QGraphicsSceneMouseEvent(event)),
QEvent.GraphicsSceneWheel: self.graph_wheelEvent(item, Qt.QGraphicsSceneWheelEvent(event))
}
return switch.get(event.type(), self.log(item, event); False)
return switch.get(event.type(), False)
else:
print(f'Graph -->\t{type(item).__name__}\t{type_}')
# switch = {
# QEvent.FocusIn: self.graph_focusInEvent(item, Qt.QFocusEvent(event)),
# QEvent.GraphicsSceneContextMenu: self.graph_contextMenuEvent(item, Qt.QGraphicsSceneContextMenuEvent(event)),
# QEvent.GraphicsSceneDragEnter: self.graph_dragEnterEvent(item, Qt.QGraphicsSceneDragDropEvent(event)),
# QEvent.GraphicsSceneDragMove: self.graph_dragMoveEvent(item, Qt.QGraphicsSceneDragDropEvent(event)),
# QEvent.GraphicsSceneDragLeave: self.graph_dragLeaveEvent(item, Qt.QGraphicsSceneDragDropEvent(event)),
# QEvent.GraphicsSceneDrop: self.graph_dropEvent(item, Qt.QGraphicsSceneDragDropEvent(event)),
# QEvent.GraphicsSceneHoverEnter: self.graph_hoverEnterEvent(item, Qt.QGraphicsSceneHoverEvent(event)),
# QEvent.GraphicsSceneHoverMove: self.graph_hoverMoveEvent(item, Qt.QGraphicsSceneHoverEvent(event)),
# QEvent.GraphicsSceneHoverLeave: self.graph_hoverLeaveEvent(item, Qt.QGraphicsSceneHoverEvent(event)),
# QEvent.GraphicsSceneMouseMove: self.graph_mouseMoveEvent(item, Qt.QGraphicsSceneMouseEvent(event)),
# QEvent.GraphicsSceneMousePress: self.graph_mousePressEvent(item, Qt.QGraphicsSceneMouseEvent(event)),
# QEvent.GraphicsSceneMouseRelease: self.graph_mouseReleaseEvent(item, Qt.QGraphicsSceneMouseEvent(event)),
# QEvent.GraphicsSceneMouseDoubleClick: self.graph_mouseDoubleClickEvent(item, Qt.QGraphicsSceneMouseEvent(event)),
# QEvent.GraphicsSceneWheel: self.graph_wheelEvent(item, Qt.QGraphicsSceneWheelEvent(event))
# }
# return switch.get(event.type(), self.log(item, event); False)
# return switch.get(event.type(), False)
# else:
# print(f'Graph -->\t{type(item).__name__}\t{type_}')
return False # returns False if event is ignored and passed through to its child
# return False # returns False if event is ignored and passed through to its child
# # def sceneEvent(self, event: QEvent) -> bool:
# # print(f'sceneEvent() --> {event.type()}')
......@@ -154,6 +154,6 @@ class GraphicsGraphItem(QGraphicsItemGroup):
@property
def items(self) -> list[GraphicsComponentItem]:
return self._component_group.childItems()
return self._components.childItems()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment