Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions NodeGraphQt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ def __init__(self):
print('Cannot import "Qt.py" module falling back on '
'"NodeGraphQt.vendor.Qt ({})"'.format(qtpy_ver))

from .base.graph import NodeGraph
from .base.graph import NodeGraph, SubGraph
from .base.menu import NodesMenu, NodeGraphMenu, NodeGraphCommand
from .base.node import NodeObject, BaseNode, BackdropNode, SubGraph
from .base.node import NodeObject, BaseNode, BackdropNode
from .base.port import Port
from .pkg_info import __version__ as VERSION
from .pkg_info import __license__ as LICENSE
Expand Down
66 changes: 65 additions & 1 deletion NodeGraphQt/base/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .factory import NodeFactory
from .menu import NodeGraphMenu, NodesMenu
from .model import NodeGraphModel
from .node import NodeObject, BaseNode, SubGraph
from .node import NodeObject, BaseNode
from .port import Port
from ..constants import (DRAG_DROP_ID,
PIPE_LAYOUT_CURVED,
Expand Down Expand Up @@ -1567,3 +1567,67 @@ def root_node(self):
node (BaseNode): node object.
"""
return self.get_node_by_id('0' * 13)


class SubGraph(object):
"""
The ``NodeGraphQt.SubGraph`` class is the base class that all
Sub Graph Node inherit from.

*Implemented on NodeGraphQt: * ``v0.1.0``

.. image:: _images/example_subgraph.gif
:width: 80%

"""

def __init__(self):
self._children = set()

def children(self):
"""
Returns the children of the sub graph.
"""
return list(self._children)

def create_from_nodes(self, nodes):
"""
Create sub graph from the nodes.

Args:
nodes (list[NodeGraphQt.NodeObject]): nodes to create the sub graph.
"""
if self in nodes:
nodes.remove(self)
[n.set_parent(self) for n in nodes]

def add_child(self, node):
"""
Add a node to the sub graph.

Args:
node (NodeGraphQt.BaseNode): node object.
"""
self._children.add(node)

def remove_child(self, node):
"""
Remove a node from the sub graph.

Args:
node (NodeGraphQt.BaseNode): node object.
"""
if node in self._children:
self._children.remove(node)

def enter(self):
"""
Action when enter the sub graph.
"""
pass

def exit(self):
"""
Action when exit the sub graph.
"""
pass
68 changes: 2 additions & 66 deletions NodeGraphQt/base/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def set_parent(self, parent_node):
Set parent node.

Args:
parent_node (SubGraph): parent node.
parent_node (NodeGraphQt.SubGraph): parent node.
"""
if parent_node is self:
parent_node = None
Expand All @@ -440,7 +440,7 @@ def parent(self):
Get parent node.

Returns:
SubGraph: parent node or None.
NodeGraphQt.SubGraph: parent node or None.
"""
return self._parent

Expand Down Expand Up @@ -1232,67 +1232,3 @@ def size(self):
self.model.width = self.view.width
self.model.height = self.view.height
return self.model.width, self.model.height


class SubGraph(object):
"""
The ``NodeGraphQt.SubGraph`` class is the base class that all
Sub Graph Node inherit from.

*Implemented on NodeGraphQt: * ``v0.1.0``

.. image:: _images/example_subgraph.gif
:width: 80%

"""

def __init__(self):
self._children = set()

def children(self):
"""
Returns the children of the sub graph.
"""
return list(self._children)

def create_from_nodes(self, nodes):
"""
Create sub graph from the nodes.

Args:
nodes (list[NodeGraphQt.NodeObject]): nodes to create the sub graph.
"""
if self in nodes:
nodes.remove(self)
[n.set_parent(self) for n in nodes]

def add_child(self, node):
"""
Add a node to the sub graph.

Args:
node (NodeGraphQt.BaseNode): node object.
"""
self._children.add(node)

def remove_child(self, node):
"""
Remove a node from the sub graph.

Args:
node (NodeGraphQt.BaseNode): node object.
"""
if node in self._children:
self._children.remove(node)

def enter(self):
"""
Action when enter the sub graph.
"""
pass

def exit(self):
"""
Action when exit the sub graph.
"""
pass
6 changes: 4 additions & 2 deletions NodeGraphQt/widgets/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def __init__(self, parent=None):
self.setAcceptDrops(True)
self.resize(850, 800)

self._scene_range = QtCore.QRectF(0, 0, self.size().width(), self.size().height())
self._scene_range = QtCore.QRectF(
0, 0, self.size().width(), self.size().height())
self._update_scene()
self._last_size = self.size()
self.editable = True
Expand Down Expand Up @@ -932,7 +933,8 @@ def force_update(self):
self._update_scene()

def scene_rect(self):
return [self._scene_range.x(), self._scene_range.y(), self._scene_range.width(), self._scene_range.height()]
return [self._scene_range.x(), self._scene_range.y(),
self._scene_range.width(), self._scene_range.height()]

def scene_center(self):
cent = self._scene_range.center()
Expand Down