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 / bgexec < prev    next >
Encoding:
Text File  |  1995-07-01  |  6.7 KB  |  191 lines

  1. #!../blt_wish -f
  2. if [file exists ../library] {
  3.     set blt_library ../library
  4. }
  5.  
  6. blt_bitmap define blt.0 {{40 40} {
  7.     00 00 00 00 00 00 fc 07 00 00 00 04 08 00 00 00 04 04 00 00 00 e4 03 00
  8.     00 00 64 fe 07 00 00 64 02 04 00 00 e4 03 04 00 00 64 7e 02 00 00 64 1a
  9.     02 00 00 e4 1b 01 00 00 04 1a 01 00 00 04 1a 01 00 00 fc 1b 02 00 00 0c
  10.     1a 02 00 00 0c 02 04 00 00 0c 02 f4 03 80 ed fe 07 04 e0 0c 00 20 09 10
  11.     0c 00 00 12 10 0c 00 00 10 30 00 00 00 19 d0 03 00 00 14 b0 fe ff ff 1b
  12.     50 55 55 55 0d e8 aa aa aa 16 e4 ff ff ff 2f f4 ff ff ff 27 d8 ae aa bd
  13.     2d 6c 5f d5 67 1b bc f3 7f d0 36 f8 01 10 cc 1f e0 45 8e 92 0f b0 32 41
  14.     43 0b d0 cf 3c 7c 0d b0 aa c2 ab 0a 60 55 55 55 05 c0 ff ab aa 03 00 00
  15.     fe ff 00 00 00 00 00 00}
  16. }
  17.  
  18. blt_bitmap define blt.1 {{40 40} {
  19.     00 00 00 00 00 00 fc 07 00 00 00 04 08 00 00 00 04 04 00 00 00 e4 ff 0f
  20.     00 00 64 06 08 00 00 64 06 08 00 00 e4 ff 04 00 00 64 36 04 00 00 64 36
  21.     02 00 00 e4 37 02 00 00 04 34 02 00 00 04 34 04 00 00 fc 35 04 00 00 0c
  22.     04 08 00 00 0c 04 08 00 00 0c fc ef 03 80 ed 01 00 04 e0 0c 00 20 09 10
  23.     0c 00 00 12 10 0c 00 00 10 30 00 00 00 19 d0 03 00 00 14 b0 fe ff ff 1b
  24.     50 55 55 55 0d e8 aa aa aa 16 e4 ff ff ff 2f f4 ff ff ff 27 d8 ae aa bd
  25.     2d 6c 5f d5 67 1b bc f3 7f d0 36 f8 01 10 cc 1f e0 45 8e 92 0f b0 32 41
  26.     43 0b d0 cf 3c 7c 0d b0 aa c2 ab 0a 60 55 55 55 05 c0 ff ab aa 03 00 00
  27.     fe ff 00 00 00 00 00 00}
  28. }
  29.  
  30. blt_bitmap define blt.2 {{40 40} {
  31.     00 00 00 00 00 00 fc 0f 00 00 00 04 10 00 00 00 04 10 00 00 00 e4 fb 3f
  32.     00 00 64 0e 20 00 00 64 0e 20 00 00 e4 fb 13 00 00 64 ce 10 00 00 64 ce
  33.     08 00 00 e4 cb 08 00 00 04 c8 08 00 00 04 c8 10 00 00 fc cf 10 00 00 0c
  34.     08 20 00 00 0c 08 20 00 00 0c f8 bf 03 80 ed 03 00 04 e0 0c 00 20 09 10
  35.     0c 00 00 12 10 0c 00 00 10 30 00 00 00 19 d0 03 00 00 14 b0 fe ff ff 1b
  36.     50 55 55 55 0d e8 aa aa aa 16 e4 ff ff ff 2f f4 ff ff ff 27 d8 ae aa bd
  37.     2d 6c 5f d5 67 1b bc f3 7f d0 36 f8 01 10 cc 1f e0 45 8e 92 0f b0 32 41
  38.     43 0b d0 cf 3c 7c 0d b0 aa c2 ab 0a 60 55 55 55 05 c0 ff ab aa 03 00 00
  39.     fe ff 00 00 00 00 00 00}
  40. }
  41.  
  42. blt_bitmap define blt.3 {{40 40} {
  43.     00 00 00 00 00 00 fc 0f 00 00 00 04 f0 ff 00 00 04 00 80 00 00 e4 03 80
  44.     00 00 64 d6 4f 00 00 64 16 43 00 00 e4 13 23 00 00 64 16 23 00 00 64 16
  45.     23 00 00 e4 13 43 00 00 04 70 43 00 00 04 00 80 00 00 fc 0f 80 00 00 0c
  46.     f0 ff 00 00 0c 00 00 00 00 0c f8 ff 03 80 ed 07 00 04 e0 0c 00 20 09 10
  47.     0c 00 00 12 10 0c 00 00 10 30 00 00 00 19 d0 03 00 00 14 b0 fe ff ff 1b
  48.     50 55 55 55 0d e8 aa aa aa 16 e4 ff ff ff 2f f4 ff ff ff 27 d8 ae aa bd
  49.     2d 6c 5f d5 67 1b bc f3 7f d0 36 f8 01 10 cc 1f e0 45 8e 92 0f b0 32 41
  50.     43 0b d0 cf 3c 7c 0d b0 aa c2 ab 0a 60 55 55 55 05 c0 ff ab aa 03 00 00
  51.     fe ff 00 00 00 00 00 00}
  52. }
  53.  
  54. blt_bitmap define blt.4 {{40 40} {
  55.     00 00 00 00 00 00 fc ff ff 03 00 04 00 00 02 00 04 00 00 02 00 e4 33 3f
  56.     01 00 64 36 0c 01 00 64 36 8c 00 00 e4 33 8c 00 00 64 36 8c 00 00 64 36
  57.     0c 01 00 e4 f3 0d 01 00 04 00 00 02 00 04 00 00 02 00 fc ff ff 03 00 0c
  58.     00 00 00 00 0c 00 00 00 00 0c f8 ff 03 80 ed 07 00 04 e0 0c 00 20 09 10
  59.     0c 00 00 12 10 0c 00 00 10 30 00 00 00 19 d0 03 00 00 14 b0 fe ff ff 1b
  60.     50 55 55 55 0d e8 aa aa aa 16 e4 ff ff ff 2f f4 ff ff ff 27 d8 ae aa bd
  61.     2d 6c 5f d5 67 1b bc f3 7f d0 36 f8 01 10 cc 1f e0 45 8e 92 0f b0 32 41
  62.     43 0b d0 cf 3c 7c 0d b0 aa c2 ab 0a 60 55 55 55 05 c0 ff ab aa 03 00 00
  63.     fe ff 00 00 00 00 00 00}
  64. }
  65.  
  66.  
  67. set command { vmstat 1 }
  68. #set command { find ../.. -print  }
  69.  
  70. set animate(index) 0
  71. set animate(interval) 200
  72. #set animate(colors) { #ff8813 #ffaa13 #ffcc13 #ffff13 #ffcc13 #ffaa13 #ff8813 }
  73. blt_bitmap define blt.5 [blt_bitmap data blt.3]
  74. blt_bitmap define blt.6 [blt_bitmap data blt.2]
  75. blt_bitmap define blt.7 [blt_bitmap data blt.1]
  76.  
  77. proc Animate {} {
  78.     global animate
  79.     if { [info commands .logo] != ".logo" } {
  80.     set animate(index) 0
  81.     return
  82.     }
  83.     if { $animate(index) >= 0 } {
  84.     .logo configure -bitmap blt.$animate(index) 
  85.     incr animate(index)
  86.     if { $animate(index) >= 7 } {
  87.         set animate(index) 0
  88.     }
  89.     after $animate(interval) Animate
  90.     }
  91. }
  92.  
  93. proc GetStats { command varArr } {
  94.     global $varArr 
  95.  
  96.     set new [format "%s(update)" $varArr]
  97.     set err [format "%s(errors)" $varArr]
  98.     set out [format "%s(output)" $varArr]
  99.  
  100.     trace variable $new w DisplayStats
  101.     eval "blt_bgexec \
  102.     -keepnewline \
  103.     -errorvar $err \
  104.     -updatevar $new \
  105.     $out $command"
  106. }
  107.  
  108. proc DisplayStats { name1 name2 how } {
  109.     upvar #0 $name1 arr
  110.  
  111.     .text insert end $arr($name2)
  112.     set arr($name2) {}
  113.     set textlen [expr int([.text index end])]
  114.     scan [.vscroll get] "%s %s %s %s" total window first last
  115.     if { $textlen > $total } {
  116.     .text yview [expr $textlen-$window]
  117.     }
  118.     update idletasks
  119. }
  120.  
  121. # Do a quick test of the command to see how long the output is going to be
  122. #
  123. catch "exec [lindex $command 0]" output
  124. set output [split $output \n]
  125. set length [string length [lindex $output 0]]
  126. if { $length > 80 } {
  127.    set length 110
  128. } else {
  129.    set length 80
  130. }
  131.  
  132. option add *text.yScrollCommand { .vscroll set }
  133. option add *text.relief sunken
  134. option add *text.width $length
  135. option add *text.height 10
  136. option add *text.borderWidth 2
  137. option add *vscroll.command { .text yview }
  138. option add *vscroll.minSlider 4p
  139. option add *quit.command { exit }
  140. option add *quit.text { quit }
  141. option add *stop.command { global results; set results(output) {} }
  142. option add *stop.text { stop }
  143. option add *logo.relief sunken
  144. option add *logo.padX 4
  145. option add *title.text "Virtual Memory Statistics"
  146. option add *title.font -*-Helvetica-Bold-R-*-*-14-*-*-*-*-*-*-*
  147.  
  148. set visual [winfo screenvisual .] 
  149. if { $visual != "staticgray" && $visual != "grayscale" } {
  150.     option add *text.background lightblue
  151.     option add *text.foreground blue
  152.     option add *quit.background red
  153.     option add *quit.foreground white
  154.     option add *stop.background yellow
  155.     option add *stop.foreground navyblue
  156.     option add *logo.background beige
  157.     option add *logo.foreground brown 
  158. }
  159.  
  160. # Create widgets
  161. text .text 
  162. scrollbar .vscroll 
  163. button .quit
  164. button .stop
  165. label .logo 
  166. label .title
  167.  
  168. # Layout widgets in table
  169. blt_table . \
  170.     .title      0,0 -columnspan 4 -fill both \
  171.     .text     1,0 -columnspan 3 -fill both \
  172.     .vscroll     1,3 -fill y \
  173.     .logo     2,0 -anchor w -padx 10 -reqheight .6i -pady 4 \
  174.     .stop     2,1 -anchor e -reqwidth .75i -reqheight .3i \
  175.     .quit      2,2 -anchor e -reqwidth .75i -reqheight .3i
  176. blt_table column . configure { 1 2 } -width 1i
  177. blt_table column . configure { 3 } -resize none
  178. wm min . 0 0
  179.  
  180. # Start command using "results(output)" as the trigger variable
  181. set results(output) {}
  182. GetStats $command results 
  183. Animate
  184. tkwait variable results(output)
  185.  
  186. # Turn off animation
  187. puts stderr "Turning off vmstat (stderr=\"$results(errors)\")"
  188. set animate(index) -1
  189.  
  190.