node_node Module

A module containing NodeEditor’s class for representing Node.

class nodeeditor.node_node.Node(scene: Scene, title: str = 'Undefined Node', inputs: list = [], outputs: list = [])

Bases: nodeeditor.node_serializable.Serializable

Class representing Node in the Scene.

Parameters
  • scene (Scene) – reference to the Scene

  • title (str) – Node Title shown in Scene

  • inputs – list of Socket types from which the Sockets will be auto created

  • outputs – list of Socket types from which the Sockets will be auto created

Instance Attributes
  • scene - reference to the Scene

  • grNode - Instance of QDMGraphicsNode handling graphical representation in the QGraphicsScene. Automatically created in the constructor

  • content - Instance of QDMGraphicsContent which is child of QWidget representing container for all inner widgets inside of the Node. Automatically created in the constructor

  • inputs - list containin Input Socket instances

  • outputs - list containin Output Socket instances

GraphicsNode_class

alias of nodeeditor.node_graphics_node.QDMGraphicsNode

NodeContent_class

alias of nodeeditor.node_content_widget.QDMNodeContentWidget

Socket_class

alias of nodeeditor.node_socket.Socket

property title

Title shown in the scene

Getter

return current Node title

Setter

sets Node title and passes it to Graphics Node class

Type

str

property pos

Retrieve Node’s position in the Scene

Returns

Node position

Return type

QPointF

setPos(x: float, y: float)

Sets position of the Graphics Node

Parameters
  • x – X Scene position

  • y – Y Scene position

initInnerClasses()

Sets up graphics Node (PyQt) and Content Widget

getNodeContentClass()

Returns class representing nodeeditor content

getGraphicsNodeClass()
initSettings()

Initialize properties and socket information

initSockets(inputs: list, outputs: list, reset: bool = True)

Create sockets for inputs and outputs

Parameters
  • inputs (list) – list of Socket Types (int)

  • outputs (list) – list of Socket Types (int)

  • reset (bool) – if True destroys and removes old Sockets

onEdgeConnectionChanged(new_edge: Edge)

Event handling that any connection (Edge) has changed. Currently not used…

Parameters

new_edge (Edge) – reference to the changed Edge

onInputChanged(socket: nodeeditor.node_socket.Socket)

Event handling when Node’s input Edge has changed. We auto-mark this Node to be Dirty with all it’s descendants

Parameters

socket (Socket) – reference to the changed Socket

onDeserialized(data: dict)

Event manually called when this node was deserialized. Currently called when node is deserialized from scene Passing data containing the data which have been deserialized

onDoubleClicked(event)

Event handling double click on Graphics Node in Scene

doSelect(new_state: bool = True)

Shortcut method for selecting/deselecting the Node

Parameters

new_state (bool) – True if you want to select the Node. False if you want to deselect the Node

isSelected()

Returns True if current Node is selected

hasConnectedEdge(edge: Edge)

Returns True if edge is connected to any Socket of this Node

getSocketPosition(index: int, position: int, num_out_of: int = 1)

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

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

  • position (int) – Socket Position Constant describing where the Socket is located. See Socket Position Constants

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

Returns

Position of described Socket on the Node

Return type

x, y

getSocketScenePosition(socket: Socket)

Get absolute Socket position in the Scene

Parameters

socketSocket which position we want to know

Returns

(x, y) Socket’s scene position

updateConnectedEdges()

Recalculate (Refresh) positions of all connected Edges. Used for updating Graphics Edges

remove()

Safely remove this Node

isDirty()bool

Is this node marked as Dirty

Returns

True if Node is marked as Dirty

Return type

bool

markDirty(new_value: bool = True)

Mark this Node as Dirty. See Evaluation for more

Parameters

new_value (bool) – True if this Node should be Dirty. False if you want to un-dirty this Node

onMarkedDirty()

Called when this Node has been marked as Dirty. This method is supposed to be overridden

markChildrenDirty(new_value: bool = True)

Mark all first level children of this Node to be Dirty. Not this Node it self. Not other descendants

Parameters

new_value (bool) – True if children should be Dirty. False if you want to un-dirty children

markDescendantsDirty(new_value: bool = True)

Mark all children and descendants of this Node to be Dirty. Not this Node it self

Parameters

new_value (bool) – True if children and descendants should be Dirty. False if you want to un-dirty children and descendants

isInvalid()bool

Is this node marked as Invalid?

Returns

True if Node is marked as Invalid

Return type

bool

markInvalid(new_value: bool = True)

Mark this Node as Invalid. See Evaluation for more

Parameters

new_value (bool) – True if this Node should be Invalid. False if you want to make this Node valid

onMarkedInvalid()

Called when this Node has been marked as Invalid. This method is supposed to be overridden

markChildrenInvalid(new_value: bool = True)

Mark all first level children of this Node to be Invalid. Not this Node it self. Not other descendants

Parameters

new_value (bool) – True if children should be Invalid. False if you want to make children valid

markDescendantsInvalid(new_value: bool = True)

Mark all children and descendants of this Node to be Invalid. Not this Node it self

Parameters

new_value (bool) – True if children and descendants should be Invalid. False if you want to make children and descendants valid

eval(index=0)

Evaluate this Node. This is supposed to be overridden. See Evaluation for more

evalChildren()

Evaluate all children of this Node

getChildrenNodes()List[Node]

Retreive all first-level children connected to this Node Outputs

Returns

list of Nodes connected to this Node from all Outputs

Return type

List[Node]

getInput(index: int = 0)[‘Node’, None]

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 the index is out of range

Return type

Node or None

getInputWithSocket(index: int = 0)[(‘Node’, ‘Socket’), (None, None)]

Get the first Node connected to the Input specified by index and the connection Socket

Parameters

index (int) – Order number of the Input Socket

Returns

Tuple containing Node and Socket which is connected to the specified Input or None if there is no connection or the index is out of range

Return type

(Node, Socket)

getInputWithSocketIndex(index: int = 0) -> ('Node', <class 'int'>)

Get the first Node connected to the Input specified by index and the connection Socket

Parameters

index (int) – Order number of the Input Socket

Returns

Tuple containing Node and Socket which is connected to the specified Input or None if there is no connection or the index is out of range

Return type

(Node, int)

getInputs(index: int = 0)List[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 the index is out of range

Return type

List[Node]

getOutputs(index: int = 0)List[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 the index is out of range

Return type

List[Node]

serialize()collections.OrderedDict

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

Returns

data serialized in OrderedDict

Return type

OrderedDict

deserialize(data: dict, hashmap: dict = {}, restore_id: bool = True, *args, **kwargs)bool

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

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

Returns

True if deserialization was successful, otherwise False

Return type

bool