home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / tcl / 1306 < prev    next >
Encoding:
Text File  |  1992-09-04  |  1.6 KB  |  65 lines

  1. Newsgroups: comp.lang.tcl
  2. Path: sparky!uunet!decwrl!parc!welch
  3. From: welch@parc.xerox.com (Brent Welch)
  4. Subject: Re: Request: Anybody have a tk-based "Tcl Listener" implemented?
  5. Message-ID: <welch.715132269@corvina>
  6. Sender: news@parc.xerox.com
  7. Organization: Xerox PARC
  8. References: <VEK.92Aug20161320@rover.allegra.att.com>
  9. Distribution: comp
  10. Date: 29 Aug 92 23:51:09 GMT
  11. Lines: 52
  12.  
  13. The mxedit editor uses an entry widget as a TCL command interpreter.
  14. Here is the main procedure that passes the contents of the
  15. entry widget the Tcl_Eval:
  16.  
  17.  
  18. # mxDoCmd --
  19. #    Execute the commands issued to the command entry
  20. #    This is ordinarily bound to hitting <Return> in the command entry
  21.  
  22. proc mxDoCmd { } {
  23.     # focus is a flag that indicates which other widget should get
  24.     # focus after the command is executed
  25.     global focus
  26.     # command is a frame widget holding a label and an entry
  27.     global command
  28.  
  29.     set cmd [$command.entry get]
  30.     if {[llength $cmd] != 0} {
  31.     case [lindex $cmd 0] in {
  32.         {echo feedback mxFeedback} {
  33.         # Echo inputs
  34.         mxFeedback "$cmd"
  35.         } help {
  36.         # Display help information
  37.         mxopen [info library]/mxedit.tutorial
  38.         } default {
  39.         # Pass on the command to Tcl
  40.         if [catch {uplevel #0 $cmd} msg] {
  41.             mxFeedback "Cmd failed: $msg"
  42.         } else {
  43.             # This displays the result in another entry widget
  44.             if {[string compare "$msg" ""] != 0} {
  45.             mxFeedback $msg
  46.             } else {
  47.             mxFeedback "ok"
  48.             }
  49.         }
  50.         }
  51.     }
  52.     }
  53.     # Let a command do its own focus if it wants,
  54.     # otherwise return the focus to the editting window
  55.     if {[string compare $focus "default"] == 0} {
  56.     mxeditFocus
  57.     }
  58.     set focus default
  59. }
  60.  
  61.  
  62. --
  63.  
  64.     Brent Welch
  65.