Skip to content

Commit

Permalink
Patched hex color when hex is a single digit
Browse files Browse the repository at this point in the history
  • Loading branch information
saur0x committed Aug 1, 2021
1 parent 9b3967e commit c2c3ed1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions tkdesigner/figma/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ def color(self) -> str:
"""
try:
color = self.node["fills"][0]["color"]
rgba = [int(color.get(i, 0) * 255) for i in "rgba"]
return f"#{rgba[0]:0X}{rgba[1]:0X}{rgba[2]:0X}"
r, g, b, *_ = [int(color.get(i, 0) * 255) for i in "rgba"]
return f"#{r:02X}{g:02X}{b:02X}"
except Exception:
return "#FFFFFF"

Expand Down
9 changes: 5 additions & 4 deletions tkdesigner/figma/vector_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ class Vector(Node):
def __init__(self, node):
super().__init__(node)

def color(self):
def color(self) -> str:
"""Returns HEX form of element RGB color (str)
"""
try:
color = self.node["fills"][0]["color"]
rgba = [int(color.get(i, 0) * 255) for i in "rgba"]
# return tuple(rgba)
return f"#{rgba[0]:0X}{rgba[1]:0X}{rgba[2]:0X}"
r, g, b, *_ = [int(color.get(i, 0) * 255) for i in "rgba"]
return f"#{r:02X}{g:02X}{b:02X}"
except Exception:
return "#FFFFFF"

Expand Down

0 comments on commit c2c3ed1

Please sign in to comment.