Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Static Public Attributes
MoinMoin.util.web.Color Class Reference

List of all members.

Public Member Functions

def __init__
def __str__
def __repr__
def __int__
def __long__

Public Attributes

 b
 r
 g

Static Public Attributes

dictionary COLORS

Detailed Description

RGB-Triple that automatically converts from and to
    "#RRGGBB" encoding, and also takes Netscape color names.

    The color values are stored in the attributes `r`, `g` and `b`.

    Example:
        >>> from color import Color
        >>> Color('yellow')
        Color(255, 255, 0)
        >>> str(Color('yellow'))
        '#FFFF00'
        >>> str(Color((128, 0, 128)))
        '#800080'
        >>> Color('#FF00FF')
        Color(255, 0, 255)

Definition at line 66 of file web.py.


Constructor & Destructor Documentation

def MoinMoin.util.web.Color.__init__ (   self,
  color 
)
Init color value, the 'color' parameter may be
    another Color instance, a tuple containing 3 color values,
    a Netscape color name or a HTML color ("#RRGGBB").

Definition at line 227 of file web.py.

00227 
00228     def __init__(self, color):
00229         """ Init color value, the 'color' parameter may be
00230             another Color instance, a tuple containing 3 color values,
00231             a Netscape color name or a HTML color ("#RRGGBB").
00232         """
00233         if isinstance(color, tuple) and len(color) == 3:
00234             self.r, self.g, self.b = int(color[0]), int(color[1]), int(color[2])
00235         elif isinstance(color, Color):
00236             self.r, self.g, self.b = color.r, color.g, color.b
00237         elif not isinstance(color, str):
00238             raise TypeError("Color() expects a Color instance, a RGB triple or a color string")
00239         elif color[0] == '#':
00240             color = long(color[1:], 16)
00241             self.r = (color >> 16) & 255
00242             self.g = (color >> 8) & 255
00243             self.b = color & 255
00244         elif color not in self.COLORS:
00245             raise ValueError("Unknown color name '%s'" % color)
00246         else:
00247             # known color name
00248             self.r, self.g, self.b = self.COLORS[color]


Member Function Documentation

Definition at line 255 of file web.py.

00255 
00256     def __int__(self):
00257         return self.__long__()

Here is the call graph for this function:

Definition at line 258 of file web.py.

00258 
00259     def __long__(self):
00260         return (self.r << 16) | (self.g << 8) | self.b
00261 

Here is the caller graph for this function:

Definition at line 252 of file web.py.

00252 
00253     def __repr__(self):
00254         return "Color(%d, %d, %d)" % (self.r, self.g, self.b)

Definition at line 249 of file web.py.

00249 
00250     def __str__(self):
00251         return "#%02X%02X%02X" % (self.r, self.g, self.b)


Member Data Documentation

Definition at line 233 of file web.py.

dictionary MoinMoin.util.web.Color.COLORS [static]

Definition at line 84 of file web.py.

Definition at line 241 of file web.py.

Definition at line 240 of file web.py.


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