#!/bin/sh
# the next line restarts using wish \
#exec wish8.0 "$0" "$@"

# timer --
# This script generates a counter with start and stop buttons.
#
# SCCS: @(#) timer 1.6 96/02/16 10:49:20
toplevel .foo
wm title .foo "Timer"

label .foo.counter -text 0.00 -relief raised -width 10
button .foo.start -text Start -command {tick } 
#    if $stopped { \
#	set stopped 0\
#	tick\
#    }\
#}
button .foo.stop -text Stop -command {set stopped 1}
pack .foo.counter -side bottom -fill both
pack .foo.start -side left -fill both -expand yes
pack .foo.stop -side right -fill both -expand yes

set seconds 0
set hundredths 0
set stopped 1

proc tick {} {
    global seconds hundredths stopped
    if $stopped return
    after 50 tick
    set hundredths [expr $hundredths+5]
    if {$hundredths >= 100} {
	set hundredths 0
	set seconds [expr $seconds+1]
    }
    .foo.counter config -text [format "%d.%02d" $seconds $hundredths]
}

bind .foo <Control-c> {destroy .}
bind .foo <Control-q> {destroy .}
focus .foo
