home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dream 46
/
Amiga_Dream_46.iso
/
Linux
/
Magazine
/
Tcltk
/
tkcalc7.tcl
< prev
next >
Wrap
Text File
|
1997-11-13
|
4KB
|
161 lines
######################################
# tkcalc7.tcl #
######################################
# Tkcalculator v0.7 #
######################################
#################################
# Creer l'interface utilisateur #
#################################
# creation d'une ligne de boutons
proc MakeRow { list } {
global NbListRow
incr NbListRow
frame .framerow${NbListRow}
pack .framerow${NbListRow} -side top -fill x -expand true
for { set i 0 } { $i < [llength $list] } { incr i } {
button .btn${i}row${NbListRow} -command "ButtonCommand $i $NbListRow" -text [ lindex $list $i] -width 3 -height 1
pack .btn${i}row${NbListRow} -side left -in .framerow${NbListRow}
}
}
# cette procedure est appelΘe lorsque l'on clique sur un bouton
# elle affiche le numero du bouton dans la ligne (0 = premier bouton)
# et le numero de ligne (entre 1 et le nombre de lignes)
proc ButtonCommand { i row } {
global ListRow1 ListRow2 ListRow3 ListRow4 ListRow5 ListRow6
.viewtxt mark set insert end
.viewtxt see end
switch $row {
1 {
if { $i==4} ResetCommand
}
2 {
if { $i>=3 } {
.viewtxt insert insert [lindex $ListRow2 $i]
}
}
3 {
.viewtxt insert insert [lindex $ListRow3 $i]
}
4 {
.viewtxt insert insert [lindex $ListRow4 $i]
}
5 {
.viewtxt insert insert [lindex $ListRow5 $i]
}
6 {
if { $i == 0 || $i == 2 || $i == 3 } {
.viewtxt insert insert [lindex $ListRow6 $i]
} elseif { $i == 1 } {
NegateCommand
} elseif { $i == 4 } {
ExecCommand
}
}
}
.viewtxt tag add calcul "insert linestart" "insert lineend"
}
# zone d'affichage de texte
text .viewtxt -height 8 -width 32
.viewtxt tag configure calcul -font -adobe-courier-*-o-normal-*-12-*-*-*-*-*-*-* -justify left
.viewtxt tag configure result -font -adobe-helvetica-bold-r-normal-*-12-*-*-*-*-*-*-* -justify right
pack .viewtxt -side top
# configuration des boutons
set ListRow1 { "Menu" "Lib" "Graph" "Help" "Reset" }
set ListRow2 { "Mem" "Rcl" "Mem+" "(" ")" }
set ListRow3 { 7 8 9 \/ "E" }
set ListRow4 { 4 5 6 \* "Last" }
set ListRow5 { 1 2 3 \- "Ans" }
set ListRow6 { 0 "+/-" "." "+" "Exe" }
# pour l'instant, aucune ligne initialisΘe
set NbListRow 0
# crΘer les lignes de boutons
MakeRow $ListRow1
MakeRow $ListRow2
MakeRow $ListRow3
MakeRow $ListRow4
MakeRow $ListRow5
MakeRow $ListRow6
# boutons de commande : about et quit
frame .comframe
button .comframe.aboutbtn -text "About ..." -command AboutCommand
button .comframe.quitbtn -text "Quit" -command exit
pack .comframe -side top
pack .comframe.aboutbtn -side left
pack .comframe.quitbtn -side left
# gestion des Θvenements (bindings)
bind .viewtxt <Button-1> {
.viewtxt mark set insert end
.viewtxt see end
}
set ReservedKeys { "Backspace" "Delete" "Left" "Right" }
bind .viewtxt <KeyRelease> {
if { "%K" == "Return" } {
ExecCommandKey
return
}
if { "%K" == "Escape" } {
ResetCommand
}
if { [lsearch -exact $ReservedKeys "%K"]!=-1 } return
.viewtxt mark set insert end
.viewtxt see end
.viewtxt tag add calcul "insert linestart" "insert lineend"
}
# interpreter dialogs.tcl au niveau global
uplevel 0 [list source dialogs.tcl]
uplevel 0 [list source calc.tcl]