Skip to content

Commit e8058b4

Browse files
committed
updated docs and doc strings.
1 parent ea62de4 commit e8058b4

File tree

9 files changed

+207
-48
lines changed

9 files changed

+207
-48
lines changed

NodeGraphQt/base/node.py

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -936,22 +936,25 @@ def set_ports(self, port_data):
936936
Set node input and output ports.
937937
938938
Args:
939-
port_data(dict):
940-
{
941-
'input_ports':
942-
[{'name':...,
943-
'multi_connection':...,
944-
'display_name':...,
945-
'data_type':...
946-
}, ...],
947-
'output_ports':
948-
[{'name':...,
949-
'multi_connection':...,
950-
'display_name':...,
951-
'data_type':...
952-
}, ...]
953-
}
954-
"""
939+
port_data(dict): port data.
940+
"""
941+
942+
# port data eg.
943+
# {
944+
# 'input_ports':
945+
# [{'name': ...,
946+
# 'multi_connection': ...,
947+
# 'display_name': ...,
948+
# 'data_type': ...
949+
# }, ...],
950+
# 'output_ports':
951+
# [{'name': ...,
952+
# 'multi_connection': ...,
953+
# 'display_name': ...,
954+
# 'data_type': ...
955+
# }, ...]
956+
# }
957+
955958
for port in self._inputs:
956959
self._view.delete_input(port.view)
957960
port.model.node = None
@@ -1231,6 +1234,12 @@ class SubGraph(object):
12311234
"""
12321235
The ``NodeGraphQt.SubGraph`` class is the base class that all
12331236
Sub Graph Node inherit from.
1237+
1238+
*Implemented on NodeGraphQt: * ``v0.1.0``
1239+
1240+
.. image:: _images/example_subgraph.gif
1241+
:width: 80%
1242+
12341243
"""
12351244

12361245
def __init__(self):
@@ -1245,8 +1254,9 @@ def children(self):
12451254
def create_from_nodes(self, nodes):
12461255
"""
12471256
Create sub graph from the nodes.
1257+
12481258
Args:
1249-
nodes(list): nodes to create the sub graph.
1259+
nodes (list[NodeGraphQt.NodeObject]): nodes to create the sub graph.
12501260
"""
12511261
if self in nodes:
12521262
nodes.remove(self)
@@ -1257,7 +1267,7 @@ def add_child(self, node):
12571267
Add a node to the sub graph.
12581268
12591269
Args:
1260-
node(NodeGraphQt.BaseNode).
1270+
node (NodeGraphQt.BaseNode): node object.
12611271
"""
12621272
self._children.add(node)
12631273

@@ -1266,7 +1276,7 @@ def remove_child(self, node):
12661276
Remove a node from the sub graph.
12671277
12681278
Args:
1269-
node(NodeGraphQt.BaseNode).
1279+
node (NodeGraphQt.BaseNode): node object.
12701280
"""
12711281
if node in self._children:
12721282
self._children.remove(node)

NodeGraphQt/base/utils.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,12 @@ def topological_sort_by_down(start_nodes=None, all_nodes=None):
498498
'start_nodes' and 'all_nodes' only one needs to be given.
499499
500500
Args:
501-
start_nodes (list[NodeGraphQt.BaseNode])(Optional): the start update nodes of the graph.
502-
all_nodes (list[NodeGraphQt.BaseNode])(Optional): if 'start_nodes' is None the function can calculate start nodes from 'all_nodes'.
501+
start_nodes (list[NodeGraphQt.BaseNode])(Optional):
502+
the start update nodes of the graph.
503+
all_nodes (list[NodeGraphQt.BaseNode])(Optional):
504+
if 'start_nodes' is None the function can calculate start nodes
505+
from 'all_nodes'.
506+
503507
Returns:
504508
list[NodeGraphQt.BaseNode]: sorted nodes.
505509
"""
@@ -528,8 +532,11 @@ def topological_sort_by_up(start_nodes=None, all_nodes=None):
528532
'start_nodes' and 'all_nodes' only one needs to be given.
529533
530534
Args:
531-
start_nodes (list[NodeGraphQt.BaseNode])(Optional): the end update nodes of the graph.
532-
all_nodes (list[NodeGraphQt.BaseNode])(Optional): if 'start_nodes' is None the function can calculate start nodes from 'all_nodes'.
535+
start_nodes (list[NodeGraphQt.BaseNode])(Optional):
536+
the end update nodes of the graph.
537+
all_nodes (list[NodeGraphQt.BaseNode])(Optional):
538+
if 'start_nodes' is None the function can calculate start nodes
539+
from 'all_nodes'.
533540
Returns:
534541
list[NodeGraphQt.BaseNode]: sorted nodes.
535542
"""
@@ -632,11 +639,12 @@ def _compute_rank_down(start_nodes):
632639
Compute the rank of the down stream nodes.
633640
634641
Args:
635-
start_nodes (list[NodeGraphQt.BaseNode])(Optional): the start nodes of the graph.
642+
start_nodes (list[NodeGraphQt.BaseNode])(Optional):
643+
the start nodes of the graph.
644+
636645
Returns:
637646
dict{NodeGraphQt.BaseNode: node_rank, ...}
638647
"""
639-
640648
nodes_rank = {}
641649
for node in start_nodes:
642650
nodes_rank[node] = 0
@@ -659,7 +667,9 @@ def _compute_rank_up(start_nodes):
659667
Compute the rank of the up stream nodes.
660668
661669
Args:
662-
start_nodes (list[NodeGraphQt.BaseNode])(Optional): the end nodes of the graph.
670+
start_nodes (list[NodeGraphQt.BaseNode]):
671+
(Optional) the end nodes of the graph.
672+
663673
Returns:
664674
dict{NodeGraphQt.BaseNode: node_rank, ...}
665675
"""
@@ -676,8 +686,11 @@ def auto_layout_up(start_nodes=None, all_nodes=None):
676686
Auto layout the nodes by up stream direction.
677687
678688
Args:
679-
start_nodes (list[NodeGraphQt.BaseNode])(Optional): the end nodes of the graph.
680-
all_nodes (list[NodeGraphQt.BaseNode])(Optional): if 'start_nodes' is None the function can calculate start nodes from 'all_nodes'.
689+
start_nodes (list[NodeGraphQt.BaseNode]):
690+
(Optional) the end nodes of the graph.
691+
all_nodes (list[NodeGraphQt.BaseNode]):
692+
(Optional) if 'start_nodes' is None the function can calculate
693+
start nodes from 'all_nodes'.
681694
"""
682695
if not start_nodes and not all_nodes:
683696
return
@@ -737,8 +750,11 @@ def auto_layout_down(start_nodes=None, all_nodes=None):
737750
Auto layout the nodes by down stream direction.
738751
739752
Args:
740-
start_nodes (list[NodeGraphQt.BaseNode])(Optional): the start update nodes of the graph.
741-
all_nodes (list[NodeGraphQt.BaseNode])(Optional): if 'start_nodes' is None the function can calculate start nodes from 'all_nodes'.
753+
start_nodes (list[NodeGraphQt.BaseNode]):
754+
(Optional) the start update nodes of the graph.
755+
all_nodes (list[NodeGraphQt.BaseNode]):
756+
(Optional) if 'start_nodes' is None the function can calculate
757+
start nodes from 'all_nodes'.
742758
"""
743759
if not start_nodes and not all_nodes:
744760
return

docs/_images/example_subgraph.gif

3.22 MB
Loading

docs/examples/ex_node.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Creating Nodes
4141
Embedding Widgets
4242
*****************
4343

44-
The :meth:`NodeGraphQt.BaseNode` class allows you to embed widgets inside a node here's a
44+
The :class:`NodeGraphQt.BaseNode` class allows you to embed widgets inside a node here's a
4545
example to simply embed a ``QComboBox`` widget when reimplementing the ``BaseNode``.
4646

4747
.. code-block:: python

docs/examples/ex_port.rst

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
Port Examples
2+
#############
3+
4+
Creating Custom Shapes
5+
**********************
6+
7+
*(Implemented on NodeGraphQt* ``v0.1.1`` *or above)*
8+
9+
To have custom port shapes the :meth:`NodeGraphQt.BaseNode.add_input` and
10+
:meth:`NodeGraphQt.BaseNode.add_output` functions now have a ``painter_func``
11+
argument where you specify you custom port painter function.
12+
13+
Example Triangle Port
14+
*********************
15+
16+
Here's an example function for drawing a triangle shaped port.
17+
18+
.. code-block:: python
19+
:linenos:
20+
21+
def draw_triangle_port(painter, rect, info):
22+
"""
23+
Custom paint function for drawing a Triangle shaped port.
24+
25+
Args:
26+
painter (QtGui.QPainter): painter object.
27+
rect (QtCore.QRectF): port rect used to describe parameters
28+
needed to draw.
29+
info (dict): information describing the ports current state.
30+
{
31+
'port_type': 'in',
32+
'color': (0, 0, 0),
33+
'border_color': (255, 255, 255),
34+
'multi_connection': False,
35+
'connected': False,
36+
'hovered': False,
37+
}
38+
"""
39+
painter.save()
40+
41+
size = int(rect.height() / 2)
42+
triangle = QtGui.QPolygonF()
43+
triangle.append(QtCore.QPointF(-size, size))
44+
triangle.append(QtCore.QPointF(0.0, -size))
45+
triangle.append(QtCore.QPointF(size, size))
46+
47+
transform = QtGui.QTransform()
48+
transform.translate(rect.center().x(), rect.center().y())
49+
port_poly = transform.map(triangle)
50+
51+
# mouse over port color.
52+
if info['hovered']:
53+
color = QtGui.QColor(14, 45, 59)
54+
border_color = QtGui.QColor(136, 255, 35)
55+
# port connected color.
56+
elif info['connected']:
57+
color = QtGui.QColor(195, 60, 60)
58+
border_color = QtGui.QColor(200, 130, 70)
59+
# default port color
60+
else:
61+
color = QtGui.QColor(*info['color'])
62+
border_color = QtGui.QColor(*info['border_color'])
63+
64+
pen = QtGui.QPen(border_color, 1.8)
65+
painter.setPen(pen)
66+
painter.setBrush(color)
67+
painter.drawPolygon(port_poly)
68+
69+
painter.restore()
70+
71+
The ``draw_triangle_port`` painter function can then be passed to the ``painter_func`` arg.
72+
73+
.. code-block:: python
74+
:linenos:
75+
76+
from NodeGraphQt import BaseNode
77+
78+
class MyListNode(BaseNode):
79+
80+
def __init__(self):
81+
super(MyListNode, self).__init__()
82+
self.add_input('triangle', painter_func=draw_triangle_port)
83+
84+
Example Square Port
85+
*******************
86+
87+
Here's simpler example function for drawing a Square shaped port.
88+
89+
.. code-block:: python
90+
:linenos:
91+
92+
def draw_square_port(painter, rect, info):
93+
"""
94+
Custom paint function for drawing a Square shaped port.
95+
96+
Args:
97+
painter (QtGui.QPainter): painter object.
98+
rect (QtCore.QRectF): port rect used to describe parameters
99+
needed to draw.
100+
info (dict): information describing the ports current state.
101+
{
102+
'port_type': 'in',
103+
'color': (0, 0, 0),
104+
'border_color': (255, 255, 255),
105+
'multi_connection': False,
106+
'connected': False,
107+
'hovered': False,
108+
}
109+
"""
110+
painter.save()
111+
112+
# mouse over port color.
113+
if info['hovered']:
114+
color = QtGui.QColor(14, 45, 59)
115+
border_color = QtGui.QColor(136, 255, 35, 255)
116+
# port connected color.
117+
elif info['connected']:
118+
color = QtGui.QColor(195, 60, 60)
119+
border_color = QtGui.QColor(200, 130, 70)
120+
# default port color
121+
else:
122+
color = QtGui.QColor(*info['color'])
123+
border_color = QtGui.QColor(*info['border_color'])
124+
125+
pen = QtGui.QPen(border_color, 1.8)
126+
painter.setPen(pen)
127+
painter.setBrush(color)
128+
painter.drawRect(rect)
129+
130+
painter.restore()

docs/graph.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
Graphs
2+
######
3+
14
NodeGraph
2-
#########
5+
*********
36

47
`See` :ref:`Basic Example` `from the NodeGraph overview.`
58

@@ -11,3 +14,10 @@ NodeGraph
1114

1215
.. autoattribute:: NodeGraphQt.NodeGraph.widget
1316
.. autoattribute:: NodeGraphQt.NodeGraph.model
17+
18+
19+
SubGraph
20+
********
21+
22+
.. autoclass:: NodeGraphQt.SubGraph
23+
:members:

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ GitHub Project: https://github.com/jchanvfx/NodeGraphQt
2929

3030
examples/ex_overview
3131
examples/ex_node
32+
examples/ex_port
3233
examples/ex_menu

docs/nodes/SubGraphNode.rst

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)