Advanced Search
Mail us
Home    Manuel    Links    Faq    Submit a tcl/tk Reference    Contact Us

    Some examples tcl/tk codes     Man of Bwidget     Man of blt     mkwidget screenshots     TkOgl     Video Demo real.


  How can I set X11 resources for a wish application in an app-defaults file?
 
 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:

# get_env varName
#   Looks up the environment variable named $varName and returns its value
#   OR {} if it does not exist
proc get_env varName {
    global env
    if {[info exists env($varName)]} { return $env($varName) }
}

# 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.

Chris Milam contributes the following modification of `loadAppDefaults`
which follows the X11R5 method of merging app-default files from several
sources.

# loadAppDefaults classNameList ?priority?
#   Searches for the app-default files corresponding to classNames in
#   the order specified by X Toolkit Intrinsics (R5), and loads them with
#   the priority specified (default: startupFile).
proc loadAppDefaults {classNameList {priority startupFile}} {
  set lang [envVal LANG]
  if {[string length $lang] > 0} { set lang /$lang }
  set filepath " /usr/lib/X11${lang}/app-defaults  [split [envVal XFILESEARCHPATH] :]  [envVal XAPPLRESDIR]${lang}  [split [envVal XUSERFILESEARCHPATH] :]  "
  foreach i $classNameList {
    foreach j $filepath {
      if {[file exists $j/$i]} {
        option readfile $j/$i $priority;
      }
    }
  }
}