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

17. class ModelSelector: Widgets to select a color model

This class is a compound widget that allows the user to select among different color models. There are a number of different ways to map color space onto coordinate systems, but three numbers are required in any case.

Although originally designed to support three models (HSV, RGB, and CMY), there is no reason why other models cannot be added later.

huey
# - - - - -   c l a s s   M o d e l S e l e c t o r

class ModelSelector(Frame):
    """Compound widget for selecting color models.

      Exports:
        ModelSelector ( parent, callback=None ):
          [ (parent is a Frame) and
            (callback is a function or None) ->
              parent  :=  parent with a new ModelSelector widget
                  added but not gridded, that lets the user select
                  a color model (initially RGB), and calls
                  callback(model) when a selection is made, where
                  model is a concrete class that inherits from ColorModel
              return that new ModelSelector widget ]

This method returns the currently selected model; see Section 17.2, “ModelSelector.getModel(): Return the current model”.

huey
        .getModel():
          [ returns self's model as a concrete class of ColorModel ]

      Internal widgets:
        .__topLabel:    [ a Label that labels the radiobuttons ]
        .__radioList:
          [ a list of Radiobutton widgets, one per model ]

      Grid plan:
           0                 1                 2...
          +-----------------+-----------------+-----+
        0 | .__topLabel                             |
          +-----------------+-----------------+-----+
        1 | .__radioList[0] | .__radioList[1] | ... |
          +-----------------+-----------------+-----+

Here are some private attributes of the class. First, self.__callback is the callback function. The control variable that links the radiobuttons together into a group is self.__radioVar.

huey
      State/Invariants:
        .__callback:     [ as passed to constructor, read-only ]
        .__radioVar:
          [ an IntVar control variable for the radiobuttons whose
            value is the model's index in self.__modelList ]

There is also a class variable that enumerates the supported color models, as instances of concrete classes implementing the ColorModel abstract class.

huey
        ModelSelector.__modelList:
          [ a list of instances of ColorModel concrete classes,
            in the same order as self.__radioList ]
    """