[ Team LiB ] Previous Section Next Section

Loading Option Database Files

The option command manipulates the resource database. The first form of the command loads a file containing database entries:

option readfile filename ?priority?

The priority distinguishes different sources of resource information and gives them different priorities. Priority levels are numeric, from 0 to 100. However, symbolic names are defined for standard priorities. From lowest to highest, the standard priorities are widgetDefault (20), startupFile (40), userDefault (60), and interactive (80). These names can be abbreviated. The default priority is interactive.

Example 31-1 Reading an option database file
if [file exists $appdefaults] {
   if [catch {option readfile $appdefaults startup} err] {
      puts stderr "error in $appdefaults: $err"
   }
}

The format of the entries in the file is:

key: value

The key has the pattern format previously described. The value can be anything, and there is no need to group multiword values with any quoting characters. In fact, quotes will be picked up as part of the value.

Comment lines are introduced by the exclamation mark (!).

Example 31-2 A file containing resource specifications
!
! Grey color set
! These values match those used by the Tk widgets on UNIX
!
*background:        #d9d9d9
*foreground:        black
*activeBackground:  #ececec
*activeForeground:  black
*selectColor:       #b03060
*selectBackground:  #c3c3c3
*troughColor:       #c3c3c3
*disabledforeground:#a3a3a3

The example resource file specifies the color scheme for the Tk widget set on UNIX that is based on a family of gray levels. Color highlighting shows up well against this backdrop. These colors are applied generically to all the widgets. The hexadecimal values for the colors specify two digits (eight bits) each for red, green, and blue. Chapter 41 describes the use of color in detail.

    [ Team LiB ] Previous Section Next Section