Graphics items
The QGraphicsItem classes that draw the scene. Applications rarely touch
these directly, but they are the extension points for custom painting.
nodeeditor.node_graphics_node ¶
A module containing Graphics representation of :class:~nodeeditor.node_node.Node
QDMGraphicsNodeLabel ¶
Bases: QGraphicsTextItem
Single-line editable textbox floating above a QDMGraphicsNode.
Parented to the graphics node, so Qt moves it with the node for free.
Click to focus/edit; Enter commits, Escape reverts, focus-out commits.
setLabelColors ¶
Set the background and border colors of the label box.
:param bg: background color of the label box :type bg: QColor :param border: border color of the label box :type border: QColor
focusInEvent ¶
Remember the current text and switch the scene into editing mode.
:param event: Qt's focus event :type event: QFocusEvent
focusOutEvent ¶
Commit the edited text and leave editing mode.
:param event: Qt's focus event :type event: QFocusEvent
keyPressEvent ¶
Commit on Return/Enter, revert the text on Escape.
:param event: Qt's key event :type event: QKeyEvent
mousePressEvent ¶
Take the keyboard focus when the label is clicked.
:param event: Qt's mouse event :type event: QMouseEvent
mouseDoubleClickEvent ¶
Select the whole text on a double click, so typing replaces it.
:param event: Qt's mouse event :type event: QMouseEvent
QDMGraphicsNode ¶
Bases: QGraphicsItem
Class describing Graphics representation of :class:~nodeeditor.node_node.Node
title
property
writable
¶
title of this Node
:getter: current Graphics Node title :setter: stores and make visible the new title :type: str
doSelect ¶
Safe version of selecting the Graphics Node. Takes care about the selection state flag used internally
:param new_state: True to select, False to deselect
:type new_state: bool
mousePressEvent ¶
Keep the default Qt behavior, so the node can be moved and selected.
:param event: Qt's mouse event :type event: QMouseEvent
itemChange ¶
Refresh this node's edges when Qt moves it.
Qt moves the dragged node - and every other node in the selection - itself. Reacting to the position change Qt already reports updates the edges of exactly the nodes that moved, replacing the old per-mouse-move scan of every node in the scene.
mouseReleaseEvent ¶
Overriden event to handle when we moved, selected or deselected this Node
mouseDoubleClickEvent ¶
Overriden event for doubleclick. Resend to Node::onDoubleClicked
initContent ¶
Set up the grContent - QGraphicsProxyWidget to have a container for Graphics Content
initLabel ¶
Create the floating single-line label above the node (hidden until text is set).
setLabelText ¶
Set label text (single-line). Empty text hides the label. No history stored.
setLabelVisible ¶
Show/hide the label. Hidden when text is empty regardless.
setLabelColor ¶
Set the text color of the label.
:param color: the new text color :type color: QColor
setLabelFont ¶
Set the font of the label and move the label to its new position.
:param font: the new font :type font: QFont
setLabelBackground ¶
Set the background and border colors of the label box.
:param bg: background color of the label box :type bg: QColor :param border: border color of the label box :type border: QColor
setDetailState ¶
Apply a resolved per-element detail state.
The scene resolves its detail policy into a mapping of element key to
"draw it" and hands the whole mapping over, so an application can add
elements of its own to the same broadcast and read them back here.
The zoom state itself rides along under the detail key.
Every child is pushed, not only the ones whose flag changed: a socket or a content proxy built after the last flip has never seen the state.
setDetailVisible ¶
Show or hide this node's fine detail at low zoom.
The legacy entry point, kept for callers outside the scene: it drops
the content widget, the floating label and the socket circles together.
The scene uses :meth:setDetailState instead, which resolves each of
those separately.
syncDetailVisibility ¶
Push the scene's current detail state onto every child item.
The sockets and the content proxy are built during Node.__init__,
after Qt already reported this node joining the scene, so the scene's
one-off broadcast never reached them - and Qt's
ItemChildAddedChange hands over a base-class wrapper for an item
still inside its own constructor, which has no setDetailVisible.
Called from Node.__init__ once the node is fully built.
nodeeditor.node_graphics_scene ¶
A module containing Graphic representation of :class:~nodeeditor.node_scene.Scene
QDMGraphicsScene ¶
Bases: QGraphicsScene
Class representing Graphic of :class:~nodeeditor.node_scene.Scene
showGrid
property
writable
¶
Get grid visibility state
Returns: bool: True if grid is visible, False otherwise
updateDetailLod ¶
Match the items' detail to scale; True when the state flipped.
Only a float comparison per frame; the broadcast to items runs once per
flip. Callers must not be inside a paint pass - see
:meth:setDetailLod.
setDetailLod ¶
Tell every item that cares whether the current zoom warrants detail.
Never call this while the scene is being painted. Hiding an item during
a paint pass leaves the pixels it had already claimed on screen, and
those ghosts then travel with the next scroll - which is why the view
decides this before it paints rather than from drawBackground.
set_detail_policy ¶
Say what each element may do when the canvas simplifies.
policy maps an element key to always, auto or never.
auto follows the zoom threshold, always keeps the element at
every zoom and never drops it at every zoom. Keys the library does
not know are kept, so an application can register an element of its own
and read the answer back with :meth:detail_enabled.
nodeeditor.node_graphics_socket ¶
A module containing Graphics representation of a :class:~nodeeditor.node_socket.Socket
QDMGraphicsSocket ¶
Bases: QGraphicsItem
Class representing Graphic Socket in QGraphicsScene
direction
property
¶
+1 on an output socket, -1 on an input socket.
Shapes that must not flip (the chevron) simply ignore it.
setShape ¶
Draw this socket with the shape registered under name.
:param name: the registered shape name
setDetailVisible ¶
Show or hide this socket's circle at low zoom.
Pushed by the owning node when the scene drops to its level-of-detail state. A dozen sockets per node at normal zoom costs more per frame than the node itself; at that scale the circles are a couple of pixels wide and cannot be aimed at, so wiring is a zoomed-in activity.
paint ¶
Painting the socket shape and its label
shape ¶
The outline used for hit testing.
What is drawn is what can be clicked: a click on a corner of a square socket misses it, exactly like a click beside a circle does.
nodeeditor.node_graphics_view ¶
A module containing Graphics View for NodeEditor
QDMGraphicsView ¶
Bases: QGraphicsView
Class representing NodeEditor's Graphics View
addDragEnterListener ¶
Register callback for Drag Enter event
:param callback: callback function
addDropListener ¶
Register callback for Drop event
:param callback: callback function
mousePressEvent ¶
Dispatch Qt's mousePress event to corresponding function below
mouseReleaseEvent ¶
Dispatch Qt's mouseRelease event to corresponding function below
keyPressEvent ¶
.. note::
This overridden Qt's method was used for handling key shortcuts, before we implemented proper
QWindow with Actions and Menu. Still the commented code serves as an example on how to handle
key presses without Qt's framework for Actions and shortcuts. There is also an example on
how to solve the problem when a Node contains Text/LineEdit and we press the Delete
key (also serving to delete Node)
:param event: Qt's Key event
:type event: QKeyEvent
:return:
cutIntersectingEdges ¶
Compare which Edges intersect with current Cut line and delete them safely
setSocketHighlights ¶
Set/disable socket highlights in Scene area defined by scenepos and radius
deleteSelected ¶
Delete selected items. Delete-key on a Group = delete Group + Children.
debug_modifiers ¶
Helper function get string if we hold Ctrl, Shift or Alt modifier keys
getItemAtClick ¶
Return the object on which we've clicked/release mouse button
:param event: Qt's mouse or key event
:type event: QEvent
:return: QGraphicsItem which the mouse event happened or None
distanceBetweenClickAndReleaseIsOff ¶
Measures if we are too far from the last Mouse button click scene position.
This is used for detection if we release too far after we clicked on a Socket
:param event: Qt's mouse event
:type event: QMouseEvent
:return: True if we released too far from where we clicked before
zoomIn ¶
Step the zoom level up and return the factor to scale the scene by.
:return: the zoom factor to apply
:rtype: float
zoomOut ¶
Step the zoom level down and return the factor to scale the scene by.
:return: the zoom factor to apply
:rtype: float
applyZoom ¶
Scale the scene by zoomFactor, keeping the zoom level inside the configured range.
:param zoomFactor: the factor to scale the scene by
:type zoomFactor: float
nodeeditor.node_graphics_edge ¶
A module containing the Graphics representation of an Edge
QDMGraphicsEdge ¶
Bases: QGraphicsPathItem
Base class for Graphics Edge
createEdgePathCalculator ¶
Create instance of :class:~nodeeditor.node_graphics_edge_path.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
setColorFromSockets ¶
Change color according to connected sockets. Returns True if color can be determined
setLabel ¶
Set the text drawn on top of the edge.
Code-only API: the label item is not selectable, movable, focusable and accepts no mouse buttons, so users cannot edit it directly.
:param text: label text, ""/None hides the label
doSelect ¶
Safe version of selecting the Graphics Node. Takes care about the selection state flag used internally
:param new_state: True to select, False to deselect
:type new_state: bool
mouseReleaseEvent ¶
Overridden Qt's method to handle selecting and deselecting this Graphics Edge
hoverEnterEvent ¶
Handle hover effect
:param event: The hover event :type event: Optional[QGraphicsSceneHoverEvent]
hoverLeaveEvent ¶
Handle hover effect
:param event: The hover event :type event: Optional[QGraphicsSceneHoverEvent]
setSource ¶
Set source point
:param x: x position
:type x: float
:param y: y position
:type y: float
setDestination ¶
Set destination point
:param x: x position
:type x: float
:param y: y position
:type y: float
setPositions ¶
Set both ends and adopt the resulting path once.
A node move changes both ends. Adopting inside each setter would run the route calculation twice per edge per move, and that calculation is the expensive part of moving a node.
:param source: new source point :param destination: new destination point
adoptGeometry ¶
Recompute the drawn path right away, so Qt invalidates the true rect.
The setters run before the caller repaints, and a path picked up only
while painting invalidates the previous geometry (see
:meth:refreshPath).
strokeMargin ¶
Half the widest pen this edge can paint with, plus an antialias pixel.
paint strokes the path, and a stroke reaches half its width past the
path on both sides. A boundingRect of the bare path is therefore
smaller than what the item draws, and every repaint leaves the outer band
of the previous stroke on screen. That is not a one-pixel cosmetic
miss: while a node is dragged, each frame adds a band along the path's
old position, and dozens of frames accumulate into the smeared arcs and
loops the canvas was showing.
refreshPath ¶
Adopt the current path and label position now.
Qt invalidates an item by its declared geometry, so an item that only
adopts a new path while painting invalidates the previous one and draws
the new one: whatever the old path covered outside both rectangles stays
on screen. Callers that know the edge moved (updatePositions) call
this first, which makes setPath repaint the union of old and new.
shape ¶
Returns QPainterPath representation of this Edge
:return: path representation
:rtype: QPainterPath
paint ¶
Qt's overridden method to paint this Graphics Edge. Path calculated
in :func:~nodeeditor.node_graphics_edge.QDMGraphicsEdge.calcPath method
intersectsWith ¶
Does this Graphics Edge intersect with the line between point A and point B ?
:param p1: point A
:type p1: QPointF
:param p2: point B
:type p2: QPointF
:return: True if this Graphics Edge intersects
:rtype: bool
calcPath ¶
Will handle drawing QPainterPath from Point A to B. Internally there exist self.pathCalculator which
is an instance of derived :class:~nodeeditor.node_graphics_edge_path.GraphicsEdgePathBase class
containing the actual calcPath() function - computing how the edge should look like.
:returns: QPainterPath of the edge connecting source and destination
:rtype: QPainterPath
nodeeditor.node_graphics_edge_path ¶
A module containing the classes that calculate the graphics path drawn for an Edge.
Every class derives from :class:GraphicsEdgePathBase and implements
:meth:GraphicsEdgePathBase.calcPath, which turns the positions of the edge's
two sockets into the :class:~qtpy.QtGui.QPainterPath that gets painted.
GraphicsEdgePathBase ¶
Base Class for calculating the graphics path to draw for an graphics Edge
calcPath ¶
Calculate the Direct line connection
:returns: QPainterPath of the graphics path to draw
:rtype: QPainterPath or None
GraphicsEdgePathDirect ¶
Bases: GraphicsEdgePathBase
Direct line connection Graphics Edge
calcPath ¶
Calculate the Direct line connection
:returns: QPainterPath of the direct line
:rtype: QPainterPath
GraphicsEdgePathBezier ¶
Bases: GraphicsEdgePathBase
Cubic line connection Graphics Edge
calcPath ¶
Calculate the cubic Bezier line connection with 2 control points
:returns: QPainterPath of the cubic Bezier line
:rtype: QPainterPath
GraphicsEdgePathSquare ¶
Bases: GraphicsEdgePathBase
Square line connection Graphics Edge
calcPath ¶
Calculate the square edge line connection
:returns: QPainterPath of the edge square line
:rtype: QPainterPath
GraphicsEdgePathImprovedSharp ¶
Bases: GraphicsEdgePathBase
Better Cubic line connection Graphics Edge
calcPath ¶
Calculate the Direct line connection
:returns: QPainterPath of the painting line
:rtype: QPainterPath
GraphicsEdgePathImprovedBezier ¶
Bases: GraphicsEdgePathBase
Better Cubic line connection Graphics Edge
calcPath ¶
Calculate the Direct line connection
:returns: QPainterPath of the painting line
:rtype: QPainterPath
nodeeditor.node_graphics_cutline ¶
A module containing the class for Cutting Line