Skip to content

A crash in add_command #298

@ziab

Description

@ziab

Hello,

There seems to be an issue with add_command, it fails with

Traceback (most recent call last):
  File ".\exm.py", line 46, in <module>
    nodes_menu.add_command('Test',
  File "\NodeGraphQt\base\menu.py", line 224, in add_command
    command = NodeGraphCommand(self._graph, qaction, func)
  File "\NodeGraphQt\base\menu.py", line 238, in __init__
    self._name = qaction.text()
AttributeError: 'NoneType' object has no attribute 'text'

qaction.text() doesn't seem to directly depend on add_command parameters.

Also the documentation might be outdated, for example setup_context_menu doesn't seem to exist.

Repro:

from Qt import QtCore, QtWidgets

from NodeGraphQt import (
    NodeGraph,
    PropertiesBinWidget,
    NodesTreeWidget,
    NodesPaletteWidget,
    BaseNode
)

# define a couple example nodes.
class FooNode(BaseNode):
    __identifier__ = 'com.chantasticvfx'
    NODE_NAME = 'foo node'

    def __init__(self):
       super(FooNode, self).__init__()
       self.add_input('in')
       self.add_output('out')

class BarNode(FooNode):

    NODE_NAME = 'bar node'

# define a test function.
def test_func(graph, node):
    print('Clicked on node: {}'.format(node.name()))

QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)

app = QtWidgets.QApplication([])

node_graph = NodeGraph()
node_graph.register_node(FooNode)
node_graph.register_node(BarNode)

nodes_menu = node_graph.get_context_menu('nodes')

# The crash is here 
nodes_menu.add_command('Test',
                       func=test_func,
                       node_type='com.chantasticvfx.FooNode')

foo_node = node_graph.create_node('com.chantasticvfx.FooNode')
bar_node = node_graph.create_node('com.chantasticvfx.BarNode', pos=[300, 100])

node_graph.widget.show()

app.exec_()

Maybe I'm missing something?
Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions