node_edge Module

A module containing NodeEditor’s class for representing Edge and Edge Type Constants.

Edge Type Constants

nodeeditor.node_edge.EDGE_TYPE_DIRECT = 1
nodeeditor.node_edge.EDGE_TYPE_BEZIER = 2

Edge Validators

Edge Validator can be registered to Edge class using its method registerEdgeValidator().

Each validator callback takes 2 params: start_socket and end_socket. Validator also needs to return True or False. For example of validators have a look in node_edge_validators module.

Here is an example how you can register the Edge Validator callbacks:

from nodeeditor.node_edge_validators import *

Edge.registerEdgeValidator(edge_validator_debug)
Edge.registerEdgeValidator(edge_cannot_connect_two_outputs_or_two_inputs)
Edge.registerEdgeValidator(edge_cannot_connect_input_and_output_of_same_node)

Edge Class

class nodeeditor.node_edge.Edge(scene: Scene, start_socket: Socket = None, end_socket: Socket = None, edge_type=1)

Bases: nodeeditor.node_serializable.Serializable

Class for representing Edge in NodeEditor.

Parameters
  • scene (Scene) – Reference to the Scene

  • start_socket (Socket) – Reference to the starting socket

  • end_socket (Socket or None) – Reference to the End socket or None

  • edge_type – Constant determining type of edge. See Edge Type Constants

Instance Attributes
  • scene - reference to the Scene

  • grEdge - Instance of QDMGraphicsEdge subclass handling graphical representation in the QGraphicsScene.

edge_validators = []

class variable containing list of registered edge validators

property start_socket

Start socket

Getter

Returns start Socket

Setter

Sets start Socket safely

Type

Socket

property end_socket

End socket

Getter

Returns end Socket or None if not set

Setter

Sets end Socket safely

Type

Socket or None

property edge_type

Edge type

Getter

get edge type constant for current Edge. See Edge Type Constants

Setter

sets new edge type. On background, creates new QDMGraphicsEdge child class if necessary, adds this QGraphicsPathItem to the QGraphicsScene and updates edge sockets positions.

classmethod getEdgeValidators()

Return the list of Edge Validator Callbacks

classmethod registerEdgeValidator(validator_callback: function)

Register Edge Validator Callback

Parameters

validator_callback (function) – A function handle to validate Edge

classmethod validateEdge(start_socket: Socket, end_socket: Socket)bool

Validate Edge agains all registered Edge Validator Callbacks

Parameters
Returns

True if the Edge is valid or False if not

Return type

bool

reconnect(from_socket: Socket, to_socket: Socket)

Helper function which reconnects edge from_socket to to_socket

getGraphicsEdgeClass()

Returns the class representing Graphics Edge

createEdgeClassInstance()

Create instance of grEdge class :return: Instance of grEdge class representing the Graphics Edge in the grScene

getOtherSocket(known_socket: Socket)

Returns the opposite socket on this Edge

Parameters

known_socket (Socket) – Provide known Socket to be able to determine the opposite one.

Returns

The oposite socket on this Edge or None

Return type

Socket or None

doSelect(new_state: bool = True)

Provide the safe selecting/deselecting operation. In the background it takes care about the flags, notifications and storing history for undo/redo.

Parameters

new_state (bool) – True if you want to select the Edge, False if you want to deselect the Edge

updatePositions()

Updates the internal Graphics Edge positions according to the start and end Socket. This should be called if you update Edge positions.

remove_from_sockets()

Helper function which sets start and end Socket to None

remove(silent_for_socket: Socket = None, silent=False)

Safely remove this Edge.

Removes Graphics Edge from the QGraphicsScene and it’s reference to all GC to clean it up. Notifies nodes previously connected Node (s) about this event.

Triggers Nodes’:

Parameters
  • silent_for_socket (Socket) – Socket of a Node which won’t be notified, when this Edge is going to be removed

  • silent (bool) – True if no events should be triggered during removing

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