Tuesday, November 15, 2005

[Tcl] Agree or Not Agree

#! /usr/local/bin/wish -f
#
# run within /etc/X11R6/xdm/Xsession
# if user agrees with the agreement, he/she will gain access, 
# if not, it will automatically logout
#
# 10 seconds waiting time is needed otherwise the display manager will complain
#
 
set mesg "
Put in your agreement statement
here for your potential
users to read.
"
 
 
set fontB [font create -family Arial -size 32]
set fontS [font create -family Arial -size 16]
set fontT [font create -family Arial -size 10]
 
 
set timeout(delay) 10
set timeout(mesg) {Buttons will be activated in %d seconds}
set timeout(text) [format $timeout(mesg) $timeout(delay)]
 
 
proc callTimeout {} {
        global timeout
 
        if { $timeout(delay) == 0 } {
                .agree configure -state normal
                .notagree configure -state normal
        } else {
                after 1000
                incr timeout(delay) -1
                set timeout(text) [format $timeout(mesg) $timeout(delay)]
                update
                callTimeout
        }
}
 
 
proc Agree { answer } {
        exit [expr [string equal yes $answer] ? 0 : 1]
}
 
proc noop { } {
 
}
 
 
 
set mesg [label .l -text $mesg -font $fontB]
set to   [label .l2 -textvariable timeout(text) -font $fontT]
set agree [button .agree         -text {Agree}         -command [list Agree yes]         -font $fontS         -state disabled]
set notagree [button .notagree         -text {Not Agree}         -command [list Agree no]         -font $fontS         -state disabled]
grid $mesg -columnspan 2
grid $to -columnspan 2
grid configure $mesg -columnspan 2 -ipadx 20 -ipady 10
grid $agree $notagree
 
 
wm geometry . +1000+1000
wm resizable . 0 0
wm protocol . WM_DELETE_WINDOW noop
update
 
 
set sw [winfo screenwidth .]
set sh [winfo screenheight .]
set dw [winfo width .]
set dh [winfo height .]
set w [expr {($sw-$dw)/2}]
set h [expr {($sh-$dh)/2}]
wm geometry . "+$w+$h"
callTimeout