Takes an "R,G,B" string or wx.Color and returns a matching xlwt
        color.
491329
def match_color_index(self, color):
        
        from jcvi.utils.webcolors import color_diff
        if isinstance(color, int):
            return color
        if color:
            if isinstance(color, six.string_types):
                rgb = map(int, color.split(','))
            else:
                rgb = color.Get()
            logging.disable(logging.DEBUG)
            distances = [color_diff(rgb, x) for x in self.xlwt_colors]
            logging.disable(logging.NOTSET)
            result = distances.index(min(distances))
            self.unused_colors.discard(self.xlwt_colors[result])
            return result
301180
def is_color(color):
    
    if not isinstance(color, basestring):
        return False
    elif RGB_HEX_REGEX.match(color):
        return True
    elif color in COLOR_ALIASES:
        return True
    elif color in cnames:
        return True
    return False
173132
def bgblue(cls, string, auto=False):
        
        return cls.colorize('bgblue', string, auto=auto)
212781
def _get_color(color):
        
        color = str(color).replace("#", "")
        qcolor = QtGui.QColor()
        qcolor.setRgb(int(color[:2], base=16),
                      int(color[2:4], base=16),
                      int(color[4:6], base=16))
        return qcolor
379032
def hex2rgb(hexvalue):
    """"""

    # Make sure a possible '#' char is eliminated
    # before processing the color.
    if ('#' in hexvalue):
        hexcolor = hexvalue.replace('#', '')
    else:
        hexcolor = hexvalue

    # Hex colors have a fixed length of 6 characters excluding the '#'
    # TODO: Include custom exception here, even if it should never happen.
    if (len(hexcolor) != 6):
        print ("Unexpected length of hex color value.\nSix characters excluding \'#\' expected.")
        return 0

    # Convert each two characters of
    # the hex to an RGB color value.
    r = int(hexcolor[0:2], HEX_BASE)
    g = int(hexcolor[2:4], HEX_BASE)
    b = int(hexcolor[4:6], HEX_BASE)

    return r, g, b
192441
def parse_color(color):
    
    if color is None:
        color = rcParams['color']
    if isinstance(color, str):
        return vtki.string_to_rgb(color)
    elif len(color) == 3:
        return color
    else:
        raise Exception("""
    Invalid color input
    Must ba string, rgb list, or hex color string.  For example:
        color='white'
        color='w'
        color=[1, 1, 1]
        color='#FFFFFF'""")
1329943
def _get_pattern(self, pys_style):
        """"""

        # Return None if there is no bgcolor
        if "bgcolor" not in pys_style:
            return

        pattern = xlwt.Pattern()
        pattern.pattern = xlwt.Pattern.SOLID_PATTERN

        bgcolor = wx.Colour()
        bgcolor.SetRGB(pys_style["bgcolor"])
        pattern.pattern_fore_colour = self.color2idx(*bgcolor.Get())

        return pattern
184963
def htmlcolor_to_rgb(str_color):
    
    if not (str_color.startswith('#') and len(str_color) == 7):
        raise ValueError("Bad html color format. Expected: '#RRGGBB' ")
    result = [1.0 * int(n, 16) / 255 for n in (str_color[1:3], str_color[3:5], str_color[5:])]
    return result
342481
def _string_to_rgb(color):
    """"""
    if not color.startswith('#'):
        if color.lower() not in _color_dict:
            raise ValueError('Color "%s" unknown' % color)
        color = _color_dict[color]
        assert color[0] == '#'
    # hex color
    color = color[1:]
    lc = len(color)
    if lc in (3, 4):
        color = ''.join(c + c for c in color)
        lc = len(color)
    if lc not in (6, 8):
        raise ValueError('Hex color must have exactly six or eight '
                         'elements following the # sign')
    color = np.array([int(color[i:i+2], 16) / 255. for i in range(0, lc, 2)])
    return color
435069
def _highlight(string, color):
	''''''
	if CONFIG['color']:
		if color < 8:
			return '\033[{color}m{string}\033[0m'.format(string = string, color = color+30)
		else:
			return '\033[{color}m{string}\033[0m'.format(string = string, color = color+82)
	else:
		return string
1308676
def get_wbfmt(self, data_nt=None):
        """"""
        if data_nt is None or self.b_plain:
            return self.fmtname2wbfmtobj.get('plain')
        # User namedtuple field/value for color
        if self.ntfld_wbfmt is not None:
            return self.__get_wbfmt_usrfld(data_nt)
        # namedtuple format_txt for color/bold/border
        if self.b_format_txt:
            wbfmt = self.__get_wbfmt_format_txt(data_nt)
            if wbfmt is not None:
                return wbfmt
        # 'ntfld_wbfmt': namedtuple field which contains a value used as a key for a xlsx format
        # 'ntval2wbfmtdict': namedtuple value and corresponding xlsx format dict.
        return self.fmtname2wbfmtobj.get('plain')
1095910
def parse_colors(s, length=1):
    '''
    '''
    if length and length > 1:
        return parse_ctuple(s,length=length);
    if re.match('^ *{} *$'.format(isrx_s), s):
        #it's just a string.
        return [s];
    elif re.match('^ *{} *$'.format(rgbrx_s), s):
        return [eval(s)];
    else:
        return parse_ctuple(s,length=length);
1297016
def bgwhite(cls, string, auto=False):
        
        return cls.colorize('bgwhite', string, auto=auto)
491508
def string2rgba(cls, colorstring):
        
        colorstring = colorstring.strip()
        if colorstring[0] == '#':
            colorstring = colorstring[1:]
        if len(colorstring) < 6:
            raise ValueError("input #%s is not in #RRGGBB format" % colorstring)
        r, g, b = colorstring[:2], colorstring[2:4], colorstring[4:6]
        a = 'ff'
        if len(colorstring) > 6:
            a = colorstring[6:8]
        r, g, b, a = [int(n, 16) for n in (r, g, b, a)]
        return (r, g, b, a)
248762
def hexcolor(color):
    " "
    # first, if this is a hex color already, return!
    # Python 3: needs rewrite for str/unicode change
    if isinstance(color, six.string_types):
        if color[0] == '#' and len(color)==7:
            return color.lower()

    # now, get color to an rgb tuple
    rgb = (0,0,0)
    if isinstance(color, tuple):
        rgb = color
    elif isinstance(color, list):
        rgb = tuple(color)
    elif isinstance(color, six.string_types):
        c = color.lower()
        if c.find(' ')>-1:    c = c.replace(' ','')
        if c.find('gray')>-1: c = c.replace('gray','grey')
        if c in x11_colors:
            rgb = x11_colors[c]
    else:
        try:
            rgb = color.Red(), color.Green(), color.Blue()
        except:
            pass

    # convert rgb to hex color
    col = '#%02x%02x%02x' % (rgb)
    return col.lower()
767669
public static final String rgbToBrowserHexColor(final int r, final int g, final int b)
    {
        return "#" + toBrowserHexValue(r) + toBrowserHexValue(g) + toBrowserHexValue(b);
    }
745273
def rgb_to_hsv(r, g, b):
    """"""
    h, s, v = colorsys.rgb_to_hsv(r / 255., g / 255., b / 255.)
    return round2(h * 360), round2(s * 100), round2(v * 100)