#!/afs/ece/usr/tcl/bin/wish -f
# The next line is executed by most shells, but not Tcl \
wish $0 $*

#
# TH calling program
#

# TH programs & descriptions
set TH_App(busyth) {Indicate when an application is busy}
set TH_App(configureth) {Change color, fonts, other display options of remote widgets}
set TH_App(dialogth) {Teach keyboard traversal to Tk's dialog routine}
set TH_App(displayth) {Repack, reorder, move, copy, and delete widgets}
set TH_App(historyth) {Teach remote entries to remember their previous contents}
set TH_App(poputh) {Teach remote widgets to use remote menus as popups}

set Number_Of_Frames 3

foreach pair {{th_history_sanity_check lib/history.tcl}
		{get_widget aux/teach.tcl}} {
  if {[info procs [lindex $pair 0]] == ""} {
    source "[file dirname [info script]]/../[lindex $pair 1]"
}}

set Help "" ; append Help {Teacher Hypertools 

This is a simple wish script designed to itemize the Teacher Hypertools
available. From this window, you can execute any hypertool available. Here are
the widgets shown:


XF Location Label and Entry

This contains the location for the source code to XF. TH attempts to read your
XF_DIR environment variable for this value, otherwise it uses a value supplied
in lib/th.tcl. Some programs, like configureth, use XF's template procedures to
allow the user more power in selecting colors, fonts, etc.

Note that this entry, as well as the others have the historyth extension (the
menu and button to their left), so you can save old values in the entry and
retrieve them later. See the historyth help page for more info.


Elsbeth Library

This contains the location for the Tk library, but if you would like to use
Elsbeth's bindings for your hyupertools, you can change this to the location of
the Elsbeth library.


Arguments Menu, Button, and Entry

This contains the arguments sent to whatever hypertool you call. Any hypertool
can be called with no arguments, and a hypertool will ignore any arguments it
doesn't understand. 


Hypertools Buttons

Each button runs a different hypertool. When you pass the mouse over each
button a short description of the button's hypertool appears in the text
widget.

} $TH_Help


set env(XF_DIR) $XF_Dir
catch {destroy .buttons.source}
catch {destroy .buttons.teach}

create_form_entry .xf "Location of XF" env(XF_DIR)
if {[catch "set env(TK_LIBRARY)"]} {set env(TK_LIBRARY) $tk_library}
create_form_entry .tkl "Elsbeth Library" env(TK_LIBRARY)
foreach widget {.xf.e  .tkl.e} {
  lappend TH(Completions,$widget) {th_line_complete th_filter_glob none}
}
create_form_entry .args "Arguments" app_args ""

.output configure -state normal -wrap word -xscrollcommand {} -yscrollcommand {}
destroy .o.sx ; destroy .o.sy

for {set f 0} {$f < $Number_Of_Frames} {incr f} {
  frame .button$f
  pack .button$f -side left -fill both -expand yes
}

set i 0
set apps [lsort [array names TH_App]]
set l [llength $apps]
foreach app $apps {
  set w .button[expr ($i * $Number_Of_Frames) / $l ].$app
  incr i
  button $w -text "$app" -command "eval exec wish $TH_Dir/bin/$app \$app_args &"
  pack $w -side top -fill x
  bind $w <Any-Enter> "[bind Button <Any-Enter>] ; .output insert 1.0 [list $TH_App($app)]"
  bind $w <Any-Leave> "[bind Button <Any-Leave>] ; .output delete 1.0 end"
}
