Back to index

python3.2  3.2.2
Public Member Functions | Static Private Attributes
pynche.ColorDB.RGBColorDB Class Reference
Inheritance diagram for pynche.ColorDB.RGBColorDB:
Inheritance graph
[legend]
Collaboration diagram for pynche.ColorDB.RGBColorDB:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def filename
def find_byrgb
def find_byname
def nearest
def unique_names
def aliases_of

Static Private Attributes

tuple _re

Detailed Description

Definition at line 136 of file ColorDB.py.


Member Function Documentation

def pynche.ColorDB.ColorDB.aliases_of (   self,
  red,
  green,
  blue 
) [inherited]

Definition at line 128 of file ColorDB.py.

00128 
00129     def aliases_of(self, red, green, blue):
00130         try:
00131             name, aliases = self.__byrgb[(red, green, blue)]
00132         except KeyError:
00133             raise BadColor((red, green, blue))
00134         return [name] + aliases
00135 

def pynche.ColorDB.ColorDB.filename (   self) [inherited]

Definition at line 83 of file ColorDB.py.

00083 
00084     def filename(self):
00085         return self.__name

Here is the caller graph for this function:

def pynche.ColorDB.ColorDB.find_byname (   self,
  name 
) [inherited]
Return (red, green, blue) for name

Definition at line 93 of file ColorDB.py.

00093 
00094     def find_byname(self, name):
00095         """Return (red, green, blue) for name"""
00096         name = name.lower()
00097         try:
00098             return self.__byname[name]
00099         except KeyError:
00100             raise BadColor(name)

def pynche.ColorDB.ColorDB.find_byrgb (   self,
  rgbtuple 
) [inherited]
Return name for rgbtuple

Definition at line 86 of file ColorDB.py.

00086 
00087     def find_byrgb(self, rgbtuple):
00088         """Return name for rgbtuple"""
00089         try:
00090             return self.__byrgb[rgbtuple]
00091         except KeyError:
00092             raise BadColor(rgbtuple)

def pynche.ColorDB.ColorDB.nearest (   self,
  red,
  green,
  blue 
) [inherited]
Return the name of color nearest (red, green, blue)

Definition at line 101 of file ColorDB.py.

00101 
00102     def nearest(self, red, green, blue):
00103         """Return the name of color nearest (red, green, blue)"""
00104         # BAW: should we use Voronoi diagrams, Delaunay triangulation, or
00105         # octree for speeding up the locating of nearest point?  Exhaustive
00106         # search is inefficient, but seems fast enough.
00107         nearest = -1
00108         nearest_name = ''
00109         for name, aliases in self.__byrgb.values():
00110             r, g, b = self.__byname[name.lower()]
00111             rdelta = red - r
00112             gdelta = green - g
00113             bdelta = blue - b
00114             distance = rdelta * rdelta + gdelta * gdelta + bdelta * bdelta
00115             if nearest == -1 or distance < nearest:
00116                 nearest = distance
00117                 nearest_name = name
00118         return nearest_name

def pynche.ColorDB.ColorDB.unique_names (   self) [inherited]

Definition at line 119 of file ColorDB.py.

00119 
00120     def unique_names(self):
00121         # sorted
00122         if not self.__allnames:
00123             self.__allnames = []
00124             for name, aliases in self.__byrgb.values():
00125                 self.__allnames.append(name)
00126             self.__allnames.sort(key=str.lower)
00127         return self.__allnames


Member Data Documentation

tuple pynche.ColorDB.RGBColorDB._re [static, private]
Initial value:
re.compile(
        '\s*(?P<red>\d+)\s+(?P<green>\d+)\s+(?P<blue>\d+)\s+(?P<name>.*)')

Definition at line 137 of file ColorDB.py.


The documentation for this class was generated from the following file: