home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / TCL / BLT / BLT1.7L1 / BLT1 / blt-1.7 / applications / extloader / demos / blt / bgexec < prev    next >
Encoding:
Text File  |  1994-04-22  |  6.6 KB  |  192 lines

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