[vtkusers] vtk and python - some questions.

David Gobbi dgobbi at irus.rri.on.ca
Wed Nov 8 15:33:54 EST 2000


Hi Prabhu,

I've made some massive changes to the python wrappers that
should be useful to you.  They'll appear in the nightlies
tomorrow (they're already in CVS).


The VTK/Python objects now have two special attributes:

__class__    the VTK/Python class that the object belongs to

__this__     returns a SWIG-style mangled 'this' pointer 


The new VTK/Python classes also have special attributes:

__bases__    the base clases of this class, as a tuple

__methods__  all the methods for this class

__name__     the name of the class, e.g. 'vtkActor'

__module__   the module the class is defined in, e.g. libVTKCommonPython

__doc__      a doc string for the class, currently empty


The methods also have __doc__ strings that return the
C++ prototypes for that method.  The format of these doc strings
is likely to change in the future.


The new VTK/Python classes and objects have a similar 'look & feel'
to Python's own classes and class instances, however, you cannot
derive a Python class from a VTK/Python class unless you write your
own wrapper class.


To list all the methods for a particular object or class, you can use the
following:

def vtkdir(c):
  try:
    c = c.__class__
  except AttributeError:
    pass
  d = c.__methods__
  d.insert(0,"from " + c.__name__ + ":")
  for b in c.__bases__:
    for m in vtkdir(b):
      if not m in d:
        d.append(m)
  return d


Finally, I've moved most of the implementation of the wrappers out
of vtkWrapPython.c and into common/vtkPythonUtil.cxx.  This will
make future modification of the wrappers much easier.

 - David

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





More information about the vtkusers mailing list