Tracing Changes to Preference Variables

   

Practical Programming in Tcl & Tk, Third Edition
By Brent B. Welch

Table of Contents
Chapter 42.  Managing User Preferences


Suppose, for example, we want to repack the scrollbars when the user changes their scrollside setting from left to right. This is done by setting a trace on the win(scrollside) variable. When the user changes that via the user interface, the trace routine is called. The trace command and its associated procedure are shown in the next example. The variable must be declared global before setting up the trace, which is not otherwise required if Pref_Add is the only command using the variable.

Example 42-10 Tracing a Tcl variable in a preference item.
 Pref_Add {    {win(scrollside) scrollbarSide {CHOICE left right}       "Scrollbar placement" "Scrollbars can be positioned on either the left or right side of the text and canvas widgets."} } global win set win(lastscrollside) $win(scrollside) trace variable win(scrollside) w ScrollFixup # Assume win(scrollbar) identifies the scrollbar widget proc ScrollFixup { name1 name2 op } {    global win    if {$win(scrollside) != $win(lastscrollside)} {       set parent [lindex [pack info $win(scrollbar)] 1]       pack forget $win(scrollbar)       set firstchild [lindex [pack slaves $parent] 0]       pack $win(scrollbar) -in $parent -before $firstchild \          -side $win(scrollside) -fill y       set win(lastscrollside) $win(scrollside)    } } 

       
    Top
     



    Practical Programming in Tcl and Tk
    Practical Programming in Tcl and Tk (4th Edition)
    ISBN: 0130385603
    EAN: 2147483647
    Year: 1999
    Pages: 478

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net