nodedge.node

Node module containing Node class.

class nodedge.node.NodesAndSockets(nodes, sockets)

Bases: object

NodesAndSockets class

Parameters
  • nodes – list of nodes to add to the structure

  • sockets – list of sockets to add to the structure

class nodedge.node.Node(scene: Scene, title: str = 'Undefined node', inputSocketTypes: Collection[int] = (), outputSocketTypes: Collection[int] = ())

Bases: nodedge.serializable.Serializable

Node class representing a node in the Scene.

Parameters
  • scene (Scene) – reference to the Scene

  • title (str) – node title shown in scene

  • inputSocketTypes (Collection[int]) – list of types of the input Sockets

  • outputSocketTypes (Collection[int]) – list of types of the output Sockets

GraphicsNodeClass

alias of nodedge.graphics_node.GraphicsNode

GraphicsNodeContentClass

alias of nodedge.graphics_node_content.GraphicsNodeContent

SocketClass

alias of nodedge.connector.Socket

contentLabelObjectName = 'undefined'
initInnerClasses() → None

Set up graphics node and content widget.

initSettings() → None

Initialize properties and sockets information.

initSockets(inputs: Collection[int], outputs: Collection[int], reset: bool = True) → None

Create input and output sockets.

Parameters
  • inputs (Collection[int]) – list of types of the input Sockets. Every type is associated with a int

  • outputs (Collection[int]) – list of types of the input Sockets

  • reset (bool) – if True destroy and remove old Sockets

onEdgeConnectionChanged(newEdge: nodedge.edge.Edge) → None

Handle event associated with a change in any of the connections (Edge). Currently unused.

Parameters

newEdge (Edge) – reference to the changed Edge

onInputChanged(socket: nodedge.connector.Socket)

Handle event associated with a change in this node’s input edge. When it happens, this node and all its descendants are labelled as dirty.

Parameters

socket (Socket) – reference to the changed Socket

property title

Title shown in the scene.

Getter

return current node title

Setter

set node title and pass it to the graphical node

Return type

str

property pos

Retrieve node’s position in the scene

Returns

node position

Return type

QPointF

property isDirty

Property stating whether or not this node is marked as Dirty, i.e. the node has not been evaluated since last node’s input/output change.

Getter

True if this node is marked as Dirty, False otherwise

Setter

set the dirtiness status of this node

Type

bool

property isInvalid

Property stating whether or not this node is marked as Invalid, i.e. the node has been evaluated since last node’s input/output change, but the evaluation was inconsistent.

Getter

True if this node is marked as Invalid, False otherwise

Setter

set the validity status of this node

Type

bool

property isSelected

Retrieve graphics node selection status.

socketPos(index: int, location: int, countOnThisSide: int = 1) → PySide2.QtCore.QPointF

Get the relative x, y position of a Socket. This is used for placing the GraphicsSocket on Graphics Node.

Parameters
  • index (int) – Order number of the Socket. (0, 1, 2, …)

  • location (SocketLocation) – Socket location constant describing where the Socket is located

  • countOnThisSide (int) – Total number of Sockets on this Socket Position

Returns

Position of described Socket on the Node

Return type

QPointF

updateConnectedEdges()

Refresh positions of all connected Edges. It is used for updating graphical edges.

remove()

Safely remove this node.

onMarkedDirty()

Called when this Node has been marked as Dirty. This method must be overridden.

markChildrenDirty(newValue: bool = True) → None

Mark the children of this node to be Dirty. Children are first-level descendants. Note: it does not apply to this node.

Parameters

newValue (bool) – True if children should be Dirty, False to un-dirty them.

markDescendantsDirty(newValue: bool = True) → None
Mark all-level descendants of this Node to be Dirty.

Note: it does not apply to this node.

Parameters

newValue (bool) – True if descendants should be Dirty, False to un-dirty them.

onMarkedInvalid() → None

Called when this node has been marked as Invalid. This method must be overridden.

markChildrenInvalid(newValue: bool = True) → None

Mark children of this node as Invalid. Children are first-level descendants. Note: it does not apply to this node.

Parameters

newValue (bool) – True if children should be Invalid, False to make them valid.

markDescendantsInvalid(newValue: bool = True) → None

Mark descendants of this node as Invalid. Note: it does not apply to this node.

Parameters

newValue (bool) – True if descendants should be Invalid, False to make descendants valid.

eval(index=0) → float

Evaluate this node. This must be overridden. See Evaluation for more details.

evalChildren() → None

Evaluate children of this node

getChildNodes() → List[nodedge.node.Node]

Retrieve all children connected to this node outputs.

Returns

list of Nodes connected to this node from all outputs

Return type

List[Node]

getParentNodes() → List[nodedge.node.Node]

Retrieve all parents connected to this node outputs.

Returns

list of Nodes connected to this node from all inputs

Return type

List[Node]

inputNodesAt(index: int) → List[nodedge.node.Node]

Get all nodes connected to the input specified by index.

Parameters

index (int) – order number of the input socket

Returns

all Node instances which are connected to the specified input or [] if there is no connection or index is out of range.

Return type

List[Node]

inputNodeAt(index: int) → Optional[nodedge.node.Node]

Get the first node connected to the input specified by index.

Parameters

index (int) – order number of the input socket

Returns

Node which is connected to the specified input or None if there is no connection or index is out of range

Return type

Node

inputNodeAndSocketAt(index)
outputNodesAt(index: int) → List[nodedge.node.Node]

Get all nodes connected to the output specified by index.

Parameters

index (int) – order number of the output socket

Returns

all Node instances which are connected to the specified output or [] if there is no connection or index is out of range.

Return type

List[Node]

serialize() → collections.OrderedDict

Serialization method to serialize this class data into OrderedDict which can be stored in memory or file easily.

Returns

data serialized in OrderedDict

Return type

OrderedDict

deserialize(data: dict, hashmap: Optional[dict] = None, restoreId: bool = True, *args, **kwargs)

Deserialization method which take data in python dict format with helping hashmap containing references to existing entities.

Parameters
  • data (dict) – dictionary containing serialized data

  • hashmap (dict) – helper dictionary containing references (by id == key) to existing objects

  • restoreId (bool) – True if we are creating new sockets. False is useful when loading existing sockets which we want to keep the existing object’s id

Returns

True if deserialization was successful, False otherwise

Return type

bool

onDoubleClicked(event: PySide2.QtWidgets.QGraphicsSceneMouseEvent) → None

Callback when the GraphicsNode is double clicked.

Parameters

event (QMouseEvent) – Qt double click event

getNodeContentClass()

Returns class representing node content.

getGraphicsNodeClass()

Returns class representing graphics node.

getSocketScenePosition(socket: nodedge.connector.Socket) → PySide2.QtCore.QPointF

Get absolute Socket position in the Socket.

Parameters

socket (Socket) – The socket from which we want to get the position

Returns

Socket’s scene position

Return type

QPointF

addSelectedListener(callback)
onDeserialized(data: dict)

Event manually called when this node was deserialized. Currently called when node is deserialized from Scene.

Parameters

data (dict) – data which have been deserialized