Skip to content

Commit 14feb27

Browse files
authored
feat: add multi-frame support πŸŽ‰ (#267)
1 parent 9a5bb56 commit 14feb27

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

β€ŽREADME.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ Tkinter Designer uses the Figma API to analyze a design file and create the resp
3535

3636
<img width="500" alt="Tkinter Designer GUI" src="https://user-images.githubusercontent.com/42001064/119863796-92af4a80-bf37-11eb-9f6c-61b1ab99b039.png">
3737

38+
## πŸ“’ Announcement
39+
### πŸŽ‰ Multi frame support is here! πŸŽ‰
40+
41+
You can now create multiple frames in a single design file and Tkinter Designer will create the respective code and files for each frame. This is a huge step for Tkinter Designer and I'm really excited to see what you guys create with it.
42+
43+
Feel free to share your creations with the community on [Discord](https://discord.gg/QfE5jMXxJv).
44+
45+
If you encounter any bugs or have any suggestions, please create an issue [here](https://github.com/ParthJadhav/Tkinter-Designer).
3846
## β˜„οΈ Advantages of Tkinter Designer
3947

4048
1. Interfaces with drag and drop.

β€Žtkdesigner/designer.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,34 @@
55

66
from pathlib import Path
77

8-
9-
CODE_FILE_NAME = "gui.py"
10-
11-
128
class Designer:
139
def __init__(self, token, file_key, output_path: Path):
1410
self.output_path = output_path
1511
self.figma_file = endpoints.Files(token, file_key)
1612
self.file_data = self.figma_file.get_file()
13+
self.frameCounter = 0
1714

1815
def to_code(self) -> str:
1916
"""Return main code.
2017
"""
21-
window_data = self.file_data["document"]["children"][0]["children"][0]
22-
try:
23-
frame = Frame(window_data, self.figma_file, self.output_path)
24-
except Exception:
25-
raise Exception("Frame not found in figma file or is empty")
26-
return frame.to_code(TEMPLATE)
18+
frames = [];
19+
for f in self.file_data["document"]["children"][0]["children"]:
20+
try:
21+
frame = Frame(f, self.figma_file, self.output_path, self.frameCounter)
22+
except Exception:
23+
raise Exception("Frame not found in figma file or is empty")
24+
frames.append(frame.to_code(TEMPLATE))
25+
self.frameCounter += 1
26+
return frames
27+
2728

2829
def design(self):
2930
"""Write code and assets to the specified directories.
3031
"""
3132
code = self.to_code()
32-
self.output_path.joinpath(CODE_FILE_NAME).write_text(code, encoding='UTF-8')
33+
for index in range(len(code)):
34+
# tutorials on youtube mention `python3 gui.py` added the below check to keep them valid
35+
if (index == 0):
36+
self.output_path.joinpath(f"gui.py").write_text(code[index], encoding='UTF-8')
37+
else:
38+
self.output_path.joinpath(f"gui{index}.py").write_text(code[index], encoding='UTF-8')

β€Žtkdesigner/figma/custom_elements.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ def to_code(self):
158158
entry_{self.id_} = {self.entry_type}(
159159
bd=0,
160160
bg="{self.bg_color}",
161+
fg="#000716",
161162
highlightthickness=0
162163
)
163164
entry_{self.id_}.place(

β€Žtkdesigner/figma/frame.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
class Frame(Node):
13-
def __init__(self, node, figma_file, output_path):
13+
def __init__(self, node, figma_file, output_path, frameCount=0):
1414
super().__init__(node)
1515

1616
self.width, self.height = self.size()
@@ -21,7 +21,7 @@ def __init__(self, node, figma_file, output_path):
2121
self.figma_file = figma_file
2222

2323
self.output_path: Path = output_path
24-
self.assets_path: Path = output_path / ASSETS_PATH
24+
self.assets_path: Path = output_path / ASSETS_PATH / f"frame{frameCount}"
2525

2626
self.output_path.mkdir(parents=True, exist_ok=True)
2727
self.assets_path.mkdir(parents=True, exist_ok=True)
@@ -123,7 +123,7 @@ def size(self) -> tuple:
123123
def to_code(self, template):
124124
t = Template(template)
125125
return t.render(
126-
window=self, elements=self.elements, assets_path=ASSETS_PATH)
126+
window=self, elements=self.elements, assets_path=self.assets_path)
127127

128128

129129
# Frame Subclasses

0 commit comments

Comments
Β (0)