home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / TCL / BLT / _BLT.TAR / usr / lib / blt / demos / busy < prev    next >
Encoding:
Text File  |  1994-01-18  |  4.0 KB  |  177 lines

  1. #!../blt_wish -f
  2.  
  3. if [file exists ../library] {
  4.     set blt_library ../library
  5. }
  6. #
  7. # Script to test the "busy" command.
  8.  
  9. #
  10. # General widget class resource attributes
  11. #
  12. option add *Button.padX     10
  13. option add *Button.padY     2
  14. option add *Scale.relief     sunken
  15. option add *Scale.orient    horizontal
  16. option add *Entry.relief     sunken
  17.  
  18. set visual [winfo screenvisual .] 
  19. if { $visual == "staticgray"  || $visual == "grayscale" } {
  20.     set activeBg black
  21.     set normalBg white
  22.     set bitmapFg black
  23.     set bitmapBg white
  24. } else {
  25.     set activeBg red
  26.     set normalBg springgreen
  27.     set bitmapFg blue
  28.     set bitmapBg green
  29. }
  30.  
  31. #
  32. # Instance specific widget options
  33. #
  34. option add Tk.top.relief     sunken
  35. option add Tk.top.borderWidth     4
  36. option add Tk.top.background     $normalBg
  37. option add Tk.b1.text         "Test"
  38. option add Tk.b2.text         "Quit"
  39. option add Tk.b3.text         "New button"
  40. option add Tk.b4.text         "Hold"
  41. option add Tk.b4.background     $activeBg
  42. option add Tk.b4.foreground     $normalBg
  43. option add Tk.b5.text         "Release"
  44. option add Tk.b5.background     $normalBg
  45. option add Tk.b5.foreground     $activeBg
  46.  
  47. #
  48. # This never gets used; it's reset by the Animate proc. It's 
  49. # here to just demonstrate how to set busy window options via
  50. # the host window path name
  51. #
  52. option add Tk.top.busyCursor     bogosity 
  53.  
  54. #
  55. # Initialize a list bitmap file names which make up the animated 
  56. # fish cursor. The bitmap mask files have a "m" appended to them.
  57. #
  58. set bitmaps { fc_left fc_left1 fc_mid fc_right1 fc_right }
  59.  
  60. #
  61. # Counter for new buttons created by the "New button" button
  62. #
  63. set numWin 0
  64. #
  65. # Current index into the bitmap list. Indicates the current cursor.
  66. # If -1, indicates to stop animating the cursor.
  67. #
  68. set cnt -1
  69.  
  70. #
  71. # Create two frames. The top frame will be the host window for the
  72. # busy window.  It'll contain widgets to test the effectiveness of
  73. # the busy window.  The bottom frame will contain buttons to 
  74. # control the testing.
  75. #
  76. frame .top
  77. frame .bottom
  78.  
  79. #
  80. # Create some widgets to test the busy window and its cursor
  81. #
  82. button .b1 -command { 
  83.     puts stdout "Not busy." 
  84. }
  85. button .b2 -command { 
  86.     destroy .
  87. }
  88. entry .e1 
  89. scale .s1
  90.  
  91. #
  92. # The following buttons sit in the lower frame to control the demo
  93. #
  94. button .b3 -command {
  95.     global numWin
  96.     incr numWin
  97.     set name button#${numWin}
  98.     button .top.$name -text "$name" \
  99.     -command [list puts stdout "I am $name"]
  100.     pack append .top .top.$name { expand padx 10 pady 10 }
  101. }
  102. button .b4 -command {
  103.     blt_busy .top -in .
  104.     focus none
  105.     global cnt activeBg
  106.     if { $cnt < 0 } {
  107.     .top configure -bg $activeBg
  108.     set cnt 0
  109.     Animate .top
  110.     }
  111. }
  112. button .b5 -command {
  113.     catch {blt_busy release .top} mesg
  114.     global cnt normalBg
  115.     set cnt -1
  116.     .top configure -bg $normalBg
  117. }
  118.  
  119. #
  120. # Notice that the widgets packed in .top and .bottom are not their children
  121. #
  122. pack append .top \
  123.     .b1 { expand padx 10 pady 10 } \
  124.     .e1 { expand padx 10 pady 10 } \
  125.     .s1 { expand padx 10 pady 10 } \
  126.     .b2 { expand padx 10 pady 10 }    
  127.  
  128. pack append .bottom \
  129.     .b3 { expand padx 10 pady 10 } \
  130.     .b4 { expand padx 10 pady 10 } \
  131.     .b5 { expand padx 10 pady 10 }
  132.  
  133. #
  134. # Finally, realize and map the top level window
  135. #
  136. pack append . .top { top expand } .bottom { fill expand }
  137.  
  138. #
  139. # Simple cursor animation routine: Uses the "after" command to 
  140. # circulate through a list of cursors every 0.075 seconds. The
  141. # first pass through the cursor list may appear sluggish because 
  142. # the bitmaps have to be read from the disk.  Tk's cursor cache
  143. # takes care of it afterwards.
  144. #
  145. proc Animate w {
  146.     global cnt 
  147.     if { $cnt >= 0 } {
  148.     global bitmaps bitmapFg bitmapBg
  149.     set name [lindex $bitmaps $cnt]
  150.     set src  @bitmaps/${name}
  151.     set mask bitmaps/${name}m
  152.     blt_busy configure $w -cursor [list $src $mask $bitmapFg $bitmapBg]
  153.     incr cnt
  154.     if { $cnt > 4 } {
  155.         set cnt 0
  156.     }
  157.     after 75 Animate $w
  158.     } else {
  159.     blt_busy configure $w -cursor watch
  160.     }
  161. }
  162.  
  163. #
  164. # For testing purposes allow the top level window to be resized 
  165. #
  166. wm min . 0 0
  167.  
  168. #
  169. # If the "raise" window command exists, force the demo to stay raised
  170. #
  171. if { [info commands "raise"] == "raise" } {
  172.     bind . <Visibility> {
  173.     raise %W
  174.     }
  175. }
  176.