enthought / mayavi

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

Usage as envisage plugin (e.g. Explorer example) not working anymore #1163

Closed JaRoSchm closed 1 year ago

JaRoSchm commented 1 year ago

Hey,

the usage of mayavi as an envisage plugin isn't working anymore. This can be noticed for example in examples/mayavi/explorer/ (there is an additional bug: explorer_app.py:110 has to be removed first).

The first run works without problem. If you now want to restart the app it fails:

  File "/home/jschmidt/Devel/mayavi_bug/explorer3d.py", line 128, in <module>
    main()
  File "/home/jschmidt/Devel/mayavi_bug/explorer3d.py", line 124, in main
    application.run()
  File "/home/jschmidt/anaconda/envs/CPG_stable/lib/python3.9/site-packages/envisage/ui/workbench/workbench_application.py", line 106, in run
    window.open()
  File "/home/jschmidt/anaconda/envs/CPG_stable/lib/python3.9/site-packages/pyface/workbench/workbench_window.py", line 159, in open
    self._create()
  File "/home/jschmidt/anaconda/envs/CPG_stable/lib/python3.9/site-packages/pyface/ui/qt4/application_window.py", line 135, in _create
    contents = self._create_contents(self.control)
  File "/home/jschmidt/anaconda/envs/CPG_stable/lib/python3.9/site-packages/pyface/workbench/workbench_window.py", line 244, in _create_contents
    self._restore_contents()
  File "/home/jschmidt/anaconda/envs/CPG_stable/lib/python3.9/site-packages/pyface/workbench/workbench_window.py", line 779, in _restore_contents
    self.layout.set_editor_memento(self._memento.editor_area_memento)
  File "/home/jschmidt/anaconda/envs/CPG_stable/lib/python3.9/site-packages/pyface/ui/qt4/workbench/workbench_window_layout.py", line 293, in set_editor_memento
    self._qt4_editor_area.restoreState(editor_layout, resolve_id)
  File "/home/jschmidt/anaconda/envs/CPG_stable/lib/python3.9/site-packages/pyface/ui/qt4/workbench/split_tab_widget.py", line 128, in restoreState
    assert self.count() == 0

The problem seems to be that the Mayavi scene is created first such that there already is an object which is not allowed for restoring the window layout of the previous run. At least this is shown if one adds

print(self.widget(0))
print(self.widget(0).count())
print(self.widget(0).tabText(0))

in front of assert self.count() == 0 in pyface/ui/qt4/workbench/split_tab_widget.py.

The problem doesn't occur if one loads only the mayavi plugins:

from mayavi.plugins.app import get_plugins
from envisage.ui.workbench.api import WorkbenchApplication

env_id = "bug.Bug"
plugins = get_plugins()
application = WorkbenchApplication(id=env_id, plugins=plugins)

application.run()

I'm using traits 6.3.2, traitsui 7.4.0, pyface 7.4.2, mayavi 4.8.0, envisage 6.0.1.

JaRoSchm commented 1 year ago

Is there some idea how to fix this? An application we are using which also uses Mayavi as an envisage plugin is affected by this too and we have to comment the assert statement mentioned above out in pyface/ui/qt4/workbench/split_tab_widget.py.

corranwebster commented 1 year ago

This is possibly an issue with Pyface. At the very least raising an assertion error probably isn't right: it's likely better to not do anything and warn or log.

If you could open an issue there that would be helpful; a PR that resolves the issue would be even better!

JaRoSchm commented 1 year ago

Thanks, I submitted two pull requests to fix the example. Nevertheless, the geometry of the window is not restored after closing the application.