From 97ea07d34bfcea20f4c938f0e6bc792968d1f453 Mon Sep 17 00:00:00 2001 From: punix Date: Sat, 26 Apr 2025 21:32:35 +0200 Subject: [PATCH] Message window optimized --- __pycache__/cls_mth_fc.cpython-312.pyc | Bin 23341 -> 23628 bytes cls_mth_fc.py | 49 +++++++---------- wirepy.py | 72 +++++++------------------ 3 files changed, 39 insertions(+), 82 deletions(-) diff --git a/__pycache__/cls_mth_fc.cpython-312.pyc b/__pycache__/cls_mth_fc.cpython-312.pyc index 8a48e2958525b25efac23b135c4f1aeb7aed6202..b917af1ef416dfd34187a85f5d3ec1dd7b7f781c 100644 GIT binary patch delta 2569 zcmc&$YfMx}6rQ>JyzCQ%@(|byxZr|34Im3xMR_TLB3SW9m2wx^@L0TiaYYxg)u#Sw zN_*Ob#+vf4STtQr(~y`prdFFq)1nkfThgRTZA{Y?kcL+Kqi1$`Eb6bOX=gLvnK}2I zZ)WGt`F1aSOmB=(<8^}}gkZanV`w?G<)TrxP$!(UY+Juw@Hjg}mq+llIGb7or&|!6 z?#{NxZigtyE1Cf1U13EOk1{D z)H+lmk39st4!a(^0lQk{nvJ6Ilxm1=1lvBoo3n)u=VcvN9?yg~^OLOEE7p8EgMl%ud4iz~*aO{8yGu#FX%@QSVpMo2OmV(0rhX*BJ z?rnX+G>^`Q?r3CwspOe0TJl+R2I3X%X1Z0c_*}Y}1l-1ZEz9@^{g_@!SdI}B| zZ53xYL1piAPZKl)tNdngx8Gb=_|0hDa{=4Z8nB*Yvn=?5f~dp%*-`@1OP3LvurD?J z!stOi+{_GzxZ(pg1D2!)OHzX+slk%ehze2D93tw2O3~P@u^ET^iU*andbptECyvg8 zr8GL+jCbs)p{}c=!_k(}*d#j-JB~qB>0i_cm1X(#G`v`rwQjj^rEy$dx{c7ZP%-}P zER}4Q0)(xJFp#Z>O&jC69u-8ErzEI(BI_3RO}y&Gq7u2*d_wxDq=fzDX&TiTa#qo! zf!E7RsTL;6Eh>$u^=jc!xee#m3R{8(3!Fd8i6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ix;&}y1t`^cZ z3289B#cW@lesWivcte|gRhzwlq;e-&B>s7Ptm>x8eynN^q!pGzULY&Jt}2+gYk+~?1ys|)qCa{yVyDIn@8j^ zStvX%L>}L^3Zv<^js-gTh((gPhcuc`B}DuM0zITfO{i8fdUOPE{s!<=zG#qhvY67- zj7lAf@M7hp2)BhNs_rqlOC;QZXC>V|e)o{eM?Y9AZz0GVNPkSdC*bk8267|QM<87D zC)UH6+EV-`{9c=%ux9yaY1Xswl+9v72zDz?@cCASDun$KLMj-f%2Luoj2!uuE3P23 zQYswNUy9H;=2b9Tw@Hdg8M7f4RP{Bi$ghXnZDujc$$}yns&_zMrV>7?x7cV2%TF zbZfZu(JWca3UN`dz}3Evi!;#Q%KnL<7=(SU<=zlwiRCs%y#jaBI_^<}4HY0C9%eA= zAmT>ZBf3B&Cw=7>i0ZI(e$)_E4b#|Z2<lIj3%PcM)-fQf|_d(J$h!yZgQ-R?Z%66B+ zJqo`PfZJ(Cm}@er-yxr_?c~?sOs-`R!uLS<_xC~l$B^4XdMP(IJD`zjMWwl0h$>bz> zSuU=PlU~-av>zv+QC^$MUbbR_{5E)h*A}CO9Fec1$EU^0%W1C!TK2{3`1`a^p@rVX z>tJd*WLjWy#rkCtA-#x*+ztYMbOorgPm}^JrUmtpKd>nD}|7^NWO#NcT<`ox;p*mwJxhlA#sdt*yHsM z_}zoKeQwUx<&O-Wz{?#To0Bd=gZO%ypGrZHqipJ$F?K#g6c_h1BN*!+B8rPcY$3KUAOga&{{X_O BNFD$H diff --git a/cls_mth_fc.py b/cls_mth_fc.py index 64c305c..ef85a7b 100755 --- a/cls_mth_fc.py +++ b/cls_mth_fc.py @@ -170,8 +170,8 @@ class LxTools(tk.Tk): """ Creates message windows - :argument img_w = Image for Tk Window - :argument img_i = Image for Icon + :argument img_w = Image for TK window which is displayed to the left of the text + :argument img_i = Image for Task Icon :argument w_title = Windows Title :argument w_txt = Text for Tk Window :argument txt2 = Text for Button two @@ -291,15 +291,17 @@ class GiteaUpdate: return req @staticmethod - def download(urld: str, down_ok_image: str, down_not_ok_image: str, res: str) -> None: + def download(urld: str, res: str, img_w: str = None, img_i: str = None, img_w2: str = None, img_i2: str = None) -> None: """ Downloads new version of wirepy Args: urld: Download URL - down_ok_image: Path to success image - down_not_ok_image: Path to error image res: Result filename + img_w: Image for TK window which is displayed to the left of the text + img_i: Image for Task Icon + img_w2: Image for TK window which is displayed to the left of the text + img_i2: Image for Task Icon """ try: to_down: str = f"wget -qP {Path.home()} {" "} {urld}" @@ -307,30 +309,21 @@ class GiteaUpdate: if result == 0: shutil.chown(f"{Path.home()}/{res}.zip", 1000, 1000) - # Message window variables - iw: str = r"/usr/share/icons/lx-icons/64/info.png" - ii: str = down_ok_image wt: str = _("Download Successful") msg_t: str = _("Your zip file is in home directory") - LxTools.msg_window(iw, ii, wt, msg_t) + LxTools.msg_window(img_w, img_i, wt, msg_t) else: - # Error message window variables - iw: str = r"/usr/share/icons/lx-icons/64/error.png" - ii: str = down_not_ok_image wt: str = _("Download error") msg_t: str = _("Download failed! Please try again") - LxTools.msg_window(iw, ii, wt, msg_t) + LxTools.msg_window(img_w2, img_i2, wt, msg_t) except subprocess.CalledProcessError: - # Exception message window variables - iw: str = r"/usr/share/icons/lx-icons/64/error.png" - ii: str = down_not_ok_image wt: str = _("Download error") msg_t: str = _("Download failed! No internet connection!") - LxTools.msg_window(iw, ii, wt, msg_t) + LxTools.msg_window(img_w2, img_i2, wt, msg_t) class Tunnel: @@ -407,11 +400,16 @@ class Tunnel: return wg_s @staticmethod - def export() -> None: + def export(img_w: str = None, img_i: str = None, img_w2: str = None, img_i2: str = None) -> None: """ This will export the tunnels. A zipfile with the current date and time is created in the user's home directory with the correct right + Args: + img_w: Image for TK window which is displayed to the left of the text + img_i: Image for Task Icon + img_w2: Image for TK window which is displayed to the left of the text + img_i2: Image for Task Icon """ now_time: datetime = datetime.now() now_datetime: str = now_time.strftime("wg-exp-%m-%d-%Y-%H:%M") @@ -427,30 +425,21 @@ class Tunnel: with zipfile.ZipFile(f"{wg_tar}.zip", "r") as zf: if len(zf.namelist()) != 0: - # Message window variables - iw: str = r"/usr/share/icons/lx-icons/64/info.png" - ii: str = r"/usr/share/icons/lx-icons/48/wg_vpn.png" wt: str = _("Export Successful") msg_t: str = _("Your zip file is in home directory") - LxTools.msg_window(iw, ii, wt, msg_t) + LxTools.msg_window(img_w, img_i, wt, msg_t) else: - # Error message window variables - iw: str = r"/usr/share/icons/lx-icons/64/error.png" - ii: str = r"/usr/share/icons/lx-icons/48/wg_msg.png" wt: str = _("Export error") msg_t: str = _("Export failed! Please try again") - LxTools.msg_window(iw, ii, wt, msg_t) + LxTools.msg_window(img_w2, img_i2, wt, msg_t) else: - # Message window variables - iw: str = r"/usr/share/icons/lx-icons/64/info.png" - ii: str = r"/usr/share/icons/lx-icons/48/wg_msg.png" wt: str = _("Select tunnel") msg_t: str = _("Please first import tunnel") - LxTools.msg_window(iw, ii, wt, msg_t) + LxTools.msg_window(img_w, img_i2, wt, msg_t) except TypeError: pass diff --git a/wirepy.py b/wirepy.py index 25c9755..9d599bc 100755 --- a/wirepy.py +++ b/wirepy.py @@ -32,6 +32,11 @@ VERSION: str = "v. 2.04.1725" res = GiteaUpdate.api_down("https://git.ilunix.de/api/v1/repos/punix/Wire-Py/releases", VERSION, set_file) +img_w: str = r"/usr/share/icons/lx-icons/64/info.png" +img_i: str = r"/usr/share/icons/lx-icons/48/wg_vpn.png" +img_w2: str = r"/usr/share/icons/lx-icons/64/error.png" +img_i2: str = r"/usr/share/icons/lx-icons/48/wg_msg.png" + # Translate APP = "wirepy" LOCALE_DIR = "/usr/share/locale/" @@ -100,8 +105,6 @@ class FrameWidgets(ttk.Frame): self.tr_pic = tk.PhotoImage(file=r"/usr/share/icons/lx-icons/48/wg_trash.png") self.exp_pic = tk.PhotoImage(file=r"/usr/share/icons/lx-icons/48/wg_export.png") self.warning_pic = tk.PhotoImage(file=r"/usr/share/icons/lx-icons/64/error.png") - self.wg_vpn_start = tk.PhotoImage(file=r"/usr/share/icons/lx-icons/48/wg_vpn-start.png") - self.wg_vpn_stop = tk.PhotoImage(file=r"/usr/share/icons/lx-icons/48/wg_vpn-stop.png") def update(): """ @@ -169,9 +172,6 @@ class FrameWidgets(ttk.Frame): def link_btn(): webbrowser.open("https://git.ilunix.de/punix/Wire-Py") - # img_w, img_i, w_title, w_txt , txt2, com hand over - iw = r"/usr/share/icons/lx-icons/48/wg_vpn.png" - ii = r"/usr/share/icons/lx-icons/48/wg_msg.png" wt = _("Info") msg_t = _("Wire-Py a simple Wireguard Gui for Linux systems.\n\n" "Wire-Py is open source software written in Python.\n\n" @@ -180,7 +180,7 @@ class FrameWidgets(ttk.Frame): txt2 = _("Go to Wire-Py git") com = link_btn - LxTools.msg_window(iw, ii, wt, msg_t, txt2, com) + LxTools.msg_window(img_i, img_i, wt, msg_t, txt2, com) # Frame for Menu self.menu_frame = ttk.Frame(self) @@ -254,9 +254,7 @@ class FrameWidgets(ttk.Frame): self.update_btn.configure(menu=self.download, style="Toolbutton") self.download.add_command( label=_("Download"), - command=lambda: GiteaUpdate.download(f"https://git.ilunix.de/punix/Wire-Py/archive/{res}.zip", - r"/usr/share/icons/lx-icons/48/wg_vpn.png", - r"/usr/share/icons/lx-icons/48/wg_msg.png", res)) + command=lambda: GiteaUpdate.download(f"https://git.ilunix.de/punix/Wire-Py/archive/{res}.zip", res, img_w, img_i, img_w2, img_i2)) # Show active Tunnel self.a = Tunnel.active() @@ -422,21 +420,15 @@ class FrameWidgets(ttk.Frame): if self.l_box.size() != 0: - # img_w, img_i, w_title, w_txt hand over - iw = r"/usr/share/icons/lx-icons/64/info.png" - ii = r"/usr/share/icons/lx-icons/48/wg_msg.png" wt = _("Select tunnel") msg_t = _("Please select a tunnel from the list") - LxTools.msg_window(iw, ii, wt, msg_t) + LxTools.msg_window(img_w, img_i2, wt, msg_t) else: - # img_w, img_i, w_title, w_txt hand over - iw = r"/usr/share/icons/lx-icons/64/info.png" - ii = r"/usr/share/icons/lx-icons/48/wg_msg.png" wt = _("Select tunnel") msg_t = _("Please first import tunnel") - LxTools.msg_window(iw, ii, wt, msg_t) + LxTools.msg_window(img_w, img_i2, wt, msg_t) # Button Trash self.btn_tr = ttk.Button(self.lb_frame_btn_lbox, image=self.tr_pic, command=delete, padding=0, @@ -449,7 +441,7 @@ class FrameWidgets(ttk.Frame): Tooltip(self.btn_tr, _("Click to delete a Wireguard Tunnel\nSelect from the list!"), tips) # Button Export - self.btn_exp = ttk.Button(self.lb_frame_btn_lbox, image=self.exp_pic, command=Tunnel.export, padding=0) + self.btn_exp = ttk.Button(self.lb_frame_btn_lbox, image=self.exp_pic, command=lambda: Tunnel.export(img_w, img_i, img_w2, img_i2), padding=0) self.btn_exp.grid(column=0, row=3, padx=15, pady=8) if self.l_box.size() == 0: @@ -474,30 +466,21 @@ class FrameWidgets(ttk.Frame): if len(self.lb_rename.get()) > 12: - # img_w, img_i, w_title, w_txt hand over - iw = r"/usr/share/icons/lx-icons/64/info.png" - ii = r"/usr/share/icons/lx-icons/48/wg_msg.png" wt = _("Renaming not possible") msg_t = _("The new name may contain only 12 characters") - LxTools.msg_window(iw, ii, wt, msg_t) + LxTools.msg_window(img_w, img_i2, wt, msg_t) elif len(self.lb_rename.get()) == 0: - # img_w, img_i, w_title, w_txt hand over - iw = r"/usr/share/icons/lx-icons/64/info.png" - ii = r"/usr/share/icons/lx-icons/48/wg_msg.png" wt = _("Renaming not possible") msg_t = _("At least one character must be entered") - LxTools.msg_window(iw, ii, wt, msg_t) + LxTools.msg_window(img_w, img_i2, wt, msg_t) elif any(ch in special_characters for ch in self.lb_rename.get()): - # img_w, img_i, w_title, w_txt hand over - iw = r"/usr/share/icons/lx-icons/64/info.png" - ii = r"/usr/share/icons/lx-icons/48/wg_msg.png" wt = _("Renaming not possible") msg_t = _("No valid sign. These must not be used.\nBlank, Slash, Backslash and { }\n") - LxTools.msg_window(iw, ii, wt, msg_t) + LxTools.msg_window(img_w, img_i2, wt, msg_t) else: @@ -532,12 +515,9 @@ class FrameWidgets(ttk.Frame): except IndexError: - # img_w, img_i, w_title, w_txt hand over - iw = r"/usr/share/icons/lx-icons/64/info.png" - ii = r"/usr/share/icons/lx-icons/48/wg_msg.png" wt = _("Renaming not possible") msg_t = _("Please select a tunnel from the list") - LxTools.msg_window(iw, ii, wt, msg_t) + LxTools.msg_window(img_w, img_i2, wt, msg_t) # Button Rename self.btn_rename = ttk.Button(self.lb_frame4, text=_("Rename"), state="disable", command=tl_rename, padding=4, @@ -605,12 +585,9 @@ class FrameWidgets(ttk.Frame): p_key = readfile.readlines() if pre_key in p_key or f"{pre_key}\n" in p_key: - # img_w, img_i, w_title, w_txt hand over - iw = r"/usr/share/icons/lx-icons/64/error.png" - ii = r"/usr/share/icons/lx-icons/48/wg_msg.png" wt = _("Import Error") msg_t = _("Tunnel already available!\nPlease use another file for import") - LxTools.msg_window(iw, ii, wt, msg_t) + LxTools.msg_window(img_w2, img_i2, wt, msg_t) else: @@ -681,12 +658,9 @@ class FrameWidgets(ttk.Frame): pass else: - # img_w, img_i, w_title, w_txt hand over - iw = r"/usr/share/icons/lx-icons/64/error.png" - ii = r"/usr/share/icons/lx-icons/48/wg_msg.png" wt = _("Import Error") msg_t = _("Oh... no valid Wireguard File!\nPlease select a valid Wireguard File") - LxTools.msg_window(iw, ii, wt, msg_t) + LxTools.msg_window(img_w2, img_i2, wt, msg_t) except EOFError as e: print(e) @@ -741,7 +715,7 @@ class FrameWidgets(ttk.Frame): lines4 = set_f4.readlines() if lines4[7] != "off\n": - print(lines4[7]) + print(f"{lines4[7]} starts automatically when the system starts.") self.selected_option.set(1) self.autoconnect_var.set("") self.auto_con = lines4[7] @@ -749,7 +723,7 @@ class FrameWidgets(ttk.Frame): else: self.selected_option.set(0) self.auto_con = _("no Autoconnect") - + print("Autostart disabled.") self.autoconnect_var.set("") self.autoconnect_var = tk.StringVar() self.autoconnect_var.set(self.auto_con) @@ -887,21 +861,15 @@ class FrameWidgets(ttk.Frame): if self.l_box.size() != 0: - # img_w, img_i, w_title, w_txt hand over - iw = r"/usr/share/icons/lx-icons/64/info.png" - ii = r"/usr/share/icons/lx-icons/48/wg_msg.png" wt = _("Select tunnel") msg_t = _("Please select a tunnel from the list") - LxTools.msg_window(iw, ii, wt, msg_t) + LxTools.msg_window(img_w, img_i2, wt, msg_t) else: - # img_w, img_i, w_title, w_txt hand over - iw = r"/usr/share/icons/lx-icons/64/info.png" - ii = r"/usr/share/icons/lx-icons/48/wg_msg.png" wt = _("Select tunnel") msg_t = _("Please first import tunnel") - LxTools.msg_window(iw, ii, wt, msg_t) + LxTools.msg_window(img_w, img_i2, wt, msg_t) if __name__ == "__main__":