#
#   Python GUI - Colors - Macintosh
#

class Color(object):
    """A drawing color.
    
    Constructors:
        rgb(red, green, blue)
            where red, green, blue are in the range 0.0 to 1.0
    
    Properties:
        red   -->  float
        green -->  float
        blue  -->  float
        rgb   -->  (red, green, blue)
    """

    def _with_rgb(cls, _rgb):
        c = cls.__new__(cls)
        c._rgb = _rgb
        return c
    
    _with_rgb = classmethod(_with_rgb)

    def __init__(self, red, green, blue):
        self._rgb = (int(red * 65535), int(green * 65535), int(blue * 65535))
    
    def get_red(self):
        return self._rgb[0] / 65535.0
    
    def get_green(self):
        return self._rgb[1] / 65535.0

    def get_blue(self):
        return self._rgb[2] / 65535.0
    
    def get_rgb(self):
        return (self.red, self.green, self.blue)
    
    red = property(get_red)
    green = property(get_green)
    blue = property(get_blue)
    rgb = property(get_rgb)
    
    def __str__(self):
        return "Color(%g,%g,%g)" % self.rgb
    
    def __repr__(self):
        return "<%s.%s _rgb=%s>" % (
            self.__class__.__module__, self.__class__.__name__,
            self._rgb)


rgb = Color

