From 14feb27439c29fa76c45f3db9522849f61498686 Mon Sep 17 00:00:00 2001 From: Parth Jadhav Date: Sun, 30 Oct 2022 22:05:59 +0530 Subject: [PATCH] =?UTF-8?q?feat:=20add=20multi-frame=20support=20?= =?UTF-8?q?=F0=9F=8E=89=20(#267)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 8 ++++++++ tkdesigner/designer.py | 28 +++++++++++++++++----------- tkdesigner/figma/custom_elements.py | 1 + tkdesigner/figma/frame.py | 6 +++--- 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index f87d8461..e68acc63 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,14 @@ Tkinter Designer uses the Figma API to analyze a design file and create the resp Tkinter Designer GUI +## 📢 Announcement +### 🎉 Multi frame support is here! 🎉 + +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. + +Feel free to share your creations with the community on [Discord](https://discord.gg/QfE5jMXxJv). + +If you encounter any bugs or have any suggestions, please create an issue [here](https://github.com/ParthJadhav/Tkinter-Designer). ## ☄️ Advantages of Tkinter Designer 1. Interfaces with drag and drop. diff --git a/tkdesigner/designer.py b/tkdesigner/designer.py index 47e9ec73..c3d65c40 100644 --- a/tkdesigner/designer.py +++ b/tkdesigner/designer.py @@ -5,28 +5,34 @@ from pathlib import Path - -CODE_FILE_NAME = "gui.py" - - class Designer: def __init__(self, token, file_key, output_path: Path): self.output_path = output_path self.figma_file = endpoints.Files(token, file_key) self.file_data = self.figma_file.get_file() + self.frameCounter = 0 def to_code(self) -> str: """Return main code. """ - window_data = self.file_data["document"]["children"][0]["children"][0] - try: - frame = Frame(window_data, self.figma_file, self.output_path) - except Exception: - raise Exception("Frame not found in figma file or is empty") - return frame.to_code(TEMPLATE) + frames = []; + for f in self.file_data["document"]["children"][0]["children"]: + try: + frame = Frame(f, self.figma_file, self.output_path, self.frameCounter) + except Exception: + raise Exception("Frame not found in figma file or is empty") + frames.append(frame.to_code(TEMPLATE)) + self.frameCounter += 1 + return frames + def design(self): """Write code and assets to the specified directories. """ code = self.to_code() - self.output_path.joinpath(CODE_FILE_NAME).write_text(code, encoding='UTF-8') + for index in range(len(code)): + # tutorials on youtube mention `python3 gui.py` added the below check to keep them valid + if (index == 0): + self.output_path.joinpath(f"gui.py").write_text(code[index], encoding='UTF-8') + else: + self.output_path.joinpath(f"gui{index}.py").write_text(code[index], encoding='UTF-8') diff --git a/tkdesigner/figma/custom_elements.py b/tkdesigner/figma/custom_elements.py index 652fa234..6980f6a4 100644 --- a/tkdesigner/figma/custom_elements.py +++ b/tkdesigner/figma/custom_elements.py @@ -158,6 +158,7 @@ def to_code(self): entry_{self.id_} = {self.entry_type}( bd=0, bg="{self.bg_color}", + fg="#000716", highlightthickness=0 ) entry_{self.id_}.place( diff --git a/tkdesigner/figma/frame.py b/tkdesigner/figma/frame.py index 3f0fd1f8..70e3611f 100644 --- a/tkdesigner/figma/frame.py +++ b/tkdesigner/figma/frame.py @@ -10,7 +10,7 @@ class Frame(Node): - def __init__(self, node, figma_file, output_path): + def __init__(self, node, figma_file, output_path, frameCount=0): super().__init__(node) self.width, self.height = self.size() @@ -21,7 +21,7 @@ def __init__(self, node, figma_file, output_path): self.figma_file = figma_file self.output_path: Path = output_path - self.assets_path: Path = output_path / ASSETS_PATH + self.assets_path: Path = output_path / ASSETS_PATH / f"frame{frameCount}" self.output_path.mkdir(parents=True, exist_ok=True) self.assets_path.mkdir(parents=True, exist_ok=True) @@ -123,7 +123,7 @@ def size(self) -> tuple: def to_code(self, template): t = Template(template) return t.render( - window=self, elements=self.elements, assets_path=ASSETS_PATH) + window=self, elements=self.elements, assets_path=self.assets_path) # Frame Subclasses