diff options
author | Barry Warsaw <barry@python.org> | 1998-10-02 14:43:30 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 1998-10-02 14:43:30 (GMT) |
commit | 8be2594a2428a18ade0cfa3e6d5d256308c1c8dd (patch) | |
tree | 59c99a1717da74f943284644822225314fdfc88b /Tools/pynche | |
parent | ad678af89b7f60c82f78111fac144065e861a0aa (diff) | |
download | cpython-8be2594a2428a18ade0cfa3e6d5d256308c1c8dd.zip cpython-8be2594a2428a18ade0cfa3e6d5d256308c1c8dd.tar.gz cpython-8be2594a2428a18ade0cfa3e6d5d256308c1c8dd.tar.bz2 |
all_names(): Return just the unique names of rgb colors
Diffstat (limited to 'Tools/pynche')
-rw-r--r-- | Tools/pynche/ColorDB.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Tools/pynche/ColorDB.py b/Tools/pynche/ColorDB.py index 5191d2b..435e0ad 100644 --- a/Tools/pynche/ColorDB.py +++ b/Tools/pynche/ColorDB.py @@ -40,6 +40,8 @@ class ColorDB: # key is name, value is (red, green, blue) self.__byname = {} # + # all unique names (non-aliases). built-on demand + self.__allnames = None while 1: line = fp.readline() if not line: @@ -101,6 +103,15 @@ class ColorDB: nearest = distance nearest_name = name return nearest_name + + def all_names(self): + # sorted + if not self.__allnames: + self.__allnames = [] + for name, aliases in self.__byrgb.values(): + self.__allnames.append(name) + self.__allnames.sort() + return self.__allnames class RGBColorDB(ColorDB): |