Previoustest.tclNext
1 #!/bin/sh 2 # vim:set syntax=tcl:\ 3 # vim:set nowrap:\ 4 wish=`( for name in $(/bin/ls $(echo $PATH | sed 's/:/ /g') 2> /dev/null | egrep '^wish(step)?([0-9]+\.[0-9]+)([a-z][a-z])?$') ; do echo $name ; done ) | tail -1` ;\ 5 [ -z "$wish" ] && wish=wish ;\ 6 echo "Using $wish" ;\ 7 exec $wish "$0" ${1+"$@"}
Show options.

  14 proc shops {} {

  16    global dir
  17    global version
  18    global tcl_platform

  20    set mess "Available options:\n"
  21    set fd [ open "| $dir/listopts.tcl" r ]
  22    while { ![eof $fd] } {
  23       gets $fd line
  24       if { [regexp {^-.*$} $line] } { set mess "$mess\n$line" }
  25    }
  26    close $fd

  28    tk_messageBox -parent . \
  29                  -title "$tcl_platform(os) $tcl_platform(osVersion)" \
  30                  -message $mess
  31 }
Create vertical meter.

  37 proc vertical {} {

  39    meter .v -mem yes \
  40             -cpu yes \
  41             -padx 5 \
  42             -pady 0 \
  43             -disk yes \
  44             -width 80 \
  45             -relief flat \
  46             -bd 2 \
  47             -command { exec xterm -e top & }

  49    bind .v <Button-3> shops

  51    return .v
  52 }
Create horizontal meter.

  58 proc horizontal {} {

  60    global tcl_platform

  62    if { $tcl_platform(os) == "Linux" } {
  63       set iface eth0
  64    } else {
  65       set iface lo0
  66    }

  68    meter .h -button yes \
  69             -cpu yes \
  70             -mem yes \
  71             -disk fd0 \
  72             -if $iface \
  73             -color1 green \
  74             -color2 salmon \
  75             -relief groove \
  76             -orient horizontal \
  77             -padx 8 \
  78             -pady 8 \
  79             -bd 2 \
  80             -fg blue \
  81             -width 70 \
  82             -legend {cpu mem floppy network} \
  83             -command { exec xterm -e top & }

  85    bind .h <Button-3> shops

  87    return .h
  88 }
Do it.

  94 set dir [ file dirname [info script] ]
  95 set version [ exec grep VER= $dir/Makefile | cut -b5- ]
  96 source $dir/meter.tcl

  98 option add *highlightThickness 0
  99 . configure -relief raised -bd 1
 100 wm resizable . 0 0
 101 wm title . "meter $version"

 103 frame .f
 104 label .f.l -text "<- click to\nlaunch top" -justify right
 105 button .f.b -text Opts -command shops
 106 pack .f.l .f.b -side top -pady 5
 107 pack [vertical] [horizontal] .f -padx 5 -pady 5 -side left