Skip to content

Commit

Permalink
fix: color parsing issue #29
Browse files Browse the repository at this point in the history
  • Loading branch information
AXeL-dev committed Sep 23, 2022
1 parent 9841a98 commit 7b0151f
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,14 @@ def parse_key(key):

# Parse color string, e.: '(255, 255, 255)'
def parse_color(color, as_hex=False):
if type(color) is tuple:
return rgb2hex(color) if as_hex else color
# check if RGB
if color.startswith('(') and color.endswith(')'):
elif color.startswith('(') and color.endswith(')'):
values = color[1:-1].split(',') # [1:-1] will remove the first & last parentheses '(' ')'
if len(values) == 3:
rgb = (int(values[0]), int(values[1]), int(values[2]))
if as_hex:
return rgb2hex(rgb)
else:
return rgb
return rgb2hex(rgb) if as_hex else rgb
else:
return None
# check if HEX
Expand Down

0 comments on commit 7b0151f

Please sign in to comment.