Next / Previous / Contents / Shipman's homepage

19.2. ParamSlider.setModel(): Change the color model

This method changes the color model being displayed.

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

    def setModel ( self, model ):
        """Change the current color model."""

First we store the new color model in self.__model.

        #-- 1 --
        self.__model  =  model

The label self.__topLabel displays the parameter name; retrieve the parameter name from the color model and change the label's text to that name.

        #-- 2 --
        # [ self.__topLabelVar  :=  self.__topLabelVar with its
        #       value set to the (self.__paramx)th parameter name
        #       of self.__model ]
        paramLabel  =  self.__model.labelList[self.__paramx]
        self.__topLabelVar.set ( paramLabel )

Note: Originally, there was logic here to change the displayed color. However, this led to a nasty defect. In the original version, the caller first sets the first slider's model—but then the callback to change the color would calculate a new color based on the positions of sliders 2 and 3, which still used the old model!

The fix was to put the burden on the caller to redisplay the new color once all the sliders were moved to the new model.