[vtkusers] How does one remove keypress events?

Greg Schussman greg.schussman at gmail.com
Fri Oct 3 21:53:57 EDT 2014


Hi.

I'm having trouble getting rid of default keypress behavior.  I've had
considerably less luck with the documentation/examples and with google than
usual.

I'm using python 2.6.8 and vtk-5.10.1.  I've been working from the example
here:

http://www.vtk.org/Wiki/index.php?title=VTK/Examples/Python/Interaction/MouseEventsObserver

If I run that directly, it works, and hit 'w, it switches to wireframe.  I
want to disconnect any default key handling so that eventually I can
substitute my own.  That is, eventually, I want to make 'w' do something
completely different.

If I edit the end of that example to look like this:

interactor.RemoveObservers('KeyPressEvent')  #  <-- I ADDED THIS
interactor.RemoveObservers('LeftButtonPressEvent')
interactor.AddObserver('LeftButtonPressEvent', DummyFunc1, 1.0)
interactor.AddObserver('LeftButtonPressEvent', DummyFunc2, -1.0)
interactor.Initialize()
interactor.Start()

and run again, pressing 'w' still switches to wireframe.   I was hoping
that by removing all KeyPressEvent observers, the program would no longer
respond to keypresses.  Why does 'w' still produce a wireframe image, and
how do I disable 'w' (so I can override it with my own action)?

In trying to debug this, I figured I'd check whether 'KeyPressEvent' really
is the correct name.  If I go back to the original example code, and change
the end to look like this:

def keypress(obj, ev):  # <-- I ADDED THIS
    print "keypress!"      # < -- I ADDED THIS

interactor.AddObserver('KeyPressEvent', keypress)  # <-- I ADDED THIS
interactor.RemoveObservers('LeftButtonPressEvent')
interactor.AddObserver('LeftButtonPressEvent', DummyFunc1, 1.0)
interactor.AddObserver('LeftButtonPressEvent', DummyFunc2, -1.0)
interactor.Initialize()
interactor.Start()

then I see "keypress!" every time I press a key.  This tells me that
'KeyPressEvent' is the correct name. So I'm baffled.  I think I'm removing
all 'KeyPressEvent' observers, yet 'w' still switches to wireframe.   What
am I doing wrong?

Many thanks for any help.

Greg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20141003/c8d84486/attachment.html>


More information about the vtkusers mailing list