diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..df45c41 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +patreon: axorax \ No newline at end of file diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..5e7dbc9 --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,30 @@ +name: Check + +on: + push: + +jobs: + check-files: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Check if required files exist or not + id: check_files + run: | + missing_files=() + [ ! -f tk.py ] && missing_files+=("tk.py") + [ ! -f README.md ] && missing_files+=("README.md") + [ ! -f tkforge.py ] && missing_files+=("tkforge.py") + [ ! -f gui.py ] && missing_files+=("gui.py") + [ ! -f CONTRIBUTING.md ] && missing_files+=("CONTRIBUTING.md") + [ ! -f requirements.txt ] && missing_files+=("requirements.txt") + [ ! -f CODE_OF_CONDUCT.md ] && missing_files+=("CODE_OF_CONDUCT.md") + + if [ ${#missing_files[@]} -ne 0 ]; then + echo "❌ Missing files: ${missing_files[@]}" + exit 1 + else + echo "✅ All required files exist." + fi \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..621c5db --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +# Folders + +.env/ +env/ +dist/ +build/ +TkForge/ +__pycache__/ +test/ + +# Files + +main.py +*.spec +*.txt \ No newline at end of file diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..ceca6e9 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,22 @@ +# Contributor Code of Conduct + +As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. + +We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality. + +Examples of unacceptable behavior by participants include: + +- The use of sexualized language or imagery +- Personal attacks +- Trolling or insulting/derogatory comments +- Public or private harassment +- Publishing other's private information, such as physical or electronic addresses, without explicit permission +- Other unethical or unprofessional conduct + +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team. + +This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers. + +This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org), version 1.2.0, available at https://www.contributor-covenant.org/version/1/2/0/code-of-conduct.html diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..e412642 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,9 @@ +# Guidelines for contributing to TkForge + +Your pull request will not be accepted if it falls into any one of the categories below: + +- Just a refactor of the code +- Only changing some text either in the comments or in any markdown file +- A negligible improvement like trimming a string +- A useless change +- Hampers the user experience or complicates things for the user too much diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md new file mode 100644 index 0000000..f22ab58 --- /dev/null +++ b/README.md @@ -0,0 +1,165 @@ +
TkForge
+Drag & drop in Figma to create a Python GUI with ease
+Upvote on Product Hunt • Donate
+ +## 📰 Table of Contents + +- [ Why and how?](#-why-and-how) +- [ App Preview](#-app-preview) +- [ Features](#-features) +- [ Usage Guide](#-usage-guide) +- [ Available names](#-available-names) +- [ Names that have unique features](#-names-that-have-unique-features) +- [ CLI Usage Guide](#-cli-usage-guide) +- [ Add the CLI exe to the environment variables in Windows](#-add-the-cli-exe-to-the-environment-variables-in-windows) + +## ❓ Why and how? + +Something like this has already been done by ParthJadhav with Tkinter Designer but I liked the concept and wanted to make something similar if not better from scratch. TkForge interacts with the Figma API to get the details of the file and turns that into code. First, it gets the file data and converts it into a format that only has the necessary details then that is converted into code. This project took me a lot longer than I had anticipated. + +## 💻 App Preview + + + +## 🔥 Features + +- Super easy to use +- Drag and drop GUI maker +- Support for placeholder text +- Support for more than one frame +- Automatically sets foreground to either black or white depending on the background (not always accurate) + +## ✨ Usage Guide + +First, you need to download the executable from the releases page. Then, you need to create a Figma token and copy the url of your project. Then, open the app and paste the token and url of your project into the app and click the button to start the magic! 🪄 + +In the Figma project, make sure to add proper names for all of your elements. + +[⟶ Go to the App Preview](#-app-preview) + +## 🧿 Available names + +| Name | Tkinter Element | +| -------------------------------------- | ---------------- | +| `text` (you can also name it anything) | canvas text | +| `button` | button | +| `image` | canvas image | +| `textbox` | entry | +| `textarea` | text | +| `spinbox` | spinbox | +| `rectangle` | canvas rectangle | +| `circle` | canvas circle | +| `oval` | canvas oval | +| `line` | canvas line | +| `label` | label | +| `scale` | scale | +| `listbox` (Read below before using) | listbox | + +If any element starts with these names then it will be considered as that Tkinter element. For example; `rectangle 1`, `rectangle`, `Rectangle`, `RecTanGle 69` will all be considered as a rectangle. The capitalization does not matter. + +## 💎 Names that have unique features + +### `label` + +You can use label instead of text if you want to change that text later on. + +### `circle` and `oval` + +Oval and circle act in the same way so you can use either one of those. + +### `circle`, `oval`, `rectangle` and `line` + +Stroke color and stroke width are supported that means if you add a stroke to them in Figma, they will appear with that stroke and stroke width in the Tkinter design as well. + +### `textarea` and `textbox` + +You can add placeholder text to them. To add placeholder text, after the name of the element put a space and the text you want. All of the text after the element name and a space will be the placeholder text. For example; if I want to make a textbox with the placeholder text "Hello world" then the name should be `textbox Hello world` and if you wanted to make it a textarea then it would be `textarea Hello world`. You can change the foreground color for the placeholder text in the code by adding `placeholder_fg="color_here"` in the widget. Here's a code example of adding placeholder_fg: + +```py +textbox_1 = TkForge_Entry( + placeholder="Code Example", + placeholder_fg="#fff" +) +``` + +If you added placeholder text, you need to use `textbox_1.is_placeholder(False)` to make sure your inserted text does not get the placeholder text color. And you can use `textbox_1.get_placeholder()` to get the placeholder text if you need to change back. Placeholder text in Tkinter can be quite tricky so you may need to handle a lot of situations yourself. + +### `scale` + +For the from, to and orient values of the scale element you can put them aftet the name one after the other separated by spaces. For example; if I want a scale that has from=10, to=50 and orient=HORIZONTAL then I can do `scale 10 50` or `scale 10 50 HORIZONTAL` and if I want orient=VERTICAL then `scale 10 50 VERTICAL` + +### `listbox` + +It is recommended to not use this. It messes up the height and width by some pixels or more. Using the units provided by Figma doesn't work, I had to divide it by some specific numbers to get it somewhat close to what it looks like in Figma. + +## 🔮 CLI Usage Guide + +If you want to run it from the Python file then use `python tkforge.py YOUR_ARGUMENTS_HERE` + +You can use `tkforge --help` to get the help command and if you are using the Python file then use `python tkforge.py --help` + +You may need to use `./tkforge.exe` or something like that if you have not added the CLI executable to the environment variables. + +Here are some example usages: + +### With arguments + +``` +tkforge --id my_id --token my_token --out ./app +``` + +You can use any one of the command below if you want the output to be in the current directory: + +``` +tkforge --id my_id --token my_token --out . +``` + +``` +tkforge --id my_id --token my_token +``` + +### Without arguments + +``` +tkforge my_id my_token output_path +``` + +You can use any one of the command below if you want the output to be in the current directory: + +``` +tkforge my_id my_token . +``` + +``` +tkforge my_id my_token +``` + +## 🪟 Add the CLI exe to the environment variables in Windows + +Step 1: Create a folder with any name like "tkforge" + +Step 2: Put the TkForge CLI exe file in that folder + +Step 3: Rename the exe from `tkforge-cli.exe` to `tkforge.exe` + +Step 4: Copy the path name. + +Example copied path name: `C:\Users\PC\Downloads\tkforge` + +Do not copy the path for the ".exe", copy the path for the folder. + +If the path name has quotes on both sides like this `"C:\Users\PC\Downloads\tkforge cli"`, then make sure to remove the quotes. + +Step 5: Open the "Edit the system environment variables" app + +Step 6: Click on "Environment Variables..." then on "System variables" click "Path" + +Step 7: Then, click "Edit" then "New" and paste the path + +Step 8: Click "Ok", "Ok" and "Ok" and you should be done! + +--- + +Support me on Patreon — Check out my socials
\ No newline at end of file diff --git a/assets/icon.ico b/assets/icon.ico new file mode 100644 index 0000000..95d4a4b Binary files /dev/null and b/assets/icon.ico differ diff --git a/assets/icon.png b/assets/icon.png new file mode 100644 index 0000000..7175852 Binary files /dev/null and b/assets/icon.png differ diff --git a/assets/image_1.png b/assets/image_1.png new file mode 100644 index 0000000..3e94ccd Binary files /dev/null and b/assets/image_1.png differ diff --git a/assets/image_2.png b/assets/image_2.png new file mode 100644 index 0000000..b6e9fc8 Binary files /dev/null and b/assets/image_2.png differ diff --git a/assets/image_3.png b/assets/image_3.png new file mode 100644 index 0000000..c706273 Binary files /dev/null and b/assets/image_3.png differ diff --git a/assets/image_4.png b/assets/image_4.png new file mode 100644 index 0000000..890dec3 Binary files /dev/null and b/assets/image_4.png differ diff --git a/assets/preview.png b/assets/preview.png new file mode 100644 index 0000000..eec0cfc Binary files /dev/null and b/assets/preview.png differ diff --git a/build.bat b/build.bat new file mode 100644 index 0000000..966ff1c --- /dev/null +++ b/build.bat @@ -0,0 +1,7 @@ +@echo off + +if "%1" == "cli" ( + pyinstaller --name="tkforge-cli" --onefile --paths=env/Lib/site-packages tkforge.py --icon=assets/icon.png +) else ( + pyinstaller --name="TkForge" --onefile --paths=env/Lib/site-packages --add-data="assets;assets" gui.py --noconsole --icon=assets/icon.png +) diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..15d6957 --- /dev/null +++ b/build.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +if [ "$1" == "cli" ]; then + pyinstaller --name="tkforge-cli" --onefile --paths=env/Lib/site-packages tkforge.py --icon=assets/icon.png +else + pyinstaller --name="TkForge" --onefile --paths=env/Lib/site-packages --add-data="assets:assets" gui.py --noconsole --icon=assets/icon.png +fi diff --git a/core.py b/core.py new file mode 100644 index 0000000..ef3322e --- /dev/null +++ b/core.py @@ -0,0 +1,169 @@ +import requests +import os +from utils import rgb_to_hex, get_foreground_color + +def get_file(file, token): + response = requests.get(f"https://api.figma.com/v1/files/{file}", headers={'X-FIGMA-TOKEN': token}) + + if response.status_code == 200: + return response.json() + else: + return response.status_code, response.text + +def download_image(file, id, count, token, out=None, frame=None): + response = requests.get(f"https://api.figma.com/v1/images/{file}", headers={'X-FIGMA-TOKEN': token}, params={'ids': id}) + + if response.status_code == 200: + json_data = response.json() + image_url = json_data.get('images', {}).get(id) + + if image_url: + if frame is not None: + folder_path = os.path.join(out, 'TkForge/assets', f'frame_{frame}') if out else os.path.join('TkForge/assets', f'frame_{frame}') + else: + folder_path = os.path.join(out, 'TkForge/assets') if out else 'TkForge/assets' + + if not os.path.exists(folder_path): + os.makedirs(folder_path) + + file_name = f'image_{count}.png' + file_path = os.path.join(folder_path, file_name) + image_response = requests.get(image_url) + + if image_response.status_code == 200: + with open(file_path, 'wb') as f: + f.write(image_response.content) + + if frame is not None: + return os.path.join(f'frame_{frame}', file_name) + else: + return file_name + else: + print("Failed to download the image.") + else: + print("No image URL found for the specified ID.") + else: + print("Failed to retrieve image URL.") + + return None + +def parse_file(file, token, download_images=True, out=None): + output = [] + result = get_file(file, token) + + if isinstance(result, tuple): + return [] + + try: + frames = result['document']['children'][0]['children'] + frame_count = 1 if len(frames) > 1 else 0 + + for frame in frames: + parsed = [] + image_count = 0 + entry_placeholder = False + text_placeholder = False + + for i in frame['children']: + if 'absoluteBoundingBox' in i: + bounds = i['absoluteBoundingBox'] + else: + bounds = i['absoluteRenderBounds'] + + items = ["image", "button", "label", "scale", "listbox", "textbox", "textarea", "rectangle", "spinbox", "circle", "oval", "line"] + type = i['name'].split(' ', 1)[0].lower() + type = type if type in items else "text" + + i['type'] = type + i['x'] = abs(int(frame['absoluteBoundingBox']['x']) - int(bounds['x'])) + i['y'] = abs(int(frame['absoluteBoundingBox']['y']) - int(bounds['y'])) + i['width'] = int(bounds['width']) + i['height'] = int(bounds['height']) + i['background'] = None + + bg_color = i.get('backgroundColor') or \ + (i.get('background', [{}])[0].get('color') if i.get('background') else None) or \ + (i.get('fills', [{}])[0].get('color') if i.get('fills') else "#000000") + + if bg_color and not bg_color == "#000000": + i['background'] = rgb_to_hex(bg_color['r'], bg_color['g'], bg_color['b']) + fg = get_foreground_color(bg_color['r'], bg_color['g'], bg_color['b']) + + if fg == i['background']: + if fg == '#000000': + i['foreground'] = '#ffffff' + elif fg == '#ffffff': + i['foreground'] = '#000000' + else: + i['foreground'] = fg + else: + i['foreground'] = fg + else: + i['background'] = "#000000" + i['foreground'] = "#FFFFFF" + + def download(image_count): + image = download_image(file, i['id'], image_count, token, out, frame_count) if frame_count > 0 else download_image(file, i['id'], image_count, token, out) + + if image: + i['image'] = image + else: + i['image'] = None + + if (i.get('strokes') and not i.get('strokes') == []): + stroke_color = i.get('strokes', [{}])[0].get('color') + i['stroke_color'] = rgb_to_hex(stroke_color['r'], stroke_color['g'], stroke_color['b']) + + if type in ['text', 'label']: + i['text'] = i.get('characters', '').replace('\n', '\\n') + style = i.get('style', {}) + i['font'] = style.get('fontFamily', 'Default Font') + i['font_size'] = int(style.get('fontSize', 12)) + elif type == 'image': + image_count += 1 + download(image_count) + elif type == 'scale': + scale = i['name'].split(' ') + i['from'] = int(scale[1]) + i['to'] = int(scale[2]) + i['orient'] = scale[3] if len(scale) > 3 else "HORIZONTAL" + elif type in ['textbox', 'textarea']: + parts = i['name'].split(' ') + placeholder = " ".join(parts[1:]) + + if not placeholder.replace(' ', '') == '': + i['placeholder'] = placeholder + if type == 'textbox': + entry_placeholder = True + elif type == 'textarea': + text_placeholder = True + elif type == 'button' and download_images: + image_count += 1 + download(image_count) + + parsed.append(i) + + frame_bg = frame.get('backgroundColor') or \ + (frame.get('background', [{}])[0].get('color') if frame.get('background') else None) or \ + (frame.get('fills', [{}])[0].get('color') if frame.get('fills') else None) + + if frame_bg: + frame_bg = rgb_to_hex(frame_bg['r'], frame_bg['g'], frame_bg['b']) + else: + frame_bg = "No background color specified" + + output.append([parsed, [ + int(frame['absoluteBoundingBox']['width']), + int(frame['absoluteBoundingBox']['height']), + frame_bg, + result['name'].replace('\n', '\\n'), + frame_count, + entry_placeholder, + text_placeholder + ]]) + + frame_count += 1 + + except KeyError as e: + print(f"KeyError: {str(e)} - likely due to missing keys in JSON response") + return output diff --git a/gui.py b/gui.py new file mode 100644 index 0000000..d6b2039 --- /dev/null +++ b/gui.py @@ -0,0 +1,222 @@ +# Code generated by TkForge