【问题标题】:how do I catch a keyboard event in a mayavi animation如何在 mayavi 动画中捕捉键盘事件
【发布时间】:2014-02-21 20:20:27
【问题描述】:

我正在寻找一种捕获键盘事件的方法,以便在 mayavi 动画中循环浏览不同的数据集。

我的基本循环是:

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()

【问题讨论】:

  • Mayavi 非常自然地支持鼠标选择,但不支持键盘事件。如果你真的需要键盘事件,你应该考虑添加一个UserInteractorStyle。源代码在tvtk/tvtk_classes.zip/interactor_style_user.py

标签: python enthought mayavi


【解决方案1】:

谷歌搜索后,我发现了这个页面:http://osdir.com/ml/python-enthought-devel/2009-01/msg00325.html

这几乎解决了我的问题

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

... and then play with vtk_obj.GetKeyCode()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-09
    • 1970-01-01
    • 2013-05-15
    • 1970-01-01
    • 1970-01-01
    • 2021-12-10
    相关资源
    最近更新 更多