[vtkusers] AddObserver with Python

Charl Botha c.p.botha at tudelft.nl
Fri May 2 03:02:06 EDT 2008


On Thu, May 1, 2008 at 9:49 PM, Doug Hackworth
<doug.hackworth at vanderbilt.edu> wrote:
>  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?

The two arguments are object_binding and event_name.  If you really
need to send more data in, you could for example inject variables into
the object namespace.  For example:

my_object.some_string = 'hello world'
my_object.AddObserver('SomeEvent', MyCallbackFunction)

def MyCallbackFunction(object_binding, event_name):
    print object_binding.some_string

You could also use a lambda statement in your AddObserver call to pass
things through that are already defined at that time:

some_string = 'hello world'
my_object.AddObserver('SomeEvent', lambda o, e, mystring=some_string:
MyCallbackFunction(o,e,mystring))

Good luck,
Charl Botha



More information about the vtkusers mailing list