[vtkusers] Inheriting vtkInteractorStyle

Sam Claassens sclaassens.ad at gmail.com
Sat Aug 9 09:29:35 EDT 2014


Hi,

I'm trying to create a class that manages a custom set of interactions in
python and having some trouble hooking to key and mouse events.

In the CustomInteraction.py example (
http://vtk.org/gitweb?p=VTK.git;a=blob_plain;f=Examples/GUI/Python/CustomInteraction.py)
it is recommended that you should subclass vtkInteractorStyle to do this
(instead of observers).

I've built a test class called Interactor3rdPerson that should override the
normal events, where at the moment I'm trying to catch the keyboard and
mouse events at the 'i=0' places in debug:
class Interactor3rdPerson(vtk.vtkInteractorStyleUser):

    # The tracked object.
    __trackedObject = None

    def __init__(self, trackedSceneObject):
        self.__trackedObject = trackedSceneObject

        i= 0

    # Overridden update method
    def OnTimer(self):
        i = 0

    def OnKeyPress(self):
        i = 0

    def OnKeyRelease(self):
        i = 0

    def OnLeftButtonDown(self):
        i = 0

In the main program I assign this to the render window interactor:

...
    # Change the interactor to the new camera
    interactor = Interactor3rdPerson.Interactor3rdPerson(axes)
    # axes is a scene object, but it isn't used yet

    # An interactor
    renderWindowInteractor = vtk.vtkRenderWindowInteractor()
    renderWindowInteractor.SetInteractorStyle(interactor)

    renderWindowInteractor.SetRenderWindow(renderWindow)
    # renderWindowInteractor.CreateTimer(0)
    interactor.EnabledOn()


    # Render an image (lights and cameras are created automatically)
    renderWindow.Render()

    # Begin mouse interaction
    renderWindowInteractor.Start()
    renderWindowInteractor.Initialize()

The issue is that I don't seem to be catching any input events. The normal
inputs are being triggered (I can pick and turn wireframes on) but I don't
see any catches when putting breakpoints at the 'i=0' places in the custom
interactor. Is there something that I'm missing or should be enabling?

Thanks,
Sam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20140809/9521ed6d/attachment.html>


More information about the vtkusers mailing list