all_names(): Return just the unique names of rgb colors

This commit is contained in:
Barry Warsaw 1998-10-02 14:43:30 +00:00
parent ad678af89b
commit 8be2594a24
1 changed files with 11 additions and 0 deletions

View File

@ -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):