[vtkusers] AddObserver with Python

Doug Hackworth doug.hackworth at vanderbilt.edu
Thu May 1 15:49:01 EDT 2008


Greetings, all.  I am wanting to do something like the following:

	import vtk
	(...)
	planewidget = vtk.vtkImplicitPlaneWidget()
	(...)
	planewidget.AddObserver("EndInteractionEvent", MyCallbackFunction)

and I want MyCallbackFunction() to be passed some arguments, i.e. my data:

	def MyCallbackFunction(PlaneWidget, Polydata, BoundaryConditions):
		(...)

 From what I've read at least in the C++ documentation, the proper way to do 
this is to subclass vtkCommand and store the call data in the subclass, then 
pass an instance of this new class to AddObserver, etc.  The trouble is, I can't 
seem to locate the vtkCommand class in the Python bindings...  Is there supposed 
to be some other way to do it for Python?  It seems like the only other option 
for MyCallbackFunction() to have access to my data is to have the data be global 
objects, which I'd vastly prefer not to do.  Insights, anyone?

Also:  When I run my program with the plane widget implemented as above, the 
widget seems to work fine, but I get the error:

	TypeError: MyCallbackFunction() takes exactly 3 arguments (2 given)

Which two arguments are getting passed automatically?  Can I add more?

Thanks,
Doug











More information about the vtkusers mailing list