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.SerializableClass for representing Edge in NodeEditor.
- Parameters
start_socket (
Socket) – Reference to the starting socketend_socket (
SocketorNone) – Reference to the End socket orNoneedge_type – Constant determining type of edge. See Edge Type Constants
- Instance Attributes
scene - reference to the
ScenegrEdge - Instance of
QDMGraphicsEdgesubclass handling graphical representation in theQGraphicsScene.
-
edge_validators= []¶ class variable containing list of registered edge validators
-
property
start_socket¶ Start socket
-
property
end_socket¶ End socket
-
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
QDMGraphicsEdgechild class if necessary, adds thisQGraphicsPathItemto theQGraphicsSceneand 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
-
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
-
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) –Trueif you want to select theEdge,Falseif you want to deselect theEdge
-
updatePositions()¶ Updates the internal Graphics Edge positions according to the start and end
Socket. This should be called if you updateEdgepositions.
-
remove(silent_for_socket: Socket = None, silent=False)¶ Safely remove this Edge.
Removes Graphics Edge from the
QGraphicsSceneand it’s reference to all GC to clean it up. Notifies nodes previously connectedNode(s) about this event.Triggers Nodes’:
-
serialize() → collections.OrderedDict¶ Serialization method to serialize this class data into
OrderedDictwhich 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
dictformat with helping hashmap containing references to existing entities.- Parameters
data (
dict) – Dictionary containing serialized datahashmap (
dict) – Helper dictionary containing references (by id == key) to existing objectsrestore_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
Trueif deserialization was successful, otherwiseFalse- Return type
bool