本文整理汇总了Python中webcolors.hex_to_rgb方法的典型用法代码示例。如果您正苦于以下问题:Python webcolors.hex_to_rgb方法的具体用法?Python webcolors.hex_to_rgb怎么用?Python webcolors.hex_to_rgb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类webcolors
的用法示例。
在下文中一共展示了webcolors.hex_to_rgb方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: color_object_to_tuple
# 需要导入模块: import webcolors [as 别名]
# 或者: from webcolors import hex_to_rgb [as 别名]
def color_object_to_tuple(color):
global webcolors_available
# see if it's already a color tuple
if type(color) is tuple and len(color) in [3, 4, 5]:
return color
# can't convert non-string
if type(color) is not str:
return None
color = color.strip()
if webcolors_available:
# try to convert from an english name
try:
return webcolors.name_to_rgb(color)
except ValueError:
pass
except:
pass
# try to convert an web hex code
try:
return webcolors.hex_to_rgb(webcolors.normalize_hex(color))
except ValueError:
pass
except:
pass
# try to convert a string RGB tuple
try:
val = ast.literal_eval(color)
if type(val) is not tuple or len(val) not in [3, 4, 5]:
raise Exception
return val
except:
pass
return None
示例2: closest_colour
# 需要导入模块: import webcolors [as 别名]
# 或者: from webcolors import hex_to_rgb [as 别名]
def closest_colour(requested_colour):
min_colours = {}
for key, name in webcolors.css3_hex_to_names.items():
r_c, g_c, b_c = webcolors.hex_to_rgb(key)
rd = (r_c - requested_colour[0]) ** 2
gd = (g_c - requested_colour[1]) ** 2
bd = (b_c - requested_colour[2]) ** 2
min_colours[(rd + gd + bd)] = name
return min_colours[min(min_colours.keys())]
示例3: hex_to_wdcolor
# 需要导入模块: import webcolors [as 别名]
# 或者: from webcolors import hex_to_rgb [as 别名]
def hex_to_wdcolor(value):
"""
Receive a HEX color attribute string like '#9bbb59' (or '9bbb59') and transform it to a numeric constant
in order to use it as a Selection.Font.Color attribute (as an item of WdColor enumeration)
:param value: A HEX color attribute
:return: A numeric WDCOLOR value
"""
rgbstrlst = webcolors.hex_to_rgb(value)
return int(rgbstrlst[0]) + 0x100 * int(rgbstrlst[1]) + 0x10000 * int(rgbstrlst[2])
示例4: closest_color
# 需要导入模块: import webcolors [as 别名]
# 或者: from webcolors import hex_to_rgb [as 别名]
def closest_color(requested_color):
min_colors = {}
for key, name in webcolors.css3_hex_to_names.items():
r_c, g_c, b_c = webcolors.hex_to_rgb(key)
rd = (r_c - requested_color[0]) ** 2
gd = (g_c - requested_color[1]) ** 2
bd = (b_c - requested_color[2]) ** 2
min_colors[(rd + gd + bd)] = name
return min_colors[min(min_colors.keys())]
示例5: fixedAddFunc
# 需要导入模块: import webcolors [as 别名]
# 或者: from webcolors import hex_to_rgb [as 别名]
def fixedAddFunc(self):
if self.fixedList.count() == 1:
self.error("Fixed cannot have more than one color")
else:
hex_color = pick("Color")
if hex_color is None:
return
color = "#" + hex_color.lower()
actual, closest = get_colour_name(webcolors.hex_to_rgb(color))
if not actual:
actual = closest
self.fixedList.addItem(QListWidgetItem(actual + "(" + color + ")"))
示例6: breathingAddFunc
# 需要导入模块: import webcolors [as 别名]
# 或者: from webcolors import hex_to_rgb [as 别名]
def breathingAddFunc(self):
color = "#" + pick("Color").lower()
actual, closest = get_colour_name(webcolors.hex_to_rgb(color))
if not actual:
actual = closest
self.breathingList.addItem(QListWidgetItem(actual + "(" + color + ")"))
示例7: fadingAddFunc
# 需要导入模块: import webcolors [as 别名]
# 或者: from webcolors import hex_to_rgb [as 别名]
def fadingAddFunc(self):
hex_color = pick("Color")
if hex_color is None:
return
color = "#" + hex_color.lower()
actual, closest = get_colour_name(webcolors.hex_to_rgb(color))
if not actual:
actual = closest
self.fadingList.addItem(QListWidgetItem(actual + "(" + color + ")"))
示例8: marqueeAddFunc
# 需要导入模块: import webcolors [as 别名]
# 或者: from webcolors import hex_to_rgb [as 别名]
def marqueeAddFunc(self):
if self.marqueeList.count() == 1:
self.error("Marquee cannot have more than one color")
else:
hex_color = pick("Color")
if hex_color is None:
return
color = "#" + hex_color.lower()
actual, closest = get_colour_name(webcolors.hex_to_rgb(color))
if not actual:
actual = closest
self.marqueeList.addItem(QListWidgetItem(actual + "(" + color + ")"))
示例9: pulseAddFunc
# 需要导入模块: import webcolors [as 别名]
# 或者: from webcolors import hex_to_rgb [as 别名]
def pulseAddFunc(self):
color = "#" + pick("Color").lower()
actual, closest = get_colour_name(webcolors.hex_to_rgb(color))
if not actual:
actual = closest
self.pulseList.addItem(QListWidgetItem(actual + "(" + color + ")"))
示例10: alternatingAddFunc
# 需要导入模块: import webcolors [as 别名]
# 或者: from webcolors import hex_to_rgb [as 别名]
def alternatingAddFunc(self):
if self.alternatingList.count() == 2:
self.error("Alternating cannot have more than two colors")
else:
hex_color = pick("Color")
if hex_color is None:
return
color = "#" + hex_color.lower()
actual, closest = get_colour_name(webcolors.hex_to_rgb(color))
if not actual:
actual = closest
self.alternatingList.addItem(QListWidgetItem(actual + "(" + color + ")"))
示例11: candleAddFunc
# 需要导入模块: import webcolors [as 别名]
# 或者: from webcolors import hex_to_rgb [as 别名]
def candleAddFunc(self):
if self.candleList.count() == 1:
self.error("Candle cannot have more than 1 color")
else:
hex_color = pick("Color")
if hex_color is None:
return
color = "#" + hex_color.lower()
actual, closest = get_colour_name(webcolors.hex_to_rgb(color))
if not actual:
actual = closest
self.candleList.addItem(QListWidgetItem(actual + "(" + color + ")"))
示例12: wingsAddFunc
# 需要导入模块: import webcolors [as 别名]
# 或者: from webcolors import hex_to_rgb [as 别名]
def wingsAddFunc(self):
if self.wingsList.count() == 1:
self.error("Wings cannot have more than 1 color")
else:
hex_color = pick("Color")
if hex_color is None:
return
color = "#" + hex_color.lower()
actual, closest = get_colour_name(webcolors.hex_to_rgb(color))
if not actual:
actual = closest
self.wingsList.addItem(QListWidgetItem(actual + "(" + color + ")"))
示例13: audioLevelAddFunc
# 需要导入模块: import webcolors [as 别名]
# 或者: from webcolors import hex_to_rgb [as 别名]
def audioLevelAddFunc(self):
hex_color = pick("Color")
if hex_color is None:
return
color = "#" + hex_color.lower()
actual, closest = get_colour_name(webcolors.hex_to_rgb(color))
if not actual:
actual = closest
self.audioLevelList.addItem(QListWidgetItem(actual + "(" + color + ")"))
示例14: customEditFunc
# 需要导入模块: import webcolors [as 别名]
# 或者: from webcolors import hex_to_rgb [as 别名]
def customEditFunc(self):
hex_color = pick("Color")
if hex_color is None:
return
color = "#" + hex_color.lower()
actual, closest = get_colour_name(webcolors.hex_to_rgb(color))
if not actual:
actual = closest
for widgetItem in self.customTable.selectedItems():
if widgetItem.column() != 0:
widgetItem.setText(actual + "(" + color + ")")
widgetItem.setBackground(QColor(*webcolors.hex_to_rgb(color)))
示例15: populateAnimated
# 需要导入模块: import webcolors [as 别名]
# 或者: from webcolors import hex_to_rgb [as 别名]
def populateAnimated(self):
actual, closest = get_colour_name(webcolors.hex_to_rgb('#FFFFFF'))
if not actual:
actual = closest
for i in range(40):
self.animatedTable.setItem(i, 0, QTableWidgetItem(str(i+1)))
self.animatedTable.setItem(i, 1, QTableWidgetItem(actual + '(#FFFFFF)'))