[vtkusers] subclassing in the python wrappers

David Gobbi dgobbi at irus.rri.ca
Mon Jan 21 06:32:21 EST 2002


The VTK python wrappers in the CVS version of VTK have been
enhanced to allow VTK classes to be subclassed within python.
The subclassing will work in any version of python from 1.5.2
through 2.2.

The following features are supported:
- declaration of new methods and class attributes via the 'class'
  statement (just like with python's built-in classes)
- set/get of user-defined attributes on vtk objects
- the special methods __init__, __setattr__, __getattr__, __delattr__,
  __repr__ and __str__
- isinstance() and issubclass() but only in python 2.1 or higher

The following features are not supported:
- special method names like __getitem__, __add__, __len__ etc. (these
  are easily doable, but require a lot of tedious work).
- multiple inheritance (fairly straightforward, as long as only one of
  the base classes is a VTK class)
- virtual method calls from C++ to python (would require significant
  changes to the wrappers, and would double the size of the wrappers)
- access to protected methods and ivars of VTK classes (ditto)
- the special method __del__ (things get complicated because of the
  mixture of python GC and VTK GC)

Hopefully, even with the missing features, people will find this
useful

 - David

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




More information about the vtkusers mailing list