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

14.6. PickList.__findColorsFile(): Read the rgb.txt file

This method searches various directories in hopes that there is a standard colors file there. If so, it sets up self.__colorList with the color values and self.__nameList with the corresponding names.

huey
# - - -   P i c k L i s t . _ _ f i n d C o l o r s F i l e

    def __findColorsFile ( self ):
        """Try to find and read the standard colors file.

          [ if self.COLOR_NAMES_FILE names a readable, valid
            rgb.txt file in one of the directories named in
            self.PATHS_LIST ->
                self.__colorMap  :=  as invariant from that file
            else ->
                self.__colorMap  :=  an empty dictionary ]
        """

        #-- 1 --
        inFile  =  None

        #-- 2 --
        # [ if self.PATHS_LIST names a directory that contains
        #   a readable file named self._COLOR_NAMES_FILE ->
        #     inFile  :=  that file opened for reading
        #   else -> I ]
        for  dir in self.PATHS_LIST:
            fileName  =  os.path.join ( dir, self.COLOR_NAMES_FILE )
            try:
                inFile  =  open ( fileName )
                break
            except IOError:
                pass

If we couldn't find the file, we set self.__colorMap to an empty list to signal failure, and return to the caller.

huey
        #-- 2 --
        if inFile is None:
            self.__colorMap  = {}
            return

We're not guaranteed success yet—the file might not be in the correct format. See Section 14.7, “PickList.__readColorsFile(): Process the rgb.txt file” for details of the file format and the process of reading it.

huey
        #-- 3 --
        # [ if inFile is a valid colors file ->
        #     self.__colorMap  :=  as invariant from that file
        #   else ->
        #     self.__colorMap  :=  an empty dictionary ]
        self.__readColorsFile ( inFile )