[vtkusers] using custom vtk classes in Python

David Gobbi dgobbi at irus.rri.ca
Mon Feb 4 15:11:50 EST 2002


Hi Robb,

You can subclass vtkInteractor and vtkInteractorStyle in python if you
get VTK 4.1-pre from CVS, but the virtual functions are not hooked into
python so your OnMouseMove etc. won't be called unless you hook them in
yourself.

My advice is to derive your class from vtkIntereractorStyleUser and then
hook in using proxy methods like so:

def MyInteractorStyle(vtkInteractorStyleUser):
    def __init__(self):
        self.SetKeyPressMethod(self._OnKeyPress)
        [...other methods...]

    def _OnKeyPress(self):
        """A proxy method for OnKeyPress"""
        self.OnKeyPress(self.GetShiftKey(), self.GetCtrlKey(),
                        self.GetChar(), self.GetKeySym(), 1)

    def OnKeyPress(self, ctrl, shift, keycode, keysym, repeatcount):
        """Your own OnKeyPress method"""
        x,y = self.GetLastPos() # current mouse position
        print ((x,y), ctrl, shift, keycode, keysym)
        [... etc ...]

As you can see, hooking in all of the OnXXX methods will be a bit
tedious, so if you go ahead with this and contribute your efforts
to the VTK repository then many people will thank you for it.

Or, if you are using Tk, then just use the vtkTkRenderWidget.

 - David

--
  David Gobbi, MSc                       dgobbi at irus.rri.ca
  Advanced Imaging Research Group
  Robarts Research Institute, University of Western Ontario

On Mon, 4 Feb 2002, Robert Brown wrote:

> If I subclass a vtk class (I'm thinking particularly of vtkinteractor) in an I then use that class in Python?
>
> Robb Brown
> Seaman Family MR Research Centre
> Calgary, Alberta
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>




More information about the vtkusers mailing list