Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame^] | 1 | #!/usr/local/bin/python |
| 2 | # |
| 3 | # $Id$ |
| 4 | # |
| 5 | # Tix Demostration Program |
| 6 | # |
| 7 | # This sample program is structured in such a way so that it can be |
| 8 | # executed from the Tix demo program "tixwidgets": 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 |
| 11 | # program. |
| 12 | |
| 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 |
| 15 | # buttons |
| 16 | # |
| 17 | |
| 18 | import Tix |
| 19 | |
| 20 | network_pixmap = """/* XPM */ |
| 21 | static char * netw_xpm[] = { |
| 22 | /* width height ncolors chars_per_pixel */ |
| 23 | "32 32 7 1", |
| 24 | /* colors */ |
| 25 | " s None c None", |
| 26 | ". c #000000000000", |
| 27 | "X c white", |
| 28 | "o c #c000c000c000", |
| 29 | "O c #404040", |
| 30 | "+ c blue", |
| 31 | "@ c red", |
| 32 | /* pixels */ |
| 33 | " ", |
| 34 | " .............. ", |
| 35 | " .XXXXXXXXXXXX. ", |
| 36 | " .XooooooooooO. ", |
| 37 | " .Xo.......XoO. ", |
| 38 | " .Xo.++++o+XoO. ", |
| 39 | " .Xo.++++o+XoO. ", |
| 40 | " .Xo.++oo++XoO. ", |
| 41 | " .Xo.++++++XoO. ", |
| 42 | " .Xo.+o++++XoO. ", |
| 43 | " .Xo.++++++XoO. ", |
| 44 | " .Xo.XXXXXXXoO. ", |
| 45 | " .XooooooooooO. ", |
| 46 | " .Xo@ooo....oO. ", |
| 47 | " .............. .XooooooooooO. ", |
| 48 | " .XXXXXXXXXXXX. .XooooooooooO. ", |
| 49 | " .XooooooooooO. .OOOOOOOOOOOO. ", |
| 50 | " .Xo.......XoO. .............. ", |
| 51 | " .Xo.++++o+XoO. @ ", |
| 52 | " .Xo.++++o+XoO. @ ", |
| 53 | " .Xo.++oo++XoO. @ ", |
| 54 | " .Xo.++++++XoO. @ ", |
| 55 | " .Xo.+o++++XoO. @ ", |
| 56 | " .Xo.++++++XoO. ..... ", |
| 57 | " .Xo.XXXXXXXoO. .XXX. ", |
| 58 | " .XooooooooooO.@@@@@@.X O. ", |
| 59 | " .Xo@ooo....oO. .OOO. ", |
| 60 | " .XooooooooooO. ..... ", |
| 61 | " .XooooooooooO. ", |
| 62 | " .OOOOOOOOOOOO. ", |
| 63 | " .............. ", |
| 64 | " "}; |
| 65 | """ |
| 66 | |
| 67 | hard_disk_pixmap = """/* XPM */ |
| 68 | static char * drivea_xpm[] = { |
| 69 | /* width height ncolors chars_per_pixel */ |
| 70 | "32 32 5 1", |
| 71 | /* colors */ |
| 72 | " s None c None", |
| 73 | ". c #000000000000", |
| 74 | "X c white", |
| 75 | "o c #c000c000c000", |
| 76 | "O c #800080008000", |
| 77 | /* pixels */ |
| 78 | " ", |
| 79 | " ", |
| 80 | " ", |
| 81 | " ", |
| 82 | " ", |
| 83 | " ", |
| 84 | " ", |
| 85 | " ", |
| 86 | " ", |
| 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 | " .......................... ", |
| 102 | " ", |
| 103 | " ", |
| 104 | " ", |
| 105 | " ", |
| 106 | " ", |
| 107 | " ", |
| 108 | " ", |
| 109 | " "}; |
| 110 | """ |
| 111 | |
| 112 | network_bitmap = """ |
| 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}; |
| 127 | """ |
| 128 | |
| 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}; |
| 144 | """ |
| 145 | |
| 146 | def RunSample(w): |
| 147 | w.img0 = Tix.Image('pixmap', data=network_pixmap) |
| 148 | if not w.img0: |
| 149 | w.img0 = Tix.Image('bitmap', data=network_bitmap) |
| 150 | w.img1 = Tix.Image('pixmap', data=hard_disk_pixmap) |
| 151 | if not w.img0: |
| 152 | w.img1 = Tix.Image('bitmap', data=hard_disk_bitmap) |
| 153 | |
| 154 | hdd = Tix.Button(w, padx=4, pady=1, width=120) |
| 155 | net = Tix.Button(w, padx=4, pady=1, width=120) |
| 156 | |
| 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 |
| 160 | # individual items |
| 161 | # |
| 162 | # The tk.calls should be methods in Tix ... |
| 163 | w.hdd_img = 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', |
| 166 | '-underline', '0') |
| 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) |
| 169 | |
| 170 | # Put this image into the first button |
| 171 | # |
| 172 | hdd['image'] = w.hdd_img |
| 173 | |
| 174 | # Next button |
| 175 | w.net_img = 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', |
| 178 | '-underline', '0') |
| 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) |
| 181 | |
| 182 | # Put this image into the first button |
| 183 | # |
| 184 | net['image'] = w.net_img |
| 185 | |
| 186 | close = Tix.Button(w, pady=1, text='Close', |
| 187 | command=lambda w=w: w.destroy()) |
| 188 | |
| 189 | hdd.pack(side=Tix.LEFT, padx=10, pady=10, fill=Tix.Y, expand=1) |
| 190 | net.pack(side=Tix.LEFT, padx=10, pady=10, fill=Tix.Y, expand=1) |
| 191 | close.pack(side=Tix.LEFT, padx=10, pady=10, fill=Tix.Y, expand=1) |
| 192 | |
| 193 | if __name__ == '__main__': |
| 194 | root = Tix.Tk() |
| 195 | RunSample(root) |
| 196 | root.mainloop() |
| 197 | |