Skip to content

Commit 556ad2c

Browse files
committed
updated docs.
1 parent 191e0fb commit 556ad2c

File tree

3 files changed

+123
-3
lines changed

3 files changed

+123
-3
lines changed

NodeGraphQt/base/graph.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,14 +794,13 @@ def set_context_menu(self, menu_name, data):
794794
[
795795
{
796796
'type': 'menu',
797-
'label': 'test sub menu',
797+
'label': 'node sub menu',
798798
'items': [
799799
{
800800
'type': 'command',
801801
'label': 'test command',
802802
'file': '../path/to/my/test_module.py',
803803
'function': 'run_test',
804-
'shortcut': 'Ctrl+b',
805804
'node_type': 'nodeGraphQt.nodes.MyNodeClass'
806805
},
807806

docs/examples/ex_menu.rst

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,124 @@ can override context menus on a per node type basis.
107107
108108
# show widget.
109109
node_graph.widget.show()
110+
111+
112+
Adding with Config files
113+
************************
114+
115+
Adding menus and commands can also be done through configs and python module files.
116+
117+
example python script containing a test function.
118+
119+
``../path/to/my/hotkeys/cmd_functions.py``
120+
121+
.. code-block:: python
122+
:linenos:
123+
124+
def graph_command(graph):
125+
"""
126+
function that's triggered on the node graph context menu.
127+
128+
Args:
129+
graph (NodeGraphQt.NodeGraph): node graph controller.
130+
"""
131+
print(graph)
132+
133+
def node_command(graph, node):
134+
"""
135+
function that's triggered on a node's node context menu.
136+
137+
Args:
138+
graph (NodeGraphQt.NodeGraph): node graph controller.
139+
node: (NodeGraphQt.NodeObject): node object triggered on.
140+
"""
141+
print(graph)
142+
print(node.name())
143+
144+
example ``json`` config for the node graph context menu.
145+
146+
``../path/to/my/hotkeys/graph_commands.json``
147+
148+
.. code-block:: json
149+
:linenos:
150+
151+
[
152+
{
153+
"type":"menu",
154+
"label":"My Sub Menu",
155+
"items":[
156+
{
157+
"type":"command",
158+
"label":"Example Graph Command",
159+
"file":"../examples/hotkeys/cmd_functions.py",
160+
"function_name":"graph_command",
161+
"shortcut":"Shift+t",
162+
}
163+
]
164+
}
165+
]
166+
167+
example ``json`` config for the nodes context menu.
168+
169+
``../path/to/my/hotkeys/node_commands.json``
170+
171+
.. code-block:: json
172+
:linenos:
173+
174+
[
175+
{
176+
"type":"command",
177+
"label":"Example Graph Command",
178+
"file":"../examples/hotkeys/cmd_functions.py",
179+
"function_name":"node_command",
180+
"node_type":"io.github.jchanvfx.FooNode",
181+
}
182+
]
183+
184+
In the main code where your node graph controller is defined we can just call the
185+
:meth:`NodeGraph.set_context_menu_from_file`
186+
187+
.. code-block:: python
188+
:linenos:
189+
190+
from NodeGraphQt import NodeGraph
191+
192+
node_graph = NodeGraph()
193+
node_graph.set_context_menu_from_file(
194+
'../path/to/a/hotkeys/graph_commands.json', menu='graph'
195+
)
196+
node_graph.set_context_menu_from_file(
197+
'../path/to/a/hotkeys/node_commands.json', menu='nodes'
198+
)
199+
200+
Adding with Serialized data
201+
***************************
202+
203+
Alternatively if you do not prefer to have ``json`` config files the node graph also has a
204+
:meth:`NodeGraph.set_context_menu` function.
205+
206+
here's an example.
207+
208+
.. code-block:: python
209+
:linenos:
210+
211+
from NodeGraphQt import NodeGraph
212+
213+
data = [
214+
{
215+
'type': 'menu',
216+
'label': 'My Sub Menu',
217+
'items': [
218+
{
219+
'type': 'command',
220+
'label': 'Example Graph Command',
221+
'file': '../examples/hotkeys/cmd_functions.py',
222+
'function_name': 'graph_command',
223+
'shortcut': 'Shift+t'
224+
},
225+
]
226+
},
227+
]
228+
229+
node_graph = NodeGraph()
230+
node_graph.set_context_menu(menu_name='graph', data)

docs/examples/ex_overview.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ Here's a basic example snippet for creating two nodes and connecting them togeth
107107
node_b = graph.create_node('io.github.jchanvfx.FooNode', name='node B', pos=(300, 50))
108108
109109
# connect node_a to node_b
110-
node_a.set_output(0, node_b.input(2))
110+
node_a.set_output(0, node_b.input(0))
111111
112112
app.exec_()
113113

0 commit comments

Comments
 (0)