Following the tutorial for drawing widgets with Cairo found at [1], I created a widget and then noticed some odd behavior when trying to render it.
When inserted into a window by itself, the widget rendered, but in more complex setups it did not. I created and attached a test script to demonstrate this problem. In it the widget and a button are added to a window in that order and render correctly. The order is then reversed and only the button is rendered. I would be grateful for any thoughts on what's going on. Please CC me on any responses. Cheers, Adam [1]http://www.pygtk.org/articles/cairo-pygtk-widgets/cairo-pygtk-widgets.htm
#!/usr/bin/env python import gtk import math class Bar(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() print "width = {0}, height = {1}, x = {2}, y = {3}".format(rect.width,rect.height, rect.x, rect.y) context.rectangle(gtk.gdk.Rectangle(rect.x + rect.width/3, rect.y + 5, rect.width/3, rect.height - 10)) context.set_source_rgba(0.0, 0.0, 0.0, 0.25) context.fill_preserve() context.set_source_rgba(0.0, 0.0, 0.0, 1.0) context.stroke() def main(): window = gtk.Window() window.set_default_size(200, 200) vbox = gtk.VBox() hbox = gtk.HBox() button = gtk.Button() bar = Bar() hbox.add(bar) hbox.add(button) vbox.add(hbox) window.add(vbox) window.connect("destroy", gtk.main_quit) window.show_all() window = gtk.Window() window.set_default_size(200, 200) vbox = gtk.VBox() hbox = gtk.HBox() button = gtk.Button() bar = Bar() hbox.add(button) hbox.add(bar) vbox.add(hbox) window.add(vbox) window.connect("destroy", gtk.main_quit) window.show_all() gtk.main() if __name__ == "__main__": main()
signature.asc
Description: This is a digitally signed message part
_______________________________________________ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/