[cairo] gtk, cairo and surfaces

Hakki Dogusan dogusanh at tr.net
Sat May 23 03:48:42 PDT 2009


Donn wrote:
> Hi,
> Sorry if I am being thick, but I can't get anywhere with this. I am scraping 
> the net far and wide, so perhaps something will come-up.
> I am using pygtk and python-cairo. I have a DrawingArea which gets an expose 
> event. In that event one draws stuff with a context; there is no hint of 
> where/what the surface is (I can't find any).
> I want to output a png of what is being drawn to the window. Can anyone point 
> me in the right direction?
> Some code:
> class Stack(gtk.DrawingArea):
> ...stuff...
> def _expose(self, widget, event):
> 	self.context = widget.window.cairo_create()
> 	Draw stuff to self.context ...

Take this drawing commands to a subroutine,ie. DrawStuff(ctx). Call it here:
>[snipped rest of def _expose

Write a subroutine for png out, ie.
def OutToPNG()
   out = cairo.ImageSurface(cairo.FORMAT_ARGB32,self.w,self.h)
   ctxout = cairo.Context( out )
   out.write_to_png("somefile%d.png" % self.outpic )
   self.outpic += 1
   destroy ctxout
   destroy out

> Thanks,
> \d

Hakki Dogusan

More information about the cairo mailing list