enthought / mayavi

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

Crash when clicking on Volume object in pipeline treeview #1206

Closed KestutisMa closed 1 year ago

KestutisMa commented 1 year ago

Wonderful project, but I observed little error while trying to edit properties (click on 'Volume' in pipeline treeview) of 'volume' plot in traits editor, it shows no properties and error in console:

I am using PySide2 as Qt backend and python 3.10.9, Arch Linux Trying to run code:

import numpy as np
from mayavi import mlab

x, y, z = np.ogrid[-10:10:20j, -10:10:20j, -10:10:20j]
s = np.sin(x*y*z)/(x*y*z)

mlab.pipeline.volume(mlab.pipeline.scalar_field(s))
mlab.show_pipeline()
mlab.show()

image

python ./mlab_test.py
libpng warning: iCCP: known incorrect sRGB profile
Exception occurred in traits notification handler for object: <mayavi.core.engine.Engine object at 0x7f4628ee2250>, trait: _current_selection, old value: <mayavi.core.scene.Scene object at 0x7f4628cace00>, new value: <mayavi.modules.volume.Volume object at 0x7f4629518bd0>
Traceback (most recent call last):
  File "/home/lab/Documents/lbmpy_projects/.venv/lib/python3.10/site-packages/traits/trait_notifiers.py", line 524, in _dispatch_change_event
    self.dispatch(handler, *args)
  File "/home/lab/Documents/lbmpy_projects/.venv/lib/python3.10/site-packages/traits/trait_notifiers.py", line 619, in dispatch
    handler(*args)
  File "/home/lab/Documents/lbmpy_projects/.venv/lib/python3.10/site-packages/traitsui/editor.py", line 601, in _update_editor
    self.update_editor()
  File "/home/lab/Documents/lbmpy_projects/.venv/lib/python3.10/site-packages/traitsui/qt4/instance_editor.py", line 266, in update_editor
    self.resynch_editor()
  File "/home/lab/Documents/lbmpy_projects/.venv/lib/python3.10/site-packages/traitsui/qt4/instance_editor.py", line 326, in resynch_editor
    self._ui = ui = view.ui(
  File "/home/lab/Documents/lbmpy_projects/.venv/lib/python3.10/site-packages/traitsui/view.py", line 457, in ui
    ui.ui(parent, kind)
  File "/home/lab/Documents/lbmpy_projects/.venv/lib/python3.10/site-packages/traitsui/ui.py", line 234, in ui
    self.rebuild(self, parent)
  File "/home/lab/Documents/lbmpy_projects/.venv/lib/python3.10/site-packages/traitsui/qt4/toolkit.py", line 152, in ui_subpanel
    ui_panel.ui_subpanel(ui, parent)
  File "/home/lab/Documents/lbmpy_projects/.venv/lib/python3.10/site-packages/traitsui/qt4/ui_panel.py", line 72, in ui_subpanel
    _ui_panel_for(ui, parent, True)
  File "/home/lab/Documents/lbmpy_projects/.venv/lib/python3.10/site-packages/traitsui/qt4/ui_panel.py", line 77, in _ui_panel_for
    ui.control = control = _Panel(ui, parent, is_subpanel).control
  File "/home/lab/Documents/lbmpy_projects/.venv/lib/python3.10/site-packages/traitsui/qt4/ui_panel.py", line 142, in __init__
    self.control = panel(ui)
  File "/home/lab/Documents/lbmpy_projects/.venv/lib/python3.10/site-packages/traitsui/qt4/ui_panel.py", line 273, in panel
    _fill_panel(panel, content, ui)
  File "/home/lab/Documents/lbmpy_projects/.venv/lib/python3.10/site-packages/traitsui/qt4/ui_panel.py", line 305, in _fill_panel
    gp = _GroupPanel(item, ui, suppress_label=True)
  File "/home/lab/Documents/lbmpy_projects/.venv/lib/python3.10/site-packages/traitsui/qt4/ui_panel.py", line 621, in __init__
    layout = self._add_items(content, inner)
  File "/home/lab/Documents/lbmpy_projects/.venv/lib/python3.10/site-packages/traitsui/qt4/ui_panel.py", line 864, in _add_items
    editor.prepare(inner)
  File "/home/lab/Documents/lbmpy_projects/.venv/lib/python3.10/site-packages/traitsui/editor.py", line 251, in prepare
    self.init(parent)
  File "/home/lab/Documents/lbmpy_projects/.venv/lib/python3.10/site-packages/traitsui/qt4/custom_editor.py", line 51, in init
    self.control = factory(*((parent, self) + self.factory.args))
  File "/home/lab/Documents/lbmpy_projects/.venv/lib/python3.10/site-packages/tvtk/util/traitsui_gradient_editor.py", line 27, in gradient_editor_factory
    widget = QGradientEditorWidget(None, tvtk_obj)
  File "/home/lab/Documents/lbmpy_projects/.venv/lib/python3.10/site-packages/tvtk/util/qt_gradient_editor.py", line 303, in __init__
    super().__init__(**kw)
AttributeError: 'master()' is not a Qt property or a signal

What could be cause of it?

corranwebster commented 1 year ago

This looks like a bug here: https://github.com/enthought/mayavi/blob/e360db9b5edec706501cfb40579b71afd8f79abb/tvtk/util/qt_gradient_editor.py#L300-L303

I think it needs direct super-class dispatch rather than using super() (ie. first dispatch to QWidget.__init__(self, ...) and then to GradientEditorWidget.__init__(self, ...) with appropriate args for each) - it seems it was done this way back in the git history of this file, and may have been broken in the Python 2 to Python 3 transition a few years back.

KestutisMa commented 1 year ago

Yes, you were right! I copied init from old version of file and it solved the problem. Thank you for quick reply, have a nice day! p.s. also needed do the same at line 170. I will try to make a pull request.