[cairo] pyCairo Quartz support

Steven Chaplin stevech1097 at yahoo.com.au
Wed Nov 21 03:39:47 PST 2007


On Tue, 2007-11-20 at 02:56 -0500, Bobby Powers wrote:
> On Nov 20, 2007, at 1:14 AM, Steven Chaplin wrote:
> > You can mail this list a patch to pyCairo (against the 1.4.0 release)
> > adding Quartz support and I'll check if it can be added to pyCairo  
> > CVS.
> >
> > Regards,
> > Steve
> >
> 
> I've attached the patch (against 1.4.0) and a basic python class that  
> uses Cairo.  It is a subclass of NSView (Apple's Objective-C class for  
> drawing to parts of a window - PyObjC provides the bridging support  
> and is included in the standard Python distribution in 10.5, I only  
> have one machine so I haven't tried building this on OS X v10.4), and  
> shows how to get the CGContextRef in python and create the context.   
> If you're making a NIB in Interface Builder you can then simply create  
> a custom view, and specify its class as 'CairoView.'
> 
> This is my first time making and submitting a patch, so if it isn't  
> right let me know (I use SVN for some of my own projects, but since  
> its me and one other person we don't really use patches).
> 
> yours,
> Bobby Powers

The code for the new QuartzSurface class looks good. But is the new
class constructor fragile or can it handle type errors?
All the other Surface class constructors are robust in that they check
their arguments' type and raise a TypeError exception if the type is
incorrect.

>From what I can tell the first argument to cairo.QuartzSurface() is not
a real Python object, (because Quartz does not have Python bindings?)
just a wrapper round a C pointer. Ideally the function should check that
a Python object holding a valid CGContextRef is passed as the first
argument and raise a TypeError otherwise.

What happens if you call
    cairo.QuartzSurface(10, 100, 100)
is TypeError raised or do you get a segmentation (or other) fault?

[Also I think the 2nd and 3rd args should be 'I' unsigned int, not 'f'
float to match the cairo_quartz_surface_create_for_cg_context prototype]

Can PyCObject_Check() be used to catch some of these errors?

Regards,
Steve




More information about the cairo mailing list