| FAQ Index - Search - Recent Changes - Everything - Add entry |
6.4. How can I draw on top of a subclassed widget?
Note, this is only accurate for PyGTK 2.6 or later.
First, subclass the type properly and make sure the constructor is chained to properly:
class MyButton(gtk.Button):
def __init__(self):
gtk.Button.__init__(self)
Secondly, override the expose-event virtual method, it will be called as soon as the widget is asked to redraw it self
def do_expose_event(self, event):
The first thing we want to do here, is to call the gtk.Button code, to draw something which looks like a button. It's simple, just chain up to the expose_event of the button itself:
retval = gtk.Button.do_expose_event(self, event)
At this point, the button is drawn. Now you can make your own "drawings" on top of the widget.
self.window.draw_ ....()
Finally return the same return value as we got from the parents call
return retval
Don't forget to register the type:
gobject.type_register(MyButton)
