blob: b1b69fbc56ed98b6ad0329695f72cec7fe9ed37c (
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
51
52
|
#!/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 pygtk
pygtk.require('2.0')
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()
|