Python webcolors.css3_names_to_hex() Examples

The following are 12 code examples of webcolors.css3_names_to_hex(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module webcolors , or try the search function .
Example #1
Source File: _format.py    From misp42splunk with GNU Lesser General Public License v3.0 5 votes vote down vote up
def is_css3_color(instance):
        if instance.lower() in webcolors.css3_names_to_hex:
            return True
        return is_css_color_code(instance) 
Example #2
Source File: _format.py    From misp42splunk with GNU Lesser General Public License v3.0 5 votes vote down vote up
def is_css3_color(instance):
        if instance.lower() in webcolors.css3_names_to_hex:
            return True
        return is_css_color_code(instance) 
Example #3
Source File: _format.py    From core with MIT License 5 votes vote down vote up
def is_css3_color(instance):
        if instance.lower() in webcolors.css3_names_to_hex:
            return True
        return is_css_color_code(instance) 
Example #4
Source File: _format.py    From deepWordBug with Apache License 2.0 5 votes vote down vote up
def is_css3_color(instance):
        if instance.lower() in webcolors.css3_names_to_hex:
            return True
        return is_css_color_code(instance) 
Example #5
Source File: com.py    From wordinserter with MIT License 5 votes vote down vote up
def style_to_wdcolor(value):
        if value == 'none':
            return None

        try:
            if value.startswith('rgb('):
                value = WordFormatter.rgbstring_to_hex(value)
            elif value in webcolors.css3_names_to_hex:
                value = webcolors.css3_names_to_hex[value]

            return WordFormatter.hex_to_wdcolor(value)
        except Exception:
            return None 
Example #6
Source File: _format.py    From accelerated-data-lake with Apache License 2.0 5 votes vote down vote up
def is_css3_color(instance):
        if instance.lower() in webcolors.css3_names_to_hex:
            return True
        return is_css_color_code(instance) 
Example #7
Source File: _format.py    From Requester with MIT License 5 votes vote down vote up
def is_css3_color(instance):
        if instance.lower() in webcolors.css3_names_to_hex:
            return True
        return is_css_color_code(instance) 
Example #8
Source File: _format.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def is_css3_color(instance):
        if instance.lower() in webcolors.css3_names_to_hex:
            return True
        return is_css_color_code(instance) 
Example #9
Source File: colormaps.py    From notebook-molecular-visualization with Apache License 2.0 5 votes vote down vote up
def is_color(s):
    """ Do our best to determine if "s" is a color spec that can be converted to hex

    Args:
        s (str or int): string or integer describing a color

    Returns:
        bool: True if this can be converted to a hex-compatible color
    """
    def in_range(i): return 0 <= i <= int('0xFFFFFF', 0)

    try:
        if type(s) == int:
            return in_range(s)
        elif type(s) not in (str, bytes):
            return False
        elif s in webcolors.css3_names_to_hex:
            return True
        elif s[0] == '#':
            return in_range(int('0x' + s[1:], 0))
        elif s[0:2] == '0x':
            return in_range(int(s, 0))
        elif len(s) == 6:
            return in_range(int('0x' + s, 0))
    except ValueError:
        return False 
Example #10
Source File: utils.py    From notebook-molecular-visualization with Apache License 2.0 5 votes vote down vote up
def translate_color(color, prefix='0x'):
    """ Return a normalized for a given color, specified as hex or as a CSS3 color name.

    Args:
        color (int or str): can be an integer, hex code (with or without '0x' or '#'), or
            css3 color name
        prefix (str): prepend the raw hex string with this (usually '#' or '0x')

    Returns:
        str: hex string of the form '0x123abc'
    """
    formatter = prefix + '{:06x}'

    if isinstance(color, basestring):
        if color.lower() in webcolors.css3_names_to_hex:
            color = webcolors.css3_names_to_hex[color.lower()]

        if len(color) == 7 and color[0] == '#':  # hex that starts with '#'
            color = color[1:]
        elif len(color) == 8 and color[0:2] == '0x':  # hex str that starts with '0x'
            color = color[2:]

        if len(color) == 6:  # hex without prefix
            color = prefix + color
        else:
            raise ValueError('Failed to translate color %s' % color)

    elif isinstance(color, int):
        color = formatter.format(color)

    else:
        raise ValueError('Unrecognized color %s of type %s' % (color, type(color)))

    return color 
Example #11
Source File: _format.py    From SA-ctf_scoreboard with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
def is_css3_color(instance):
        if instance.lower() in webcolors.css3_names_to_hex:
            return True
        return is_css_color_code(instance) 
Example #12
Source File: _format.py    From pyblish-qml with GNU Lesser General Public License v3.0 5 votes vote down vote up
def is_css3_color(instance):
        if instance.lower() in webcolors.css3_names_to_hex:
            return True
        return is_css_color_code(instance)