node_socket Module

A module containing NodeEditor’s class for representing Socket and Socket Position Constants.

Socket Position Constants

nodeeditor.node_socket.LEFT_TOP = 1
nodeeditor.node_socket.LEFT_CENTER = 2
nodeeditor.node_socket.LEFT_BOTTOM = 3
nodeeditor.node_socket.RIGHT_TOP = 4
nodeeditor.node_socket.RIGHT_CENTER = 5
nodeeditor.node_socket.RIGHT_BOTTOM = 6

Socket Class

class nodeeditor.node_socket.Socket(node: Node, index: int = 0, position: int = 1, socket_type: int = 1, multi_edges: bool = True, count_on_this_node_side: int = 1, is_input: bool = False)

Bases: nodeeditor.node_serializable.Serializable

Parameters
  • node (Node) – reference to the Node containing this Socket

  • index (int) – Current index of this socket in the position

  • position – Socket position. See Socket Position Constants

  • socket_type – Constant defining type(color) of this socket

  • multi_edges (bool) – Can this socket have multiple Edges connected?

  • count_on_this_node_side (int) – number of total sockets on this position

  • is_input (bool) – Is this an input Socket?

Instance Attributes
  • node - reference to the Node containing this Socket

  • edges - list of Edges connected to this Socket

  • grSocket - reference to the QDMGraphicsSocket

  • position - Socket position. See Socket Position Constants

  • index - Current index of this socket in the position

  • socket_type - Constant defining type(color) of this socket

  • count_on_this_node_side - number of sockets on this position

  • is_multi_edges - True if Socket can contain multiple Edges

  • is_input - True if this socket serves for Input

  • is_output - True if this socket serves for Output

Socket_GR_Class

alias of nodeeditor.node_graphics_socket.QDMGraphicsSocket

delete()

Delete this Socket from graphics scene for sure

changeSocketType(new_socket_type: int)bool

Change the Socket Type

Parameters

new_socket_type (int) – new socket type

Returns

Returns True if the socket type was actually changed

Return type

bool

setSocketPosition()

Helper function to set Graphics Socket position. Exact socket position is calculated inside Node.

getSocketPosition()
Returns

Returns this Socket position according to the implementation stored in Node

Return type

x, y position

hasAnyEdge()bool

Returns True if any Edge is connected to this socket

Returns

True if any Edge is connected to this socket

Return type

bool

isConnected(edge: Edge)bool

Returns True if Edge is connected to this Socket

Parameters

edge (Edge) – Edge to check if it is connected to this Socket

Returns

True if Edge is connected to this socket

Return type

bool

addEdge(edge: Edge)

Append an Edge to the list of connected Edges

Parameters

edge (Edge) – Edge to connect to this Socket

removeEdge(edge: Edge)

Disconnect passed Edge from this Socket :param edge: Edge to disconnect :type edge: Edge

removeAllEdges(silent=False)

Disconnect all Edges from this Socket

determineMultiEdges(data: dict)bool

Deserialization helper function. In our tutorials we created a new version of graph data format. This function is here to help solve the issue of opening older files in the newer format. If the ‘multi_edges’ param is missing in the dictionary, we determine if this Socket should support multiple Edges.

Parameters

data (dict) – Socket data in dict format for deserialization

Returns

True if this Socket should support multi_edges

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)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