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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
#!/usr/bin/env python
'''Toolbar Demo
This demonstration demonstrates the use of toolbars in GTK+'''
description = 'Toolbars'
import gtk
folder_icon = [
"20 19 5 1",
" c None",
". c #000000",
"X c #FFFFFF",
"o c #FFFF00",
"O c #7F7F00",
" ",
" ",
" ",
" ... ",
" . . . ",
" .. ",
" ... ... ",
" .oXo....... ",
" .XoXoXoXoX. ",
" .oXoXoXoXo. ",
" .XoXo........... ",
" .oXo.OOOOOOOOO. ",
" .Xo.OOOOOOOOO. ",
" .o.OOOOOOOOO. ",
" ..OOOOOOOOO. ",
" ........... ",
" ",
" ",
" "
]
def set_orient_cb(button, toolbar, orient):
toolbar.set_orientation(orient)
def set_style_cb(button, toolbar, style):
toolbar.set_style(style)
def set_tooltips_cb(button, toolbar, enable):
toolbar.set_tooltips(enable)
def Image(pix, mask):
image = gtk.Image()
image.set_from_pixmap(pix, mask)
return image
def main():
win = gtk.Window()
win.connect('destroy', lambda win: gtk.main_quit())
win.set_title("Toolbar")
win.set_resizable(gtk.FALSE)
win.set_border_width(5)
pix, mask = gtk.gdk.pixmap_colormap_create_from_xpm_d(None,
win.get_colormap(),
None, folder_icon)
toolbar = gtk.Toolbar()
win.add(toolbar)
button = toolbar.append_item("Horizontal", "Horizontal toolbar layout",
None, Image(pix, mask), None, None)
button.connect("clicked", set_orient_cb, toolbar,
gtk.ORIENTATION_HORIZONTAL)
button = toolbar.append_item("Vertical", "Vertical toolbar layout",
None, Image(pix, mask), None, None)
button.connect("clicked", set_orient_cb, toolbar,
gtk.ORIENTATION_VERTICAL)
toolbar.append_space()
button = toolbar.append_item("Icons", "Only show toolbar icons",
None, Image(pix, mask), None, None)
button.connect("clicked", set_style_cb, toolbar, gtk.TOOLBAR_ICONS)
button = toolbar.append_item("Text", "Only show toolbar texts",
None, Image(pix, mask), None, None)
button.connect("clicked", set_style_cb, toolbar, gtk.TOOLBAR_TEXT)
button = toolbar.append_item("Both", "Show toolbar icons and text",
None, Image(pix, mask), None, None)
button.connect("clicked", set_style_cb, toolbar, gtk.TOOLBAR_BOTH)
toolbar.append_space()
entry = gtk.Entry()
toolbar.append_widget(entry, None, None)
toolbar.append_space()
button = toolbar.append_item("Enable", "Enable tooltips",
None, Image(pix, mask), None, None)
button.connect("clicked", set_tooltips_cb, toolbar, gtk.TRUE)
button = toolbar.append_item("Disable", "Disable tooltips",
None, Image(pix, mask), None, None)
button.connect("clicked", set_tooltips_cb, toolbar, gtk.FALSE)
win.show_all()
gtk.main()
if __name__ == '__main__':
main()
|