Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified gui/assets/TextBox_Bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 29 additions & 18 deletions tkdesigner/figma/custom_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@ def __init__(self, node, frame, image_path, *, id_):
self.id_ = id_

def to_code(self):
identify = self.id_
name = self.get("name").strip().lower()
if '_' in name:
identify = name.split('_')[1]
return f"""
button_image_{self.id_} = PhotoImage(
file=relative_to_assets("{self.image_path}"))
button_{self.id_} = Button(
image=button_image_{self.id_},
button_image_{identify} = ImageTk.PhotoImage(Image.open(
relative_to_assets("{self.image_path}")))
button_{identify} = Button(
image=button_image_{identify},
borderwidth=0,
highlightthickness=0,
command=lambda: print("button_{self.id_} clicked"),
command=lambda: print("button_{identify} clicked"),
relief="flat"
)
button_{self.id_}.place(
button_{identify}.place(
x={self.x},
y={self.y},
width={self.width},
Expand Down Expand Up @@ -109,13 +113,17 @@ def __init__(self, node, frame, image_path, *, id_):
self.id_ = id_

def to_code(self):
identify = self.id_
name = self.get("name").strip().lower()
if '_' in name:
identify = name.split('_')[1]
return f"""
image_image_{self.id_} = PhotoImage(
file=relative_to_assets("{self.image_path}"))
image_{self.id_} = canvas.create_image(
image_image_{identify} = ImageTk.PhotoImage(Image.open(
relative_to_assets("{self.image_path}")))
image_{identify} = canvas.create_image(
{self.x},
{self.y},
image=image_image_{self.id_}
image=image_image_{identify}
)
"""

Expand Down Expand Up @@ -143,25 +151,28 @@ def __init__(self, node, frame, image_path, *, id_):

self.entry_x, self.entry_y = self.position(frame)
self.entry_x += corner_radius

self.entry_type = TEXT_INPUT_ELEMENT_TYPES.get(self.get("name"))
self.entry_type = TEXT_INPUT_ELEMENT_TYPES.get(self.get("name").split("_")[0])

def to_code(self):
identify = self.id_
name = self.get("name").strip().lower()
if '_' in name:
identify = name.split('_')[1]
return f"""
entry_image_{self.id_} = PhotoImage(
file=relative_to_assets("{self.image_path}"))
entry_bg_{self.id_} = canvas.create_image(
entry_image_{identify} = ImageTk.PhotoImage(Image.open(
relative_to_assets("{self.image_path}")))
entry_bg_{identify} = canvas.create_image(
{self.x},
{self.y},
image=entry_image_{self.id_}
image=entry_image_{identify}
)
entry_{self.id_} = {self.entry_type}(
entry_{identify} = {self.entry_type}(
bd=0,
bg="{self.bg_color}",
fg="#000716",
highlightthickness=0
)
entry_{self.id_}.place(
entry_{identify}.place(
x={self.entry_x},
y={self.entry_y},
width={self.entry_width},
Expand Down
6 changes: 3 additions & 3 deletions tkdesigner/figma/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def create_element(self, element):
f"{{ name: {element_name}, type: {element_type} }}"
)

if element_name == "button":
if element_name == "button" or element_name.startswith("button_"):
self.counter[Button] = self.counter.get(Button, 0) + 1

item_id = element["id"]
Expand All @@ -55,7 +55,7 @@ def create_element(self, element):
return Button(
element, self, image_path, id_=f"{self.counter[Button]}")

elif element_name in ("textbox", "textarea"):
elif element_name in ("textbox", "textarea") or any(element_name.startswith(prefix) for prefix in ('textbox_', 'textarea_')):
self.counter[TextEntry] = self.counter.get(TextEntry, 0) + 1

item_id = element["id"]
Expand All @@ -69,7 +69,7 @@ def create_element(self, element):
return TextEntry(
element, self, image_path, id_=f"{self.counter[TextEntry]}")

elif element_name == "image":
elif element_name == "image" or element_name.startswith("image_"):
self.counter[Image] = self.counter.get(Image, 0) + 1

item_id = element["id"]
Expand Down
1 change: 1 addition & 0 deletions tkdesigner/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# from tkinter import *
# Explicit imports to satisfy Flake8
from tkinter import Tk, Canvas, Entry, Text, Button, PhotoImage
from PIL import Image, ImageTk


OUTPUT_PATH = Path(__file__).parent
Expand Down