1
# -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
3
# $Id: CmpImg.py 68309 2009-01-04 18:53:28Z benjamin.peterson $
5
# Tix Demostration Program
7
# This sample program is structured in such a way so that it can be
8
# executed from the Tix demo program "tixwidgets.py": it must have a
9
# procedure called "RunSample". It should also have the "if" statment
10
# at the end of this file so that it can be run as a standalone
13
# This file demonstrates the use of the compound images: it uses compound
14
# images to display a text string together with a pixmap inside
20
network_pixmap = """/* XPM */
21
static char * netw_xpm[] = {
22
/* width height ncolors chars_per_pixel */
47
" .............. .XooooooooooO. ",
48
" .XXXXXXXXXXXX. .XooooooooooO. ",
49
" .XooooooooooO. .OOOOOOOOOOOO. ",
50
" .Xo.......XoO. .............. ",
56
" .Xo.++++++XoO. ..... ",
57
" .Xo.XXXXXXXoO. .XXX. ",
58
" .XooooooooooO.@@@@@@.X O. ",
59
" .Xo@ooo....oO. .OOO. ",
60
" .XooooooooooO. ..... ",
67
hard_disk_pixmap = """/* XPM */
68
static char * drivea_xpm[] = {
69
/* width height ncolors chars_per_pixel */
87
" .......................... ",
88
" .XXXXXXXXXXXXXXXXXXXXXXXo. ",
89
" .XooooooooooooooooooooooO. ",
90
" .Xooooooooooooooooo..oooO. ",
91
" .Xooooooooooooooooo..oooO. ",
92
" .XooooooooooooooooooooooO. ",
93
" .Xoooooooo.......oooooooO. ",
94
" .Xoo...................oO. ",
95
" .Xoooooooo.......oooooooO. ",
96
" .XooooooooooooooooooooooO. ",
97
" .XooooooooooooooooooooooO. ",
98
" .XooooooooooooooooooooooO. ",
99
" .XooooooooooooooooooooooO. ",
100
" .oOOOOOOOOOOOOOOOOOOOOOOO. ",
101
" .......................... ",
113
#define netw_width 32
114
#define netw_height 32
115
static unsigned char netw_bits[] = {
116
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x7f, 0x00, 0x00, 0x02, 0x40,
117
0x00, 0x00, 0xfa, 0x5f, 0x00, 0x00, 0x0a, 0x50, 0x00, 0x00, 0x0a, 0x52,
118
0x00, 0x00, 0x0a, 0x52, 0x00, 0x00, 0x8a, 0x51, 0x00, 0x00, 0x0a, 0x50,
119
0x00, 0x00, 0x4a, 0x50, 0x00, 0x00, 0x0a, 0x50, 0x00, 0x00, 0x0a, 0x50,
120
0x00, 0x00, 0xfa, 0x5f, 0x00, 0x00, 0x02, 0x40, 0xfe, 0x7f, 0x52, 0x55,
121
0x02, 0x40, 0xaa, 0x6a, 0xfa, 0x5f, 0xfe, 0x7f, 0x0a, 0x50, 0xfe, 0x7f,
122
0x0a, 0x52, 0x80, 0x00, 0x0a, 0x52, 0x80, 0x00, 0x8a, 0x51, 0x80, 0x00,
123
0x0a, 0x50, 0x80, 0x00, 0x4a, 0x50, 0x80, 0x00, 0x0a, 0x50, 0xe0, 0x03,
124
0x0a, 0x50, 0x20, 0x02, 0xfa, 0xdf, 0x3f, 0x03, 0x02, 0x40, 0xa0, 0x02,
125
0x52, 0x55, 0xe0, 0x03, 0xaa, 0x6a, 0x00, 0x00, 0xfe, 0x7f, 0x00, 0x00,
126
0xfe, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
129
hard_disk_bitmap = """
130
#define drivea_width 32
131
#define drivea_height 32
132
static unsigned char drivea_bits[] = {
133
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
134
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
135
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
136
0xf8, 0xff, 0xff, 0x1f, 0x08, 0x00, 0x00, 0x18, 0xa8, 0xaa, 0xaa, 0x1a,
137
0x48, 0x55, 0xd5, 0x1d, 0xa8, 0xaa, 0xaa, 0x1b, 0x48, 0x55, 0x55, 0x1d,
138
0xa8, 0xfa, 0xaf, 0x1a, 0xc8, 0xff, 0xff, 0x1d, 0xa8, 0xfa, 0xaf, 0x1a,
139
0x48, 0x55, 0x55, 0x1d, 0xa8, 0xaa, 0xaa, 0x1a, 0x48, 0x55, 0x55, 0x1d,
140
0xa8, 0xaa, 0xaa, 0x1a, 0xf8, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0x1f,
141
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
142
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
143
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
147
w.img0 = tkinter.tix.Image('pixmap', data=network_pixmap)
149
w.img0 = tkinter.tix.Image('bitmap', data=network_bitmap)
150
w.img1 = tkinter.tix.Image('pixmap', data=hard_disk_pixmap)
152
w.img1 = tkinter.tix.Image('bitmap', data=hard_disk_bitmap)
154
hdd = tkinter.tix.Button(w, padx=4, pady=1, width=120)
155
net = tkinter.tix.Button(w, padx=4, pady=1, width=120)
157
# Create the first image: we create a line, then put a string,
158
# a space and a image into this line, from left to right.
159
# The result: we have a one-line image that consists of three
162
# The tk.calls should be methods in Tix ...
163
w.hdd_img = tkinter.tix.Image('compound', window=hdd)
164
w.hdd_img.tk.call(str(w.hdd_img), 'add', 'line')
165
w.hdd_img.tk.call(str(w.hdd_img), 'add', 'text', '-text', 'Hard Disk',
167
w.hdd_img.tk.call(str(w.hdd_img), 'add', 'space', '-width', '7')
168
w.hdd_img.tk.call(str(w.hdd_img), 'add', 'image', '-image', w.img1)
170
# Put this image into the first button
172
hdd['image'] = w.hdd_img
175
w.net_img = tkinter.tix.Image('compound', window=net)
176
w.net_img.tk.call(str(w.net_img), 'add', 'line')
177
w.net_img.tk.call(str(w.net_img), 'add', 'text', '-text', 'Network',
179
w.net_img.tk.call(str(w.net_img), 'add', 'space', '-width', '7')
180
w.net_img.tk.call(str(w.net_img), 'add', 'image', '-image', w.img0)
182
# Put this image into the first button
184
net['image'] = w.net_img
186
close = tkinter.tix.Button(w, pady=1, text='Close',
187
command=lambda w=w: w.destroy())
189
hdd.pack(side=tkinter.tix.LEFT, padx=10, pady=10, fill=tkinter.tix.Y, expand=1)
190
net.pack(side=tkinter.tix.LEFT, padx=10, pady=10, fill=tkinter.tix.Y, expand=1)
191
close.pack(side=tkinter.tix.LEFT, padx=10, pady=10, fill=tkinter.tix.Y, expand=1)
193
if __name__ == '__main__':
194
root = tkinter.tix.Tk()