node_scene Module¶
A module containing the representation of the NodeEditor’s Scene
Events¶
- Has Been Modified
when something has changed in the Scene
- Item Selected
when Node or Edge is selected
- Items Deselected
when deselect everything appears
- Drag Enter
when something is Dragged onto the Scene. Here we do allow or deny the drag
- Drop
when we Drop something into the Scene
Scene Class¶
-
class
nodeeditor.node_scene.Scene¶ Bases:
nodeeditor.node_serializable.SerializableClass representing NodeEditor’s Scene
- Instance Attributes
nodes - list of Nodes in this Scene
edges - list of Edges in this Scene
history - Instance of
SceneHistoryclipboard - Instance of
SceneClipboardscene_width - width of this Scene in pixels
scene_height - height of this Scene in pixels
-
property
has_been_modified¶ Has this Scene been modified?
- Getter
Trueif the Scene has been modified- Setter
set new state. Triggers Has Been Modified event
- Type
bool
-
initUI()¶ Set up Graphics Scene Instance
-
getNodeByID(node_id: int)¶ Find node in the scene according to provided node_id
- Parameters
node_id (
int) – ID of the node we are looking for- Returns
Found
NodeorNone
-
setSilentSelectionEvents(value: bool = True)¶ Calling this can suppress onItemSelected events to be triggered. This is useful when working with clipboard
-
onItemSelected(silent: bool = False)¶ Handle Item selection and trigger event Item Selected
- Parameters
silent (
bool) – IfTruescene’s onItemSelected won’t be called and history stamp not stored
-
onItemsDeselected(silent: bool = False)¶ Handle Items deselection and trigger event Items Deselected
- Parameters
silent (
bool) – IfTruescene’s onItemsDeselected won’t be called and history stamp not stored
-
isModified() → bool¶ Is this Scene dirty aka has been modified ?
- Returns
Trueif Scene has been modified- Return type
bool
-
getSelectedItems() → list¶ Returns currently selected Graphics Items
- Returns
list of
QGraphicsItems- Return type
list[QGraphicsItem]
-
doDeselectItems(silent: bool = False) → None¶ Deselects everything in scene
- Parameters
silent (
bool) – IfTruescene’s onItemsDeselected won’t be called
-
addHasBeenModifiedListener(callback: function)¶ Register callback for Has Been Modified event
- Parameters
callback – callback function
-
addItemSelectedListener(callback: function)¶ Register callback for Item Selected event
- Parameters
callback – callback function
-
addItemsDeselectedListener(callback: function)¶ Register callback for Items Deselected event
- Parameters
callback – callback function
-
addDragEnterListener(callback: function)¶ Register callback for Drag Enter event
- Parameters
callback – callback function
-
addDropListener(callback: function)¶ Register callback for Drop event
- Parameters
callback – callback function
-
resetLastSelectedStates()¶ Resets internal selected flags in all Nodes and Edges in the Scene
-
getView() → QGraphicsView¶ Shortcut for returning Scene
QGraphicsView- Returns
QGraphicsViewattached to the Scene- Return type
QGraphicsView
-
getItemAt(pos: QPointF)¶ Shortcut for retrieving item at provided Scene position
- Parameters
pos (
QPointF) – scene position- Returns
Qt Graphics Item at scene position
- Return type
QGraphicsItem
-
addNode(node: nodeeditor.node_node.Node)¶ Add
Nodeto this Scene
-
addEdge(edge: nodeeditor.node_edge.Edge)¶ Add
Edgeto this Scene
-
removeNode(node: nodeeditor.node_node.Node)¶ Remove
Nodefrom this Scene
-
removeEdge(edge: nodeeditor.node_edge.Edge)¶ Remove
Edgefrom this Scene
-
clear()¶ Remove all Nodes from this Scene. This causes also to remove all Edges
-
saveToFile(filename: str)¶ Save this Scene to the file on disk.
- Parameters
filename (
str) – where to save this scene
-
loadFromFile(filename: str)¶ Load Scene from a file on disk
- Parameters
filename (
str) – from what file to load the Scene- Raises
InvalidFileif there was an error decoding JSON file
-
getEdgeClass()¶ Return the class representing Edge. Override me if needed
-
setNodeClassSelector(class_selecting_function: functon) → Node class type¶ Set the function which decides what Node class to instantiate when deserializing Scene. If not set, we will always instantiate
Nodefor each Node in the Scene- Parameters
class_selecting_function (
function) – function which returns Node class type (not instance) from Node serializeddictdata- Returns
Class Type of Node to be instantiated during deserialization
- Return type
Node class type
-
getNodeClassFromData(data: dict) → Node class instance¶ Takes Node serialized data and determines which Node Class to instantiate according the description in the serialized Node
- Parameters
data (
dict) – serialized Node object data- Returns
Instance of Node class to be used in this Scene
- Return type
Node class instance
-
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