enthought / mayavi

3D visualization of scientific data in Python
http://docs.enthought.com/mayavi/mayavi/
Other
1.3k stars 285 forks source link

mayavi2 does not start - traceback traits.trait_errors.TraitError: Each element of the 'groups' trait of a Menu instance must be a Group or None, but a value of 'OpenGroup' <class 'str'> was specified. #1182

Closed dpinte closed 1 year ago

dpinte commented 1 year ago
$ mayavi2
ERROR|2022-10-12 16:29:39,689|getting extensions from Plugin(id='envisage.ui.workbench', name='Workbench'), trait <my_action_sets>
Traceback (most recent call last):
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/envisage/plugin.py", line 326, in _get_extensions_from_trait
    extensions = getattr(self, trait_name)
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/envisage/ui/workbench/workbench_plugin.py", line 185, in _my_action_sets_default
    from .default_action_set import DefaultActionSet
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/envisage/ui/workbench/default_action_set.py", line 21, in <module>
    class DefaultActionSet(ActionSet):
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/envisage/ui/workbench/default_action_set.py", line 25, in DefaultActionSet
    Menu(
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/traits/trait_types.py", line 2695, in validate
    return TraitListObject(self, object, name, value)
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/traits/trait_list_object.py", line 584, in __init__
    super().__init__(
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/traits/trait_list_object.py", line 213, in __init__
    super().__init__(self.item_validator(item) for item in iterable)
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/traits/trait_list_object.py", line 213, in <genexpr>
    super().__init__(self.item_validator(item) for item in iterable)
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/traits/trait_list_object.py", line 867, in _item_validator
    return trait_validator(object, self.name, value)
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/traits/base_trait_handler.py", line 74, in error
    raise TraitError(
traits.trait_errors.TraitError: Each element of the 'groups' trait of a Menu instance must be a Group or None, but a value of 'OpenGroup' <class 'str'> was specified.
Traceback (most recent call last):
  File "/Users/dpinte/.edm/envs/test/bin/mayavi2", line 10, in <module>
    sys.exit(main())
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/mayavi/scripts/mayavi2.py", line 600, in main
    mayavi.main(sys.argv[1:])
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/mayavi/plugins/app.py", line 197, in main
    app.run()
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/mayavi/plugins/mayavi_workbench_application.py", line 81, in run
    window.open()
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/pyface/workbench/workbench_window.py", line 159, in open
    self._create()
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/pyface/ui/qt4/application_window.py", line 138, in _create
    self._create_trim_widgets(self.control)
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/pyface/i_application_window.py", line 155, in _create_trim_widgets
    self._create_menu_bar(parent)
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/pyface/ui/qt4/application_window.py", line 79, in _create_menu_bar
    if self.menu_bar_manager is not None:
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/envisage/ui/workbench/workbench_window.py", line 106, in _menu_bar_manager_default
    return self._action_manager_builder.create_menu_bar_manager("MenuBar")
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/envisage/ui/workbench/workbench_window.py", line 224, in __action_manager_builder_default
    window=self, action_sets=self.action_sets
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/envisage/ui/workbench/workbench_window.py", line 168, in _action_sets_default
    return [factory(window=self) for factory in self._action_sets]
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/envisage/extension_point.py", line 122, in get
    extensions = extension_registry.get_extensions(self.id)
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/envisage/application.py", line 203, in get_extensions
    return self.extension_registry.get_extensions(extension_point_id)
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/envisage/extension_registry.py", line 110, in get_extensions
    return self._get_extensions(extension_point_id)[:]
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/envisage/provider_extension_registry.py", line 99, in _get_extensions
    extensions = self._initialize_extensions(extension_point_id)
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/envisage/provider_extension_registry.py", line 279, in _initialize_extensions
    extensions.append(provider.get_extensions(extension_point_id)[:])
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/envisage/plugin.py", line 137, in get_extensions
    extensions = self._get_extensions_from_trait(trait_names[0])
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/envisage/plugin.py", line 326, in _get_extensions_from_trait
    extensions = getattr(self, trait_name)
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/envisage/ui/workbench/workbench_plugin.py", line 185, in _my_action_sets_default
    from .default_action_set import DefaultActionSet
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/envisage/ui/workbench/default_action_set.py", line 21, in <module>
    class DefaultActionSet(ActionSet):
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/envisage/ui/workbench/default_action_set.py", line 25, in DefaultActionSet
    Menu(
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/traits/trait_types.py", line 2695, in validate
    return TraitListObject(self, object, name, value)
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/traits/trait_list_object.py", line 584, in __init__
    super().__init__(
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/traits/trait_list_object.py", line 213, in __init__
    super().__init__(self.item_validator(item) for item in iterable)
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/traits/trait_list_object.py", line 213, in <genexpr>
    super().__init__(self.item_validator(item) for item in iterable)
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/traits/trait_list_object.py", line 867, in _item_validator
    return trait_validator(object, self.name, value)
  File "/Users/dpinte/.edm/envs/test/lib/python3.8/site-packages/traits/base_trait_handler.py", line 74, in error
    raise TraitError(
traits.trait_errors.TraitError: Each element of the 'groups' trait of a Menu instance must be a Group or None, but a value of 'OpenGroup' <class 'str'> was specified.
dpinte commented 1 year ago

The bug seems to be an issue due to the traits validation for https://github.com/enthought/envisage/blob/main/envisage/ui/workbench/default_action_set.py#L28 .

dpinte commented 1 year ago

The traits validation seemed to be the culprit. Testing with traits 6.3.2 works fine. The issue starts with 6.4.1 or the combination of other ETS dependencies coming with that version

corranwebster commented 1 year ago

~The trait error here is misleading. The problem is that the groups trait of a Menu is a read-only property: https://github.com/enthought/pyface/blob/608e153cb0f067223de82df608f8067f1d94a6a2/pyface/action/action_manager.py#L47-L48 Instead groups are intended to be passed through as *args to the Menu().~

~So the code here: https://github.com/enthought/envisage/blob/ebca726572a4ec565c82cc4091ec1f2d3c96a76c/envisage/ui/workbench/default_action_set.py#L25-L29 should instead look like:~

        Menu(
            "OpenGroup", "SaveGroup", "ImportGroup", "ExitGroup"
            name="&File",
            path="MenuBar",
        ),

~and so on for the other menus.~

~If this code worked in the past, it was purely by accident!~

Edit: Sorry, this is a different Menu object, from here: https://github.com/enthought/envisage/blob/ebca726572a4ec565c82cc4091ec1f2d3c96a76c/envisage/ui/action/menu.py#L50

The change in traits which is responsible is this one: https://github.com/enthought/traits/pull/1625 (see https://github.com/enthought/traits/issues/1619 for the issue it fixed).

I'm not quite sure how it worked previously, as traits typically don't validate default values, so I'm not sure if it is a bug or not. In any case, a work around is to use Group("OpenGroup") and so forth.

prabhuramachandran commented 1 year ago

I tried your workaround and the syntax that works is Group(id="OpenGroup") and this fixes the issue. Should I send a PR to envisage for this?

prabhuramachandran commented 1 year ago

I just submitted a PR to envisage that addresses this. https://github.com/enthought/envisage/pull/485

PaoloSuin commented 1 year ago

I am still having an issue. Downgrading traits to 6.3.1 or applying the fix in https://github.com/enthought/traits/issues/1619 gives another error:

mayavi2
      QSocketNotifier: Can only be used with threads started with QThread
      multiple 'tvtk.toolkits' plugins found for toolkit 'qt4': tvtk.pyface.ui.qt4.init, tvtk.pyface.ui.qt4.init
      X Error of failed request:  BadWindow (invalid Window parameter)
            Major opcode of failed request:  3 (X_GetWindowAttributes)
            Resource id in failed request:  0x5
            Serial number of failed request:  7
            Current serial number in output stream:  8

Anyway I am not sure where to apply the fix Group(id="OpenGroup")

Any help?