jchanvfx / NodeGraphQt

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

[Linux] 'PySide2.QtWidgets.QAction.setShortcut' called with wrong argument types #370

Closed adro79 closed 1 year ago

adro79 commented 1 year ago

Another error I found:

  File "/usr/lib/python3.11/site-packages/QuiltiX/quiltix.py", line 117, in init_ui
    self.qx_node_graph.set_context_menu_from_file(os.path.dirname(__file__) + "/hotkeys/hotkeys.json")
  File "/usr/lib/python3.11/site-packages/NodeGraphQt/base/graph.py", line 883, in set_context_menu_from_file
    self._deserialize_context_menu(context_menu, data)
  File "/usr/lib/python3.11/site-packages/QuiltiX/qx_nodegraph.py", line 408, in _deserialize_context_menu
    super(QxNodeGraph, self)._deserialize_context_menu(menu, menu_data)
  File "/usr/lib/python3.11/site-packages/NodeGraphQt/base/graph.py", line 817, in _deserialize_context_menu
    self._deserialize_context_menu(menu, item_data)
  File "/usr/lib/python3.11/site-packages/QuiltiX/qx_nodegraph.py", line 408, in _deserialize_context_menu
    super(QxNodeGraph, self)._deserialize_context_menu(menu, menu_data)
  File "/usr/lib/python3.11/site-packages/NodeGraphQt/base/graph.py", line 814, in _deserialize_context_menu
    self._deserialize_context_menu(sub_menu, items)
  File "/usr/lib/python3.11/site-packages/QuiltiX/qx_nodegraph.py", line 408, in _deserialize_context_menu
    super(QxNodeGraph, self)._deserialize_context_menu(menu, menu_data)
  File "/usr/lib/python3.11/site-packages/NodeGraphQt/base/graph.py", line 817, in _deserialize_context_menu
    self._deserialize_context_menu(menu, item_data)
  File "/usr/lib/python3.11/site-packages/QuiltiX/qx_nodegraph.py", line 408, in _deserialize_context_menu
    super(QxNodeGraph, self)._deserialize_context_menu(menu, menu_data)
  File "/usr/lib/python3.11/site-packages/NodeGraphQt/base/graph.py", line 810, in _deserialize_context_menu
    build_menu_command(menu, menu_data)
  File "/usr/lib/python3.11/site-packages/NodeGraphQt/base/graph.py", line 803, in build_menu_command
    menu.add_command(name=cmd_name, **cmd_kwargs)
  File "/usr/lib/python3.11/site-packages/NodeGraphQt/base/menu.py", line 144, in add_command
    action.setShortcut(shortcut)
TypeError: 'PySide2.QtWidgets.QAction.setShortcut' called with wrong argument types:
  PySide2.QtWidgets.QAction.setShortcut(Key)
Supported signatures:
  PySide2.QtWidgets.QAction.setShortcut(PySide2.QtGui.QKeySequence)

I'm using nodegraphqt 0.6.16 with python 3.11 and PySide2 5.15.10 on Arch Linux

adro79 commented 1 year ago

I was able to fix the error by changing menu.py

        if isinstance(shortcut, QtGui.QKeySequence): # changed str to QtGui.QKeySequence
            search = re.search(r'(?:\.|)QKeySequence\.(\w+)', shortcut)
            if search:
                shortcut = getattr(QtGui.QKeySequence, search.group(1))
            elif all([i in ['Alt', 'Enter'] for i in shortcut.split('+')]):
                shortcut = QtGui.QKeySequence(
                    QtCore.Qt.Modifier.ALT | QtCore.Qt.Key.Key_Return
                )
            elif all([i in ['Return', 'Enter'] for i in shortcut.split('+')]):
                shortcut = QtCore.Qt.Key.Key_Return

        if shortcut:
            action.setShortcut(shortcut)

Maybe it's not the appropiate fix but it allows me to use shortcuts in Quiltix