nodedge.socket

Socket module containing Nodedge’s class for representing Socket class and SocketLocation constants.

class nodedge.socket.SocketLocation

Bases: enum.IntEnum

An enumeration.

LEFT_TOP = 1

Left top

LEFT_CENTER = 2

Left center

LEFT_BOTTOM = 3

Left bottom

RIGHT_TOP = 4

Right top

RIGHT_CENTER = 5

Right center

RIGHT_BOTTOM = 6

Right bottom

class nodedge.socket.Socket(node: Node, index: int = 0, location: int = <SocketLocation.LEFT_TOP: 1>, socketType: int = 1, allowMultiEdges: bool = True, countOnThisNodeSide: int = 1, isInput: bool = False)

Bases: nodedge.serializable.Serializable

Class representing input/output sockets of the nodes.

Parameters:
  • node (Node) – reference to the Node containing this socket
  • index (int) – current index of this socket in the position
  • location (SocketLocation) – socket position
  • socketType – constant defining type of this socket. Every type is visually associated to a color.
  • allowMultiEdges (bool) – attribute that defines if this socket can have multiple connected edges
  • countOnThisNodeSide (int) – number of total sockets on this socket side, i.e. input/output
  • isInput (bool) – attribute that defines whether this is an input or an output socket
GraphicsSocketClass

alias of nodedge.graphics_socket.GraphicsSocket

socketType
isOutput
Getter:Return True is the Socket is not an input, False otherwise.
Return type:bool
delete()

Delete this Socket from Scene.

hasAnyEdge

Whether the Socket has any Edge connected to it.

Returns:True if any Edge is connected to this Socket
Return type:bool
pos
Returns:return this socket’s position according the implementation stored in Node
Return type:x, y position
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
updateSocketPos() → None

Helper function to set the graphical socket position. The exact socket position is calculated inside Node.

addEdge(edge: Optional[Edge] = None) → None

Append an Edge to the list of the connected Edge.

Parameters:edge (Edge) – Edge to connect to this Socket
removeEdge(edgeToRemove: Edge) → None

Disconnect passed Edge from this Socket.

Parameters:edgeToRemove (Edge) – Edge to disconnect
removeAllEdges(silent=False) → None

Disconnect all Edge from this Socket.

Parameters:silent (bool) – If true, remove the edge without notifications
static determineAllowMultiEdges(data)

Deserialization helper function.

Note

This function is here to help solve the issue of opening older files in the newer format.

If the allowMultiEdges param is missing in the dictionary, we determine if this Socket should support multiple Edge.

Parameters:data (dict) – socket’s data in dict format for deserialization
Returns:True if this socket should support multiple edges
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