Skip to content

Socket

Sockets are the connection points on a node.

nodeeditor.node_socket

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

Socket

Bases: QObject, Serializable

Class representing Socket.

Socket_GR_Class class-attribute instance-attribute

Socket_GR_Class = QDMGraphicsSocket

Class representing Socket.

delete

delete()

Delete this Socket from graphics scene for sure

changeSocketType

changeSocketType(new_socket_type)

Change the Socket Type

:param new_socket_type: new socket type :type new_socket_type: int :return: Returns True if the socket type was actually changed :rtype: bool

setSocketPosition

setSocketPosition()

Helper function to set Graphics Socket position. Exact socket position is calculated inside :class:~nodeeditor.node_node.Node.

getSocketPosition

getSocketPosition()

:return: Returns this Socket position according to the implementation stored in :class:~nodeeditor.node_node.Node :rtype: x, y position

hasAnyEdge

hasAnyEdge()

Returns True if any :class:~nodeeditor.node_edge.Edge is connected to this socket

:return: True if any :class:~nodeeditor.node_edge.Edge is connected to this socket :rtype: bool

isConnected

isConnected(edge)

Returns True if :class:~nodeeditor.node_edge.Edge is connected to this Socket

:param edge: :class:~nodeeditor.node_edge.Edge to check if it is connected to this Socket :type edge: :class:~nodeeditor.node_edge.Edge :return: True if Edge is connected to this socket :rtype: bool

addEdge

addEdge(edge, index=None)

Append an Edge to the list of connected Edges

On an input socket the Edge also gets a read position (see :attr:~nodeeditor.node_edge.Edge.input_index). Pass index to place it at a specific slot; when index is None a value already set on the Edge (Edge(..., input_index=n) or deserialization) is used, and otherwise the Edge is appended, i.e. it is read last. Output sockets are not ordered and ignore index.

:param edge: :class:~nodeeditor.node_edge.Edge to connect to this Socket :type edge: :class:~nodeeditor.node_edge.Edge :param index: 0-based read position on an input socket or None to append at the end (default: order of connection) :type index: int or None

removeEdge

removeEdge(edge)

Disconnect passed :class:~nodeeditor.node_edge.Edge from this Socket :param edge: :class:~nodeeditor.node_edge.Edge to disconnect :type edge: :class:~nodeeditor.node_edge.Edge

removeAllEdges

removeAllEdges(silent=False)

Disconnect all Edges from this Socket

orderedEdges

orderedEdges()

Connected Edges in read order.

On an input Socket this is the connection order maintained by :meth:addEdge; on an output Socket it is the plain connection list.

:return: Edges connected to this Socket, first read position first :rtype: List[:class:~nodeeditor.node_edge.Edge]

edgeIndex

edgeIndex(edge)

Read position of edge on this input Socket.

:param edge: :class:~nodeeditor.node_edge.Edge to look up :type edge: :class:~nodeeditor.node_edge.Edge :return: 0-based read position or -1 if not connected to this Socket :rtype: int

compactEdgeOrder

compactEdgeOrder()

Re-sort and renumber this input Socket's Edges to a gap free 0..n-1 sequence. Useful after assigning :attr:~nodeeditor.node_edge.Edge.input_index directly from code.

:return: True if anything actually changed :rtype: bool

setEdgeOrder

setEdgeOrder(edges)

Set the read order of the Edges connected to this input Socket.

edges may be a partial list; connected Edges missing from it are appended afterwards keeping their current relative order. Duplicates and Edges of other sockets are ignored, so passing a stale or reordered reference is safe.

:param edges: Edges of this socket, first read position first :type edges: List[:class:~nodeeditor.node_edge.Edge] :return: True if the order changed :rtype: bool

moveEdgeTo

moveEdgeTo(edge, position)

Move edge to read position position on this input Socket.

:param edge: :class:~nodeeditor.node_edge.Edge to move :type edge: :class:~nodeeditor.node_edge.Edge :param position: target read position :type position: int :return: True if the order changed :rtype: bool

swapEdges

swapEdges(edge_a, edge_b)

Swap the read positions of two Edges of this input Socket.

:param edge_a: first :class:~nodeeditor.node_edge.Edge to swap :type edge_a: :class:~nodeeditor.node_edge.Edge :param edge_b: second :class:~nodeeditor.node_edge.Edge to swap :type edge_b: :class:~nodeeditor.node_edge.Edge :return: True if the order changed :rtype: bool

determineMultiEdges

determineMultiEdges(data)

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.

:param data: Socket data in dict format for deserialization :type data: dict :return: True if this Socket should support multi_edges

serialize

serialize()

Serialize this Socket into an OrderedDict for storing in memory or on disk.

:return: data serialized in OrderedDict :rtype: OrderedDict

deserialize

deserialize(data, hashmap={}, restore_id=True)

Deserialize this Socket from a dict of serialized data.

:param data: Dictionary containing serialized data :type data: dict :param hashmap: Helper dictionary containing references (by id == key) to existing objects :type hashmap: dict :param restore_id: 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. :type restore_id: bool :return: True if deserialization was successful, otherwise False :rtype: bool