|
10 | 10 | NodeMovedCmd, |
11 | 11 | PortConnectedCmd) |
12 | 12 | from NodeGraphQt.base.factory import NodeFactory |
13 | | -from NodeGraphQt.base.menu import Menu |
| 13 | +from NodeGraphQt.base.menu import NodeGraphMenu, NodesMenu |
14 | 14 | from NodeGraphQt.base.model import NodeGraphModel |
15 | 15 | from NodeGraphQt.base.node import NodeObject |
16 | 16 | from NodeGraphQt.base.port import Port |
@@ -393,47 +393,73 @@ def context_menu(self): |
393 | 393 | """ |
394 | 394 | Returns the main context menu from the node graph. |
395 | 395 |
|
| 396 | + Note: |
| 397 | + This is a convenience function to |
| 398 | + :meth:`NodeGraphQt.NodeGraph.get_context_menu` |
| 399 | + with the arg ``menu="graph"`` |
| 400 | +
|
396 | 401 | 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): |
398 | 407 | """ |
399 | | - return Menu(self._viewer, self._viewer.context_menus()['Main']) |
| 408 | + Returns the main context menu for the nodes. |
400 | 409 |
|
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): |
402 | 421 | """ |
403 | 422 | Returns the context menu specified by the name. |
404 | 423 |
|
405 | 424 | 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. |
409 | 427 |
|
410 | 428 | Args: |
411 | | - name (str): menu name. |
| 429 | + menu (str): menu name. |
412 | 430 |
|
413 | 431 | Returns: |
414 | | - Menu: context menu object. |
| 432 | + NodeGraphMenu or NodesMenu: context menu object. |
415 | 433 | """ |
416 | 434 | 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]) |
420 | 440 |
|
421 | | - def disable_context_menu(self, disabled=True, name='Main'): |
| 441 | + def disable_context_menu(self, disabled=True, name='all'): |
422 | 442 | """ |
423 | | - Disable/Enable the main context menu from the node graph. |
| 443 | + Disable/Enable context menus from the node graph. |
424 | 444 |
|
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. |
429 | 449 |
|
430 | 450 | Args: |
431 | 451 | disabled (bool): true to enable context menu. |
432 | | - name (str): menu name. (default: Main) |
| 452 | + name (str): menu name. (default: ``"all"``) |
433 | 453 | """ |
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) |
437 | 463 |
|
438 | 464 | def acyclic(self): |
439 | 465 | """ |
|
0 commit comments