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

19.3. ParamSlider.setColor(): Change the current color

This method changes the color whose parameter is currently displayed.

huey
# - - -   P a r a m S l i d e r . s e t C o l o r

    def setColor ( self, color ):
        """Change the currently displayed color."""

        #-- 1 --
        self.__color  =  color

We must readjust the position of the Scale widget. First, we translate the new color into its three parameters using the current color model. For this interface, see Section 7, “class ColorModel: Base class for color models”.

huey
        #-- 2 --
        # [ paramList  :=  self.__color expressed as a list of
        #       N_PARAMS parameters using color model self.__model ]
        paramList  =  self.__model.colorToParams ( color )

The parameter displayed is an element of paramList, with that element's position specified by self.__paramx. This value must be shifted right by 8 bits to fit into the range [0,MAX_BYTE]. Then the Scale widget is repositioned by calling the .set() method on its control variable.

huey
        #-- 3 --
        scaleValue  =  paramList[self.__paramx] >> 8

        #-- 4 --
        # [ self.__scale  :=  self.__scale repositioned to value
        #                     (scaleValue) ]
        self.__scaleVar.set ( scaleValue )

Finally, we must notify the external observers that the color has changed.

huey
        #-- 5 --
        if  self.__callback is not None:
            self.__callback()