home *** CD-ROM | disk | FTP | other *** search
/ PC World 2002 May / PCWorld_2002-05_cd.bin / Software / TemaCD / activetcltk / ActiveTcl8.3.4.1-8.win32-ix86.exe / ActiveTcl8.3.4.1-win32-ix86 / demos / Tk / rolodex < prev    next >
Encoding:
Text File  |  2001-10-22  |  8.1 KB  |  204 lines

  1. #!/bin/sh
  2. # the next line restarts using wish \
  3. exec wish "$0" "$@"
  4.  
  5. # rolodex --
  6. # This script was written as an entry in Tom LaStrange's rolodex
  7. # benchmark.  It creates something that has some of the look and
  8. # feel of a rolodex program, although it's lifeless and doesn't
  9. # actually do the rolodex application.
  10. #
  11. # RCS: @(#) $Id: rolodex,v 1.2.18.1 2001/10/12 10:56:13 dkf Exp $
  12.  
  13. foreach i [winfo child .] {
  14.     catch {destroy $i}
  15. }
  16.  
  17. set version 1.1
  18.  
  19. #------------------------------------------
  20. # Phase 0: create the front end.
  21. #------------------------------------------
  22.  
  23. frame .frame -relief flat
  24. pack .frame -side top -fill y -anchor center
  25.  
  26. set names {{} Name: Address: {} {} {Home Phone:} {Work Phone:} Fax:}
  27. foreach i {1 2 3 4 5 6 7} {
  28.     frame .frame.$i
  29.     pack .frame.$i -side top -pady 2 -anchor e
  30.  
  31.     label .frame.$i.label -text [lindex $names $i] -anchor e
  32.     entry .frame.$i.entry -width 30 -relief sunken
  33.     pack .frame.$i.entry .frame.$i.label -side right
  34. }
  35.  
  36. frame .buttons
  37. pack .buttons -side bottom -pady 2 -anchor center
  38. button .buttons.clear -text Clear
  39. button .buttons.add -text Add
  40. button .buttons.search -text Search
  41. button .buttons.delete -text "Delete ..."
  42. pack .buttons.clear .buttons.add .buttons.search .buttons.delete \
  43.     -side left -padx 2
  44.  
  45. #------------------------------------------
  46. # Phase 1: Add menus, dialog boxes
  47. #------------------------------------------
  48.  
  49. frame .menu -relief raised -borderwidth 1
  50. pack .menu -before .frame -side top -fill x
  51.  
  52. menubutton .menu.file -text "File" -menu .menu.file.m -underline 0
  53. menu .menu.file.m
  54. .menu.file.m add command -label "Load ..." -command fileAction -underline 0
  55. .menu.file.m add command -label "Exit" -command {destroy .} -underline 0
  56. pack .menu.file -side left
  57.  
  58. menubutton .menu.help -text "Help" -menu .menu.help.m -underline 0
  59. menu .menu.help.m
  60. pack .menu.help -side right
  61.  
  62. proc deleteAction {} {
  63.     if {[tk_dialog .delete {Confirm Action} {Are you sure?} {} 0  Cancel]
  64.         == 0} {
  65.     clearAction
  66.     }
  67. }
  68. .buttons.delete config -command deleteAction
  69.  
  70. proc fileAction {} {
  71.     tk_dialog .fileSelection {File Selection} {This is a dummy file selection dialog box, which is used because there isn't a good file selection dialog built into Tk yet.} {} 0 OK
  72.     puts stderr {dummy file name}
  73. }
  74.  
  75. #------------------------------------------
  76. # Phase 3: Print contents of card
  77. #------------------------------------------
  78.  
  79. proc addAction {} {
  80.     global names
  81.     foreach i {1 2 3 4 5 6 7} {
  82.     puts stderr [format "%-12s %s" [lindex $names $i] [.frame.$i.entry get]]
  83.     }
  84. }
  85. .buttons.add config -command addAction
  86.  
  87. #------------------------------------------
  88. # Phase 4: Miscellaneous other actions
  89. #------------------------------------------
  90.  
  91. proc clearAction {} {
  92.     foreach i {1 2 3 4 5 6 7} {
  93.     .frame.$i.entry delete 0 end
  94.     }
  95. }
  96. .buttons.clear config -command clearAction
  97.  
  98. proc fillCard {} {
  99.     clearAction
  100.     .frame.1.entry insert 0 "John Ousterhout"
  101.     .frame.2.entry insert 0 "CS Division, Department of EECS"
  102.     .frame.3.entry insert 0 "University of California"
  103.     .frame.4.entry insert 0 "Berkeley, CA 94720"
  104.     .frame.5.entry insert 0 "private"
  105.     .frame.6.entry insert 0 "510-642-0865"
  106.     .frame.7.entry insert 0 "510-642-5775"
  107. }
  108. .buttons.search config -command "addAction; fillCard"
  109.  
  110. #----------------------------------------------------
  111. # Phase 5: Accelerators, mnemonics, command-line info
  112. #----------------------------------------------------
  113.  
  114. .buttons.clear config -text "Clear    Ctrl+C"
  115. bind . <Control-c> clearAction
  116. .buttons.add config -text "Add    Ctrl+A"
  117. bind . <Control-a> addAction
  118. .buttons.search config -text "Search    Ctrl+S"
  119. bind . <Control-s> "addAction; fillCard"
  120. .buttons.delete config -text "Delete...    Ctrl+D"
  121. bind . <Control-d> deleteAction
  122.  
  123. .menu.file.m entryconfig 1 -accel Ctrl+F
  124. bind . <Control-f> fileAction
  125. .menu.file.m entryconfig 2 -accel Ctrl+Q
  126. bind . <Control-q> {destroy .}
  127.  
  128. focus .frame.1.entry
  129.  
  130. #----------------------------------------------------
  131. # Phase 6: help
  132. #----------------------------------------------------
  133.  
  134. proc Help {topic {x 0} {y 0}} {
  135.     global helpTopics helpCmds
  136.     if {$topic == ""} return
  137.     while {[info exists helpCmds($topic)]} {
  138.     set topic [eval $helpCmds($topic)]
  139.     }
  140.     if [info exists helpTopics($topic)] {
  141.     set msg $helpTopics($topic)
  142.     } else {
  143.     set msg "Sorry, but no help is available for this topic"
  144.     }
  145.     tk_dialog .help {Rolodex Help} "Information on $topic:\n\n$msg" \
  146.         {} 0 OK
  147. }
  148.  
  149. proc getMenuTopic {w x y} {
  150.     return $w.[$w index @[expr {$y-[winfo rooty $w]}]]
  151. }
  152.  
  153. event add <<Help>> <F1> <Help>
  154. bind .    <<Help>> {Help [winfo containing %X %Y] %X %Y}
  155. bind Menu <<Help>> {Help [winfo containing %X %Y] %X %Y}
  156.  
  157. # Help text and commands follow:
  158.  
  159. set helpTopics(.menu.file) {This is the "file" menu.  It can be used to invoke some overall operations on the rolodex applications, such as loading a file or exiting.}
  160.  
  161. set helpCmds(.menu.file.m) {getMenuTopic $topic $x $y}
  162. set helpTopics(.menu.file.m.1) {The "Load" entry in the "File" menu posts a dialog box that you can use to select a rolodex file}
  163. set helpTopics(.menu.file.m.2) {The "Exit" entry in the "File" menu causes the rolodex application to terminate}
  164. set helpCmds(.menu.file.m.none) {set topic ".menu.file"}
  165.  
  166. set helpTopics(.frame.1.entry) {In this field of the rolodex entry you should type the person's name}
  167. set helpTopics(.frame.2.entry) {In this field of the rolodex entry you should type the first line of the person's address}
  168. set helpTopics(.frame.3.entry) {In this field of the rolodex entry you should type the second line of the person's address}
  169. set helpTopics(.frame.4.entry) {In this field of the rolodex entry you should type the third line of the person's address}
  170. set helpTopics(.frame.5.entry) {In this field of the rolodex entry you should type the person's home phone number, or "private" if the person doesn't want his or her number publicized}
  171. set helpTopics(.frame.6.entry) {In this field of the rolodex entry you should type the person's work phone number}
  172. set helpTopics(.frame.7.entry) {In this field of the rolodex entry you should type the phone number for the person's FAX machine}
  173.  
  174. set helpCmds(.frame.1.label) {set topic .frame.1.entry}
  175. set helpCmds(.frame.2.label) {set topic .frame.2.entry}
  176. set helpCmds(.frame.3.label) {set topic .frame.3.entry}
  177. set helpCmds(.frame.4.label) {set topic .frame.4.entry}
  178. set helpCmds(.frame.5.label) {set topic .frame.5.entry}
  179. set helpCmds(.frame.6.label) {set topic .frame.6.entry}
  180. set helpCmds(.frame.7.label) {set topic .frame.7.entry}
  181.  
  182. set helpTopics(context) {Unfortunately, this application doesn't support context-sensitive help in the usual way, because when this demo was written Tk didn't have a grab mechanism and this is needed for context-sensitive help.  Instead, you can achieve much the same effect by simply moving the mouse over the window you're curious about and pressing the Help or F1 keys.  You can do this anytime.}
  183. set helpTopics(help) {This application provides only very crude help.  Besides the entries in this menu, you can get help on individual windows by moving the mouse cursor over the window and pressing the Help or F1 keys.}
  184. set helpTopics(window) {This window is a dummy rolodex application created as part of Tom LaStrange's toolkit benchmark.  It doesn't really do anything useful except to demonstrate a few features of the Tk toolkit.}
  185. set helpTopics(keys) "The following accelerator keys are defined for this application (in addition to those already available for the entry windows):\n\nCtrl+A:\t\tAdd\nCtrl+C:\t\tClear\nCtrl+D:\t\tDelete\nCtrl+F:\t\tEnter file name\nCtrl+Q:\t\tExit application (quit)\nCtrl+S:\t\tSearch (dummy operation)"
  186. set helpTopics(version) "This is version $version."
  187.  
  188. # Entries in "Help" menu
  189.  
  190. .menu.help.m add command -label "On Context..." -command {Help context} \
  191.     -underline 3
  192. .menu.help.m add command -label "On Help..." -command {Help help} \
  193.     -underline 3
  194. .menu.help.m add command -label "On Window..." -command {Help window} \
  195.     -underline 3
  196. .menu.help.m add command -label "On Keys..." -command {Help keys} \
  197.     -underline 3
  198. .menu.help.m add command -label "On Version..." -command {Help version}  \
  199.     -underline 3
  200.  
  201. # Local Variables:
  202. # mode: tcl
  203. # End:
  204.