spinetoolbox.graphics_items¶
Classes for drawing graphics items on QGraphicsScene.
| authors: |
|
|---|---|
| date: | 4.4.2018 |
Module Contents¶
Classes¶
ProjectItemIcon |
Base class for project item icons drawn in Design View. |
ConnectorButton |
Connector button graphics item. Used for Link drawing between project items. |
ExclamationIcon |
Exclamation icon graphics item. |
RankIcon |
Rank icon graphics item. |
LinkBase |
Base class for Link and LinkDrawer. |
Link |
Base class for Link and LinkDrawer. |
LinkDrawer |
An item for drawing links between project items. |
-
class
spinetoolbox.graphics_items.ProjectItemIcon(toolbox, x, y, project_item, icon_file, icon_color, background_color)[source]¶ Bases:
PySide2.QtWidgets.QGraphicsRectItemBase class for project item icons drawn in Design View.
Parameters: - toolbox (ToolBoxUI) – QMainWindow instance
- x (float) – Icon x coordinate
- y (float) – Icon y coordinate
- project_item (ProjectItem) – Item
- icon_file (str) – Path to icon resource
- icon_color (QColor) – Icon’s color
- background_color (QColor) – Background color
-
activate(self)[source]¶ Adds items to scene and setup graphics effect. Called in the constructor and when re-adding the item to the project in the context of undo/redo.
-
_setup(self, brush, svg, svg_color)[source]¶ Setup item’s attributes.
Parameters: - brush (QBrush) – Used in filling the background rectangle
- svg (str) – Path to SVG icon file
- svg_color (QColor) – Color of SVG icon
-
update_name_item(self, new_name)[source]¶ Set a new text to name item. Used when a project item is renamed.
-
set_name_attributes(self)[source]¶ Set name QGraphicsSimpleTextItem attributes (font, size, position, etc.)
Returns items connector button (QWidget).
-
hoverEnterEvent(self, event)[source]¶ Sets a drop shadow effect to icon when mouse enters its boundaries.
Parameters: event (QGraphicsSceneMouseEvent) – Event
-
hoverLeaveEvent(self, event)[source]¶ Disables the drop shadow when mouse leaves icon boundaries.
Parameters: event (QGraphicsSceneMouseEvent) – Event
-
mouseMoveEvent(self, event)[source]¶ Moves icon(s) while the mouse button is pressed. Update links that are connected to selected icons.
Parameters: event (QGraphicsSceneMouseEvent) – Event
-
update_links_geometry(self)[source]¶ Updates geometry of connected links to reflect this item’s most recent position.
-
contextMenuEvent(self, event)[source]¶ Show item context menu.
Parameters: event (QGraphicsSceneMouseEvent) – Mouse event
-
keyPressEvent(self, event)[source]¶ Handles deleting and rotating the selected item when dedicated keys are pressed.
Parameters: event (QKeyEvent) – Key event
-
itemChange(self, change, value)[source]¶ Reacts to item removal and position changes.
In particular, destroys the drop shadow effect when the items is removed from a scene and keeps track of item’s movements on the scene.
Parameters: - change (GraphicsItemChange) – a flag signalling the type of the change
- value – a value related to the change
Returns: Whatever super() does with the value parameter
-
class
spinetoolbox.graphics_items.ConnectorButton(parent, toolbox, position='left')[source]¶ Bases:
PySide2.QtWidgets.QGraphicsRectItemConnector button graphics item. Used for Link drawing between project items.
Parameters: - parent (QGraphicsItem) – Project item bg rectangle
- toolbox (ToolBoxUI) – QMainWindow instance
- position (str) – Either “top”, “left”, “bottom”, or “right”
-
mousePressEvent(self, event)[source]¶ Connector button mouse press event. Either starts or closes a link.
Parameters: event (QGraphicsSceneMouseEvent) – Event
-
set_friend_connectors_enabled(self, enabled)[source]¶ Enables or disables all connectors in the parent. This is called by LinkDrawer to disable invalid connectors while drawing and reenabling them back when done.
-
mouseDoubleClickEvent(self, event)[source]¶ Connector button mouse double click event. Makes sure the LinkDrawer is hidden.
Parameters: event (QGraphicsSceneMouseEvent) – Event
-
class
spinetoolbox.graphics_items.ExclamationIcon(parent)[source]¶ Bases:
PySide2.QtSvg.QGraphicsSvgItemExclamation icon graphics item. Used to notify that a ProjectItem is missing some configuration.
Parameters: parent (ProjectItemIcon) – the parent item
-
class
spinetoolbox.graphics_items.RankIcon(parent)[source]¶ Bases:
PySide2.QtWidgets.QGraphicsTextItemRank icon graphics item. Used to show the rank of a ProjectItem within its DAG
Parameters: parent (ProjectItemIcon) – the parent item
-
class
spinetoolbox.graphics_items.LinkBase(toolbox)[source]¶ Bases:
PySide2.QtWidgets.QGraphicsPathItemBase class for Link and LinkDrawer.
Mainly provides the
update_geometrymethod for ‘drawing’ the link on the scene.Initializes the instance.
Parameters: toolbox (ToolboxUI) – main UI class instance -
moveBy(self, _dx, _dy)[source]¶ Does nothing. This item is not moved the regular way, but follows the ConnectorButtons it connects.
-
do_update_geometry(self, curved_links)[source]¶ Sets the path for this item.
Parameters: curved_links (bool) – Whether the path should follow a curvy line or a straight line
-
_make_guide_path(self, curved_links)[source]¶ Returns a ‘narrow’ path connecting this item’s source and destination.
Parameters: curved_links (bool) – Whether the path should follow a curved line or just a straight line Returns: QPainterPath
-
_points_and_angles_from_path(self, path)[source]¶ Returns a list of representative points and angles from given path.
Parameters: path (QPainterPath) – Returns: points list(float): angles Return type: list(QPointF)
-
_make_connecting_path(self, guide_path)[source]¶ Returns a ‘thick’ path connecting source and destination, by following the given ‘guide’ path.
Parameters: guide_path (QPainterPath) – Returns: QPainterPath
-
-
class
spinetoolbox.graphics_items.Link(toolbox, src_connector, dst_connector)[source]¶ Bases:
spinetoolbox.graphics_items.LinkBaseBase class for Link and LinkDrawer.
Mainly provides the
update_geometrymethod for ‘drawing’ the link on the scene.A graphics item to represent the connection between two project items.
Parameters: - toolbox (ToolboxUI) – main UI class instance
- src_connector (ConnectorButton) – Source connector button
- dst_connector (ConnectorButton) – Destination connector button
-
make_execution_animation(self)[source]¶ Returns an animation to play when execution ‘passes’ through this link.
Returns: QVariantAnimation
-
mousePressEvent(self, e)[source]¶ Ignores event if there’s a connector button underneath, to allow creation of new links.
Parameters: e (QGraphicsSceneMouseEvent) – Mouse event
-
class
spinetoolbox.graphics_items.LinkDrawer(toolbox)[source]¶ Bases:
spinetoolbox.graphics_items.LinkBaseAn item for drawing links between project items.
Init class.
Parameters: toolbox (ToolboxUI) – main UI class instance -
wake_up(self, src_connector)[source]¶ Sets the source connector, shows this item and adds it to the scene. After calling this, the scene is in link drawing mode.
Parameters: src_connector (ConnectorButton) –
-