[vtkusers] About MouseEvents.py example

Elvis Stansvik elvis.stansvik at orexplore.com
Thu Jun 16 10:08:08 EDT 2016

2016-06-16 15:52 GMT+02:00 Elvis Stansvik <elvis.stansvik at orexplore.com>:

> The MouseEvents.py example [1] currently does:
> class MyInteractorStyle(vtk.vtkInteractorStyleTrackballCamera):
>     def __init__(self,parent=None):
> self.AddObserver("MiddleButtonPressEvent",self.middleButtonPressEvent)
> self.AddObserver("MiddleButtonReleaseEvent",self.middleButtonReleaseEvent)
>     def middleButtonPressEvent(self,obj,event):
>         print("Middle Button pressed")
>         self.OnMiddleButtonDown()
>         return
>     def middleButtonReleaseEvent(self,obj,event):
>         print("Middle Button released")
>         self.OnMiddleButtonUp()
>         return
> But I don't understand the reason for calling e.g.
> self.OnMiddleButtonDown() ? Since this is not an override of a virtual
> function (which is not possible in Python), but simply adding another
> observer, I don't think it is needed? (..and I would think it would mean
> OnMiddleButtonDown is called twice, right?).

Sorry, I realize I wasn't really clear here: What I mean is that, if the
interactor style above is used, the behavior of
vtkInteractorStyleTrackballCamera (the base class) will still be there,
even if the call to self.OnMiddleButtonDown() is removed, since the base
class will observe the interactor. That's why I don't understand the need
for the self.OnMiddleButtonDown() call in the example.

This ties in to my other question (another mail), since what I want to do
is to actually override the behavior of the base interactor style (similar
to how you can in C++, but I need to find some other mechanism to do so,
overriding of virtual functions won't work from Python).


> This leads me to another question: What if I really do want to override
> the behavior that the parent interactor style provides (or modify it by
> manipulating the event), what are my options?
> I saw at
> http://www.vtk.org/Wiki/VTK/Examples/Python/Interaction/MouseEventsObserver
> that you can remove all observers of an event from the interactor, but
> that seems like quite a hack :/ In my case, I'm interested in locking the
> camera rotation to a certain axis, but perhaps a custom interactor style is
> not the way to go?
> Elvis
> [1] http://www.vtk.org/Wiki/VTK/Examples/Python/Interaction/MouseEvents
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160616/a6b6b2b7/attachment.html>

More information about the vtkusers mailing list