[vtkusers] How does one remove keypress events?

Greg Schussman greg.schussman at gmail.com
Mon Oct 6 13:58:01 EDT 2014


Hi, David.

Many, many thanks!  That's exactly what I needed, and it's working
perfectly.

Greg


On Sat, Oct 4, 2014 at 9:52 AM, David Cole <DLRdave at aol.com> wrote:

> The keypresses VTK handles by default are documented here:
>
>
> http://www.vtk.org/doc/release/5.10/html/classvtkInteractorStyle.html#details
>
> (The 5.10 documentation, since that's the version you said you're using...)
>
> The implementation for handling those keys is in the method
> vtkInteractorStyle::OnChar, which is documented here:
>
>
> http://www.vtk.org/doc/release/5.10/html/classvtkInteractorStyle.html#a4357cd197cdf5c2d9ff8821cb4a50d82
>
> The event triggering OnChar is the CharEvent, though, not the
> KeyPressEvent. Try removing observers for CharEvent instead.
>
>
> HTH,
> David C.
>
> On Fri, Oct 3, 2014 at 9:53 PM, Greg Schussman <greg.schussman at gmail.com>
> wrote:
> > 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
> >
> >
> > _______________________________________________
> > Powered by www.kitware.com
> >
> > Visit other Kitware open-source projects at
> > http://www.kitware.com/opensource/opensource.html
> >
> > Please keep messages on-topic and check the VTK FAQ at:
> > http://www.vtk.org/Wiki/VTK_FAQ
> >
> > Follow this link to subscribe/unsubscribe:
> > http://public.kitware.com/mailman/listinfo/vtkusers
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20141006/9f640c9b/attachment.html>


More information about the vtkusers mailing list