spinetoolbox.graphics_items

Classes for drawing graphics items on QGraphicsScene.

authors:
  1. Marin (KTH), P. Savolainen (VTT)
date:

4.4.2018

Module Contents

class spinetoolbox.graphics_items.ConnectorButton(parent, toolbox, position='left')[source]

Bases: PySide2.QtWidgets.QGraphicsRectItem

Connector 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”
brush[source]
hover_brush[source]
parent_name(self)[source]

Returns project item name owning this connector button.

mousePressEvent(self, event)[source]

Connector button mouse press event. Starts drawing a link.

Parameters:event (QGraphicsSceneMouseEvent) – Event
mouseDoubleClickEvent(self, event)[source]

Connector button mouse double click event. Makes sure the LinkDrawer is hidden.

Parameters:event (QGraphicsSceneMouseEvent) – Event
hoverEnterEvent(self, event)[source]

Sets a darker shade to connector button when mouse enters its boundaries.

Parameters:event (QGraphicsSceneMouseEvent) – Event
hoverLeaveEvent(self, event)[source]

Restore original brush when mouse leaves connector button boundaries.

Parameters:event (QGraphicsSceneMouseEvent) – Event
class spinetoolbox.graphics_items.ExclamationIcon(parent)[source]

Bases: PySide2.QtSvg.QGraphicsSvgItem

Exclamation icon graphics item. Used to notify that a ProjectItem is missing some configuration.

Parameters:parent (ProjectItemIcon) – the parent item
clear_notifications(self)[source]

Clear all notifications.

add_notification(self, text)[source]

Add a notification.

hoverEnterEvent(self, event)[source]

Shows notifications as tool tip.

Parameters:event (QGraphicsSceneMouseEvent) – Event
hoverLeaveEvent(self, event)[source]

Hides tool tip.

Parameters:event (QGraphicsSceneMouseEvent) – Event
class spinetoolbox.graphics_items.NotificationListItem[source]

Bases: PySide2.QtWidgets.QGraphicsTextItem

Notification list graphics item. Used to show notifications for a ProjectItem

setHtml(self, html)[source]
class spinetoolbox.graphics_items.RankIcon(parent)[source]

Bases: PySide2.QtWidgets.QGraphicsTextItem

Rank icon graphics item. Used to show the rank of a ProjectItem within its DAG

Parameters:parent (ProjectItemIcon) – the parent item
set_rank(self, rank)[source]
class spinetoolbox.graphics_items.ProjectItemIcon(toolbox, x, y, w, h, project_item, icon_file, icon_color, background_color)[source]

Bases: PySide2.QtWidgets.QGraphicsRectItem

Base class for project item icons drawn in Design View.

Parameters:
  • toolbox (ToolBoxUI) – QMainWindow instance
  • x (float) – Icon x coordinate
  • y (float) – Icon y coordinate
  • w (float) – Icon width
  • h (float) – Icon height
  • 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
name(self)[source]

Returns name of the item that is represented by this 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.)

conn_button(self, position='left')[source]

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
mousePressEvent(self, event)[source]
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

Updates geometry of connected links to reflect this item’s most recent position.

mouseReleaseEvent(self, event)[source]
shrink_scene_if_needed(self)[source]
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

show_item_info(self)[source]

Update GUI to show the details of the selected item.

class spinetoolbox.graphics_items.LinkBase(toolbox)[source]

Bases: PySide2.QtWidgets.QGraphicsPathItem

Base class for Link and LinkDrawer.

Mainly provides the update_geometry method for ‘drawing’ the link on the scene.

Initializes the instance.

Parameters:toolbox (ToolboxUI) – main UI class instance
src_rect[source]

Returns the scene rectangle of the source connector.

src_center[source]

Returns the center point of the source rectangle.

dst_rect[source]

Returns the scene rectangle of the destination connector.

dst_center[source]

Returns the center point of the destination rectangle.

update_geometry(self)[source]

Updates geometry.

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_ellipse_path(self)[source]

Returns an ellipse path for the link’s base.

Returns:QPainterPath
_get_src_offset(self)[source]
_get_dst_offset(self, c1)[source]
_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
static _follow_points(curve_path, points)[source]
_radius_from_point_and_angle(self, point, angle)[source]
_make_arrow_path(self, guide_path)[source]

Returns an arrow path for the link’s tip.

Parameters:guide_path (QPainterPath) – A narrow path connecting source and destination, used to determine the arrow orientation.
Returns:QPainterPath
_get_joint_line(self, guide_path)[source]
_get_joint_angle(self, guide_path)[source]

Bases: spinetoolbox.graphics_items.LinkBase

A graphics item to represent the connection between two project items.

Parameters:
make_execution_animation(self)[source]

Returns an animation to play when execution ‘passes’ through this link.

Returns:QVariantAnimation
_handle_execution_animation_value_changed(self, step)[source]

Returns whether or not this link entirely overlaps another.

send_to_bottom(self)[source]

Stacks this link before the parallel one if any.

mousePressEvent(self, e)[source]

Ignores event if there’s a connector button underneath, to allow creation of new links.

Parameters:e (QGraphicsSceneMouseEvent) – Mouse event
mouseDoubleClickEvent(self, e)[source]

Accepts event if there’s a connector button underneath, to prevent unwanted creation of feedback links.

contextMenuEvent(self, e)[source]

Selects the link and shows context menu.

Parameters:e (QGraphicsSceneMouseEvent) – Mouse event
keyPressEvent(self, event)[source]

Removes this link if delete is pressed.

paint(self, painter, option, widget)[source]

Sets a dashed pen if selected.

itemChange(self, change, value)[source]

Brings selected link to top.

wipe_out(self)[source]

Removes any trace of this item from the system.

class spinetoolbox.graphics_items.LinkDrawer(toolbox)[source]

Bases: spinetoolbox.graphics_items.LinkBase

An item for drawing links between project items.

Parameters:toolbox (ToolboxUI) – main UI class instance
dst_connector[source]
dst_rect[source]
dst_center[source]
start_drawing_at(self, src_connector)[source]

Starts drawing a link from the given connector.

Parameters:src_connector (ConnectorButton) –