Skip to content

Commit 497b4a2

Browse files
committed
docs update.
1 parent b0a69b9 commit 497b4a2

File tree

3 files changed

+79
-44
lines changed

3 files changed

+79
-44
lines changed

NodeGraphQt/base/menu.py

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

179220
class NodeGraphCommand(object):
180221
"""
181-
base class for a menu command.
222+
Node graph menu command.
182223
"""
183224

184225
def __init__(self, graph, qaction):

NodeGraphQt/base/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ def setup_context_menu(graph):
88
"""
99
Sets up the node graphs context menu with some basic menus and commands.
1010
11+
.. code-block:: python
12+
:linenos:
13+
14+
from NodeGraphQt import NodeGraph, setup_context_menu
15+
16+
graph = NodeGraph()
17+
setup_context_menu(graph)
18+
1119
Args:
1220
graph (NodeGraphQt.NodeGraph): node graph.
1321
"""

docs/menu.rst

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,66 +4,56 @@ Menus
44
.. image:: _images/menu_hotkeys.png
55
:width: 50%
66

7-
The ``NodeGraphQt.setup_context_menu`` has a built in function that'll populate the node graphs context menu a few
8-
default menus and commands.
97

10-
.. code-block:: python
11-
:linenos:
12-
13-
from NodeGraphQt import NodeGraph, setup_context_menu
14-
15-
graph = NodeGraph()
16-
setup_context_menu(graph)
17-
18-
example adding "Foo" menu to the node graphs context menu.
8+
Here's an example where we add a ``"Foo"`` menu and then a ``"Bar"`` command with
9+
the function ``my_test()`` registered.
1910

2011
.. code-block:: python
2112
:linenos:
2213
2314
from NodeGraphQt import NodeGraph
2415
16+
# test function.
17+
def my_test(graph):
18+
selected_nodes = graph.selected_nodes()
19+
print('Number of nodes selected: {}'.format(len(selected_nodes)))
20+
2521
# create node graph.
2622
graph = NodeGraph()
2723
2824
# get the main context menu.
29-
root_menu = graph.context_menu()
25+
context_menu = node_graph.get_context_menu('graph')
3026
3127
# add a menu called "Foo".
32-
foo_menu = root_menu.add_menu('Foo')
33-
34-
add "Bar" command to the "Foo" menu.
35-
36-
.. code-block:: python
37-
:linenos:
38-
:lineno-start: 11
39-
40-
# test function.
41-
def my_test():
42-
print('Hello World')
28+
foo_menu = context_menu.add_menu('Foo')
4329
4430
# add "Bar" command to the "Foo" menu.
31+
# we also assign a short cut key "Shift+t" for this example.
4532
foo_menu.add_command('Bar', my_test, 'Shift+t')
4633
4734
----
4835

49-
.. autofunction:: NodeGraphQt.setup_context_menu
50-
:noindex:
51-
52-
36+
The ``NodeGraphQt.setup_context_menu`` is a built in function that'll populate
37+
the node graphs context menu a few default menus and commands.
5338

5439

55-
Graph Menus
56-
***********
40+
.. autofunction:: NodeGraphQt.setup_context_menu
41+
:noindex:
5742

58-
Node graph menu.
5943

44+
NodeGraph Menu
45+
**************
6046

61-
----
47+
The context menu triggered from the node graph.
6248

6349
.. autoclass:: NodeGraphQt.NodeGraphMenu
6450
:members:
6551

66-
----
52+
53+
Nodes Menu
54+
**********
55+
56+
The context menu triggered from a node.
6757

6858
.. autoclass:: NodeGraphQt.NodesMenu
6959
:members:
@@ -72,9 +62,5 @@ Node graph menu.
7262
Command
7363
*******
7464

75-
Node graph menu command.
76-
77-
----
78-
7965
.. autoclass:: NodeGraphQt.NodeGraphCommand
8066
:members:

0 commit comments

Comments
 (0)