[cairo] pycairo subclass

Behdad Esfahbod behdad at behdad.org
Mon Dec 10 11:05:30 PST 2007


On Tue, 2007-12-11 at 00:48 +0900, Steven Chaplin wrote:
> On Mon, 2007-12-10 at 05:01 -0500, Behdad Esfahbod wrote:
> > On Sun, 2007-12-09 at 20:25 -0500, Steven Chaplin wrote:
> > > 
> > > The cairo bindings doc 'Memory Management' page describes why its not a
> > > good idea to subclass cairo surfaces. So should cairo.Context be kept
> > > consistent with cairo surfaces, and not allow subclassing, or is
> > > cairo.Context a special case which should allow subclassing?
> > > How useful would subclassing cairo.Context be?
> > 
> > As you said both pango and gdk subclass cairo.Context, for good.  So
> > that one should stay like that.
> > 
> > One reason that subclassing cairo.Surface doesn't make sense, other than
> > the issues pointed out in the Memory Management page, is that you can't
> > override its methods.  That's a real limitation.  For example,
> > subclassing the show_page() method can be quite useful.
> 
> I'm not sure I understand. Do you mean that because cairo itself is not
> object-oriented there is little point subclassing a surface because you
> won't be able to override cairo's show_page() function?

Yes.

> > For cairo.Context this is less of an issue because no other cairo object
> > takes a cairo_t and work on it, but it's not true about the other cairo
> > types.  It still is a problem with for example pango.  That is, I can't
> > subclass a pango.CairoContext and override its stroke() method and have
> > pango underlines use my brand new stroke implementation...
> 
> I've thought about it a bit more. Since pango and gdk subclass
> cairo.Context I think we should allow subclassing from Python too to be
> consistent. It took ages to find out how to get it working, but all the
> required code was already there, I just had to change one 'NULL' to
> 'type'! I've updated pycairo in CVS, so the next version of pycairo
> should allow subclassing cairo.Context from Python.

Great.

> regards,
> Steve

While at that, any chance you can implement something like this:

  http://bugzilla.gnome.org/show_bug.cgi?id=489571

-- 
behdad
http://behdad.org/

...very few phenomena can pull someone out of Deep Hack Mode, with two
noted exceptions: being struck by lightning, or worse, your *computer*
being struck by lightning.  -- Matt Welsh



More information about the cairo mailing list