problem with mayavi2 mouse callbacks in traitsui

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

problem with mayavi2 mouse callbacks in traitsui

Roan LaPlante
Hi,

I am having difficulties using mouse callbacks in a traitsui application using an MlabSceneModel to expose mayavi.  Here is a set of examples depicting the problem:


from mayavi import mlab
from tvtk.api import tvtk

def printhello(f):
    print "hello world"

fig = mlab.figure()
fig.on_mouse_pick(printhello)
mlab.show()

This works just fine, and registers mouse clicks.

=================================

from mayavi import mlab
from tvtk.api import tvtk
from enthought.traits.api import *
from enthought.traits.ui.api import *
from mayavi.core.ui.api import MlabSceneModel,SceneEditor,MayaviScene
from mayavi.core.scene import Scene

def printhello(f):
    print "hello world"

class MyTraitsuiClickable(HasTraits):
    scene=Instance(MlabSceneModel,())

    view = View(Item(name='scene',
                editor=SceneEditor(scene_class=MayaviScene)))

    def setup(self):
        self.fig = mlab.figure(figure=self.scene.mayavi_scene)
        self.fig.on_mouse_pick(printhello)

m = MyTraitsuiClickable()
m.setup()
m.configure_traits()


When I attempt to run this program, it produces the following errors:

truffles:rlaplant[115] python mousebad.py

Exception occurred in traits notification handler.
Please check the log file for details.
Exception occurred in traits notification handler for object: <mayavi.core.mouse_pick_dispatcher.MousePickDispatcher object at 0x67c7a70>, trait: callbacks_items, old value: <undefined>, new value: <traits.trait_handlers.TraitListEvent object at 0x6723e50>

Traceback (most recent call last):
  File "/usr/pubsw/packages/python/epd/lib/python2.7/site-packages/traits/trait_notifiers.py", line 526, in rebind_call_2
    trait_name, new )
  File "/usr/pubsw/packages/python/epd/lib/python2.7/site-packages/traits/trait_notifiers.py", line 454, in dispatch
    handler( *args )
  File "/usr/pubsw/packages/python/epd/lib/python2.7/site-packages/mayavi/core/mouse_pick_dispatcher.py", line 77, in dispatch_callbacks_change
    self.callback_added(item)
  File "/usr/pubsw/packages/python/epd/lib/python2.7/site-packages/mayavi/core/mouse_pick_dispatcher.py", line 86, in callback_added
    picker = getattr(self.scene.scene.picker, '%spicker' % type)
AttributeError: 'NoneType' object has no attribute 'pointpicker'
Traceback (most recent call last):
  File "mousebad.py", line 23, in <module>
    m.setup()
  File "mousebad.py", line 20, in setup
    self.fig.on_mouse_pick(printhello)

  File "/usr/pubsw/packages/python/epd/lib/python2.7/site-packages/mayavi/core/scene.py", line 114, in on_mouse_pick
    return self._mouse_pick_dispatcher._active_pickers[type]
KeyError: 'point'



I have tried to trace down the source of this error with no luck.  Any assistance would be highly appreciated.

thanks,
Roan LaPlante



--
Roan LaPlante
Athinoula A. Martinos Center for Biomedical Imaging



_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: problem with mayavi2 mouse callbacks in traitsui

Gael Varoquaux
Hi,

You need to register these events after the scene has been activated,
which does not happen in your example, as it goes live at the
'configure_traits()' call, which is after the 'setup()' call. Use the
scene.activated event, as explained in
http://docs.enthought.com/mayavi/mayavi/building_applications.html#making-the-visualization-live

HTH,

Gaël

On Thu, Dec 13, 2012 at 01:20:28PM -0500, Roan LaPlante wrote:
> Hi,

> I am having difficulties using mouse callbacks in a traitsui application using
> an MlabSceneModel to expose mayavi.  Here is a set of examples depicting the
> problem:


> from mayavi import mlab
> from tvtk.api import tvtk

> def printhello(f):
>     print "hello world"

> fig = mlab.figure()
> fig.on_mouse_pick(printhello)
> mlab.show()

> This works just fine, and registers mouse clicks.

> =================================

> from mayavi import mlab
> from tvtk.api import tvtk
> from enthought.traits.api import *
> from enthought.traits.ui.api import *
> from mayavi.core.ui.api import MlabSceneModel,SceneEditor,MayaviScene
> from mayavi.core.scene import Scene

> def printhello(f):
>     print "hello world"

> class MyTraitsuiClickable(HasTraits):
>     scene=Instance(MlabSceneModel,())

>     view = View(Item(name='scene',
>                 editor=SceneEditor(scene_class=MayaviScene)))

>     def setup(self):
>         self.fig = mlab.figure(figure=self.scene.mayavi_scene)
>         self.fig.on_mouse_pick(printhello)

> m = MyTraitsuiClickable()
> m.setup()
> m.configure_traits()


> When I attempt to run this program, it produces the following errors:

> truffles:rlaplant[115] python mousebad.py

> Exception occurred in traits notification handler.
> Please check the log file for details.
> Exception occurred in traits notification handler for object:
> <mayavi.core.mouse_pick_dispatcher.MousePickDispatcher object at 0x67c7a70>,
> trait: callbacks_items, old value: <undefined>, new value:
> <traits.trait_handlers.TraitListEvent object at 0x6723e50>

> Traceback (most recent call last):
>   File "/usr/pubsw/packages/python/epd/lib/python2.7/site-packages/traits/
> trait_notifiers.py", line 526, in rebind_call_2
>     trait_name, new )
>   File "/usr/pubsw/packages/python/epd/lib/python2.7/site-packages/traits/
> trait_notifiers.py", line 454, in dispatch
>     handler( *args )
>   File "/usr/pubsw/packages/python/epd/lib/python2.7/site-packages/mayavi/core/
> mouse_pick_dispatcher.py", line 77, in dispatch_callbacks_change
>     self.callback_added(item)
>   File "/usr/pubsw/packages/python/epd/lib/python2.7/site-packages/mayavi/core/
> mouse_pick_dispatcher.py", line 86, in callback_added
>     picker = getattr(self.scene.scene.picker, '%spicker' % type)
> AttributeError: 'NoneType' object has no attribute 'pointpicker'
> Traceback (most recent call last):
>   File "mousebad.py", line 23, in <module>
>     m.setup()
>   File "mousebad.py", line 20, in setup
>     self.fig.on_mouse_pick(printhello)

>   File "/usr/pubsw/packages/python/epd/lib/python2.7/site-packages/mayavi/core/
> scene.py", line 114, in on_mouse_pick
>     return self._mouse_pick_dispatcher._active_pickers[type]
> KeyError: 'point'



> I have tried to trace down the source of this error with no luck.  Any
> assistance would be highly appreciated.

> thanks,
> Roan LaPlante
--
    Gael Varoquaux
    Researcher, INRIA Parietal
    Laboratoire de Neuro-Imagerie Assistee par Ordinateur
    NeuroSpin/CEA Saclay , Bat 145, 91191 Gif-sur-Yvette France
    Phone:  ++ 33-1-69-08-79-68
    http://gael-varoquaux.info            http://twitter.com/GaelVaroquaux
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: problem with mayavi2 mouse callbacks in traitsui

Roan LaPlante
Thanks Gael for following up,

i figured out scene.activated eventually.

R

On Wed, Jan 30, 2013 at 8:03 AM, Gael Varoquaux <[hidden email]> wrote:
Hi,

You need to register these events after the scene has been activated,
which does not happen in your example, as it goes live at the
'configure_traits()' call, which is after the 'setup()' call. Use the
scene.activated event, as explained in
http://docs.enthought.com/mayavi/mayavi/building_applications.html#making-the-visualization-live

HTH,

Gaël

On Thu, Dec 13, 2012 at 01:20:28PM -0500, Roan LaPlante wrote:
> Hi,

> I am having difficulties using mouse callbacks in a traitsui application using
> an MlabSceneModel to expose mayavi.  Here is a set of examples depicting the
> problem:


> from mayavi import mlab
> from tvtk.api import tvtk

> def printhello(f):
>     print "hello world"

> fig = mlab.figure()
> fig.on_mouse_pick(printhello)
> mlab.show()

> This works just fine, and registers mouse clicks.

> =================================

> from mayavi import mlab
> from tvtk.api import tvtk
> from enthought.traits.api import *
> from enthought.traits.ui.api import *
> from mayavi.core.ui.api import MlabSceneModel,SceneEditor,MayaviScene
> from mayavi.core.scene import Scene

> def printhello(f):
>     print "hello world"

> class MyTraitsuiClickable(HasTraits):
>     scene=Instance(MlabSceneModel,())

>     view = View(Item(name='scene',
>                 editor=SceneEditor(scene_class=MayaviScene)))

>     def setup(self):
>         self.fig = mlab.figure(figure=self.scene.mayavi_scene)
>         self.fig.on_mouse_pick(printhello)

> m = MyTraitsuiClickable()
> m.setup()
> m.configure_traits()


> When I attempt to run this program, it produces the following errors:

> truffles:rlaplant[115] python mousebad.py

> Exception occurred in traits notification handler.
> Please check the log file for details.
> Exception occurred in traits notification handler for object:
> <mayavi.core.mouse_pick_dispatcher.MousePickDispatcher object at 0x67c7a70>,
> trait: callbacks_items, old value: <undefined>, new value:
> <traits.trait_handlers.TraitListEvent object at 0x6723e50>

> Traceback (most recent call last):
>   File "/usr/pubsw/packages/python/epd/lib/python2.7/site-packages/traits/
> trait_notifiers.py", line 526, in rebind_call_2
>     trait_name, new )
>   File "/usr/pubsw/packages/python/epd/lib/python2.7/site-packages/traits/
> trait_notifiers.py", line 454, in dispatch
>     handler( *args )
>   File "/usr/pubsw/packages/python/epd/lib/python2.7/site-packages/mayavi/core/
> mouse_pick_dispatcher.py", line 77, in dispatch_callbacks_change
>     self.callback_added(item)
>   File "/usr/pubsw/packages/python/epd/lib/python2.7/site-packages/mayavi/core/
> mouse_pick_dispatcher.py", line 86, in callback_added
>     picker = getattr(self.scene.scene.picker, '%spicker' % type)
> AttributeError: 'NoneType' object has no attribute 'pointpicker'
> Traceback (most recent call last):
>   File "mousebad.py", line 23, in <module>
>     m.setup()
>   File "mousebad.py", line 20, in setup
>     self.fig.on_mouse_pick(printhello)

>   File "/usr/pubsw/packages/python/epd/lib/python2.7/site-packages/mayavi/core/
> scene.py", line 114, in on_mouse_pick
>     return self._mouse_pick_dispatcher._active_pickers[type]
> KeyError: 'point'



> I have tried to trace down the source of this error with no luck.  Any
> assistance would be highly appreciated.

> thanks,
> Roan LaPlante
--
    Gael Varoquaux
    Researcher, INRIA Parietal
    Laboratoire de Neuro-Imagerie Assistee par Ordinateur
    NeuroSpin/CEA Saclay , Bat 145, 91191 Gif-sur-Yvette France
    Phone:  ++ 33-1-69-08-79-68
    http://gael-varoquaux.info            http://twitter.com/GaelVaroquaux
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev


The information in this e-mail is intended only for the person to whom it is
addressed. If you believe this e-mail was sent to you in error and the e-mail
contains patient information, please contact the Partners Compliance HelpLine at
http://www.partners.org/complianceline . If the e-mail was sent to you in error
but does not contain patient information, please contact the sender and properly
dispose of the e-mail.




--
Roan LaPlante
Athinoula A. Martinos Center for Biomedical Imaging


_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: problem with mayavi2 mouse callbacks in traitsui

Gael Varoquaux
On Wed, Jan 30, 2013 at 10:26:17AM -0500, Roan LaPlante wrote:
> Thanks Gael for following up,

> i figured out scene.activated eventually.

Good! And sorry for the slow reply, I spend hours each day answering
email, and I still cannot keep up with the constant stream.

G
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev