allow hex colors without leading #

This commit is contained in:
Denis Lehmann 2021-04-28 17:30:00 +02:00
parent e9a205e812
commit 06234ed222
3 changed files with 11 additions and 6 deletions

View file

@ -39,7 +39,12 @@ def get_color_tuple(color_string):
try:
color = Color(color_string).rgb
except:
raise Exception("'{}' is not a valid color".format(color_string))
# Try again with leading #
try:
color = Color("#{}".format(color_string)).rgb
except:
raise Exception("'{}' is not a valid color".format(color_string))
# Scale RGB tuple from [0, 1] to [0, 255]
color_tuple = tuple(map(lambda x: int(x * 255), color))