[PyKDE] SIP...Need help

Phil Thompson phil at riverbankcomputing.co.uk
Mon Jan 16 09:44:58 GMT 2006


On Saturday 14 January 2006 11:04 pm, computernet2000 at mail.bg wrote:
> Hi all !
>
> We try to create binding for Ultimate++ lib
> have most of widgets and non-gui classes (~70%)
> without Callback system :(
>
> We using SIP to wrap the code.
>
> this is a simple code ...
>
> Callback TheBack::THE_Callback(void *args)
> {
>            typedef TheBack CLASSNAME;
>            PyObject *p = (PyObject *)args;
>            Py_INCREF(p);
>            return callback1(this, &CLASSNAME::py_call,(void
> *)p);
> }
>
> void TheBack::py_call(void *data)
> {
> 		    PyObject *p = (PyObject *)data;
>
> 		    PyObject *func = PyTuple_GetItem(p, 0);
> 		    PyObject *args = PyTuple_GetItem(p, 1);
> 		    PyObject *kw = PyTuple_GetItem(p, 2);
> 		    PyObject_Call(func, args, kw);
> }
>
>
> "return THISBACK1(py_call, (void *)p)"
> This line is part from the Callback system,
> take a pointer-function and return Callback object.
>
>
> In Python i want wrap something like this  :
>
> def test(*args, **kw):
> 	print "bla-bla"
> module.THE_Callback(test,"some args...")
>
>
> After that, call the Python function and pass her into
> "module.THE_Callback(...)"
> but this not work.I dont know how to implement this in SIP.
> In the moment "*args" from "module.THE_Callback" is not a
> valid python-function argument
>
> Question is :
> How to wrap this method "THE_Callback(void *args)" in SIP ?

You have to use handwritten code. You could look at the implementation of 
qInstallMsgHandler() in PyQt as a simple example of passing a Python callable 
as a C++ callback. The general approach is to provide a single C++ callback 
and a data structure that enables that callback to select the correct Python 
callable. This can only work if the library being wrapped supplies enough 
information to enable the C++ callback to identify the correct Python 
callable.

Phil




More information about the PyQt mailing list