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

Exceptions

class nodeeditor.node_scene.InvalidFile

Bases: Exception

Scene Class

class nodeeditor.node_scene.Scene

Bases: nodeeditor.node_serializable.Serializable

Class representing NodeEditor’s Scene

Instance Attributes
  • nodes - list of Nodes in this Scene

  • edges - list of Edges in this Scene

  • history - Instance of SceneHistory

  • clipboard - Instance of SceneClipboard

  • scene_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

True if 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 Node or None

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) – If True scene’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) – If True scene’s onItemsDeselected won’t be called and history stamp not stored

isModified()bool

Is this Scene dirty aka has been modified ?

Returns

True if 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) – If True scene’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

QGraphicsView attached 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 Node to this Scene

Parameters

node (Node) – Node to be added to this Scene

addEdge(edge: nodeeditor.node_edge.Edge)

Add Edge to this Scene

Parameters

edgeEdge to be added to this Scene

Returns

Edge

removeNode(node: nodeeditor.node_node.Node)

Remove Node from this Scene

Parameters

node (Node) – Node to be removed from this Scene

removeEdge(edge: nodeeditor.node_edge.Edge)

Remove Edge from this Scene

Parameters

edgeEdge to be remove from this Scene

Returns

Edge

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

InvalidFile if 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 Node for each Node in the Scene

Parameters

class_selecting_function (function) – function which returns Node class type (not instance) from Node serialized dict data

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 OrderedDict which 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 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

  • restore_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

True if deserialization was successful, otherwise False

Return type

bool