当前位置: 首页>>代码示例>>Python>>正文


Python webcolors.css3_names_to_hex方法代码示例

本文整理汇总了Python中webcolors.css3_names_to_hex方法的典型用法代码示例。如果您正苦于以下问题:Python webcolors.css3_names_to_hex方法的具体用法?Python webcolors.css3_names_to_hex怎么用?Python webcolors.css3_names_to_hex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在webcolors的用法示例。


在下文中一共展示了webcolors.css3_names_to_hex方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: is_css3_color

# 需要导入模块: import webcolors [as 别名]
# 或者: from webcolors import css3_names_to_hex [as 别名]
def is_css3_color(instance):
        if instance.lower() in webcolors.css3_names_to_hex:
            return True
        return is_css_color_code(instance) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:6,代码来源:_format.py

示例2: style_to_wdcolor

# 需要导入模块: import webcolors [as 别名]
# 或者: from webcolors import css3_names_to_hex [as 别名]
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 
开发者ID:orf,项目名称:wordinserter,代码行数:15,代码来源:com.py

示例3: is_color

# 需要导入模块: import webcolors [as 别名]
# 或者: from webcolors import css3_names_to_hex [as 别名]
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 
开发者ID:Autodesk,项目名称:notebook-molecular-visualization,代码行数:28,代码来源:colormaps.py

示例4: translate_color

# 需要导入模块: import webcolors [as 别名]
# 或者: from webcolors import css3_names_to_hex [as 别名]
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 
开发者ID:Autodesk,项目名称:notebook-molecular-visualization,代码行数:36,代码来源:utils.py


注:本文中的webcolors.css3_names_to_hex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。