Path: lvirden
  From: lvirden@cas.org (Larry W. Virden)
  Subject: comp.lang.tcl Frequently Asked Questions (2/3)
! 	 (Last updated: August 24, 1992)
  Followup-To: comp.lang.tcl
  Summary: A regular posting of the comp.lang.tcl Frequently Asked Questions 
  	(FAQ) and their answers.  This is the first of three parts.
***************
*** 15,22 ****
  
  
  Archive-name: tcl-faq/part2
! Version: 2.2
! Last-modified: July 6, 1992
  
  Index of questions:
  
--- 15,22 ----
  
  
  Archive-name: tcl-faq/part2
! Version: 2.3
! Last-modified: August 24, 1992
  
  Index of questions:
  
***************
*** 39,45 ****
  	Q8b. call one proc with the multi parameter value returned by 
  		another proc?
  	Q8c. pass an array into a proc?
! 	Q8d. set resources for a wish application in an app-defaults file?
  	Q8e. get my wish application to execute - I just get a wish prompt!
  	Q8f. pipe output of a command back into a tcl parsing procedure?
  	Q8g. use extended Tcl and wish or expect?
--- 39,45 ----
  	Q8b. call one proc with the multi parameter value returned by 
  		another proc?
  	Q8c. pass an array into a proc?
! 	Q8d. set X11 resources for a wish application in an app-defaults file?
  	Q8e. get my wish application to execute - I just get a wish prompt!
  	Q8f. pipe output of a command back into a tcl parsing procedure?
  	Q8g. use extended Tcl and wish or expect?
***************
*** 46,51 ****
--- 46,55 ----
  	Q8h. delete a procedure from within a tcl/tk script?
          Q8i. select two items that are not adjacent in the listbox at 
  		one time?
+ 	Q8j. change the default class bindings?
+ 	Q8k. delete a binding?
+ 	Q8l. raise or lower a window?
+ 	Q8m. change the X11 cursor?
  	
  End of FAQ Index
  
***************
*** 80,86 ****
  
  strtod.c
  
! Subject: -Q7c- Has anyone built Tcl 6.2 on an RS/6000 AIX 3.1? 
  
  A7c.  See porting notes - especially the note about strtoul.
  
--- 84,90 ----
  
  strtod.c
  
! Subject: -Q7c- Has anyone built Tcl 6.x on an RS/6000 AIX 3.1? 
  
  A7c.  See porting notes - especially the note about strtoul.
  
***************
*** 263,292 ****
  made out of lists of key-value pairs and can be passed by value to routines,
  over networks, etc.
  
! Subject: -Q8d-	pass an array into a proc?
  
  A8d. Read the documentation for the option command.
  Then you should consider something like the following - assume the program
  name is xwf.
  
! option add Tk.BoldFont "*-lucida sans-Bold-R-Normal-*-100-*" widgetDefault
! option readfile $HOME/.Xdefaults userDefault
! if {[file exists $Home/app-defaults/xwf] == 1} \
!     {option readfile $Home/app-defaults/xwf userDefault}
! elif {[file exists $Home/app-defaults/XWF] == 1} \
!     {option readfile $Home/app-defaults/XWF userDefault}
  
! set fb [option get . Tk BoldFont]
  
! This sets a program default, then any defaults specified in the user's
! default resources and finally any app-defaults resource.  Of course,
! you might want to add some command line handling to allow the user to
! override things at execution time.
  
  Subject: -Q8e- get my wish application to execute - I just get a 
! 		wish prompt!
  
! A8e. Some Unix systems have a maximum length of characters that you can
  put on a #! line.  If you exceed this, you do not get the behaviour you
  expect.  So do not try to put something like:
  
--- 267,325 ----
  made out of lists of key-value pairs and can be passed by value to routines,
  over networks, etc.
  
! Subject: -Q8d- set X11 resources for a wish application in an app-defaults file?
  
  A8d. Read the documentation for the option command.
  Then you should consider something like the following - assume the program
  name is xwf.
  
! The following are two general purpose functions to put into a library:
  
! # envVal envValName
! #   Looks up the envValName environment variable and returns its
! #   value, or {} if it does not exists
! proc envVal {envValName} {
!   global env
!   if [info exists env($envValName)] {return $env($envValName)} {return {}}
! }
  
! # loadAppDefaults classNameList ?priority?
! #   Searches for the app-default files corresponding to classNames in
! #   the order specified by X Toolkit Intrinsics, and loads them with
! #   the priority specified (default: startupFile).
! proc loadAppDefaults {classNameList {priority startupFile}} {
!   set filepath "[split [envVal XUSERFILESEARCHPATH] :] \
! 		[envVal XAPPLRESDIR] \
! 		[split [envVal XFILESEARCHPATH] :] \
! 		/usr/lib/X11"
!   foreach i $classNameList {
!     foreach j $filepath {
!       if {[file exists $j/$i]} {
! 	option readfile $j/$i $priority; break
!       }
!     }
!   }
! }
  
+ # Now, here is what you would put into xwf:
+ 
+ option add Tk.BoldFont "*-lucida sans-Bold-R-Normal-*-100-*" widgetDefault
+ loadAppDefaults {xwf XWF} userDefault
+ 
+ This sets a program default, then load any defaults specified in the user's
+ default resources and finally any site or general app-defaults resource.  
+ Of course, you would want to add some xwf command line handling to allow 
+ the user to override things at execution time.
+ 
  Subject: -Q8e- get my wish application to execute - I just get a
! 		wish prompt!  Or I just get error msgs about permission
! 		denied, not found, etc.
  
! A8e. Most systems require a full pathname to the interpreter.  So you cannot
! start a wish script out as 
! #! wish -f
! 
! Likewise, many Unix systems have a maximum length of characters that you can
  put on a #! line.  If you exceed this, you do not get the behaviour you
  expect.  So do not try to put something like:
  
***************
*** 344,350 ****
  
  A8h. rename procedureName ""
  
! Subject: -Q8h-	delete a procedure from within a tcl/tk script?
    
! A8h. You can't.  Build your own listbox using boxes and text on a canvas.
  Then you will be able to select non-contiguous entries.
--- 377,464 ----
  
  A8h. rename procedureName ""
  
! Subject: -Q8i- select two items that are not adjacent in the listbox at 
! 		one time?
  
! A8i. You can't.  Build your own listbox using boxes and text on a canvas.
  Then you will be able to select non-contiguous entries.
+ 
+ Subject: -Q8j- change the default class bindings?
+ 
+ A8j. All default class bindings for Tk widgets are initialized in
+ $tk_library/tk.tcl.  Use this file as a guide to implement new
+ bindings.  For instance, the following code duplicates Button 1's
+ drag-select facility in Button 3 for all listboxes:
+ 
+ bind Listbox <3> {%W select from [%W nearest %y]}
+ bind Listbox <B3-Motion> {%W select to [%W nearest %y]}
+ 
+ Subject: -Q8k- delete a binding?
+ 
+ A8k. Give an empty-string command to the "bind" invocation.  For
+ example, to disable the Delete key in all entry fields:
+ 
+ 	bind Entry <Delete> {}
+ 
+ Subject: -Q8l- raise or lower a window?
+ 
+ A8l. This is on the (semi-infinite) list of things to be done in the future.
+ If you have the time, please go ahead and add it and submit the code and all
+ will be grateful.
+ 
+ Subject: -Q8m- re-map a withdrawn window id?
+ 
+ A8m. Use wm deiconify <windowid>.
+ 
+ Subject: -Q8m- change the X11 cursor?
+ 
+ Here is a tip from mgc@cray.com (M. G. Christenson).
+ 
+ Look at /usr/include/X11/cursorfont.h for a list of available cursors.
+ You can use the names in there by removing the 'XC_'.  
+ 
+ Here's a little proc I use to make my entire application go 'busy'
+ while it's doing something. Just call it with the commands you want to
+ execute, and the watch cursor will be displayed for the time it takes
+ the commands to complete.  Note that any new windows will have their
+ normal cursor.
+ 
+ proc busy {cmds} {
+     global errorInfo
+ 
+     set busy {.app .root}
+     set list [winfo children .]
+     while {$list != ""} {
+ 	set next {}
+ 	foreach w $list {
+ 	    set class [winfo class $w]
+ 	    set cursor [lindex [$w config -cursor] 4]
+ 	    if {[winfo toplevel $w] == $w || $cursor != ""} {
+ 		lappend busy [list $w $cursor]
+ 	    }
+ 	    set next [concat $next [winfo children $w]]
+ 	}
+ 	set list $next
+     }
+ 
+     foreach w $busy {
+ 	catch {[lindex $w 0] config -cursor watch}
+     }
+ 
+     update idletasks
+ 
+     set error [catch {uplevel eval [list $cmds]} result]
+     set ei $errorInfo
+ 
+     foreach w $busy {
+ 	catch {[lindex $w 0] config -cursor [lindex $w 1]}
+     }
+ 
+     if $error {
+ 	error $result $ei
+     } else {
+ 	return $result
+     }
+ }
+ 
+ 
*** old.tcl-faq.p03	Mon Jul  6 12:29:06 1992
--- tcl-faq.p03	Wed Sep  2 14:32:28 1992
***************
*** 2,8 ****