/Demo/tix/samples/CmpImg.py

http://unladen-swallow.googlecode.com/ · Python · 196 lines · 155 code · 15 blank · 26 comment · 3 complexity · 8ad9d2fe17e2cd65508531d5236da2d2 MD5 · raw file

  1. # -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. # $Id: CmpImg.py 36560 2004-07-18 06:16:08Z tim_one $
  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.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
  11. # program.
  12. # This file demonstrates the use of the compound images: it uses compound
  13. # images to display a text string together with a pixmap inside
  14. # buttons
  15. #
  16. import Tix
  17. network_pixmap = """/* XPM */
  18. static char * netw_xpm[] = {
  19. /* width height ncolors chars_per_pixel */
  20. "32 32 7 1",
  21. /* colors */
  22. " s None c None",
  23. ". c #000000000000",
  24. "X c white",
  25. "o c #c000c000c000",
  26. "O c #404040",
  27. "+ c blue",
  28. "@ c red",
  29. /* pixels */
  30. " ",
  31. " .............. ",
  32. " .XXXXXXXXXXXX. ",
  33. " .XooooooooooO. ",
  34. " .Xo.......XoO. ",
  35. " .Xo.++++o+XoO. ",
  36. " .Xo.++++o+XoO. ",
  37. " .Xo.++oo++XoO. ",
  38. " .Xo.++++++XoO. ",
  39. " .Xo.+o++++XoO. ",
  40. " .Xo.++++++XoO. ",
  41. " .Xo.XXXXXXXoO. ",
  42. " .XooooooooooO. ",
  43. " .Xo@ooo....oO. ",
  44. " .............. .XooooooooooO. ",
  45. " .XXXXXXXXXXXX. .XooooooooooO. ",
  46. " .XooooooooooO. .OOOOOOOOOOOO. ",
  47. " .Xo.......XoO. .............. ",
  48. " .Xo.++++o+XoO. @ ",
  49. " .Xo.++++o+XoO. @ ",
  50. " .Xo.++oo++XoO. @ ",
  51. " .Xo.++++++XoO. @ ",
  52. " .Xo.+o++++XoO. @ ",
  53. " .Xo.++++++XoO. ..... ",
  54. " .Xo.XXXXXXXoO. .XXX. ",
  55. " .XooooooooooO.@@@@@@.X O. ",
  56. " .Xo@ooo....oO. .OOO. ",
  57. " .XooooooooooO. ..... ",
  58. " .XooooooooooO. ",
  59. " .OOOOOOOOOOOO. ",
  60. " .............. ",
  61. " "};
  62. """
  63. hard_disk_pixmap = """/* XPM */
  64. static char * drivea_xpm[] = {
  65. /* width height ncolors chars_per_pixel */
  66. "32 32 5 1",
  67. /* colors */
  68. " s None c None",
  69. ". c #000000000000",
  70. "X c white",
  71. "o c #c000c000c000",
  72. "O c #800080008000",
  73. /* pixels */
  74. " ",
  75. " ",
  76. " ",
  77. " ",
  78. " ",
  79. " ",
  80. " ",
  81. " ",
  82. " ",
  83. " .......................... ",
  84. " .XXXXXXXXXXXXXXXXXXXXXXXo. ",
  85. " .XooooooooooooooooooooooO. ",
  86. " .Xooooooooooooooooo..oooO. ",
  87. " .Xooooooooooooooooo..oooO. ",
  88. " .XooooooooooooooooooooooO. ",
  89. " .Xoooooooo.......oooooooO. ",
  90. " .Xoo...................oO. ",
  91. " .Xoooooooo.......oooooooO. ",
  92. " .XooooooooooooooooooooooO. ",
  93. " .XooooooooooooooooooooooO. ",
  94. " .XooooooooooooooooooooooO. ",
  95. " .XooooooooooooooooooooooO. ",
  96. " .oOOOOOOOOOOOOOOOOOOOOOOO. ",
  97. " .......................... ",
  98. " ",
  99. " ",
  100. " ",
  101. " ",
  102. " ",
  103. " ",
  104. " ",
  105. " "};
  106. """
  107. network_bitmap = """
  108. #define netw_width 32
  109. #define netw_height 32
  110. static unsigned char netw_bits[] = {
  111. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x7f, 0x00, 0x00, 0x02, 0x40,
  112. 0x00, 0x00, 0xfa, 0x5f, 0x00, 0x00, 0x0a, 0x50, 0x00, 0x00, 0x0a, 0x52,
  113. 0x00, 0x00, 0x0a, 0x52, 0x00, 0x00, 0x8a, 0x51, 0x00, 0x00, 0x0a, 0x50,
  114. 0x00, 0x00, 0x4a, 0x50, 0x00, 0x00, 0x0a, 0x50, 0x00, 0x00, 0x0a, 0x50,
  115. 0x00, 0x00, 0xfa, 0x5f, 0x00, 0x00, 0x02, 0x40, 0xfe, 0x7f, 0x52, 0x55,
  116. 0x02, 0x40, 0xaa, 0x6a, 0xfa, 0x5f, 0xfe, 0x7f, 0x0a, 0x50, 0xfe, 0x7f,
  117. 0x0a, 0x52, 0x80, 0x00, 0x0a, 0x52, 0x80, 0x00, 0x8a, 0x51, 0x80, 0x00,
  118. 0x0a, 0x50, 0x80, 0x00, 0x4a, 0x50, 0x80, 0x00, 0x0a, 0x50, 0xe0, 0x03,
  119. 0x0a, 0x50, 0x20, 0x02, 0xfa, 0xdf, 0x3f, 0x03, 0x02, 0x40, 0xa0, 0x02,
  120. 0x52, 0x55, 0xe0, 0x03, 0xaa, 0x6a, 0x00, 0x00, 0xfe, 0x7f, 0x00, 0x00,
  121. 0xfe, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  122. """
  123. hard_disk_bitmap = """
  124. #define drivea_width 32
  125. #define drivea_height 32
  126. static unsigned char drivea_bits[] = {
  127. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  128. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  129. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  130. 0xf8, 0xff, 0xff, 0x1f, 0x08, 0x00, 0x00, 0x18, 0xa8, 0xaa, 0xaa, 0x1a,
  131. 0x48, 0x55, 0xd5, 0x1d, 0xa8, 0xaa, 0xaa, 0x1b, 0x48, 0x55, 0x55, 0x1d,
  132. 0xa8, 0xfa, 0xaf, 0x1a, 0xc8, 0xff, 0xff, 0x1d, 0xa8, 0xfa, 0xaf, 0x1a,
  133. 0x48, 0x55, 0x55, 0x1d, 0xa8, 0xaa, 0xaa, 0x1a, 0x48, 0x55, 0x55, 0x1d,
  134. 0xa8, 0xaa, 0xaa, 0x1a, 0xf8, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0x1f,
  135. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  136. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  137. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  138. """
  139. def RunSample(w):
  140. w.img0 = Tix.Image('pixmap', data=network_pixmap)
  141. if not w.img0:
  142. w.img0 = Tix.Image('bitmap', data=network_bitmap)
  143. w.img1 = Tix.Image('pixmap', data=hard_disk_pixmap)
  144. if not w.img0:
  145. w.img1 = Tix.Image('bitmap', data=hard_disk_bitmap)
  146. hdd = Tix.Button(w, padx=4, pady=1, width=120)
  147. net = Tix.Button(w, padx=4, pady=1, width=120)
  148. # Create the first image: we create a line, then put a string,
  149. # a space and a image into this line, from left to right.
  150. # The result: we have a one-line image that consists of three
  151. # individual items
  152. #
  153. # The tk.calls should be methods in Tix ...
  154. w.hdd_img = Tix.Image('compound', window=hdd)
  155. w.hdd_img.tk.call(str(w.hdd_img), 'add', 'line')
  156. w.hdd_img.tk.call(str(w.hdd_img), 'add', 'text', '-text', 'Hard Disk',
  157. '-underline', '0')
  158. w.hdd_img.tk.call(str(w.hdd_img), 'add', 'space', '-width', '7')
  159. w.hdd_img.tk.call(str(w.hdd_img), 'add', 'image', '-image', w.img1)
  160. # Put this image into the first button
  161. #
  162. hdd['image'] = w.hdd_img
  163. # Next button
  164. w.net_img = Tix.Image('compound', window=net)
  165. w.net_img.tk.call(str(w.net_img), 'add', 'line')
  166. w.net_img.tk.call(str(w.net_img), 'add', 'text', '-text', 'Network',
  167. '-underline', '0')
  168. w.net_img.tk.call(str(w.net_img), 'add', 'space', '-width', '7')
  169. w.net_img.tk.call(str(w.net_img), 'add', 'image', '-image', w.img0)
  170. # Put this image into the first button
  171. #
  172. net['image'] = w.net_img
  173. close = Tix.Button(w, pady=1, text='Close',
  174. command=lambda w=w: w.destroy())
  175. hdd.pack(side=Tix.LEFT, padx=10, pady=10, fill=Tix.Y, expand=1)
  176. net.pack(side=Tix.LEFT, padx=10, pady=10, fill=Tix.Y, expand=1)
  177. close.pack(side=Tix.LEFT, padx=10, pady=10, fill=Tix.Y, expand=1)
  178. if __name__ == '__main__':
  179. root = Tix.Tk()
  180. RunSample(root)
  181. root.mainloop()