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