Scene module containing Scene.

class nodedge.scene.Scene

Bases: nodedge.serializable.Serializable

Scene class

Instance Attributes:
  • nodes - list of Nodes in this Scene
  • edges - list of Edges in this Scene
  • history - Instance of SceneHistory
  • clipboard - Instance of
  • scene_width - width of this Scene in pixels
  • scene_height - height of this Scene in pixels

Has this Scene been modified?

Getter:True if the Scene has been modified
Setter:set new state. Triggers Has Been Modified event

Returns last selected graphics items. This property is used to detect if selection has changed.

Returns:Last selected items
Return type:list[QGraphicsItem]

Returns currently selected Graphics Items

Returns:list of QGraphicsItems
Return type:list[QGraphicsItem]

Shortcut for returning Scene QGraphicsView

Returns:QGraphicsView attached to the Scene
Return type:QGraphicsView

” If this property is true, do not trigger onItemSelected when an item is selected

Returns:True is onItemSelected is not triggered when an item is selected
Return type:bool
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.
doDeselectItems(silent: bool = False) → None

Deselects everything in scene

Parameters:silent (bool) – If True scene’s onItemsDeselected won’t be called
addHasBeenModifiedListener(callback: Callable[None])

Register callback for Has Been Modified event

Parameters:callback (Callable[[], None]) – callback function
addItemSelectedListener(callback: Callable[None])

Register callback for Item Selected event

Parameters:callback (Callable[[], None]) – callback function
addItemsDeselectedListener(callback: Callable[None])

Register callback for Items Deselected event

Parameters:callback – callback function
addDragEnterListener(callback: Callable[PySide2.QtGui.QDragEnterEvent, None])

Register callback for Drag Enter event

Parameters:callback – callback function
addDropListener(callback: Callable[PySide2.QtGui.QDropEvent, None])

Register callback for Drop event

Parameters:callback – callback function
resetLastSelectedStates() → None

Resets internal selected flags in all Nodes and Edges in the Scene

addNode(node: nodedge.node.Node)

Add Node to this Scene

Parameters:node (Node) – Node to be added to this Scene
addEdge(edge: nodedge.edge.Edge)

Add Edge to this Scene

Parameters:edgeEdge to be added to this Scene
removeNode(nodeToRemove: nodedge.node.Node)

Remove Node from this Scene :param nodeToRemove: Node to be removed from this Scene :type nodeToRemove: Node

removeEdge(edgeToRemove: nodedge.edge.Edge)

Remove Edge from this Scene

Parameters:edgeToRemoveEdge to be remove from this Scene
clear() → None

Remove all Nodes from this Scene. This causes also to remove all Edges


Save this Scene to the file on disk.

Parameters:filename (str) – where to save this scene
loadFromFile(filename: str) → None

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.
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) → bool

Deserialization method which take data in python dict format with helping hashmap containing references to existing entities.

  • 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

True if deserialization was successful, False otherwise

Return type:



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

Set the function which decides what Node class to instantiate during Scene deserialization. If not set, we will always instantiate Node for each Node in the Scene

Parameters:classSelectingFunction (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

Shortcut for retrieving item at provided Scene position

Parameters:pos (QPointF) – scene position
Returns:Qt Graphics Item at scene position
Return type:QGraphicsItem
getNodeById(nodeId: int) → Optional[nodedge.node.Node]

Find node in the scene according to provided nodeId

Parameters:nodeId (int) – ID of the node we are looking for
Returns:Found :class:`~nodedge.node.Node` or None
Return type::class:`~nodedge.node.Node` or None
exception nodedge.scene.InvalidFile

Bases: Exception