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

18.5. ColorSliders.__sliderHandler(): Handler for a parameter change

This method is called when the user changes the setting of any of the ParamSlider widgets. This method takes no arguments; when any slider changes, we have to look at all three and convert those settings into the new color.

# - - -   C o l o r S l i d e r s . _ _ s l i d e r H a n d l e r

    def __sliderHandler ( self ):
        """Read the ParamSliders and convert them to a new color

First we read all three sliders and build a list of their values, each value in [0,MAX_PARAM].

        #-- 1 --
        paramList  =  []

        #-- 2 --
        # [ paramList  +:=  parameter values of the ParamSlider
        #       widgets in self.__sliderList ]
        for  paramx in range(N_PARAMS):
            paramList.append (self.__sliderList[paramx].get() )

In classes that inherit from ColorModel, the .paramsToColor() method converts the list of parameters into a Color object. See Section 7, “class ColorModel: Base class for color models”.

        #-- 3 --
        # [ paramList  is a list of N_PARAMS numbers, each in
        #   [0,MAX_PARAM] ->
        #     self.__color  :=  paramList converted to a color using
        #                       the color model in self.__model ]
        self.__color  =  self.__model.paramsToColor ( paramList )

We must call our callback now to notify external observers that the color has changed.

        #-- 4 --
        if  self.__callback is not None:
            self.__callback ( self.__color )