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

Bill Hoffman bill . hoffman at kitware . com
Tue, 22 Jul 2003 12:10:37 -0400


You may want to look at Wrapping/CSwig/Common/SwigExtras.i.
This is a traditional swig input file that is used in the 
build of CSwig wrapped ITK.   You may be able to add your typemap
code there, or do something similar.

-Bill


At 10:34 AM 7/21/2003, Charl P. Botha wrote:
>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/
>_______________________________________________
>Insight-users mailing list
>Insight-users at itk . org
>http://www . itk . org/mailman/listinfo/insight-users