[Insight-users] Getting PyObject* through to wrapped C++ code

Charl P. Botha c . p . botha at ewi . tudelft . nl
21 Jul 2003 16:34:32 +0200


Dear list,

Currently, there is no way to get observers working in CableSwig wrapped
Python.  The problem on the Tcl side was solved by creating a
itk::TclCommand itk::Command derivative that can take a Tcl string that
will be interpreted when the Observer is called.

I'm doing the same for Python (itk::PyCommand) but I would like to do it
somewhat more flexibly by passing a callable Python object instead of a
string.  However, the CableSwig wrapping is mangling my PyObject*
parameter.

In traditional Swig, something like this would be appropriate:
%typemap(python, in) PyObject * {
    $target = $source; 
}

This tells swig to pass the PyObjects through unaltered, which would
enable me to do things like the following:
def handler(object, eventString):
    print "Hello world"

a = itk.itkPyCommand_Pointer()
a.SetPythonCallable(handler)
and then use this Command in an AddObserver() call.

I'm guessing that a call to Swig_typemap_register() in CableSwig.cxx
should do the trick, although I would appreciate any guidance in this,
as I have no idea yet what this call should register.

Comments?

Thanks,
Charl

-- 
charl p. botha http://cpbotha . net/ http://visualisation . tudelft . nl/