on_mouse_pick does not work on Jupyter
- Dominant language
- Python
- Stars
- 1.4k
- Forks
- 316
- Avg merge
- 7h 44m
- Merged PRs (30d)
- 5
Description
Greetings all,
I've been trying to set up a callback to execute when I click on a given object of the scene. However, the following code leads to a failure to access the `picker` member of the `scene` object:
```
from mayavi import mlab
mlab.init_notebook(width=1280, height=1024)
def picker_callback(picker):
pass
figure = mlab.figure(bgcolor=(0, 0, 0), size=(1024,768))
picker = figure.on_mouse_pick(picker_callback)
```
```
Exception occurred in traits notification handler for object: , trait: callbacks_items, old value: , new value: TraitListEvent(index=0, removed=[], added=[(, 'point', 'Left')])
Traceback (most recent call last):
File "/lib/python3.6/site-packages/traits/trait_notifiers.py", line 524, in _dispatch_change_event
self.dispatch(handler, *args)
File "/lib/python3.6/site-packages/traits/trait_notifiers.py", line 486, in dispatch
handler(*args)
File "/lib/python3.6/site-packages/mayavi/core/mouse_pick_dispatcher.py", line 77, in dispatch_callbacks_change
self.callback_added(item)
File "/lib/python3.6/site-packages/mayavi/core/mouse_pick_dispatcher.py", line 86, in callback_added
picker = getattr(self.scene.scene.picker, '%spicker' % type)
```
The problem has to do with the call to `mlab.init_notebook()`, as it sets up its own widget manager. By inspection I can see that `figure.scene` doesn't have a `picker` object when `init_notebook()` is called. I tried to monkey-patch the code by adding a call to `figure.scene.picker = picker.Picker(figure.scene)`, but that leads to another problem:
```
---------------------------------------------------------------------------
SystemError Traceback (most recent call last)
in
9
10 from tvtk.pyface import picker
---> 11 figure.scene.picker = picker.Picker(figure.scene)
12
13 picker = figure.on_mouse_pick(picker_callback)
SystemError: error return without exception set
```
Note that, when `init_notebook()` is called, `figure.scene` is an instance of `class 'tvtk.pyface.tvtk_scene.TVTKScene'`. On a regular application that doesn't do Jupyter embedding that object is an instance of `class 'mayavi.core.ui.mayavi_scene.MayaviScene'`.
Does anybody have ideas on how to workaround this issue?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.