[cairo] gtk, cairo and surfaces

Donn donn.ingle at gmail.com
Sat May 23 03:11:31 PDT 2009

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):


def _expose(self, widget, event):
	self.context = widget.window.cairo_create()

	Draw stuff to self.context ...

	## I want a "copy" of the DrawingArea written out
	## to a PNG file as well.
	## This code writes blanks, not sure why:
	out = cairo.ImageSurface(cairo.FORMAT_ARGB32,self.w,self.h)
	ctxout = cairo.Context( out )

	## Trying to 'capture' my self.context into a pattern.

	ctxout.set_source( p )
	out.write_to_png("somefile%d.png" % self.outpic )
	self.outpic += 1

	return True

home: http://otherwise.relics.co.za/

More information about the cairo mailing list