From 87943b24895ed7f8aa740cd105e21b474410fa4f Mon Sep 17 00:00:00 2001 From: punix Date: Thu, 24 Apr 2025 12:43:39 +0200 Subject: [PATCH] add new class LxTools and funktion to methode in new class --- __pycache__/cls_mth_fc.cpython-312.pyc | Bin 20555 -> 22727 bytes cls_mth_fc.py | 63 +++++++++++---- wirepy.py | 104 +++++++++---------------- 3 files changed, 86 insertions(+), 81 deletions(-) diff --git a/__pycache__/cls_mth_fc.cpython-312.pyc b/__pycache__/cls_mth_fc.cpython-312.pyc index 913ab8ca6982a8cb6d75f9685030a59858d28970..604aa1f922a23fb84a7819951e01c6d85be5503f 100644 GIT binary patch delta 3571 zcmd^BeQZ#I(}F0IG{^-bmVHbRIsI86q33;DO<7+(~f-2mJYUzC0l{y7$zOd zrA)vTntd7AvzF|I1A;3j{x|xjo#&UEqZ=XQadMi-q=QPNLl_}lRHDPC4xJ=G1ihpK zG{~Z)A0`)*Np~1W$n&(rw2!z9sL(n*t6{KMBvgWtVkfLG~h5?->#bVKB% zo{%9LAVWg*4f;Jw$pE=PJuX2tDE)mhQ%zoPAQT9Dy)M0~SL9%qs`oL!qKZ8c?ceP6 zb_RWl;`J&Ji4+zV9%b1eu*U%g?a7SXi&2h&R#^sc|0ua_vc-&(rkwHO_e`#dQr(ov z#XoDx6OK`SX=g6qvO6Zrk|P@1FR=6&>?!r%-0s?MFq(+BuFWn!B4W{=PM%Fz9dpga+nAHqQb@G1k*?2 z4v|B)MOXfrep%EyU|mJl5`{(tO4qaTRto==@%^FaL>k#N_ZeBs|L-c>iQLV!4mO>WmX~iSdVH}qH@@qFdDQdDrF0X z{%}`C?FFiuBs`}nOIi!jazgLmNs+q|? zDHsUJifW0lKv+)5DV@E+Ugiz@o|A(v9or6pR7#yd&pR#=h z49&6T(bib&cri&dM=yCck7% z9Q)QO^SlA9b0W#edY}WfxuJtS_m;h6(q1yrHEpk$*MagwtNoTWf6|)&fpz(88nN!6 z^Lps6jj%8;g2$>^0=RH52a>*?mesgMcYRw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C7HDNHZPMsHEy9Ib@P?x(Nc%3S;y<3-_$_c_CpU ze|c_gFf|s{(+m00IM_2w8mx)tu^MkxqanOy+|$y>hqCB@B?je$v|QqM!Ww&P_yBp^ zzsg?%X%wfUIN;esl8-*bm+Vq+MFdrV@9Yee(mGtQGb!o1bO@SBNx{2DqPM_Ht>a*w zfalS)!ywbCACOgDqSV@vKRFiYD!QUk4n6!>tO$!_(X6(4ljGKlw4F`L<2^Dl&r!*Boq diff --git a/cls_mth_fc.py b/cls_mth_fc.py index f78278c..9179d64 100755 --- a/cls_mth_fc.py +++ b/cls_mth_fc.py @@ -129,19 +129,52 @@ class Create: else: print(f"Error with the following code... {process.returncode}") +class LxTools(tk.Tk): + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) -def uos(): - """ - uos = LOGIN USERNAME + def theme_change_light(self): + """ + Set light theme + """ + if self.tk.call("ttk::style", "theme", "use") == "water-dark": + self.tk.call("set_theme", "light") + with open(wg_set, "r", encoding="utf-8") as theme_set2: + lines3 = theme_set2.readlines() + lines3[3] = "light\n" + with open(wg_set, "w", encoding="utf-8") as theme_set2: + theme_set2.writelines(lines3) + self.color_label() - This method displays the user name of the logged-in user, - even if you are rooted in a shell - """ - logname = f"{Path.home()}"[6:] - file = Path.home() / "/tmp/.loguser" - with open(file, "w", encoding="utf-8") as f: - f.write(logname) + + def theme_change_dark(self): + """ + Set dark theme + """ + if not self.tk.call("ttk::style", "theme", "use") == "water-dark": + self.tk.call("set_theme", "dark") + with open(wg_set, "r", encoding="utf-8") as theme_set2: + lines4 = theme_set2.readlines() + lines4[3] = "dark\n" + with open(wg_set, "w", encoding="utf-8") as theme_set2: + theme_set2.writelines(lines4) + self.color_label() + + @staticmethod + def uos(): + """ + + uos = LOGIN USERNAME + + This method displays the user name of the logged-in user, + even if you are rooted in a shell + """ + logname = f"{Path.home()}"[6:] + file = Path.home() / "/tmp/.loguser" + with open(file, "w", encoding="utf-8") as f: + f.write(logname) class GiteaUpdate: @@ -161,9 +194,9 @@ class GiteaUpdate: response = requests.get(update_api_url, timeout=10) response_dict = response.json() response_dict = response_dict[0] - with open(wg_set, "r", encoding="utf-8") as set_file: - set_file = set_file.read() - if "on\n" in set_file: + with open(wg_set, "r", encoding="utf-8") as set_f: + set_f = set_f.read() + if "on\n" in set_f: if version[3:] != response_dict["tag_name"]: req = response_dict["tag_name"] else: @@ -425,8 +458,8 @@ def if_tip(path): """ method that writes in file whether tooltip is displayed or not """ - with open(path, "r", encoding="utf-8") as set_file2: - lines2 = set_file2.readlines() + with open(path, "r", encoding="utf-8") as set_f2: + lines2 = set_f2.readlines() if "False\n" in lines2: tip = False else: diff --git a/wirepy.py b/wirepy.py index 16f8b67..0560043 100755 --- a/wirepy.py +++ b/wirepy.py @@ -15,9 +15,9 @@ from subprocess import check_call from tkinter import TclError, filedialog, ttk from cls_mth_fc import (Create, GiteaUpdate, Tooltip, Tunnel, if_tip, - msg_window, sigi, uos) + LxTools, msg_window, sigi) -uos() +LxTools.uos() Create.dir_and_files() Create.make_dir() Create.decrypt() @@ -120,62 +120,36 @@ class FrameWidgets(ttk.Frame): Set on or off in file """ if set_update.get() == 1: - with open(wg_set, "r", encoding="utf-8") as set_file2: - lines2 = set_file2.readlines() + with open(wg_set, "r", encoding="utf-8") as set_f2: + lines2 = set_f2.readlines() lines2[1] = "off\n" - with open(wg_set, "w", encoding="utf-8") as set_file2: - set_file2.writelines(lines2) + with open(wg_set, "w", encoding="utf-8") as set_f2: + set_f2.writelines(lines2) if set_update.get() == 0: - with open(wg_set, "r", encoding="utf-8") as set_file2: - lines2 = set_file2.readlines() + with open(wg_set, "r", encoding="utf-8") as set_f2: + lines2 = set_f2.readlines() lines2[1] = "on\n" - with open(wg_set, "w", encoding="utf-8") as set_file2: - set_file2.writelines(lines2) + with open(wg_set, "w", encoding="utf-8") as set_f2: + set_f2.writelines(lines2) def tooltip(): """ Set True or False in file """ if set_tip.get(): - with open(wg_set, "r", encoding="utf-8") as set_file2: - lines2 = set_file2.readlines() + with open(wg_set, "r", encoding="utf-8") as set_f2: + lines2 = set_f2.readlines() lines2[5] = "False\n" - with open(wg_set, "w", encoding="utf-8") as set_file2: - set_file2.writelines(lines2) + with open(wg_set, "w", encoding="utf-8") as set_f2: + set_f2.writelines(lines2) else: - with open(wg_set, "r", encoding="utf-8") as set_file2: - lines2 = set_file2.readlines() + with open(wg_set, "r", encoding="utf-8") as set_f2: + lines2 = set_f2.readlines() lines2[5] = "True\n" - with open(wg_set, "w", encoding="utf-8") as set_file2: - set_file2.writelines(lines2) - - def theme_change_light(): - """ - Set light theme - """ - if self.tk.call("ttk::style", "theme", "use") == "water-dark": - self.tk.call("set_theme", "light") - with open(wg_set, "r", encoding="utf-8") as theme_set2: - lines3 = theme_set2.readlines() - lines3[3] = "light\n" - with open(wg_set, "w", encoding="utf-8") as theme_set2: - theme_set2.writelines(lines3) - self.color_label() - - def theme_change_dark(): - """ - Set dark theme - """ - if not self.tk.call("ttk::style", "theme", "use") == "water-dark": - self.tk.call("set_theme", "dark") - with open(wg_set, "r", encoding="utf-8") as theme_set2: - lines4 = theme_set2.readlines() - lines4[3] = "dark\n" - with open(wg_set, "w", encoding="utf-8") as theme_set2: - theme_set2.writelines(lines4) - self.color_label() + with open(wg_set, "w", encoding="utf-8") as set_f2: + set_f2.writelines(lines2) def info(): def link_btn(): @@ -223,8 +197,8 @@ class FrameWidgets(ttk.Frame): self.settings.add_checkbutton( label=_("Disable Tooltips"), command=tooltip, variable=set_tip ) - self.settings.add_command(label=_("Light"), command=theme_change_light) - self.settings.add_command(label=_("Dark"), command=theme_change_dark) + self.settings.add_command(label=_("Light"), command=lambda: LxTools.theme_change_light(self)) + self.settings.add_command(label=_("Dark"), command=lambda: LxTools.theme_change_dark(self)) # About BTN Menu / Label self.about_btn = ttk.Button( @@ -398,15 +372,15 @@ class FrameWidgets(ttk.Frame): pre_key = key[3] check_call(["nmcli", "connection", "delete", select_tl]) self.l_box.delete(self.select_tunnel[0]) - with open(wg_set, "r", encoding="utf-8") as set_file6: - lines6 = set_file6.readlines() + with open(wg_set, "r", encoding="utf-8") as set_f6: + lines6 = set_f6.readlines() if ( select_tl == lines6[7].strip() and "off\n" not in lines6[7].strip() ): lines6[7] = "off\n" - with open(wg_set, "w", encoding="utf-8") as set_file7: - set_file7.writelines(lines6) + with open(wg_set, "w", encoding="utf-8") as set_f7: + set_f7.writelines(lines6) self.selected_option.set(0) self.autoconnect_var.set(_("no Autoconnect")) is_encrypt = Path.home() / f".config/wire_py/{select_tl}.dat" @@ -427,13 +401,11 @@ class FrameWidgets(ttk.Frame): if self.l_box.size() == 0: self.wg_autostart.configure(state="disabled") self.lb_rename.configure(state="disabled") - Tooltip(self.wg_autostart, _("You must have at least one\ntunnel", - "in the list,to use the autostart"), tips) + Tooltip(self.wg_autostart, _("You must have at least one\ntunnel in the list,to use the autostart"), tips) Tooltip(self.btn_exp, _("No Tunnels in List for Export"), tips) Tooltip(self.btn_stst, _("No tunnels to start in the list"), tips) - Tooltip(self.lb_rename, _("To rename a tunnel, at least one must", - "be in the list"), tips, ) + Tooltip(self.lb_rename, _("To rename a tunnel, at least one must be in the list"), tips, ) self.lb_rename.insert(0, _("Max. 12 characters!")) if self.a != "" and self.a == select_tl: @@ -580,8 +552,8 @@ class FrameWidgets(ttk.Frame): if self.a != "" and self.a == select_tl: self.a = Tunnel.active() self.str_var.set(value=self.a) - with open(wg_set, "r", encoding="utf-8") as set_file5: - lines5 = set_file5.readlines() + with open(wg_set, "r", encoding="utf-8") as set_f5: + lines5 = set_f5.readlines() if ( select_tl == lines5[7].strip() and "off\n" not in lines5[7].strip() @@ -877,11 +849,11 @@ class FrameWidgets(ttk.Frame): select_tl = self.l_box.get(select_tunnel[0]) if self.selected_option.get() == 0: - with open(wg_set, "r", encoding="utf-8") as set_file3: - lines3 = set_file3.readlines() + with open(wg_set, "r", encoding="utf-8") as set_f3: + lines3 = set_f3.readlines() lines3[7] = "off\n" - with open(wg_set, "w", encoding="utf-8") as set_file3: - set_file3.writelines(lines3) + with open(wg_set, "w", encoding="utf-8") as set_f3: + set_f3.writelines(lines3) tl = Tunnel.list() @@ -889,11 +861,11 @@ class FrameWidgets(ttk.Frame): self.wg_autostart.configure(state="disabled") if self.selected_option.get() >= 1: - with open(wg_set, "r", encoding="utf-8") as set_file3: - lines3 = set_file3.readlines() + with open(wg_set, "r", encoding="utf-8") as set_f3: + lines3 = set_f3.readlines() lines3[7] = select_tl - with open(wg_set, "w", encoding="utf-8") as set_file3: - set_file3.writelines(lines3) + with open(wg_set, "w", encoding="utf-8") as set_f3: + set_f3.writelines(lines3) except IndexError: self.selected_option.set(1) @@ -906,8 +878,8 @@ class FrameWidgets(ttk.Frame): Set (on), the selected tunnel is displayed in the label. At (off) the label is first emptied then filled with No Autoconnect """ - with open(wg_set, "r", encoding="utf-8") as set_file4: - lines4 = set_file4.readlines() + with open(wg_set, "r", encoding="utf-8") as set_f4: + lines4 = set_f4.readlines() if lines4[7] != "off\n": print(lines4[7])