#!demo2 -f

#######################################################################
#       Demo program on Tcl/Tk and C
# 		Written by Eunmi Choi
#######################################################################

set auto_path "$tk_library/demos /opt/tk/lib/tk $auto_path"
wm title . "Animation Demonstration"

frame .sfirst
frame .ssecond

pack .sfirst .ssecond -side top -padx 3m -pady 3m

message .headmsg -width 600 -borderwidth 3 \
	-font -Adobe-Helvetica-Medium-R-Normal--*-180-* \
	-text "Animation Demo" -bg lightblue 
pack .headmsg -in .sfirst

button .bstart -text "START" -command {MyFileList}
button .bcalc -text "TEST" -command {MyCalc}
button .bhelp -text "HELP" -command {
        tk_dialog .ddd {About the Demo} {This is a demo program on Tcl/Tk and C, which is made by Eunmi Choi. If you have any question about this, please send me an e-mail at choie@cps.msu.edu} {} -1 OK
    }
button .bexit -text "EXIT" -command {exit}

pack .bstart .bcalc .bhelp .bexit -in .ssecond -side left \
	-padx 1m -pady 1m -ipadx 2m -ipady 2m 

. config -bg lightblue


#######################################################################
# MyCalc w

proc MyCalc {{w .calc}} {

catch {destroy $w}
toplevel $w
wm geometry $w +400+400
wm title $w "Simple Calculator"

frame $w.mbar -relief raised -bd 2
frame $w.first
frame $w.second
frame $w.third

pack $w.mbar -side top -fill x
 
menubutton $w.mbar.help -text Help -underline 0 \
        -menu $w.mbar.help.menu
pack $w.mbar.help -side right
menu $w.mbar.help.menu
$w.mbar.help.menu add command -label "Help"
$w.mbar.help.menu add separator
$w.mbar.help.menu add command -label "About" -command {
        tk_dialog .ddd {About the demo} {This is a demo program on Tcl/Tk and C, which is made by Eunmi Choi. If you have any question about this, please send me an e-mail at choie@cps.msu.edu} {} -1 OK
    }
$w.mbar.help.menu add separator
$w.mbar.help.menu add command -label "Quit" -command "destroy $w" -underline 0
 
tk_menuBar $w.mbar $w.mbar.help
focus $w.mbar

pack $w.first $w.second $w.third -side top -padx 3m -pady 3m 

entry $w.entryl -width 10 -relief sunken -textvariable boxl
entry $w.entryr -width 10 -relief sunken -textvariable boxr
entry $w.entryc -width 20 -relief sunken -textvariable boxc
button $w.bp -text "+" -command {set boxc [expr $boxl + $boxr]}
button $w.bm -text "-" -command {set boxc [expr $boxl - $boxr]} 
button $w.bml -text "*" -command {set boxc [expr $boxl * $boxr]} 
button $w.bcon -text "Concatenate" -command {set boxc [concat $boxl$boxr]} 
button $w.beq -text "Equal" -command {set boxc [eq $boxl $boxr]} 
button $w.bbt -text "Beat" -command {set boxc [beat $boxl]} 
button $w.be -text "Exit" -command "
        tk_dialog .dexit {Goodbye} {Have a nice day, my pal !} \
 {} -1 OK; 
	destroy $w "
 
pack $w.entryl $w.entryr -in $w.first -side left  \
        -padx 1m -pady 1m -ipadx 2m -ipady 2m
pack $w.entryc -in $w.second \
        -padx 1m -pady 1m -ipadx 2m -ipady 2m
pack $w.bp $w.bm $w.bml $w.bcon $w.beq $w.bbt $w.be -in $w.third -side left \
        -padx 1m -pady 1m -ipadx 2m -ipady 2m
 
$w config -bg blue

}  

#######################################################################


proc MyFileList {} {

# timer
# from /opt/tk/lib/tk/demos

frame .fourth

label .counter -text 0.00 -relief raised -width 10
button .start -text Start -command {
    if $stopped {
        set stopped 0
        tick
    }
}
button .stop -text Stop -command {set stopped 1}
label .entcnt -text 0 -relief sunken -width 10
pack .start .stop .counter .entcnt -in .fourth -side left \
	-padx 1m -pady 1m -ipadx 2m -ipady 2m
 
set seconds 0
set hundredths 0
set stopped 1
set numents 0
}


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


