@@ -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)
0 commit comments