Re: [Pyobjc-dev] Passing objects between PyObjc and SWIG
Brought to you by:
ronaldoussoren
|
From: Kyle J. <osm...@gm...> - 2008-03-21 05:08:49
|
On Thu, Mar 20, 2008 at 7:05 AM, Ronald Oussoren <ron...@ma...> wrote:
>
> On 20 Mar, 2008, at 11:27, Kyle Johnson wrote:
> > So basically, I need to code something which converts the PyObjc
> > internal type to a SWIG-understandable internal type.
>
> Those types are automaticly generated.
>
> You can use the __cobject__() method on all Objective-C or
> CoreFoundation objects to get a Python CObject that wraps the raw
> pointer. That might be easier to convert to something that swig might
> understand.
Thank you for the info, Ronald. I think I'm going in the right
direction with this now.
I think there may be some wrapping still going on though with
__cobject__ as I'm getting invalid context errors from Core Graphics
(via Cairo).
I call the cairo function from Python like so:
ctx = NSGraphicsContext.currentContext().graphicsPort()
cairo.cairo_quartz_surface_create_for_cg_context(ctx.__cobject__(), 400, 400)
My wrapper code looks like this:
// definition of cairo function
cairo_surface_t *cairo_quartz_surface_create_for_cg_context
(CGContextRef cgContext, unsigned int width, unsigned int height);
// BEGIN: wrapper code (simplified)
CGContextRef arg1;
unsigned int arg2, arg3;
PyObject *obj0, *obj1, *obj2;
PyArg_ParseTuple(args,(char
*)"OOO:cairo_quartz_surface_create_for_cg_context",&obj0,&obj1,&obj2);
if( PyCObject_Check(obj0) ) {
// !!! something is wrong here; either the void ptr returned isn't for
// a CGContextRef or my typecasting/de-pointerizing is bad
arg1 = *(CGContextRef *) PyCObject_AsVoidPtr(obj0);
} else {
PyErr_SetString(PyExc_TypeError, "cgContext is not type PyCObject");
return NULL;
}
// [...] code for obj1/arg2, obj2/arg3
result = cairo_quartz_surface_create_for_cg_context(arg1,arg2,arg3);
// END: wrapper code (simplified)
This shouldn't be a Cairo issue. I have a identical C/Objective-C copy
of my program working without a problem.
--
Kyle Johnson
|