[pygtk] Multiple Gtk.DrawingArea

Antoine Cailliau antoinecailliau at gmail.com
Wed Sep 9 23:23:46 WST 2009


Dear all,

First of all, a short presentation since I'm new on the ML. I'm student
in Belgium (UCLouvain) in Computer Science (especially computer langages
and software engineering). I just started a small project (a game for
gnome) to get familiar with Cairo and Pango libs.

I need two distinct drawing area in a gtk window. I tried a naive way
but I only get one working area (the first is accordingly filled with a
black rectangle, the other seems to be not displayed). I presume this is
not the right way to do it.

Here is the code:

#!/usr/bin/env python
#

import gtk, cairo

class DA(gtk.DrawingArea):

	def __init__(self):
		gtk.DrawingArea.__init__(self)
		self.connect("expose_event", self.expose)

	def expose(self, widget, event):
		self.context = widget.window.cairo_create()
		
		# set a clip region for the expose event
		self.context.rectangle(event.area.x, event.area.y,
							event.area.width, event.area.height)
		self.context.clip()
		
		self.draw(self.context)
		
		return False
		
	def draw(self, context):
		rect = self.get_allocation()
		context.rectangle(rect.x, rect.y, rect.width, rect.height)
		context.fill()
		return False

def main():
	window = gtk.Window()
	da1 = DA()
	da2 = DA()
	
	vbox = gtk.VBox()
	vbox.add(da1)
	vbox.add(da2)
	window.add(vbox)

	window.connect("destroy", gtk.main_quit)
	window.show_all()
	gtk.main()
	
if __name__ == "__main__":
	main()

and the result is attached.

Waiting for your help and of course, thanks in advance,

Antoine C.

-- 
Antoine Cailliau
www.ac-graphic.net
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screenshot-11.png
Type: image/png
Size: 9783 bytes
Desc: not available
Url : http://www.daa.com.au/pipermail/pygtk/attachments/20090909/479a8903/attachment.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3573 bytes
Desc: not available
Url : http://www.daa.com.au/pipermail/pygtk/attachments/20090909/479a8903/attachment.bin 


More information about the pygtk mailing list