Skip to content

Commit 1223fb9

Browse files
authored
Fix invalid hex color error.
Patched hex color when hex is a single digit
2 parents 9b3967e + c2c3ed1 commit 1223fb9

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

tkdesigner/figma/frame.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ def color(self) -> str:
104104
"""
105105
try:
106106
color = self.node["fills"][0]["color"]
107-
rgba = [int(color.get(i, 0) * 255) for i in "rgba"]
108-
return f"#{rgba[0]:0X}{rgba[1]:0X}{rgba[2]:0X}"
107+
r, g, b, *_ = [int(color.get(i, 0) * 255) for i in "rgba"]
108+
return f"#{r:02X}{g:02X}{b:02X}"
109109
except Exception:
110110
return "#FFFFFF"
111111

tkdesigner/figma/vector_elements.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ class Vector(Node):
55
def __init__(self, node):
66
super().__init__(node)
77

8-
def color(self):
8+
def color(self) -> str:
9+
"""Returns HEX form of element RGB color (str)
10+
"""
911
try:
1012
color = self.node["fills"][0]["color"]
11-
rgba = [int(color.get(i, 0) * 255) for i in "rgba"]
12-
# return tuple(rgba)
13-
return f"#{rgba[0]:0X}{rgba[1]:0X}{rgba[2]:0X}"
13+
r, g, b, *_ = [int(color.get(i, 0) * 255) for i in "rgba"]
14+
return f"#{r:02X}{g:02X}{b:02X}"
1415
except Exception:
1516
return "#FFFFFF"
1617

0 commit comments

Comments
 (0)