Next / Previous / Contents / TCC Help System / NM Tech homepage

15. class Adjuster: Color adjustment and color model selection

This class includes all the widgets down the center third of the application:

This Adjuster widget class, then, is really the central “brain” of the application. Inside this object are stored the current background and text colors.

Here is the class interface. As with all compound widgets, it inherits its widgetness from the Frame class.

huey
# - - - - -   c l a s s   A d j u s t e r

class Adjuster(Frame):
    """Widgets to store and adjust the current colors.

      Exports:
        Adjuster ( parent, callback=None ):
          [ (parent is a Frame) and
            (callback is a function or None) ->
              parent  :=  parent with a new Adjuster widget added
                  but not gridded, which will call callback
                  whenever the displayed color is changed, where
                  the calling sequence is
                    callback(isText, newColor)
                  and isText is True to set the text color, False
                  to set the background color, and newColor is a
                  the new color as a Color instance
              return that new Adjuster widget ]

The next two methods return the current colors; see Section 15.3, “Adjuster.textColor(): Return the current text color” and Section 15.4, “Adjuster.bgColor(): Return the current text color”.

huey
        .textColor():
           [ return the current text color as a Color instance ]
        .bgColor():
           [ return the current background color as a Color instance ]

The .set() method changes the currently displayed color; see Section 15.2, “Adjuster.set(): Change the color”.

huey
        .set ( color ):
          [ color is a Color instance ->
              if self is displaying the text color ->
                 self's text color  :=  color
              else ->
                 self's background color  :=  color ]

The .isText() method tests whether the sliders are displaying the text color or the background color; see Section 15.5, “Adjuster.isText(): Which color is being displayed?”.

huey
        .isText():
           [ if self is displaying the text color ->
               return True
             else -> return False ]

One might ask, instead of making isText() a method call, why not make it simply an exported read-only Boolean? It is made a method strictly for the convenience of the implementer: this way, the actual value can be kept in the same Tkinter IntVar control variable that is linked to the two radiobuttons that control that switch.

Here is the layout of the widgets inside.

huey
      Contained widgets:
         .__colorReadout:
           [ a ColorReadout widget that displays self's text and
             background colors, and a pair of radiobuttons to
             switch between them ]
         .__modelSelector:
           [ a ModelSelector widget that lets the user select
             which color model to display ]
         .__colorSliders:
           [ a ColorSliders widget that lets the user adjust
             the color model's parameters ]

       Grid plan:  Vertically stacked in a single column.
    """