QNodeEditor.edge.Edge#

class QNodeEditor.edge.Edge(start: ~QNodeEditor.socket.Socket | None = None, end: ~QNodeEditor.socket.Socket | None = None, scene: NodeScene | None = None, theme: ~typing.Type[~QNodeEditor.themes.theme.Theme] = <class 'QNodeEditor.themes.dark.DarkTheme'>)#

Bases: QObject

Edge container holding a start and end socket, and various utility methods.

This class represents a connection between two sockets. It is also possible for only one end of the edge to be connected to a socket.

Edges can only connect an input to an output, or vice versa. It is not possible to connect two inputs or two outputs together.

In general, it is not necessary to instantiate this class since it is handled by the node editor itself. However, in case you want to set the state of a node editor before opening it, this class can be used to already connect nodes in your scene.

Examples

To define an edge that connects two nodes:

node1 = SomeNode()     # Node containing the output entry 'Output'
node2 = AnotherNode()  # Node containing the input entry 'Value'

edge = Edge(node1['Output'], node2['Value'])

This adds an edge to the NodeScene the nodes are part of.

graphics#

Graphics object that is shown in the scene representing this edge

Type:

EdgeGraphics

Properties

edge_type_changed()

Signal that is emitted when the edge type is changed

end

Get or set the end socket of the edge

end_changed()

Signal that is emitted when the end socket changed

scene

Get or set the scene this edge is part of.

start

Get or set the start socket of the edge

start_changed()

Signal that is emitted when the start socket changed

theme

Get or set the theme of the edge.

Methods

__init__

Create a new edge.

get_state

Get the state of this edge as a (JSON-safe) dictionary.

remove

Remove this edge from the scene (and from the sockets it is connected to)

remove_from_sockets

Remove the edge from the sockets it is connected to.

set_state

Set the state of this edge from a state dictionary.

update_positions

Update the positions of the start and end points.

__init__(start: ~QNodeEditor.socket.Socket | None = None, end: ~QNodeEditor.socket.Socket | None = None, scene: NodeScene | None = None, theme: ~typing.Type[~QNodeEditor.themes.theme.Theme] = <class 'QNodeEditor.themes.dark.DarkTheme'>)#

Create a new edge.

Parameters:
  • start (Socket or Entry, optional) – Start point of the edge (either a socket or an entry with a socket)

  • end (Socket or Entry, optional) – End point of the edge (either a socket or an entry with a socket)

  • scene (NodeScene, optional) – Scene to place the edge in. In general, this argument is not needed and the scene is deduced from the start and end sockets. If neither are provided, this argument is required.

  • theme (Type[Theme], optional) – Theme for the edge (default: DarkTheme)

get_state() dict#

Get the state of this edge as a (JSON-safe) dictionary.

The dictionary contains:

  • start: the ID of the start socket (or None if no start socket)

  • end: the ID of the end socket (or None if no end socket)

Returns:

JSON-safe dictionary representing the edge state

Return type:

dict

remove() None#

Remove this edge from the scene (and from the sockets it is connected to) . :rtype: None

remove_from_sockets() None#

Remove the edge from the sockets it is connected to.

Return type:

None

set_state(state: dict, lookup: dict[str, str] = None) bool#

Set the state of this edge from a state dictionary.

The dictionary contains:

  • start: the ID of the start socket (or None if no start socket)

  • end: the ID of the end socket (or None if no end socket)

Parameters:
  • state (dict) – Dictionary representation of the desired edge state

  • lookup (dict[str, str], optional) – Dictionary with mapping of state socket ID to actual socket ID. If the socket was added from a state with restore_id=True, these two are equal. Otherwise, the socket will take on a new unique ID, which will be the value in (key, value) pairs.

Returns:

Whether setting the edge state succeeded

Return type:

bool

update_positions() None#

Update the positions of the start and end points.

Used when a node is moved to read the new positions of the start and end sockets and update them in the graphics of the edge.

Return type:

None

edge_type_changed: Signal#

Signal that is emitted when the edge type is changed

Type:

Signal

property end: Socket | None#

Get or set the end socket of the edge

Setting a new end node removes the edge from the old ending point (if it was set) and connects the edge to the new end point.

end_changed: Signal#

Signal that is emitted when the end socket changed

Type:

Signal

property scene: NodeScene#

Get or set the scene this edge is part of.

Setting a new scene removes the edge from the old scene (if it was set) and adds the edge to the new scene.

property start: Socket | None#

Get or set the start socket of the edge

Setting a new start node removes the edge from the old starting point (if it was set) and connects the edge to the new start point.

start_changed: Signal#

Signal that is emitted when the start socket changed

Type:

Signal

property theme: Type[Theme]#

Get or set the theme of the edge.