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

19. class ParamSlider: Scale widget for a color model parameter

This class is a compound widget containing the controls that let the user adjust one of the parameters of the current color.

Since colors in external form show only 8 bits per pixel, the length of the vertical Scale widget for the parameter is exactly 256 pixels, covering the range [0,255]. Because color model parameter values are in the range [0,65535], conversion from the scale value to the parameter value are a simple shift of 8 bits.

# - - - - -   c l a s s   P a r a m S l i d e r

class ParamSlider(Frame):
    """Compound widget with a Scale for adjusting one color parameter.

        ParamSlider ( parent, model, color, paramx, callback=None ):
          [ (parent is a Frame) and
            (model is a ColorModel) and
            (color is a Color) and
            (param is an int in [0,N_PARAMS)) and
            (callback is a function or None) ->
              parent  :=  parent with a new ParamSlider widget added
                  but not gridded, that displays the (paramx)th
                  parameter of (color) using (model), and calls
                  callback() whenever its scale is moved
              return that new ParamSlider widget ]

The .get() method returns the 16-bit integer value of this parameter; see Section 19.1, “ParamSlider.get(): Retrieve the current parameter value”.

        .get():  [ return self's slider value in [0,MAX_PARAM] ]

The .setModel() and .setColor() methods change the current color model and color, respectively; see Section 19.2, “ParamSlider.setModel(): Change the color model” and Section 19.3, “ParamSlider.setColor(): Change the current color”.

        .setModel ( model ):
          [ self  :=  self displaying labels for the (paramx)th
                      parameter of model ]
        .setColor ( color ):
          [ self  :=  self displaying the (paramx)th parameter of
                      self.model ]

Each ParamSlider contains four widgets in a vertical row:

      Internal widgets:
        .__topLabel:    [ Label showing the parameter's name ]
        .__plusButton:  [ Button that increments the parameter ]
        .__scale:       [ Scale for adjusting the parameter ]
        .__minusButton: [ Button that decrements the parameter ]

      Grid plan:  One vertical column.

Here are the private attributes.

        .__paramx:      [ as passed to the constructor ]
        .__callback:    [ as passed to the constructor ]
        .__topLabelVar: [ StringVar for self.__topLabel ]
        .__scaleVar:    [ IntVar for self.__scale ]
        .__model:       [ current model as a ColorModel ]
        .__color:       [ current color as a Color ]