[pygtk] Setting widget.window in widget.do_realize where widget inherits from DrawingArea

Bjartur Thorlacius svartman95 at gmail.com
Sun Jan 1 09:55:53 WST 2012


Hi,
as a part of a custom widget that inherits gtk.DrawingArea:
	def do_realize(self):
		self.window = gtk.gdk.Window(
			self.get_parent_window(),
			self.allocation.width,
			self.allocation.height,
			gtk.gdk.WINDOW_CHILD,
			gtk.gdk.INPUT_OUTPUT,
			self.get_events() | gtk.gdk.EXPOSURE_MASK)
		self.window.set_user_data(self)
		self.style.attach(self.window)
		img = gtk.Image()
		img.set_from_file(self.pathname)
		self.pixbuf = img.get_pixbuf()
		self.set_flags(self.flags() | gtk.REALIZED)
	def do_expose_event(self, event):
		gc = self.window.new_gc(clip_mask=round(self.window, 20,  
self.allocation))
		self.window.draw_pixbuf(gc, self.pixbuf, 0,0,0,0)

Self.window is set just fine in do_realize, and passes the type sanity  
check as being a gtk.gdk.Window. On the other hand, it is None in  
do_expose_event and self.flags() & gtk.REALIZED is zero. Should I not be  
overriding do_realize? Or maybe not subclassing gtk.DrawingArea at all,  
but rather encapsulating it?

Also do_expose_event is not being called at all, even if I  
self.connect('expose-event', self.do_expose_event) in self.__init__.  
Do_realize and (snipped) do_size_allocate are called appropriately. The  
correct amount of space is reserved for the widget when used.

-- 
-,Bjartur


More information about the pygtk mailing list