Groups
A Group is a visual container for nodes. It is not a Node: it has no
sockets, it takes no part in evaluation, and the nodes inside it keep their
positions and edges when the group is collapsed.
nodeeditor.node_group_node is a backward-compatible alias for this module.
nodeeditor.node_group ¶
Reliable ground-up grouping system.
Design notes (v2, clean break): - Group is a pure visual container (QGraphicsRectItem + Serializable), NOT a Node. - Nodes keep their positions/sizes at all times. Collapse only hides/shows, never resizes/scales nodes. This removes the fragile 0.2/scale(0)/width==5 hacks. - Logical Edges never mutate on collapse. Only their graphics endpoints are overridden to per-edge stub rows on the collapsed box. - Auto-fit + header-drag only. Child moves auto-expand, never auto-remove. - Serialization is versioned (version=2, type="Group", key "children"). Old files (type="GroupNode", "child_node_ids") load best-effort as expanded. - Delete-key semantics (handled in view): delete group + children. Context menu offers Ungroup (delete only the group, keep nodes). - Stub stacking: per-edge rows, left=incoming (end inside), right=outgoing (start inside).
Group ¶
Bases: Serializable, QGraphicsRectItem
Visual container grouping Nodes together.
addNode ¶
Add a node to the group.
A node belongs to at most one group, so adding it here detaches it from the group it was in before.
:param node: the :class:~nodeeditor.node_node.Node to add
removeNode ¶
Detach a node from the group, keeping the node itself.
:param node: the node to detach from the group :param update_bounds: recalculate the group box afterwards
calculateBounds ¶
Return the rectangle that tightly fits the child nodes.
The result is at least :attr:MIN_WIDTH by :attr:MIN_HEIGHT_EXPANDED
and leaves :attr:PADDING around the children.
onChildMoved ¶
Recalculate the group boundary whenever a child node moves.
Tight refit (may grow, shrink, or shift the origin). Never removes nodes — use Ungroup/detach explicitly. Collapsed groups ignore child moves (children are hidden and move with the container instead).
externalEdges ¶
Return the edges that cross the group boundary.
:return: a tuple of (incoming, outgoing) edges, where an incoming edge ends inside the group and an outgoing edge starts inside it
refreshExternalEdges ¶
Show or hide edges according to the collapsed state.
External edges are rerouted to their stub rows on the collapsed box, internal edges are hidden while the group is collapsed.
collapse ¶
Collapse the group into its title bar.
Child nodes and the edges between them are hidden, the box shrinks to the collapsed width, and the edges crossing the boundary are rerouted to stub rows. Node positions are preserved, so expanding restores the graph exactly as it was.
expand ¶
Expand the group, restoring the hidden nodes and edges.
The children reappear at the positions they had before the group was collapsed.
restoreExpandedVisuals ¶
Idempotent expanded visuals for undo/redo/load (mirrors expand without toggling).
setCollapsed ¶
Collapse or expand the group.
:param collapsed: True to collapse the group, False to expand it
renameInteractive ¶
Open rename dialog. Returns True if renamed (caller stores history).
setColors ¶
Set group colors. Any None arg is left unchanged. Returns True if changed.
recolorInteractive ¶
Open color dialog for fill color. Returns True if changed.
setDropHighlight ¶
Highlight the group while nodes are dragged over it.
:param enabled: whether the drop highlight should be shown
ungroup ¶
Delete only the group, keep all child nodes (explicit, no auto-remove elsewhere).
deleteWithChildren ¶
Delete-key semantics: delete container AND all child nodes (and their edges).
dispose ¶
Remove the group from the scene and from the graphics scene.
This is the low-level removal used by :meth:ungroup and
:meth:deleteWithChildren.
shape ¶
Hit-testing only: expanded = header (+toggle) only, collapsed = full rect.
boundingRect()/paint() stay full so the background still draws; only clicks/selection/rubber-band/itemAt ignore the expanded body, making it behave like plain canvas.
mousePressEvent ¶
Handle a press on the group.
The collapse toggle is handled first; a press on the title bar afterwards starts a drag of the group and its children.
mouseDoubleClickEvent ¶
Rename the group when its title bar is double-clicked.
mouseMoveEvent ¶
Move the group and its children while the title bar is dragged.
mouseReleaseEvent ¶
Finish dragging the group and store the move in the history.
contextMenuEvent ¶
Show the group context menu.
The menu offers collapsing, renaming, the colour presets, ungrouping and deleting the group together with its children.
paint ¶
Paint the group box, its title bar and the collapse toggle.
serialize ¶
Return the group as a JSON-serializable dictionary.
The format is versioned with :data:GROUP_SERIALIZATION_VERSION.
deserialize ¶
Restore the group from a dictionary created by :meth:serialize.
Files written by the old GroupNode format are loaded as expanded.
:param data: the serialized group :param hashmap: mapping of ids to objects, used to relink the children :param restore_id: whether the id stored in the file is restored :return: whether the group was restored
applyCollapsedAfterLoad ¶
Apply collapsed visuals after Scene linked children (no history).