Skip to content

Commit 7b0271e

Browse files
committed
renamed menu classes
1 parent 1a64dd6 commit 7b0271e

File tree

5 files changed

+39
-33
lines changed

5 files changed

+39
-33
lines changed

NodeGraphQt/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@
4747
from .base.graph import NodeGraph
4848
from .base.node import NodeObject, Node, Backdrop
4949
from .base.port import Port
50-
from .base.menu import ContextMenu, ContextMenuCommand
50+
from .base.menu import Menu, MenuCommand

NodeGraphQt/base/graph.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
NodeRemovedCmd,
1111
NodeMovedCmd,
1212
PortConnectedCmd)
13-
from NodeGraphQt.base.menu import ContextMenu
13+
from NodeGraphQt.base.menu import Menu
1414
from NodeGraphQt.base.model import NodeGraphModel
1515
from NodeGraphQt.base.node import NodeObject
1616
from NodeGraphQt.base.port import Port
@@ -222,9 +222,9 @@ def context_menu(self):
222222
Returns the node graph root context menu object.
223223
224224
Returns:
225-
ContextMenu: context menu object.
225+
Menu: context menu object.
226226
"""
227-
return ContextMenu(self._viewer, self._viewer.context_menu())
227+
return Menu(self._viewer, self._viewer.context_menu())
228228

229229
def acyclic(self):
230230
"""

NodeGraphQt/base/menu.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
from NodeGraphQt.widgets.stylesheet import STYLE_QMENU
77

88

9-
class ContextMenu(object):
9+
class Menu(object):
1010
"""
11-
base class for a context menu item.
11+
base class for a menu item.
1212
"""
1313

1414
def __init__(self, viewer, qmenu):
@@ -25,7 +25,7 @@ def qmenu(self):
2525

2626
def name(self):
2727
"""
28-
Returns the label for the menu.
28+
Returns the name for the menu.
2929
3030
Returns:
3131
str: label name.
@@ -34,38 +34,38 @@ def name(self):
3434

3535
def get_menu(self, name):
3636
"""
37-
Returns the child context menu item by name.
37+
Returns the child menu by name.
3838
3939
Args:
4040
name (str): name of the menu.
4141
4242
Returns:
43-
NodeGraphQt.ContextMenu: menu item.
43+
NodeGraphQt.Menu: menu item.
4444
"""
4545
for action in self.qmenu.actions():
4646
if action.menu() and action.menu().title() == name:
47-
return ContextMenu(self.__viewer, action.menu())
47+
return Menu(self.__viewer, action.menu())
4848

4949
def get_command(self, name):
5050
"""
51-
Returns the child menu command item by name.
51+
Returns the child menu command by name.
5252
5353
Args:
5454
name (str): name of the command.
5555
5656
Returns:
57-
NodeGraphQt.ContextMenuCommand: context menu command.
57+
NodeGraphQt.MenuCommand: context menu command.
5858
"""
5959
for action in self.qmenu.actions():
6060
if not action.menu() and action.text() == name:
61-
return ContextMenuCommand(self.__viewer, action)
61+
return MenuCommand(self.__viewer, action)
6262

6363
def all_commands(self):
6464
"""
6565
Returns all child and sub child commands from the current context menu.
6666
6767
Returns:
68-
list[NodeGraphQt.ContextMenuCommand]: list of commands.
68+
list[NodeGraphQt.MenuCommand]: list of commands.
6969
"""
7070
def get_actions(menu):
7171
actions = []
@@ -77,7 +77,7 @@ def get_actions(menu):
7777
actions += get_actions(action.menu())
7878
return actions
7979
child_actions = get_actions(self.qmenu)
80-
return [ContextMenuCommand(self.__viewer, a) for a in child_actions]
80+
return [MenuCommand(self.__viewer, a) for a in child_actions]
8181

8282
def add_menu(self, name):
8383
"""
@@ -87,12 +87,12 @@ def add_menu(self, name):
8787
name (str): menu name.
8888
8989
Returns:
90-
NodeGraphQt.ContextMenu: the appended menu.
90+
NodeGraphQt.Menu: the appended menu item.
9191
"""
9292
menu = QtWidgets.QMenu(None, title=name)
9393
menu.setStyleSheet(STYLE_QMENU)
9494
self.qmenu.addMenu(menu)
95-
return ContextMenu(self.__viewer, menu)
95+
return Menu(self.__viewer, menu)
9696

9797
def add_command(self, name, func=None, shortcut=None):
9898
"""
@@ -101,10 +101,10 @@ def add_command(self, name, func=None, shortcut=None):
101101
Args:
102102
name (str): command name.
103103
func (function): command function.
104-
shortcut (str): shotcut key.
104+
shortcut (str): function shotcut key.
105105
106106
Returns:
107-
NodeGraphQt.ContextMenuCommand: the appended command.
107+
NodeGraphQt.MenuCommand: the appended command.
108108
"""
109109
action = QtWidgets.QAction(name, self.__viewer)
110110
if LooseVersion(QtCore.qVersion()) >= LooseVersion('5.10'):
@@ -114,7 +114,7 @@ def add_command(self, name, func=None, shortcut=None):
114114
if func:
115115
action.triggered.connect(func)
116116
qaction = self.qmenu.addAction(action, shortcut=shortcut)
117-
return ContextMenuCommand(self.__viewer, qaction)
117+
return MenuCommand(self.__viewer, qaction)
118118

119119
def add_separator(self):
120120
"""
@@ -123,9 +123,9 @@ def add_separator(self):
123123
self.qmenu.addSeparator()
124124

125125

126-
class ContextMenuCommand(object):
126+
class MenuCommand(object):
127127
"""
128-
base class for a context menu command.
128+
base class for a menu command.
129129
"""
130130

131131
def __init__(self, viewer, qaction):
@@ -142,7 +142,7 @@ def qaction(self):
142142

143143
def name(self):
144144
"""
145-
Returns the label for the menu command.
145+
Returns the name for the menu command.
146146
147147
Returns:
148148
str: label name.

docs/_static/ngqt.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ pre {
288288
line-height: 1.2em;
289289
border: 1px solid #C6C9CB;
290290
font-size: 1.1em;
291-
margin: 1.5em 0 1.5em 0;
291+
margin: 0.5em 0 0.5em 0;
292292
-webkit-box-shadow: 1px 1px 1px #d8d8d8;
293293
-moz-box-shadow: 1px 1px 1px #d8d8d8;
294294
}

docs/menu.rst

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,34 @@ context menu some default menus and commands.
1818
Example
1919
=======
2020

21-
Here's a example to adding a menu and command.
21+
Here's a example where we a menu with the name "Foo" to the node graphs context menu.
2222

2323
.. code-block:: python
2424
:linenos:
2525
2626
from NodeGraphQt import NodeGraph
2727
28-
# test function.
29-
def my_test_func():
30-
print('Hello World')
31-
3228
# create node graph.
3329
graph = NodeGraph()
3430
3531
# get the main context menu.
3632
root_menu = graph.context_menu()
3733
38-
# add "Foo" menu.
34+
# add a menu called "Foo".
3935
foo_menu = root_menu.add_menu('Foo')
4036
37+
and here we add a menu command with the name "Bar" to the "Foo" menu that will execute the ``my_test()`` method.
38+
39+
.. code-block:: python
40+
:linenos:
41+
:lineno-start: 11
42+
43+
# test function.
44+
def my_test():
45+
print('Hello World')
46+
4147
# add "Bar" command to the "Foo" menu.
42-
foo_menu.add_command('Bar', my_test_func, 'Shift+t')
48+
foo_menu.add_command('Bar', my_test, 'Shift+t')
4349
4450
4551
Menu
@@ -50,7 +56,7 @@ Node graph context menu.
5056

5157
----
5258

53-
.. autoclass:: NodeGraphQt.ContextMenu
59+
.. autoclass:: NodeGraphQt.Menu
5460
:members:
5561

5662

@@ -61,5 +67,5 @@ Node graph context menu command.
6167

6268
----
6369

64-
.. autoclass:: NodeGraphQt.ContextMenuCommand
70+
.. autoclass:: NodeGraphQt.MenuCommand
6571
:members:

0 commit comments

Comments
 (0)