Copyright © 2008, 2009 Arndt Roger Schneider
The Tile controls do not support the same attributes as their Tk counterparts. This is very troublesome when designing the properties of a template. The Runtime Library ignores interface errors while Tile is present. This is especially necessary for the 'highlight' properties, since 'highlight' is not available in Tile. The widely used substitution of Tk controls with those from Tile is possible with the Runtime Library. However, I do not recommend substitution for 'Toplevel', 'Label', 'Frame' and 'Entry'.
Only the Rtl_mlistbox and Rtl_gridwin templates are affected by Tile. See: the section called “Rtl_mlistbox” and the section called “Rtl_gridwin”.
Tile is bundled with Tk 8.5. And Tile with Templates applies for this particular version, only.
Any Runtime Library based template supports a »-creator« property. The creator property can be used with a ttk::frame as its argument. The instance of that template then is created from a ttk::frame.
Example 2.1. Using a Template with ttk::frame
# A gridwin using ttk::frame as its creator rtl_gridwin .gridwin -creator ttk::frame ...
Critical missing Properties in Tile bundled with Tk 8.5
background
foreground
highlightThickness
highlightBackground
highlightColor
borderWidth
relief
Although, the Runtime Library is able to detect, when a Tile window is used, and silently ignores errors steming from the attempt to configure such a window. The retrieval however is a different part and requires either a fix of Tile –that it allows queries on such properties– or a workaround inside each template to remove the base properties from the interface and query the theme instead for their values.
Without either one, a template based window can not report what properties it actually has. The »configure« all message must fail for the window.
Example 2.2. Failed configure all
rtl_gridwin .gwin -creator ttk::frame # This must fail: .gwin configure # This must fail, too: .gwin cget -background # This succeeds, but only for non # Tile based elements: .gwin configure -background red
»cget« and »configure« are not affected as long as the property does not originate from the Tile window.
The template interface must be changed in order to allow proper property retrieval from themed elements. This can be done by replacing the first item inside property map table with special code which queries the theme instead of the window for the property in question.
Example 2.3. Inoculate the Template Interface against Tile
namespace eval rtl_gridwin { set var(background) \ [list tileBackground $var(background)]] proc set-tileBackground { base color } { # do nothing ... } proc get-tileBackground { base } { # retrieve the background from the theme. # and return it as color. return [ttk::style lookup frame -background] } } # Now the rtl_gridwin -background is # inoculated against Tile.
Any window belonging to the template interface will after Example 2.3, “Inoculate the Template Interface against Tile” partake in Tiles colour scheme –regardless of its origin from »tk::« or »ttk::«.
Example 2.4. Inoculate inside »pkgIndex.tcl«
# This code is an excerpt from pkgIndex.tcl. # Its purpose is to inoculate the gistbox # template against missing properties in # ttk windows. As a side-effect any usage # of this template will partake in theme # changes, too. package ifneeded inoculate_gistbox 1.0 { package require Tk 8.5 package require gttk package provide inoculate_gistbox 1.0 namespace eval gistbox { # Make all the wrapper known. namespace import ::gttk::* # Extend the interface with wrappers at # 1st-position. Notice: case / lowercase. variable var foreach _ { background highlightThickness borderWidth highlightBackground relief highlightColor } { # lsort cannot being used here, # would disorder things. set var($_) \ [concat tile[mkFirstUp \ [string tolower $_]] \ $var($_)] }
Example 2.5. ...Inoculate »pkgIndex.tcl«
# The template will monitor themes. bind Gistbox <<ThemeChanged>> { foreach _ { background highlightthickness borderwidth highlightbackground relief highlightcolor } { %W configure -$_ [%W cget -$_] } } } }
The Rtl_mlistbox header design will be disrupted when 'Label' is substituted with 'TLabel' –the header label uses a different background colour. The following code fragment presents how to preserve Tk’s label for Rtl_mlistbox.
Example 2.6. Tcl/Tk 8.4 Combine Tile and Rtl_mlistbox
# Loading Tile … # Rescue 'label' using 'rename'. rename label labelTk # Substitute 'label' with 'ttk::label'. … # Tell mlistbox to use 'labelTk' # for the header column. option add *Rtl_mlistbox.label labelTk
Example 2.7. Tcl/Tk 8.5 Combine Tile and Rtl_mlistbox
# package require tile; –not needed under 8.5. # Tell the multi-column-listbox to use a # Tk Label for its header row: option add *Rtl_mlistbox.label tk::label
Under Tcl/Tk 8.5 and higher, the tk label is imported into the Rtl_mlistbox namespace. The rescue operation Example 2.6, “Tcl/Tk 8.4 Combine Tile and Rtl_mlistbox” is thus only necessary for 8.4 and earlier Tcl/Tk releases.
The Rtl_gridwin template provides scrollbar management. The Rtl_tree and combobox template do have an embedded Rtl_gridwin.
The template contains code designated to work with Tile
Instructing Rtl_gridwin to use Tile
Add this:
*Rtl_gridwin.scrollbar: ttk::scrollbar
to your X Resource Database resource file…
…or this:
option add *Rtl_gridwin.scrollbar ttk::scrollbar
to your source code.