jchanvfx / NodeGraphQt

Node graph framework that can be re-implemented into applications that supports PySide2
http://chantonic.com/NodeGraphQt/
MIT License
1.29k stars 264 forks source link

Deserializing hotkeys.json for nodes menu fail #375

Closed Gaspounet closed 1 year ago

Gaspounet commented 1 year ago

Hello!

I'm trying to set nodes context menus using a .json. I found that there is a kwarg in NodeGraph.set_context_menu_from_file to make this happen: menu='nodes' But using it, I get the following error:

File "E:\WORK\CODING\packages\nomad\examples\basic_example.py", line 28, in <module>
    graph.set_context_menu_from_file('../nomad/hotkeys/hotkeys.json', menu='nodes')
  File "C:\Users\Gaspounet\AppData\Roaming\Python\Python37\site-packages\NodeGraphQt\base\graph.py", line 883, in set_context_menu_from_file
    self._deserialize_context_menu(context_menu, data)
  File "C:\Users\Gaspounet\AppData\Roaming\Python\Python37\site-packages\NodeGraphQt\base\graph.py", line 817, in _deserialize_context_menu
    self._deserialize_context_menu(menu, item_data)
  File "C:\Users\Gaspounet\AppData\Roaming\Python\Python37\site-packages\NodeGraphQt\base\graph.py", line 810, in _deserialize_context_menu
    build_menu_command(menu, menu_data)
  File "C:\Users\Gaspounet\AppData\Roaming\Python\Python37\site-packages\NodeGraphQt\base\graph.py", line 803, in build_menu_command
    menu.add_command(name=cmd_name, **cmd_kwargs)
TypeError: add_command() got an unexpected keyword argument 'shortcut'

When I remove the menu='nodes', it works fine on the graph menu.

Here's the command I use: graph.set_context_menu_from_file('../nomad/nodes/hotkeys.json', menu='nodes')

Here's my hotkeys.json:

[
  {
    "type":"command",
    "label":"Disable",
    "file":"../nomad/hotkeys/hotkey_functions.py",
    "function_name":"disable",
    "shortcut":"D"
  }
]

Here's my hotkey_functions.py:

def disable(graph, node):
    if node.disabled():
        node.set_disabled(False)
    else:
        node.set_disabled(True)
jchanvfx commented 1 year ago

Hi @Gaspounet,

Thanks for catching that bug I've just released a new version here: https://github.com/jchanvfx/NodeGraphQt/releases/tag/v0.6.24

Gaspounet commented 1 year ago

Thanks @jchanvfx !