dialog
TCL/TK UseCase2
Abstract : Contains the dialog boxes used through out the program.
Comments : Pay close attention to the way in which the save and
open works. Most of the code is reused for both
functions and for the different type of saves.
proc yesno { words x y } {
global flagno
toplevel .asking
wm transient .asking .
set temp [winfo x .]
set temp2 [winfo y .]
set x2 [expr $x + $temp]
set y2 [expr $y + $temp2]
wm geometry .asking 200x125+$x2+$y2
message .asking.t -relief raised -background gray \
-width 150 -text $words
button .asking.b1 -text "No!" -background red -command \
{set flagno 0 ; destroy .asking}
button .asking.b2 -text "Sure do." -background red -command \
{set flagno 1 ; destroy .asking}
pack .asking.t
pack .asking.b2 .asking.b1 -fill y -padx 1m -pady 1m
update idletask
grab .asking
tkwait window .asking
}
proc nextcord {words} {
global passx
global passy
toplevel .asking
wm transient .asking .
message .asking.t -relief raised -background gray \
-width 150 -text $words
pack .asking.t -fill x
bind .area {set passx %x ; set passy %y ; destroy .asking}
update idletask
grab set .
tkwait window .asking
bind .area {whattodo %x %y}
}
proc ask {words} {
toplevel .asking
wm transient .asking .
wm group .asking .
# wm geometry .asking 100x100+$x+$y
message .asking.t -relief raised -background gray \
-width 150 -text $words
button .asking.b -text "Okay" -background red\
-command "destroy .asking"
pack .asking.t .asking.b -fill x
update idletask
grab .asking
tkwait window .asking
}
proc asklabel {words x y} {
global askingName
set askingName ""
toplevel .asking
wm transient .asking .
set temp [winfo x .]
set temp2 [winfo y .]
set x2 [expr $x + $temp]
set y2 [expr $y + $temp2]
wm geometry .asking 150x75+$x2+$y2
message .asking.t -relief raised -background gray \
-width 150 -text $words
entry .asking.name -background green -textvariable askingName
button .asking.b -text "Enter" -background red \
-command "destroy .asking"
button .asking.b2 -text "Cancel" -background red \
-command {set askingName "" ; destroy .asking}
pack .asking.t .asking.name -fill x
pack .asking.b .asking.b2 -side right -padx 1m -pady 1m
bind .asking.name {destroy .asking}
update idletask
grab .asking
tkwait window .asking
return $askingName
}
#Chi-Chen's and Mike's opening & saving
proc openentry {entry} {
global boxflag iGraph changes
if [file exists $entry] {
if [file isdirectory $entry] {
cd $entry
destroy .fs.files
listbox .fs.files -relief raised -borderwidth 4 \
-yscrollcommand ".fs.scroll set"
pack .fs.files -side left
bind .fs.files {openentry [selection get]}
list-out
global entered
set entered {}
} elseif [file exists $entry] {
if [file isfile $entry] {
#this is where the open & save shit happens
if {$boxflag == "open"} {
puts "Sending: openfile $entry\n"
set n [$iGraph cppOpenCD: $entry]
destroy .fs
}
} } } elseif {[file exists $entry] != 1} {
if {$boxflag == "savefile"} {
puts "Sending: savefile $entry"
set changes no
# set retVal [$iGraph cppSaveCD: $entry]
destroy .fs
} elseif {$boxflag == "savecd"} {
puts "Sending: GenCD $entry"
# set retVal [$iGraph cppGenCD: $entry]
destroy .fs
} else {
# puts "Sorry, that file doesn't exist."
} }
}
proc file-entry {type} {
frame .fs.file
label .fs.file.label -text $type
entry .fs.file.entry -width 20 -relief sunken -bd 2 -textvariable entered
pack .fs.file.label .fs.file.entry -side left -padx 1m -pady 2m
bind .fs.file.entry {openentry $entered}
pack .fs.file -side top
}
proc list-out {} {
.fs.files insert end .
.fs.files insert end ..
foreach i [lsort [glob *]] {
.fs.files insert end $i
}
}
proc list-box {} {
listbox .fs.files -relief raised -borderwidth 4 \
-yscrollcommand ".fs.scroll set"
pack .fs.files -side left
scrollbar .fs.scroll -command ".fs.files yview"
pack .fs.scroll -side right -fill y
list-out
bind .fs.files {openentry [selection get]}
}
proc openfile {} {
global boxflag
set boxflag open
toplevel .fs
wm title .fs "Select File:"
file-entry "Open File:"
list-box
}
proc savefile {} {
global boxflag
set boxflag savefile
toplevel .fs
wm title .fs "Save File:"
file-entry "Save File:"
list-box
}
proc savecd {} {
global boxflag
set boxflag savecd
toplevel .fs
wm title .fs "Save CD:"
file-entry "Save CD:"
list-box
}
# Print dialogue:
proc printwindow {} {
toplevel .pw
wm title .pw "Print:"
frame .pw.frame1
frame .pw.frame2
# Pack the 2 frames:
pack .pw.frame1 -side top -fill x
pack .pw.frame2 -side bottom -fill x
label .pw.frame1.label -text {Enter Printer:}
# Text entry widget
entry .pw.frame1.entry -width 20 -relief sunken -textvariable printer
frame .pw.frame2.p -borderwidth 2 -relief sunken
# Print button runs print procedure
button .pw.frame2.p.print -text "Print" -padx 5 -pady 5 \
-command {print $printer}
# Cancel button destroys window
button .pw.frame2.cancel -text "Cancel" -padx 5 -pady 5 -command\
{destroy .pw}
# When you push , it prints
bind .pw.frame1.entry {print $printer}
# Pack labels and entries and buttons (oh, my!) in each frame:
pack .pw.frame1.label -side left
pack .pw.frame1.entry -side right
pack .pw.frame2.p .pw.frame2.p.print -side left
pack .pw.frame2.cancel -side right
}
proc print {printer} {
printcanvas $printer
# Destroy the printer window:
destroy .pw
}