[vtkusers] Browsing VTK objects in python

David Gobbi dgobbi at irus.rri.on.ca
Fri Jul 7 14:41:00 EDT 2000


Just thought I should forward this to the whole list, just
in case anyone has comments to add.

---------- Forwarded message ----------
Date: Fri, 7 Jul 2000 14:36:28 -0400 (EDT)
From: David Gobbi <dgobbi at irus.rri.on.ca>
To: Prabhu Ramachandran <prabhu at aero.iitm.ernet.in>
Subject: Re: Some python help.

On Fri, 7 Jul 2000, Prabhu Ramachandran wrote:

> >>>>> "David" == David Gobbi <dgobbi at irus.rri.on.ca> writes:
> 
>     David> Hi Prabhu, I don't think that there _is_ a sensible way to
>     David> query a callable object for the number and types of the
>     David> arguments.  That information isn't really stored anywhere,
>     David> except for implicitly in the code that handles the function
> 
>     David> The best solution is for the wrappers to insert the
>     David> information into the .__doc__ attribute of the methods.  I
>     David> could add this to vtkWrapPython.c fairly easily:
> 
>     David> w = vtkWhatever() print w.SetValue.__doc__ 'void
>     David> SetValue(int value)'
> 
> 	Wow!  That would be really nice.  Are there other advantages
> to this, i.e. do others also see the need for this?  

Well, the __doc__ string isn't being used for anything yet.  This usage
is consistent with the 'python' way of doing things, for example:
>>> from math import *
>>> sin.__doc__
'sin(x)\012\012Return the sine of x.'

The actual format of the docstrings varies quite a bit, but usually
follows the form "func(arg1,arg2)\n\nDescription", if there are multiple
overloaded functions they are listed in order before the description.
For our purposes, type information should also be included.

> If so it should
> be easy to do something like this: wrap all of the vtk classes with
> python equivalents and add a Configure method that simply opens up a
> "toplevel" widget and displays all the current values in entries that
> can be modified.  

I don't know if creating python-level wrapper classes for all the VTK
classes would be a good idea -- that's one heck of a lot of automatically
generated python code!  It would be more efficient for the
Configure widget to have a SetObject() method. That way, if you wanted,
you could have just one Configure widget that would show the methods
for the currently selected object if you wanted.

> Writing simple python code that does this
> automatically from the __doc__ string should be easy, shouldnt it?  If
> this is done one could easily develop highly configurable vtk-python
> applications.  I guess it would be useful to do this for the vtkGUI
> project as well.  What do you think?

I haven't been following the vtkGUI project very closely, because I've
been too busy trying to get real research done recently...

>     David> Actually, the .__doc__ string could carry all the
>     David> information contained in the .html documentation.
> 
> 	Even better. :)
 
I'll see about adding the .__doc__ strings sometime this weekend.  There
really shouldn't be all that much work involved.

 - 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