dabo Commit
Revision 4350
Date: 2008-08-04 02:13:09 -0700 (Mon, 04 Aug 2008)
Author: Ed
Trac: http://svn.dabodev.com/trac/dabo/changeset/4350

Changed:
U   trunk/dabo/dColors.py

Log:
Added the 'colorNameFromTuple()' method. Given an RGB color tuple, it will 
return a list of the common names for that tuple, or an empty list if there is 
no match. If the 'firstOnly' parameter is passed as True, only the first 
element in the list will be returned as a simple string value, or an empty 
string if there are no matches.


Diff:
Modified: trunk/dabo/dColors.py
===================================================================
--- trunk/dabo/dColors.py       2008-08-03 20:18:01 UTC (rev 4349)
+++ trunk/dabo/dColors.py       2008-08-04 09:13:09 UTC (rev 4350)
@@ -254,3 +254,19 @@
 def randomColor():
        import random
        return colorDict[random.choice(colorDict.keys())]
+
+
+def colorNameFromTuple(colorTuple, firstOnly=False):
+       """Returns a list of color names, if any, whose RGB tuple matches
+       the specified tuple. If 'firstOnly' is True, then a single color name 
+       will be returned as a string, not a list; the string will be empty
+       if there is no match.
+       """
+       ret = [nm for nm, tup in colorDict.items()
+                       if tup == colorTuple]
+       if firstOnly:
+               try:
+                       ret = ret[0]
+               except IndexError:
+                       ret = ""
+       return ret




_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: http://leafe.com/archives/byMID/[EMAIL PROTECTED]

Reply via email to