#
#   Python GUI - Colors - Gtk
#

from gtk import gdk
from GColors import Color as GColor

class Color(GColor):
    """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 _from_gdk_color(cls, _gdk_color):
        c = cls.__new__(cls)
        c._gdk_color = _gdk_color
        return c
    
    _from_gdk_color = classmethod(_from_gdk_color)

    def __init__(self, red, green, blue):
        gdk_color = gdk.Color()
        gdk_color.red = int(red * 65535)
        gdk_color.green = int(green * 65535)
        gdk_color.blue = int(blue * 65535)
        self._gdk_color = gdk_color
    
    def get_red(self):
        return self._gdk_color.red / 65535.0
    
    def get_green(self):
        return self._gdk_color.green / 65535.0

    def get_blue(self):
        return self._gdk_color.blue / 65535.0
    
    def __str__(self):
        return "Color(%g,%g,%g)" % self.rgb
    
#	def __repr__(self):
#		return "<%s.%s 0x%04X,0x%04X,0x%04X>" % (
#			self.__class__.__module__, self.__class__.__name__,
#			self._gdk_color.red, self._gdk_color.green, self._gdk_color.blue)


rgb = Color

