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

14.10. PickList.__useDefaultColors(): Set up a default color list

This method is called when the rgb.txt file is missing or invalid. It sets up the class's color list from the default color set in Section 14.2, “PickList: Default color list”.

huey
# - - -   P i c k L i s t . _ _ u s e D e f a u l t C o l o r s

    def __useDefaultColors ( self ):
        """Set up self's colors from the default list.

          [ self.__colorMap  +:=  as invariant from
                                  self.DEFAULT_COLORS ]
        """

This method sets up the color pick list from our internal, default list of colors.

The self.DEFAULT_COLORS list is a list of strings with the same values as lines from rgb.txt: 8-bit values for red, green, and blue, followed by the color name.

As we set up self.__colorMap, the 8-bit values are shifted left eight bits to scale them to the [0,MAX_PARAM] range expected by the Color() constructor.

huey
        #-- 1 --
        for  index in range ( len ( self.DEFAULT_COLORS ) ):
            # [ self.DEFAULT_COLORS[index] is a string with the
            #   8-bit red, green, and blue values followed by the
            #   color name ->
            #     self.__colorMap  +:=  an entry mapping the uppercased
            #         color name |-> a tuple (index, a Color instance
            #         made from those color values, the color name) ]
            #-- 1.1 --
            colorString  =  self.DEFAULT_COLORS [ index ]
            red    =  ord ( colorString[0] ) <<8
            green  =  ord ( colorString[1] ) <<8
            blue   =  ord ( colorString[2] ) <<8
            color  =  Color ( red, green, blue )
            colorName  =  colorString[3:]

            #-- 1.2 --
            colorKey  =  colorName.upper()
            colorTuple  =  (index, color, colorName)

            #-- 1.3 --
            self.__colorMap [ colorKey ]  =  colorTuple