From 4f2ff645dc60793714269af04820fe43c8152878 Mon Sep 17 00:00:00 2001 From: soft98-top Date: Thu, 25 May 2023 17:17:55 +0800 Subject: [PATCH 1/3] change template code of imgae --- gui/assets/TextBox_Bg.png | Bin 567 -> 1504 bytes tkdesigner/figma/custom_elements.py | 12 ++++++------ tkdesigner/template.py | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/gui/assets/TextBox_Bg.png b/gui/assets/TextBox_Bg.png index 514d9d6deca8210091452ebd853a7566579a89bb..b1f7533389a25c5a794d357ba150763f06b0904b 100644 GIT binary patch literal 1504 zcmeAS@N?(olHy`uVBq!ia0y~yV2lK^Z8_M0B>Mv?Wgx|p?&#~tz_78O`%fY(kgt&J z5#-CjP^HGe(9pub@Czu^@PdJ%)PRBERRRNp)eHs(@q#(K0&Rd2EvXTnX}-P;T0k}j z11qBt12d4t2!srbQVbx|fGh?tMrk-Zh*1NohKYfpJ(Gb2swN6ZgMbGRgY-aX<^_xh z6BjVSR5L~{V1}_7Y(d&|=Pc*}Qk(@Ik;M!Q+`=Ht$S`Y;1kkj|%#etZ2wxwoh+i#(Mch>H3D2mX`Vk zM*2oZx=P7{9O-#x!EwNQn0$BtH5O0c3d|4@L;p!l8k%E&cMK&=;`7ZQo;E4cA(#@01?&;_hxx`J(^RHa%|#F%b6Dv z7S+a7sD^USk*gQ)WITQEZ-l(HZ{wvql{|+ZrskYlmwD{*e0D}A7LGZrUh%UwzTb8B zweG~Cw`c!;_?Q;4{-uRq14H9ZhnL&$KK}gY#Ft;!PweAA{BB`pKl5wH1_nl^Y!z^-Q_xkzVeC6zf=O%H&3JwW-51e1Pw`WabZ2wB2sz%kupBLiX%Isy1E!~jJ!Xcor zAui!|uHWxl*IxZ}UiVe~qJjfZRcd2qxWD&ntuo1zfk5~Caa|C1cH7tL4fU3tdLRet za9^p-J#TLk!DrzGvbwTy*ZQMtn`{=S0cGED&awNkOZ<}^NaYijo}6>O-9R;pjLOnU zLP`z|4t@ttJiD_6Xt#in!6rpD#ZhIn3J{CFoR`j?pa2$#&fo->^{QsVE*C^tl8Zc5D8xB;4`-g8beVb*LpymV=Sm3a? zYwg9;+qpr>EFruHXbMXn$C>Y6id3UNzdyX8I^))M>DYWhU88t?-wz-E*j0AN_kXn-D7|GfExljX-@QF%eczjsRf!gR wdVFt6-tjyF(zVLLvW~s%&F;LMv?Wgx{_;1OBOz`!jG!i)^F=12eq z8HEBI}PnqqVQ!K07?~G<*NrUUS17<_7u7zUgOU*Ixd)xqPB%M8p1_Ja08O zF>!C``FvrX((dfvmJAU`cCGvOz4V2CyZlauh*KL^KQ-9U%^DGP|195Mxg3TKJMLY7 z_`#i-VcNCdQ8JLfq)GvU1MJ*O_HS<0@iB;PUAOvEncC|U3<;6#>!v-vkSCU4Su1|~zW;Xad5=?t z8UEa?^gsRcNOJaLU!L0x55lVw-e=A2dt9{BA%n5*xzUE$pE)1b+3syClVfhsKDA}t zc6qs-)3W1pbL;KhC0WHE#LWCrmM! Date: Mon, 29 May 2023 16:03:28 +0800 Subject: [PATCH 2/3] add custom names for Button, TextArea, TextBox, Image to generate more readable code --- tkdesigner/figma/custom_elements.py | 41 ++++++++++++++++++----------- tkdesigner/figma/frame.py | 6 ++--- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/tkdesigner/figma/custom_elements.py b/tkdesigner/figma/custom_elements.py index 7dc2f1c9..8029846e 100644 --- a/tkdesigner/figma/custom_elements.py +++ b/tkdesigner/figma/custom_elements.py @@ -13,17 +13,21 @@ def __init__(self, node, frame, image_path, *, id_): self.id_ = id_ def to_code(self): + identiy = self.id_ + name = self.get("name").strip().lower() + if '_' in name: + identiy = name.split('_')[1] return f""" -button_image_{self.id_} = ImageTk.PhotoImage(Image.open( +button_image_{identiy} = ImageTk.PhotoImage(Image.open( relative_to_assets("{self.image_path}"))) -button_{self.id_} = Button( - image=button_image_{self.id_}, +button_{identiy} = Button( + image=button_image_{identiy}, borderwidth=0, highlightthickness=0, - command=lambda: print("button_{self.id_} clicked"), + command=lambda: print("button_{identiy} clicked"), relief="flat" ) -button_{self.id_}.place( +button_{identiy}.place( x={self.x}, y={self.y}, width={self.width}, @@ -109,13 +113,17 @@ def __init__(self, node, frame, image_path, *, id_): self.id_ = id_ def to_code(self): + identiy = self.id_ + name = self.get("name").strip().lower() + if '_' in name: + identiy = name.split('_')[1] return f""" -image_image_{self.id_} = ImageTk.PhotoImage(Image.open( +image_image_{identiy} = ImageTk.PhotoImage(Image.open( relative_to_assets("{self.image_path}"))) -image_{self.id_} = canvas.create_image( +image_{identiy} = canvas.create_image( {self.x}, {self.y}, - image=image_image_{self.id_} + image=image_image_{identiy} ) """ @@ -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): + identiy = self.id_ + name = self.get("name").strip().lower() + if '_' in name: + identiy = name.split('_')[1] return f""" -entry_image_{self.id_} = ImageTk.PhotoImage(Image.open( +entry_image_{identiy} = ImageTk.PhotoImage(Image.open( relative_to_assets("{self.image_path}"))) -entry_bg_{self.id_} = canvas.create_image( +entry_bg_{identiy} = canvas.create_image( {self.x}, {self.y}, - image=entry_image_{self.id_} + image=entry_image_{identiy} ) -entry_{self.id_} = {self.entry_type}( +entry_{identiy} = {self.entry_type}( bd=0, bg="{self.bg_color}", fg="#000716", highlightthickness=0 ) -entry_{self.id_}.place( +entry_{identiy}.place( x={self.entry_x}, y={self.entry_y}, width={self.entry_width}, diff --git a/tkdesigner/figma/frame.py b/tkdesigner/figma/frame.py index 70e3611f..ce9e3d36 100644 --- a/tkdesigner/figma/frame.py +++ b/tkdesigner/figma/frame.py @@ -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"] @@ -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"] @@ -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"] From 63f539e1af781f2a15322f62d5c19941721061ad Mon Sep 17 00:00:00 2001 From: soft98-top Date: Mon, 29 May 2023 17:56:36 +0800 Subject: [PATCH 3/3] fix variables name --- tkdesigner/figma/custom_elements.py | 38 ++++++++++++++--------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/tkdesigner/figma/custom_elements.py b/tkdesigner/figma/custom_elements.py index 8029846e..69d88a58 100644 --- a/tkdesigner/figma/custom_elements.py +++ b/tkdesigner/figma/custom_elements.py @@ -13,21 +13,21 @@ def __init__(self, node, frame, image_path, *, id_): self.id_ = id_ def to_code(self): - identiy = self.id_ + identify = self.id_ name = self.get("name").strip().lower() if '_' in name: - identiy = name.split('_')[1] + identify = name.split('_')[1] return f""" -button_image_{identiy} = ImageTk.PhotoImage(Image.open( +button_image_{identify} = ImageTk.PhotoImage(Image.open( relative_to_assets("{self.image_path}"))) -button_{identiy} = Button( - image=button_image_{identiy}, +button_{identify} = Button( + image=button_image_{identify}, borderwidth=0, highlightthickness=0, - command=lambda: print("button_{identiy} clicked"), + command=lambda: print("button_{identify} clicked"), relief="flat" ) -button_{identiy}.place( +button_{identify}.place( x={self.x}, y={self.y}, width={self.width}, @@ -113,17 +113,17 @@ def __init__(self, node, frame, image_path, *, id_): self.id_ = id_ def to_code(self): - identiy = self.id_ + identify = self.id_ name = self.get("name").strip().lower() if '_' in name: - identiy = name.split('_')[1] + identify = name.split('_')[1] return f""" -image_image_{identiy} = ImageTk.PhotoImage(Image.open( +image_image_{identify} = ImageTk.PhotoImage(Image.open( relative_to_assets("{self.image_path}"))) -image_{identiy} = canvas.create_image( +image_{identify} = canvas.create_image( {self.x}, {self.y}, - image=image_image_{identiy} + image=image_image_{identify} ) """ @@ -154,25 +154,25 @@ def __init__(self, node, frame, image_path, *, id_): self.entry_type = TEXT_INPUT_ELEMENT_TYPES.get(self.get("name").split("_")[0]) def to_code(self): - identiy = self.id_ + identify = self.id_ name = self.get("name").strip().lower() if '_' in name: - identiy = name.split('_')[1] + identify = name.split('_')[1] return f""" -entry_image_{identiy} = ImageTk.PhotoImage(Image.open( +entry_image_{identify} = ImageTk.PhotoImage(Image.open( relative_to_assets("{self.image_path}"))) -entry_bg_{identiy} = canvas.create_image( +entry_bg_{identify} = canvas.create_image( {self.x}, {self.y}, - image=entry_image_{identiy} + image=entry_image_{identify} ) -entry_{identiy} = {self.entry_type}( +entry_{identify} = {self.entry_type}( bd=0, bg="{self.bg_color}", fg="#000716", highlightthickness=0 ) -entry_{identiy}.place( +entry_{identify}.place( x={self.entry_x}, y={self.entry_y}, width={self.entry_width},