[pygtk] Custom classes, Glade, and gtk.Builder

Robin Munn rmunn at pobox.com
Thu Jun 3 22:43:40 WST 2010

I'm trying to learn to use Glade to create UIs with gtk.Builder, and
there's one thing I can't figure out how to do. What I want to do is
something like this:

    class MainWindow(gtk.Window):
        def on_window_destroy(self):
        def handle_some_other_event(self):

    builder = gtk.Builder()
    wnd = builder.get_object('mainwindow')

However, I can't find anywhere in Glade to specify that I want to use
my MainWindow class rather than the gtk.Window class, so the "wnd"
object ends up as a gtk.Window instance and doesn't have the event
handler functions (on_window_destroy(), handle_some_other_event(), and
so on). If I edit the UI XML file by hand and change
'class="gtk.Window"' to 'class="MainWindow"', gtk.Builder doesn't know
where to find the MainWindow class to instantiate it.

I can work around this by putting the event names and handler
functions in a dict and passing that dict to gtk.Builder, but that
feels like unnecessary duplication. Glade lets me type in signal
handler names, and I have functions of those names in the class... so
how do I make this work? How do I tell gtk.Builder that I want to
instantiate my MainWindow class rather than the gtk.Window class?

Robin Munn
Robin.Munn at gmail.com
GPG key 0x4543D577

More information about the pygtk mailing list