Skip to content

Commit e16c981

Browse files
committed
moved SubGraph class into graph module.
1 parent b830a85 commit e16c981

File tree

4 files changed

+73
-71
lines changed

4 files changed

+73
-71
lines changed

NodeGraphQt/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ def __init__(self):
8181
print('Cannot import "Qt.py" module falling back on '
8282
'"NodeGraphQt.vendor.Qt ({})"'.format(qtpy_ver))
8383

84-
from .base.graph import NodeGraph
84+
from .base.graph import NodeGraph, SubGraph
8585
from .base.menu import NodesMenu, NodeGraphMenu, NodeGraphCommand
86-
from .base.node import NodeObject, BaseNode, BackdropNode, SubGraph
86+
from .base.node import NodeObject, BaseNode, BackdropNode
8787
from .base.port import Port
8888
from .pkg_info import __version__ as VERSION
8989
from .pkg_info import __license__ as LICENSE

NodeGraphQt/base/graph.py

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from .factory import NodeFactory
1414
from .menu import NodeGraphMenu, NodesMenu
1515
from .model import NodeGraphModel
16-
from .node import NodeObject, BaseNode, SubGraph
16+
from .node import NodeObject, BaseNode
1717
from .port import Port
1818
from ..constants import (DRAG_DROP_ID,
1919
PIPE_LAYOUT_CURVED,
@@ -1567,3 +1567,67 @@ def root_node(self):
15671567
node (BaseNode): node object.
15681568
"""
15691569
return self.get_node_by_id('0' * 13)
1570+
1571+
1572+
class SubGraph(object):
1573+
"""
1574+
The ``NodeGraphQt.SubGraph`` class is the base class that all
1575+
Sub Graph Node inherit from.
1576+
1577+
*Implemented on NodeGraphQt: * ``v0.1.0``
1578+
1579+
.. image:: _images/example_subgraph.gif
1580+
:width: 80%
1581+
1582+
"""
1583+
1584+
def __init__(self):
1585+
self._children = set()
1586+
1587+
def children(self):
1588+
"""
1589+
Returns the children of the sub graph.
1590+
"""
1591+
return list(self._children)
1592+
1593+
def create_from_nodes(self, nodes):
1594+
"""
1595+
Create sub graph from the nodes.
1596+
1597+
Args:
1598+
nodes (list[NodeGraphQt.NodeObject]): nodes to create the sub graph.
1599+
"""
1600+
if self in nodes:
1601+
nodes.remove(self)
1602+
[n.set_parent(self) for n in nodes]
1603+
1604+
def add_child(self, node):
1605+
"""
1606+
Add a node to the sub graph.
1607+
1608+
Args:
1609+
node (NodeGraphQt.BaseNode): node object.
1610+
"""
1611+
self._children.add(node)
1612+
1613+
def remove_child(self, node):
1614+
"""
1615+
Remove a node from the sub graph.
1616+
1617+
Args:
1618+
node (NodeGraphQt.BaseNode): node object.
1619+
"""
1620+
if node in self._children:
1621+
self._children.remove(node)
1622+
1623+
def enter(self):
1624+
"""
1625+
Action when enter the sub graph.
1626+
"""
1627+
pass
1628+
1629+
def exit(self):
1630+
"""
1631+
Action when exit the sub graph.
1632+
"""
1633+
pass

NodeGraphQt/base/node.py

Lines changed: 2 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ def set_parent(self, parent_node):
419419
Set parent node.
420420
421421
Args:
422-
parent_node (SubGraph): parent node.
422+
parent_node (NodeGraphQt.SubGraph): parent node.
423423
"""
424424
if parent_node is self:
425425
parent_node = None
@@ -440,7 +440,7 @@ def parent(self):
440440
Get parent node.
441441
442442
Returns:
443-
SubGraph: parent node or None.
443+
NodeGraphQt.SubGraph: parent node or None.
444444
"""
445445
return self._parent
446446

@@ -1232,67 +1232,3 @@ def size(self):
12321232
self.model.width = self.view.width
12331233
self.model.height = self.view.height
12341234
return self.model.width, self.model.height
1235-
1236-
1237-
class SubGraph(object):
1238-
"""
1239-
The ``NodeGraphQt.SubGraph`` class is the base class that all
1240-
Sub Graph Node inherit from.
1241-
1242-
*Implemented on NodeGraphQt: * ``v0.1.0``
1243-
1244-
.. image:: _images/example_subgraph.gif
1245-
:width: 80%
1246-
1247-
"""
1248-
1249-
def __init__(self):
1250-
self._children = set()
1251-
1252-
def children(self):
1253-
"""
1254-
Returns the children of the sub graph.
1255-
"""
1256-
return list(self._children)
1257-
1258-
def create_from_nodes(self, nodes):
1259-
"""
1260-
Create sub graph from the nodes.
1261-
1262-
Args:
1263-
nodes (list[NodeGraphQt.NodeObject]): nodes to create the sub graph.
1264-
"""
1265-
if self in nodes:
1266-
nodes.remove(self)
1267-
[n.set_parent(self) for n in nodes]
1268-
1269-
def add_child(self, node):
1270-
"""
1271-
Add a node to the sub graph.
1272-
1273-
Args:
1274-
node (NodeGraphQt.BaseNode): node object.
1275-
"""
1276-
self._children.add(node)
1277-
1278-
def remove_child(self, node):
1279-
"""
1280-
Remove a node from the sub graph.
1281-
1282-
Args:
1283-
node (NodeGraphQt.BaseNode): node object.
1284-
"""
1285-
if node in self._children:
1286-
self._children.remove(node)
1287-
1288-
def enter(self):
1289-
"""
1290-
Action when enter the sub graph.
1291-
"""
1292-
pass
1293-
1294-
def exit(self):
1295-
"""
1296-
Action when exit the sub graph.
1297-
"""
1298-
pass

NodeGraphQt/widgets/viewer.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ def __init__(self, parent=None):
5454
self.setAcceptDrops(True)
5555
self.resize(850, 800)
5656

57-
self._scene_range = QtCore.QRectF(0, 0, self.size().width(), self.size().height())
57+
self._scene_range = QtCore.QRectF(
58+
0, 0, self.size().width(), self.size().height())
5859
self._update_scene()
5960
self._last_size = self.size()
6061
self.editable = True
@@ -932,7 +933,8 @@ def force_update(self):
932933
self._update_scene()
933934

934935
def scene_rect(self):
935-
return [self._scene_range.x(), self._scene_range.y(), self._scene_range.width(), self._scene_range.height()]
936+
return [self._scene_range.x(), self._scene_range.y(),
937+
self._scene_range.width(), self._scene_range.height()]
936938

937939
def scene_center(self):
938940
cent = self._scene_range.center()

0 commit comments

Comments
 (0)