Skip to content

Commit 3da0baa

Browse files
authored
Merge pull request #139 from jchanvfx/examples_#110
Examples #110
2 parents 59ecbfd + e256908 commit 3da0baa

File tree

15 files changed

+445
-170
lines changed

15 files changed

+445
-170
lines changed

NodeGraphQt/__init__.py

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,45 +30,47 @@
3030
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
3131
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3232
"""
33-
NodeGraphQt is a node graph framework that can be implemented and re purposed
34-
into applications that supports PySide2.
33+
**NodeGraphQt** is a node graph framework that can be implemented and re purposed
34+
into applications that supports **PySide2**.
3535
36-
url: https://github.com/jchanvfx/NodeGraphQt
37-
docs: http://chantasticvfx.com/nodeGraphQt/html/index.html
36+
project: https://github.com/jchanvfx/NodeGraphQt
3837
39-
Basic Example:
38+
example code:
4039
41-
import sys
42-
from NodeGraphQt import QtWidgets, NodeGraph, BaseNode
40+
.. code-block:: python
41+
:linenos:
4342
43+
import sys
44+
from NodeGraphQt import QtWidgets, NodeGraph, BaseNode
4445
45-
class MyNode(BaseNode):
4646
47-
__identifier__ = 'com.chantasticvfx'
48-
NODE_NAME = 'My Node'
47+
class MyNode(BaseNode):
4948
50-
def __init__(self):
51-
super(MyNode, self).__init__()
52-
self.add_input('foo', color=(180, 80, 0))
53-
self.add_output('bar')
49+
__identifier__ = 'com.chantasticvfx'
50+
NODE_NAME = 'My Node'
5451
55-
if __name__ == '__main__':
56-
app = QtWidgets.QApplication(sys.argv)
57-
graph = NodeGraph()
52+
def __init__(self):
53+
super(MyNode, self).__init__()
54+
self.add_input('foo', color=(180, 80, 0))
55+
self.add_output('bar')
5856
59-
graph.register_node(BaseNode)
60-
graph.register_node(BackdropNode)
57+
if __name__ == '__main__':
58+
app = QtWidgets.QApplication(sys.argv)
59+
graph = NodeGraph()
6160
62-
backdrop = graph.create_node('nodeGraphQt.nodes.Backdrop', name='Backdrop')
63-
node_a = graph.create_node('com.chantasticvfx.MyNode', name='Node A')
64-
node_b = graph.create_node('com.chantasticvfx.MyNode', name='Node B', color='#5b162f')
61+
graph.register_node(BaseNode)
62+
graph.register_node(BackdropNode)
6563
66-
node_a.set_input(0, node_b.output(0))
64+
backdrop = graph.create_node('nodeGraphQt.nodes.Backdrop', name='Backdrop')
65+
node_a = graph.create_node('com.chantasticvfx.MyNode', name='Node A')
66+
node_b = graph.create_node('com.chantasticvfx.MyNode', name='Node B', color='#5b162f')
6767
68-
viewer = graph.viewer()
69-
viewer.show()
68+
node_a.set_input(0, node_b.output(0))
7069
71-
app.exec_()
70+
viewer = graph.viewer()
71+
viewer.show()
72+
73+
app.exec_()
7274
"""
7375

7476
try:

NodeGraphQt/base/graph.py

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,68 @@ class NodeGraph(QtCore.QObject):
2626
"""
2727
The ``NodeGraph`` class is the main controller for managing all nodes.
2828
29-
Inherited from: ``PySide2.QtCore.QObject``
29+
Inherited from: :class:`PySide2.QtCore.QObject`
3030
3131
.. image:: _images/graph.png
3232
:width: 60%
3333
"""
3434

35-
#:QtCore.Signal: emits the node object when a node is created in the node graph.
3635
node_created = QtCore.Signal(NodeObject)
37-
#:QtCore.Signal: emits a ``list[str]`` of node ids from the deleted nodes.
36+
"""
37+
Signal triggered when a node is created in the node graph.
38+
39+
:parameters: :class:`NodeGraphQt.NodeObject`
40+
:emits: created node
41+
"""
3842
nodes_deleted = QtCore.Signal(list)
39-
#:QtCore.Signal: emits the node object when selected in the node graph.
43+
"""
44+
Signal triggered when nodes have been deleted from the node graph.
45+
46+
:parameters: list[str]
47+
:emits: list of deleted node ids.
48+
"""
4049
node_selected = QtCore.Signal(NodeObject)
41-
#:QtCore.Signal: triggered when a node is double clicked and emits the node.
50+
"""
51+
Signal triggered when a node is clicked with the LMB.
52+
53+
:parameters: :class:`NodeGraphQt.NodeObject`
54+
:emits: selected node
55+
"""
4256
node_double_clicked = QtCore.Signal(NodeObject)
43-
#:QtCore.Signal: for when a node has been connected emits (``input port``, ``output port``).
57+
"""
58+
Signal triggered when a node is double clicked and emits the node.
59+
60+
:parameters: :class:`NodeGraphQt.NodeObject`
61+
:emits: selected node
62+
"""
4463
port_connected = QtCore.Signal(Port, Port)
45-
#:QtCore.Signal: for when a node has been disconnected emits (``input port``, ``output port``).
64+
"""
65+
Signal triggered when a node port has been connected.
66+
67+
:parameters: :class:`NodeGraphQt.Port`, :class:`NodeGraphQt.Port`
68+
:emits: input port, output port
69+
"""
4670
port_disconnected = QtCore.Signal(Port, Port)
47-
#:QtCore.Signal: for when a node property has changed emits (``node``, ``property name``, ``property value``).
71+
"""
72+
Signal triggered when a node port has been disconnected.
73+
74+
:parameters: :class:`NodeGraphQt.Port`, :class:`NodeGraphQt.Port`
75+
:emits: input port, output port
76+
"""
4877
property_changed = QtCore.Signal(NodeObject, str, object)
49-
#:QtCore.Signal: for when drop data has been added to the graph.
78+
"""
79+
Signal is triggered when a property has changed on a node.
80+
81+
:parameters: :class:`NodeGraphQt.BaseNode`, str, object
82+
:emits: triggered node, property name, property value
83+
"""
5084
data_dropped = QtCore.Signal(QtCore.QMimeData, QtCore.QPoint)
85+
"""
86+
Signal is triggered when data has been dropped to the graph.
87+
88+
:parameters: :class:`PySide2.QtCore.QMimeData`, :class:`PySide2.QtCore.QPoint`
89+
:emits: mime data, node graph position
90+
"""
5191

5292
def __init__(self, parent=None):
5393
super(NodeGraph, self).__init__(parent)
@@ -237,7 +277,7 @@ def widget(self):
237277
The node graph widget for adding into a layout.
238278
239279
Returns:
240-
QtWidgets.QWidget: node graph widget.
280+
PySide2.QtWidgets.QWidget: node graph widget.
241281
"""
242282
if self._widget is None:
243283
self._widget = QtWidgets.QWidget()
@@ -249,16 +289,16 @@ def widget(self):
249289
def show(self):
250290
"""
251291
Show node graph widget this is just a convenience
252-
function to :meth:`NodeGraph.widget().show()`.
292+
function to :meth:`NodeGraph.widget.show()`.
253293
"""
254-
self._widget.show()
294+
self.widget.show()
255295

256296
def close(self):
257297
"""
258298
Close node graph NodeViewer widget this is just a convenience
259-
function to :meth:`NodeGraph.widget().close()`.
299+
function to :meth:`NodeGraph.widget.close()`.
260300
"""
261-
self._widget.close()
301+
self.widget.close()
262302

263303
def viewer(self):
264304
"""
@@ -270,7 +310,7 @@ def viewer(self):
270310
271311
See Also:
272312
:attr:`NodeGraph.widget` for adding the node graph into a
273-
QtWidgets.QLayout.
313+
:class:`PySide2.QtWidgets.QLayout`.
274314
275315
Returns:
276316
NodeGraphQt.widgets.viewer.NodeViewer: viewer interface.
@@ -429,7 +469,7 @@ def get_context_menu(self, menu):
429469
menu (str): menu name.
430470
431471
Returns:
432-
NodeGraphMenu or NodesMenu: context menu object.
472+
NodeGraphQt.NodeGraphMenu or NodeGraphQt.NodesMenu: context menu object.
433473
"""
434474
menus = self._viewer.context_menus()
435475
if menus.get(menu):

NodeGraphQt/base/menu.py

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class NodeGraphMenu(object):
1010
"""
11-
The ``NodeGraphMenu`` is the context menu triggered from the node graph.
11+
The ``NodeGraphMenu`` is the main context menu triggered from the node graph.
1212
1313
example for accessing the node graph context menu.
1414
@@ -22,8 +22,6 @@ class NodeGraphMenu(object):
2222
# get the context menu for the node graph.
2323
context_menu = node_graph.get_context_menu('graph')
2424
25-
print(context_menu)
26-
# >> <NodeGraphMenu("NodeGraph") object at 0x10910fdd8>
2725
"""
2826

2927
def __init__(self, graph, qmenu):
@@ -124,7 +122,7 @@ def add_command(self, name, func=None, shortcut=None):
124122
shortcut (str): shotcut key.
125123
126124
Returns:
127-
NodeGraphQt.MenuCommand: the appended command.
125+
NodeGraphQt.NodeGraphCommand: the appended command.
128126
"""
129127
action = GraphAction(name, self._graph.viewer())
130128
action.graph = self._graph
@@ -146,45 +144,21 @@ def add_separator(self):
146144

147145
class NodesMenu(NodeGraphMenu):
148146
"""
149-
The ``NodesMenu`` is the context menu triggered from the nodes.
147+
The ``NodesMenu`` is the context menu triggered from a node.
150148
151149
**Inherited from:** :class:`NodeGraphQt.NodeGraphMenu`
152150
153-
example for adding a command to the nodes context menu.
151+
example for accessing the nodes context menu.
154152
155153
.. code-block:: python
156154
:linenos:
157155
158-
from NodeGraphQt import BaseNode, NodeGraph
159-
160-
# example node.
161-
class MyNode(BaseNode):
162-
163-
__identifier__ = 'com.chantasticvfx'
164-
NODE_NAME = 'my node'
165-
166-
def __init__(self):
167-
super(MyNode, self).__init__()
168-
self.add_input('in')
169-
self.add_output('out')
156+
from NodeGraphQt import NodeGraph
170157
171-
# create node graph.
172158
node_graph = NodeGraph()
173159
174-
# register example node.
175-
node_graph.register_node(MyNode)
176-
177-
# get the context menu for the nodes.
160+
# get the nodes context menu.
178161
nodes_menu = node_graph.get_context_menu('nodes')
179-
180-
# create a command
181-
def test_func(graph, node):
182-
print('Clicked on node: {}'.format(node.name()))
183-
184-
nodes_menu.add_command('test',
185-
func=test_func,
186-
node_type='com.chantasticvfx.MyNode')
187-
188162
"""
189163

190164
def add_command(self, name, func=None, node_type=None):
@@ -197,7 +171,7 @@ def add_command(self, name, func=None, node_type=None):
197171
node_type (str): specified node type for the command.
198172
199173
Returns:
200-
NodeGraphQt.MenuCommand: the appended command.
174+
NodeGraphQt.NodeGraphCommand: the appended command.
201175
"""
202176
if not node_type:
203177
raise NodeMenuError('Node type not specified!')
@@ -239,7 +213,7 @@ def qaction(self):
239213
The underlying qaction.
240214
241215
Returns:
242-
BaseAction: qaction object.
216+
GraphAction: qaction object.
243217
"""
244218
return self._qaction
245219

NodeGraphQt/base/node.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ class NodeObject(object):
3636
qgraphics_item (AbstractNodeItem): graphic item used for drawing.
3737
"""
3838

39-
#:str: unique node identifier domain.
39+
# Unique node identifier domain. `eg.` ``"com.chantacticvfx"``
4040
__identifier__ = 'nodeGraphQt.nodes'
4141

42-
#:str: base node name.
42+
# Base node name.
4343
NODE_NAME = None
4444

4545
def __init__(self, qgraphics_item=None):
@@ -61,7 +61,7 @@ def __repr__(self):
6161
def type_(cls):
6262
"""
6363
Node type identifier followed by the class name.
64-
eg. nodeGraphQt.nodes.MyNode
64+
`eg.` ``"com.chantacticvfx.NodeObject"``
6565
6666
Returns:
6767
str: node type.

NodeGraphQt/base/utils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
def setup_context_menu(graph):
88
"""
9-
Sets up the node graphs context menu with some basic menus and commands.
9+
populate the specified graph's context menu with essential menus commands.
10+
11+
example code:
1012
1113
.. code-block:: python
1214
:linenos:
@@ -16,6 +18,11 @@ def setup_context_menu(graph):
1618
graph = NodeGraph()
1719
setup_context_menu(graph)
1820
21+
result:
22+
23+
.. image:: _images/menu_hotkeys.png
24+
:width: 300px
25+
1926
Args:
2027
graph (NodeGraphQt.NodeGraph): node graph.
2128
"""

docs/_images/selection.png

54 KB
Loading

docs/constants.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ Constants
44
.. automodule:: NodeGraphQt.constants
55
:members:
66
:member-order: bysource
7-
:noindex:

0 commit comments

Comments
 (0)