Skip to content

Commit b5c8a4b

Browse files
committed
wip node context menu and doc updates
1 parent dea4703 commit b5c8a4b

File tree

8 files changed

+320
-148
lines changed

8 files changed

+320
-148
lines changed

NodeGraphQt/__init__.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,34 @@ def __init__(self):
8080
'"NodeGraphQt.vendor.Qt ({})"'.format(qtpy_ver))
8181

8282
from .base.graph import NodeGraph
83-
from .base.menu import Menu, MenuCommand
83+
from .base.menu import NodesMenu, NodeGraphMenu, NodeGraphCommand
8484
from .base.node import NodeObject, BaseNode, BackdropNode
8585
from .base.port import Port
8686
from .pkg_info import __version__ as VERSION
8787
from .pkg_info import __license__ as LICENSE
8888

8989
# functions
90-
from .base.actions import setup_context_menu
90+
from .base.utils import setup_context_menu
9191

9292
# widgets
9393
from .widgets.node_tree import NodeTreeWidget
9494
from .widgets.properties_bin import PropertiesBinWidget
9595

9696
__version__ = VERSION
9797
__all__ = [
98-
'BackdropNode', 'BaseNode', 'LICENSE', 'Menu', 'MenuCommand', 'NodeGraph',
99-
'NodeObject', 'NodeTreeWidget', 'Port', 'PropertiesBinWidget', 'VERSION',
100-
'constants', 'setup_context_menu'
98+
'BackdropNode',
99+
'BaseNode',
100+
'LICENSE',
101+
'NodeGraph',
102+
'NodeGraphCommand',
103+
'NodeGraphMenu',
104+
'NodeObject',
105+
'NodeTreeWidget',
106+
'NodesMenu',
107+
'Port',
108+
'PropertiesBinWidget',
109+
'VERSION',
110+
'constants',
111+
'setup_context_menu'
101112
]
113+

NodeGraphQt/base/graph.py

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
NodeMovedCmd,
1111
PortConnectedCmd)
1212
from NodeGraphQt.base.factory import NodeFactory
13-
from NodeGraphQt.base.menu import Menu
13+
from NodeGraphQt.base.menu import NodeGraphMenu, NodesMenu
1414
from NodeGraphQt.base.model import NodeGraphModel
1515
from NodeGraphQt.base.node import NodeObject
1616
from NodeGraphQt.base.port import Port
@@ -393,47 +393,73 @@ def context_menu(self):
393393
"""
394394
Returns the main context menu from the node graph.
395395
396+
Note:
397+
This is a convenience function to
398+
:meth:`NodeGraphQt.NodeGraph.get_context_menu`
399+
with the arg ``menu="graph"``
400+
396401
Returns:
397-
Menu: context menu object.
402+
NodeGraphQt.NodeGraphMenu: context menu object.
403+
"""
404+
return self.get_context_menu('graph')
405+
406+
def context_nodes_menu(self):
398407
"""
399-
return Menu(self._viewer, self._viewer.context_menus()['Main'])
408+
Returns the main context menu for the nodes.
400409
401-
def get_context_menu(self, name='Main'):
410+
Note:
411+
This is a convenience function to
412+
:meth:`NodeGraphQt.NodeGraph.get_context_menu`
413+
with the arg ``menu="nodes"``
414+
415+
Returns:
416+
NodeGraphQt.NodesMenu: context menu object.
417+
"""
418+
return self.get_context_menu('nodes')
419+
420+
def get_context_menu(self, menu):
402421
"""
403422
Returns the context menu specified by the name.
404423
405424
Menu types:
406-
"Main" - context menu from the node graph.
407-
"Node" - context menu from a Node.
408-
"Port" - context menu from a Port.
425+
"graph" - context menu from the node graph.
426+
"nodes" - context menu for the nodes.
409427
410428
Args:
411-
name (str): menu name.
429+
menu (str): menu name.
412430
413431
Returns:
414-
Menu: context menu object.
432+
NodeGraphMenu or NodesMenu: context menu object.
415433
"""
416434
menus = self._viewer.context_menus()
417-
if name not in menus:
418-
return
419-
return Menu(self._viewer, menus['Main'])
435+
if menus.get(menu):
436+
if menu == 'graph':
437+
return NodeGraphMenu(self, menus[menu])
438+
elif menu == 'nodes':
439+
return NodesMenu(self, menus[menu])
420440

421-
def disable_context_menu(self, disabled=True, name='Main'):
441+
def disable_context_menu(self, disabled=True, name='all'):
422442
"""
423-
Disable/Enable the main context menu from the node graph.
443+
Disable/Enable context menus from the node graph.
424444
425-
Menu types:
426-
"Main" - context menu from the node graph.
427-
"Node" - context menu from a Node.
428-
"Port" - context menu from a Port.
445+
Menu Types:
446+
- ``"all"`` all context menus from the node graph.
447+
- ``"graph"`` context menu from the node graph.
448+
- ``"nodes"`` context menu for the nodes.
429449
430450
Args:
431451
disabled (bool): true to enable context menu.
432-
name (str): menu name. (default: Main)
452+
name (str): menu name. (default: ``"all"``)
433453
"""
434-
menu = self._viewer.context_menus()[name]
435-
menu.setDisabled(disabled)
436-
menu.setVisible(not disabled)
454+
if name == 'all':
455+
for k, menu in self._viewer.context_menus().items():
456+
menu.setDisabled(disabled)
457+
menu.setVisible(not disabled)
458+
return
459+
menus = self._viewer.context_menus()
460+
if menus.get(name):
461+
menus[name].setDisabled(disabled)
462+
menus[name].setVisible(not disabled)
437463

438464
def acyclic(self):
439465
"""

0 commit comments

Comments
 (0)