node_graphics_edge Module

A module containing the Graphics representation of an Edge

QDMGraphicsEdge class

class nodeeditor.node_graphics_edge.QDMGraphicsEdge(edge: Edge, parent: PyQt5.QtWidgets.QWidget = None)

Bases: PyQt5.QtWidgets.QGraphicsPathItem

Base class for Graphics Edge

Parameters
  • edge (Edge) – reference to Edge

  • parent (QWidget) – parent widget

Instance attributes
  • edge - reference to Edge

  • posSource - [x, y] source position in the Scene

  • posDestination - [x, y] destination position in the Scene

initUI()

Set up this QGraphicsPathItem

initAssets()

Initialize QObjects like QColor, QPen and QBrush

createEdgePathCalculator()

Create instance of GraphicsEdgePathBase

determineEdgePathClass()

Decide which GraphicsEdgePath class should be used to calculate path according to edge.edge_type value

makeUnselectable()

Used for drag edge to disable click detection over this graphics item

changeColor(color)

Change color of the edge from string hex value ‘#00ff00’

setColorFromSockets()bool

Change color according to connected sockets. Returns True if color can be determined

onSelected()

Our event handling when the edge was selected

doSelect(new_state: bool = True)

Safe version of selecting the Graphics Node. Takes care about the selection state flag used internally

Parameters

new_state (bool) – True to select, False to deselect

mouseReleaseEvent(event)

Overridden Qt’s method to handle selecting and deselecting this Graphics Edge

hoverEnterEvent(event: PyQt5.QtWidgets.QGraphicsSceneHoverEvent)None

Handle hover effect

hoverLeaveEvent(event: PyQt5.QtWidgets.QGraphicsSceneHoverEvent)None

Handle hover effect

setSource(x: float, y: float)

Set source point

Parameters
  • x (float) – x position

  • y (float) – y position

setDestination(x: float, y: float)

Set destination point

Parameters
  • x (float) – x position

  • y (float) – y position

boundingRect()PyQt5.QtCore.QRectF

Defining Qt’ bounding rectangle

shape()PyQt5.QtGui.QPainterPath

Returns QPainterPath representation of this Edge

Returns

path representation

Return type

QPainterPath

paint(painter, QStyleOptionGraphicsItem, widget=None)

Qt’s overridden method to paint this Graphics Edge. Path calculated in calcPath() method

intersectsWith(p1: PyQt5.QtCore.QPointF, p2: PyQt5.QtCore.QPointF)bool

Does this Graphics Edge intersect with the line between point A and point B ?

Parameters
  • p1 (QPointF) – point A

  • p2 (QPointF) – point B

Returns

True if this Graphics Edge intersects

Return type

bool

calcPath()PyQt5.QtGui.QPainterPath

Will handle drawing QPainterPath from Point A to B. Internally there exist self.pathCalculator which is an instance of derived GraphicsEdgePathBase class containing the actual calcPath() function - computing how the edge should look like.

Returns

QPainterPath of the edge connecting source and destination

Return type

QPainterPath