def __init__(self, *args, **kwargs):

        """ Color object with string input and adjustment methods.

        Accepts strings that are (or resemble) named colors, hex strings,
        RGB, CMYK, HSB and Lab values.

        You can supply a "name" parameter.
        Other valid named parameters are "mode" and "range",
        which default to the state colormode and color range.

        """

        self.name = ""

        RGB = Bot.RGB
        HSB = Bot.HSB
        mode, range = _ctx.color_mode, _ctx.color_range
        modes = [RGB, HSB]

        # One string parameter,
        # either hexadecimal color key
        # or a named color or descriptive word.
        if len(args) == 1 \
                and isinstance(args[0], (str, unicode)):
            if args[0].startswith("#"):
                r, g, b = hex_to_rgb(args[0])
                a = 1.0
            else:
                v = self.str_to_rgb(args[0])
                if len(v) == 3:
                    r, g, b = v
                    a = 1.0
                else:
                    r, g, b, a = v
                self.name = args[0]

            _ctx.colormode(RGB, 1.0)
            BaseColor.__init__(self, r, g, b, a, mode='rgb', color_range=1.0)

        # One color object parameter.
        elif len(args) == 1 \
                and isinstance(args[0], BaseColor):

            _ctx.colormode(RGB, 1.0)
            BaseColor.__init__(self, args[0].r, args[0].g, args[0].b, args[0].a, mode='rgb', color_range=1.0)

        # Lab color values.
        elif kwargs.has_key("mode") \
                and kwargs["mode"].lower() == "lab":
            if kwargs.has_key("l") and \
                    kwargs.has_key("a") and \
                    kwargs.has_key("b"):
                r, g, b = lab_to_rgb(kwargs["l"], kwargs["a"], kwargs["b"])
            else:
                r, g, b = lab_to_rgb(*args)

            _ctx.colormode(RGB, 1.0)
            BaseColor.__init__(self, r, g, b, 1, mode='rgb', color_range=1.0)


        # RGB, HSB or CMYK color values.
        elif (kwargs.has_key("mode") \
              and kwargs["mode"].lower() in modes) \
                or mode in modes:
            m, ra = mode, range
            if kwargs.has_key("mode"): m = kwargs["mode"]
            if kwargs.has_key("color_range"):
                ra = kwargs["color_range"]
            else:
                ra = 1.0

            if m == "hsb":
                if kwargs.has_key("h") and \
                        kwargs.has_key("s") and \
                        kwargs.has_key("v"):
                    r, g, b = hsv_to_rgb(kwargs["h"], kwargs["s"], kwargs["v"])
                else:
                    h, s, l, a = (args)
                    r, g, b = hsv_to_rgb(h, s, l)
            elif m == "rgb":
                if kwargs.has_key("r") and \
                        kwargs.has_key("g") and \
                        kwargs.has_key("b"):
                    r, g, b = kwargs["r"], kwargs["g"], kwargs["b"]
                else:
                    if len(args) == 3:
                        r, g, b = args
                        a = 1.0
                    else:
                        r, g, b, a = (args)

                _ctx.colormode(RGB, ra)
                BaseColor.__init__(self, r, g, b, a, mode='rgb', color_range=ra)

        if kwargs.has_key("name") and kwargs["name"] != "":
            self.name = kwargs["name"]
        elif self.name == "":
            self.name = self.nearest_hue()

        # Reset the state.
        _ctx.colormode(mode, range)
def __init__ ( self , * args , ** kwargs ) : self . name = "" RGB = Bot . RGB HSB = Bot . HSB mode , range = _ctx . color_mode , _ctx . color_range modes = [ RGB , HSB ] if len ( args ) == 1 and isinstance ( args [ 0 ] , ( str , unicode ) ) : if args [ 0 ] . startswith ( "#" ) : r , g , b = hex_to_rgb ( args [ 0 ] ) a = 1.0 else : v = self . str_to_rgb ( args [ 0 ] ) if len ( v ) == 3 : r , g , b = v a = 1.0 else : r , g , b , a = v self . name = args [ 0 ] _ctx . colormode ( RGB , 1.0 ) BaseColor . __init__ ( self , r , g , b , a , mode = 'rgb' , color_range = 1.0 ) elif len ( args ) == 1 and isinstance ( args [ 0 ] , BaseColor ) : _ctx . colormode ( RGB , 1.0 ) BaseColor . __init__ ( self , args [ 0 ] . r , args [ 0 ] . g , args [ 0 ] . b , args [ 0 ] . a , mode = 'rgb' , color_range = 1.0 ) elif kwargs . has_key ( "mode" ) and kwargs [ "mode" ] . lower ( ) == "lab" : if kwargs . has_key ( "l" ) and kwargs . has_key ( "a" ) and kwargs . has_key ( "b" ) : r , g , b = lab_to_rgb ( kwargs [ "l" ] , kwargs [ "a" ] , kwargs [ "b" ] ) else : r , g , b = lab_to_rgb ( * args ) _ctx . colormode ( RGB , 1.0 ) BaseColor . __init__ ( self , r , g , b , 1 , mode = 'rgb' , color_range = 1.0 ) elif ( kwargs . has_key ( "mode" ) and kwargs [ "mode" ] . lower ( ) in modes ) or mode in modes : m , ra = mode , range if kwargs . has_key ( "mode" ) : m = kwargs [ "mode" ] if kwargs . has_key ( "color_range" ) : ra = kwargs [ "color_range" ] else : ra = 1.0 if m == "hsb" : if kwargs . has_key ( "h" ) and kwargs . has_key ( "s" ) and kwargs . has_key ( "v" ) : r , g , b = hsv_to_rgb ( kwargs [ "h" ] , kwargs [ "s" ] , kwargs [ "v" ] ) else : h , s , l , a = ( args ) r , g , b = hsv_to_rgb ( h , s , l ) elif m == "rgb" : if kwargs . has_key ( "r" ) and kwargs . has_key ( "g" ) and kwargs . has_key ( "b" ) : r , g , b = kwargs [ "r" ] , kwargs [ "g" ] , kwargs [ "b" ] else : if len ( args ) == 3 : r , g , b = args a = 1.0 else : r , g , b , a = ( args ) _ctx . colormode ( RGB , ra ) BaseColor . __init__ ( self , r , g , b , a , mode = 'rgb' , color_range = ra ) if kwargs . has_key ( "name" ) and kwargs [ "name" ] != "" : self . name = kwargs [ "name" ] elif self . name == "" : self . name = self . nearest_hue ( ) _ctx . colormode ( mode , range )
Color object with string input and adjustment methods.

        Accepts strings that are (or resemble) named colors, hex strings,
        RGB, CMYK, HSB and Lab values.

        You can supply a "name" parameter.
        Other valid named parameters are "mode" and "range",
        which default to the state colormode and color range.