4

I am looking for a way to catch keyboard events in order to cycle through different datasets in a mayavi animation.

My basic loop is:

while 1:
    time = TIME() - zero
    wx.Yield()
    atomsanim[:,:3] = atoms[:,3:]*cos(speed*time) + atoms[:,:3]
    f.scene.disable_render = True
    atom_index = 0
    for t, p in zip(types, plots):
        ms = p.mlab_source
        start = atom_index
        stop = atom_index+t
        ms.set(x=atomsanim[start:stop,0],y=atomsanim[start:stop,1],z=atomsanim[start:stop,2])
        atom_index += t
    f.scene.disable_render = False

mlab.show()
sonium
  • 918
  • 1
  • 11
  • 25
  • Mayavi has very natural support for mouse picks but not for keyboard events. If you really need keyboard events you should look at adding a `UserInteractorStyle`. The source code for this is in `tvtk/tvtk_classes.zip/interactor_style_user.py`. – aestrivex Feb 24 '14 at 21:53

1 Answers1

4

After googling around I found this page: http://osdir.com/ml/python-enthought-devel/2009-01/msg00325.html

Which pretty much solved the problem for me

scene.interactor.add_observer('KeyPressEvent', your_function); 
def your_function(vtk_obj, event): 

... and then play with vtk_obj.GetKeyCode()
Rndm
  • 6,710
  • 7
  • 39
  • 58
fabrica
  • 121
  • 1
  • 4