本文整理汇总了Python中webcolors.name_to_rgb方法的典型用法代码示例。如果您正苦于以下问题:Python webcolors.name_to_rgb方法的具体用法?Python webcolors.name_to_rgb怎么用?Python webcolors.name_to_rgb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类webcolors
的用法示例。
在下文中一共展示了webcolors.name_to_rgb方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: convert_color
# 需要导入模块: import webcolors [as 别名]
# 或者: from webcolors import name_to_rgb [as 别名]
def convert_color(c):
rgb = c
# Check for hex string
try:
rgb = hex_to_rgb(rgb)
except (TypeError, ValueError):
pass
# Check for named color
if have_webcolors:
try:
rgb = webcolors.name_to_rgb(rgb)
except AttributeError:
pass
# Restrict to valid range
rgb = tuple(0 if c < 0 else 255 if c > 255 else c for c in rgb)
return rgb
示例2: Color
# 需要导入模块: import webcolors [as 别名]
# 或者: from webcolors import name_to_rgb [as 别名]
def Color(name):
"""Return BGR value for given color name"""
return webcolors.name_to_rgb(name)[::-1]
示例3: color_object_to_tuple
# 需要导入模块: import webcolors [as 别名]
# 或者: from webcolors import name_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
示例4: color_to_rgb
# 需要导入模块: import webcolors [as 别名]
# 或者: from webcolors import name_to_rgb [as 别名]
def color_to_rgb(color):
import webcolors
if color == 'none' or isinstance(color, (list, tuple)):
rgb = color
elif re.match('#', color):
rgb = webcolors.hex_to_rgb(color)
else:
rgb = webcolors.name_to_rgb(color)
return rgb
示例5: color_object_to_tuple
# 需要导入模块: import webcolors [as 别名]
# 或者: from webcolors import name_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) == 3:
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) != 3:
raise Exception
return val
except:
pass
return None
示例6: _do_dose_drink
# 需要导入模块: import webcolors [as 别名]
# 或者: from webcolors import name_to_rgb [as 别名]
def _do_dose_drink(self, msg):
debug("start dosing drink")
id = int(msg.payload)
drink = drinks.available_drinks[id - 1]
# Return ID of drink to identify that drink creation starts
self.client.publish(self.get_returnTopic(msg.topic), msg.payload)
progress = 0
self.client.publish(self.get_progressTopic(msg.topic), progress)
steps = 100 / len(drink["recipe"])
if self.LED:
if "color" in drink.keys():
self.hector.dosedrink(color=webcolors.name_to_rgb(drink["color"]))
else:
self.hector.dosedrink()
if self.client.want_write():
self.client.loop_write()
self.hector.light_on()
self.hector.arm_out()
debug("dose drink preparation complete")
for step in drink["recipe"]:
debug("dosing progress: " + str(progress))
if step[0] == "ingr":
pump = drinks.available_ingredients.index(step[1])
self.hector.valve_dose(index=int(pump), amount=int(step[2]), cback=self.dose_callback, progress=(progress, steps), topic="Hector9000/doseDrink/progress")
self.client.publish(self.get_progressTopic(msg.topic), progress + steps)
if self.client.want_write():
self.client.loop_write()
progress = progress + steps
debug("dosing drink finished")
if self.LED: self.hector.drinkfinish()
time.sleep(1)
self.hector.arm_in()
self.hector.light_off()
self.hector.ping(3, 0)
debug("reset hardware")
self.client.publish(self.get_progressTopic(msg.topic), "end", qos=1)
while not self.client.want_write():
pass
self.client.loop_write()