rolodex 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. #!/bin/sh
  2. # the next line restarts using wish \
  3. exec wish "$0" ${1+"$@"}
  4. # rolodex --
  5. # This script was written as an entry in Tom LaStrange's rolodex
  6. # benchmark. It creates something that has some of the look and
  7. # feel of a rolodex program, although it's lifeless and doesn't
  8. # actually do the rolodex application.
  9. package require Tk
  10. foreach i [winfo child .] {
  11. catch {destroy $i}
  12. }
  13. set version 1.2
  14. #------------------------------------------
  15. # Phase 0: create the front end.
  16. #------------------------------------------
  17. frame .frame -relief flat
  18. pack .frame -side top -fill y -anchor center
  19. set names {{} Name: Address: {} {} {Home Phone:} {Work Phone:} Fax:}
  20. foreach i {1 2 3 4 5 6 7} {
  21. label .frame.label$i -text [lindex $names $i] -anchor e
  22. entry .frame.entry$i -width 35
  23. grid .frame.label$i .frame.entry$i -sticky ew -pady 2 -padx 1
  24. }
  25. frame .buttons
  26. pack .buttons -side bottom -pady 2 -anchor center
  27. button .buttons.clear -text Clear
  28. button .buttons.add -text Add
  29. button .buttons.search -text Search
  30. button .buttons.delete -text "Delete ..."
  31. pack .buttons.clear .buttons.add .buttons.search .buttons.delete \
  32. -side left -padx 2
  33. #------------------------------------------
  34. # Phase 1: Add menus, dialog boxes
  35. #------------------------------------------
  36. # DKF - note that this is an old-style menu bar; I just have not yet
  37. # got around to converting the context help code to work with the new
  38. # menu system and its <<MenuSelect>> virtual event.
  39. frame .menu -relief raised -borderwidth 1
  40. pack .menu -before .frame -side top -fill x
  41. menubutton .menu.file -text "File" -menu .menu.file.m -underline 0
  42. menu .menu.file.m
  43. .menu.file.m add command -label "Load ..." -command fileAction -underline 0
  44. .menu.file.m add command -label "Exit" -command {destroy .} -underline 0
  45. pack .menu.file -side left
  46. menubutton .menu.help -text "Help" -menu .menu.help.m -underline 0
  47. menu .menu.help.m
  48. pack .menu.help -side right
  49. proc deleteAction {} {
  50. if {[tk_dialog .delete {Confirm Action} {Are you sure?} {} 0 Cancel]
  51. == 0} {
  52. clearAction
  53. }
  54. }
  55. .buttons.delete config -command deleteAction
  56. proc fileAction {} {
  57. 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
  58. puts stderr {dummy file name}
  59. }
  60. #------------------------------------------
  61. # Phase 3: Print contents of card
  62. #------------------------------------------
  63. proc addAction {} {
  64. global names
  65. foreach i {1 2 3 4 5 6 7} {
  66. puts stderr [format "%-12s %s" [lindex $names $i] [.frame.entry$i get]]
  67. }
  68. }
  69. .buttons.add config -command addAction
  70. #------------------------------------------
  71. # Phase 4: Miscellaneous other actions
  72. #------------------------------------------
  73. proc clearAction {} {
  74. foreach i {1 2 3 4 5 6 7} {
  75. .frame.entry$i delete 0 end
  76. }
  77. }
  78. .buttons.clear config -command clearAction
  79. proc fillCard {} {
  80. clearAction
  81. .frame.entry1 insert 0 "John Ousterhout"
  82. .frame.entry2 insert 0 "CS Division, Department of EECS"
  83. .frame.entry3 insert 0 "University of California"
  84. .frame.entry4 insert 0 "Berkeley, CA 94720"
  85. .frame.entry5 insert 0 "private"
  86. .frame.entry6 insert 0 "510-642-0865"
  87. .frame.entry7 insert 0 "510-642-5775"
  88. }
  89. .buttons.search config -command "addAction; fillCard"
  90. #----------------------------------------------------
  91. # Phase 5: Accelerators, mnemonics, command-line info
  92. #----------------------------------------------------
  93. .buttons.clear config -text "Clear Ctrl+C"
  94. bind . <Control-c> clearAction
  95. .buttons.add config -text "Add Ctrl+A"
  96. bind . <Control-a> addAction
  97. .buttons.search config -text "Search Ctrl+S"
  98. bind . <Control-s> "addAction; fillCard"
  99. .buttons.delete config -text "Delete... Ctrl+D"
  100. bind . <Control-d> deleteAction
  101. .menu.file.m entryconfig 1 -accel Ctrl+F
  102. bind . <Control-f> fileAction
  103. .menu.file.m entryconfig 2 -accel Ctrl+Q
  104. bind . <Control-q> {destroy .}
  105. focus .frame.entry1
  106. #----------------------------------------------------
  107. # Phase 6: help
  108. #----------------------------------------------------
  109. proc Help {topic {x 0} {y 0}} {
  110. global helpTopics helpCmds
  111. if {$topic == ""} return
  112. while {[info exists helpCmds($topic)]} {
  113. set topic [eval $helpCmds($topic)]
  114. }
  115. if [info exists helpTopics($topic)] {
  116. set msg $helpTopics($topic)
  117. } else {
  118. set msg "Sorry, but no help is available for this topic"
  119. }
  120. tk_dialog .help {Rolodex Help} "Information on $topic:\n\n$msg" \
  121. {} 0 OK
  122. }
  123. proc getMenuTopic {w x y} {
  124. return $w.[$w index @[expr {$y-[winfo rooty $w]}]]
  125. }
  126. event add <<Help>> <F1> <Help>
  127. bind . <<Help>> {Help [winfo containing %X %Y] %X %Y}
  128. bind Menu <<Help>> {Help [winfo containing %X %Y] %X %Y}
  129. # Help text and commands follow:
  130. 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.}
  131. set helpCmds(.menu.file.m) {getMenuTopic $topic $x $y}
  132. 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}
  133. set helpTopics(.menu.file.m.2) {The "Exit" entry in the "File" menu causes the rolodex application to terminate}
  134. set helpCmds(.menu.file.m.none) {set topic ".menu.file"}
  135. set helpTopics(.frame.entry1) {In this field of the rolodex entry you should type the person's name}
  136. set helpTopics(.frame.entry2) {In this field of the rolodex entry you should type the first line of the person's address}
  137. set helpTopics(.frame.entry3) {In this field of the rolodex entry you should type the second line of the person's address}
  138. set helpTopics(.frame.entry4) {In this field of the rolodex entry you should type the third line of the person's address}
  139. set helpTopics(.frame.entry5) {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}
  140. set helpTopics(.frame.entry6) {In this field of the rolodex entry you should type the person's work phone number}
  141. set helpTopics(.frame.entry7) {In this field of the rolodex entry you should type the phone number for the person's FAX machine}
  142. set helpCmds(.frame.label1) {set topic .frame.entry1}
  143. set helpCmds(.frame.label2) {set topic .frame.entry2}
  144. set helpCmds(.frame.label3) {set topic .frame.entry3}
  145. set helpCmds(.frame.label4) {set topic .frame.entry4}
  146. set helpCmds(.frame.label5) {set topic .frame.entry5}
  147. set helpCmds(.frame.label6) {set topic .frame.entry6}
  148. set helpCmds(.frame.label7) {set topic .frame.entry7}
  149. 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.}
  150. 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.}
  151. 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.}
  152. 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)"
  153. set helpTopics(version) "This is version $version."
  154. # Entries in "Help" menu
  155. .menu.help.m add command -label "On Context..." -command {Help context} \
  156. -underline 3
  157. .menu.help.m add command -label "On Help..." -command {Help help} \
  158. -underline 3
  159. .menu.help.m add command -label "On Window..." -command {Help window} \
  160. -underline 3
  161. .menu.help.m add command -label "On Keys..." -command {Help keys} \
  162. -underline 3
  163. .menu.help.m add command -label "On Version..." -command {Help version} \
  164. -underline 3
  165. # Local Variables:
  166. # mode: tcl
  167. # End: