@@ -10,7 +10,17 @@ class NodeGraphMenu(object):
1010 """
1111 The ``NodeGraphMenu`` is the context menu triggered from the node graph.
1212
13- This class is an abstraction layer for the QMenu object.
13+ example to accessing the node graph context menu.
14+
15+ .. code-block:: python
16+ :linenos:
17+
18+ from NodeGraphQt import NodeGraph
19+
20+ node_graph = NodeGraph()
21+
22+ # get the context menu for the node graph.
23+ context_menu = node_graph.get_context_menu('graph')
1424 """
1525
1626 def __init__ (self , graph , qmenu ):
@@ -135,19 +145,52 @@ class NodesMenu(NodeGraphMenu):
135145 """
136146 The ``NodesMenu`` is the context menu triggered from the nodes.
137147
138- This class is an abstraction layer for the QMenu object.
139-
140148 **Inherited from:** :class:`NodeGraphQt.NodeGraphMenu`
149+
150+ example for adding a command to the nodes context menu.
151+
152+ .. code-block:: python
153+ :linenos:
154+
155+ from NodeGraphQt import BaseNode, NodeGraph
156+
157+ # example node.
158+ class MyNode(BaseNode):
159+
160+ __identifier__ = 'com.chantasticvfx'
161+ NODE_NAME = 'my node'
162+
163+ def __init__(self):
164+ super(MyNode, self).__init__()
165+ self.add_input('in')
166+ self.add_output('out')
167+
168+ # create node graph.
169+ node_graph = NodeGraph()
170+
171+ # register example node.
172+ node_graph.register_node(MyNode)
173+
174+ # get the context menu for the nodes.
175+ nodes_menu = node_graph.get_context_menu('nodes')
176+
177+ # create a command
178+ def test_func(graph, node):
179+ print('Clicked on node: {}'.format(node.name()))
180+
181+ nodes_menu.add_command('test',
182+ func=test_func,
183+ node_type='com.chantasticvfx.MyNode')
184+
141185 """
142186
143- def add_command (self , name , func = None , shortcut = None , node_type = None ):
187+ def add_command (self , name , func = None , node_type = None ):
144188 """
145189 Re-implemented to add a command to the specified node type menu.
146190
147191 Args:
148192 name (str): command name.
149193 func (function): command function eg. "func(``graph``, ``node``)".
150- shortcut (str): shotcut key.
151194 node_type (str): specified node type for the command.
152195
153196 Returns:
@@ -168,8 +211,6 @@ def add_command(self, name, func=None, shortcut=None, node_type=None):
168211 action .graph = self ._graph
169212 if LooseVersion (QtCore .qVersion ()) >= LooseVersion ('5.10' ):
170213 action .setShortcutVisibleInContextMenu (True )
171- if shortcut :
172- action .setShortcut (shortcut )
173214 if func :
174215 action .executed .connect (func )
175216 qaction = node_menu .addAction (action )
@@ -178,7 +219,7 @@ def add_command(self, name, func=None, shortcut=None, node_type=None):
178219
179220class NodeGraphCommand (object ):
180221 """
181- base class for a menu command.
222+ Node graph menu command.
182223 """
183224
184225 def __init__ (self , graph , qaction ):
0 commit comments