Option Database

The properties of a window are its dominant feature; properties constitute the window type.

There are roughly three groups of properties.

Various Properties

There are two ways to set properties in Tk. The first method is to specify the property on the command line.

Example 7.2. Command Line Property

button .b \
      -text "caption" \
    -relief raised \
   -command do-something
        

Properties, specified on the command line, are immutable, they cannot be altered through customization. Imutable is a disired restriction for functional and also for some contents related properties.

It should however not being used for properties, which communicate purpose through visual means: Like shape, dimensions, text, icon or colour, such properties better remain customizable.

The ability to customize window properties is implemented through the Option Database in Tcl/Tk.

Example 7.3. Option Database Properties

option add *Button.relief raised
option add *b.text "caption"
button .b -command do-something

Example 7.3, “Option Database Properties”, uses two Option Database entries to define the same properties as seen in Example 7.2, “Command Line Property”. The »relief« property is uniformly defined for all Button windows, whereas the »text« property is predefined for a single button. The button instance ».b« is present with its pathname and a leading asterisk (*) instead of a leading dot (.). The function »do-something« remains a command line property, because »do-something« is part of the application logic and must be imutable.

Figure 7.1. Preferences: Option DB


Combinations of Class and Instance names can used inside the Option Database. The latest Option Database is dominant to previous definitions.


Figure 7.1, “Preferences: Option DB”, shows the Jeszra Option Database »Generate« preferences page. There are a series of predefined properties, dedicated to certain usage scenarios. These different sets are themselves customizable and new sets can be defined as-well. On default: all properties from all sets are being used. Jeszra makes the maximum use of the Option Database.


There are five atoms defining a property. The first atom is the command line argument. The second atom is the Option Database name, the third atom is the class name (for this property), the fourth atom is the default value and the last atom the real value. Example 7.5, “Details of Property background” displays all atoms for a background property. This list is only available through the»configure« command; which queries all window properties.

Jeszra evaluates the details of a property, it omits code generation when the real value is identical to the default value.