summaryrefslogtreecommitdiff
path: root/examples/pygtk-demo/demos/builder.py
blob: 5df9d10cac890cb85ba429f3aeaf883dea2176c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
'''Builder

This is a test of the new gtk builder system.  It is a
fairly straight forward port of the example distributed with gtk.
'''

import gtk

class BuilderDemo(gtk.Window):
    def __init__(self, parent=None, filename="demos/demo.ui"):        
        gtk.Window.__init__(self)
        try:
            self.set_screen(parent.get_screen())
        except AttributeError:
            self.connect('destroy', lambda *w: gtk.main_quit())
        self.set_title(self.__class__.__name__)
        self.set_default_size(440, 250)
        
        # create a new empty Builer object
        builder = gtk.Builder()
        
        # load an XML definition
        builder.add_from_file(filename)
        
        # We must get the vbox and reparent it to self
        # since we don't use the main window defined in the ui file
        vbox = builder.get_object("vbox1")
        vbox.reparent(self)
        
        # autoconnect the signals from the instance self
        builder.connect_signals(self)

        self.show_all()

    def about_activate(self, action, data=None):
        about_dlg = gtk.AboutDialog()
        about_dlg.set_name("GtkBuilder demo")
        about_dlg.run()
        about_dlg.destroy()

    def quit_activate(self, action, data=None):
        gtk.main_quit()
    
    def main(self):
        gtk.main()

if __name__ == '__main__':
    build = BuilderDemo(None, "demo.ui")
    build.main()