File size: 2,022 Bytes
85a1cb0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f357771
 
f03efc3
f357771
 
 
96be831
f357771
 
96be831
f357771
96be831
ccc1663
f357771
 
 
96be831
f357771
96be831
f357771
 
 
 
 
 
 
 
 
 
85a1cb0
f357771
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import gradio as gr
import os
import subprocess
import zipfile
from pathlib import Path

def process_figma(figma_url, figma_token):
    if not Path("Tkinter-Designer").exists():
        subprocess.run(["git", "clone", "https://github.com/ParthJadhav/Tkinter-Designer.git"], check=True)
        print("Cloning to the github repo")
    
    os.chdir("Tkinter-Designer")
    conversion_command = [
        "python",
        "-m",
        "tkdesigner.cli",
        figma_url,
        figma_token
    ]

    subprocess.run(conversion_command, check=True)
    zip_file_path = "output.zip"
    with zipfile.ZipFile(zip_file_path, 'w') as zip_file:
        for foldername, subfolders, filenames in os.walk("build"):
            for filename in filenames:
                filepath = os.path.join(foldername, filename)
                zip_file.write(filepath, os.path.relpath(filepath, "build"))
    
    return zip_file_path

with gr.Blocks() as demo:
    gr.Markdown("## Figma to Tkinter Converter")  # Title

    with gr.Row():
        url_input = gr.Textbox(label="Figma URL")
        token_input = gr.Textbox(label="Figma Token")

    submit_button = gr.Button("Convert")
    output_file = gr.File(label="Download Output")

    submit_button.click(fn=process_figma, inputs=[url_input, token_input], outputs=output_file)

    gr.Markdown(
        """
        Upload your Figma design by providing the URL and token.
        <br>

        ### Naming is Important

        | Figma Element Name | Tkinter Element |
        | --- | --- |
        | Button | Button |
        | Line | Line |
        | Text | Name it anything |
        | Rectangle | Rectangle |
        | TextArea | Text Area |
        | TextBox | Entry |
        | Image | Canvas.Image() |
        | ButtonHover (EXPERIMENTAL) | Button shown on hover |

        <br>

        **NOTE** : This project is created by : ParthJadhav

        Checkout this repo to know more : [GitHub Repo](https://github.com/ParthJadhav/Tkinter-Designer)
        """
    )

demo.launch()