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
53
54
55
|
#!/usr/bin/env python
# example toolbar.py by Usmar A Padow
import pygtk
pygtk.require('2.0')
import gtk
class ToolbarExample:
def __init__(self):
dialog = gtk.Dialog()
dialog.connect("delete-event", gtk.main_quit)
dialog.set_size_request(450, -1)
dialog.set_resizable(True)
# to make it nice we'll put the toolbar into the handle box,
# so that it can be detached from the main window
handlebox = gtk.HandleBox()
dialog.vbox.pack_start(handlebox, False, False, 5)
# toolbar will be horizontal, with both icons and text, and
# with 5pxl spaces between items and finally,
# we'll also put it into our handlebox
toolbar = gtk.Toolbar()
toolbar.set_orientation(gtk.ORIENTATION_HORIZONTAL)
toolbar.set_style(gtk.TOOLBAR_BOTH)
toolbar.set_border_width(5)
handlebox.add(toolbar)
self.buttons=[]
for a in range(0,5):
if a == 0:
#first button with none group
widget = None
else:
#additional buttons with belong to the group of the first button
widget = but
but = gtk.RadioToolButton(group=widget, stock_id=gtk.STOCK_APPLY)
but.set_label("button %d" % a)
but.connect("clicked", self.radio_event, a)
toolbar.insert(but,a)
self.buttons.append(but)
dialog.show_all()
def radio_event(self, widget, btn_num):
if widget.get_active():
print "button %d toggled on" % btn_num
if __name__ == "__main__":
ToolbarExample()
gtk.main()
|