main window
TCL/TK UseCase3
Abstract : Sets up the main drawing window and menus.
Comments : Also contains the printing procedure and some
misc. procedures.
#
#MAINWIN.TCL
#
#Sets up the main window and creates the menu and canvas. Includes code for
#some basic operations and menu options.
#
#
#Returns x-coordinate value
proc getXCoord { coord } {
return [lindex $coord 0]
}
#
#Returns y-coordinate value
proc getYCoord { coord } {
return [lindex $coord 1]
}
#
#Clears all verticies and edges from within Tcl.
proc clearDocument {} {
#Make global vars accessible
global Vertex Edge can
$can delete all
catch { unset Vertex Edge }
}
#
#Removes the existing C++ graph. (Also clears drawing.)
proc destroyDocument {} {
global iGraph filename
clearDocument
$iGraph cppClear:
set filename ""
}
#
#Warns user before any unsaved work is lost.
proc savecheck {} {
#Make global vars accessible
global changes flagno
#puts $changes
if {$changes != "no"} {
yesno "You are about to destroy your work without saving\
any changes. Do you wish to continue?" 20 20
if {$flagno == 1} {
set changes no
return 1
}
return 0
}
return 1
}
#
# Steve's print stuff...
#
# Printing canvas:
proc printcanvas {printer} {
global can
# Sets string variables.
set tmp_file /tmp/temp.ps
# Generates postscript file
Postscript $can $tmp_file
# Automatically print the file:
if [catch { exec print -P$printer -N $tmp_file } result] {
puts $result
}
# Remove the temporary file:
if [catch { exec rm -f $tmp_file } result] {
puts $result
}
}
#
# Generate postscript file:
proc Postscript { c file} {
$c postscript -file $file -pagewidth 8.i -pageheight 11.i
}
# End Steve's print stuff
#
#Creates menu bar
proc setup_menu {} {
global menucolor filename changes
#Adds file and help menu buttons to window
menubutton .mbar.file -text File \
-menu .mbar.file.menu -background $menucolor
menubutton .mbar.help -text Help \
-menu .mbar.help.menu -background $menucolor
#Creates empty menus
menu .mbar.file.menu
menu .mbar.help.menu
#.mbar.help.menu add command -label "Help Me..." -command {ask "Go Paul Go!"}
#Adds options to file menu
.mbar.file.menu add command -label "New" \
-command { if {[savecheck] == 1} {destroyDocument} }
.mbar.file.menu add command -label "Open" \
-command { if {[savecheck] == 1} { destroyDocument ; openfile } }
# Leaving close out for now.
#.mbar.file.menu add command -label "Close" \
# -command { clearDocument }
.mbar.file.menu add separator
.mbar.file.menu add command -label "Save" \
-command savefile
.mbar.file.menu add command -label "Save As" \
-command { savefileas }
.mbar.file.menu add command -label "Save Postscript" \
-command savepost
.mbar.file.menu add separator
.mbar.file.menu add command -label "Gen-CD" \
-command savecd
.mbar.file.menu add command -label "Print" \
-command printwindow
.mbar.file.menu add separator
.mbar.file.menu add command -label "Quit" \
-command { if {[savecheck] == 1} {destroyDocument ; exit } }
#############
# Paul's awesone on-line help stuff...
#############
#Adds options to help menu
.mbar.help.menu add command -label "About DemDraw" -command "about"
.mbar.help.menu add separator
.mbar.help.menu add command -label "Topics" -command "listTopics"
.mbar.help.menu add command -label "Search by keyword" -command "HelpMe"
.mbar.help.menu add separator
.mbar.help.menu add cascade -label "Web Help" -menu .mbar.help.menu.web
menu .mbar.help.menu.web
.mbar.help.menu.web add command -label "Demeter Home Page" -command "WebHelp"
.mbar.help.menu.web add command -label "Demeter FAQ" -command "WebHelp.faq"
# Our DemDraw home page.
.mbar.help.menu.web add command -label "DemDraw Page" \
-command "DemDrawPage"
#############
pack .mbar.file -side left
pack .mbar.help -side right
}
#
#Sets up main window
proc setup_mainwin {} {
#Makes global vars accessible
global can inform changes menucolor filename
set inform 0
set changes no
set menucolor white
set filename ""
#Create canvas
frame .mbar -relief raised -bd 2 -background $menucolor
canvas .area -background gray
set can .area
#Add title
wm title . "Our Funky CD Drawing Program"
#Set max window size
#wm minsize . 0 0
wm maxsize . 9999 9999
pack .mbar -side top -fill x
pack .area -fill both -expand true
setup_menu
}