methods optimized in wirepy and cls_mth_fc

This commit is contained in:
Désiré Werner Menrath 2025-04-29 11:39:05 +02:00
parent 6f02724daa
commit 213f772f40
3 changed files with 36 additions and 50 deletions

View File

@ -135,8 +135,7 @@ class LxTools(tk.Tk):
"""
log_name: str = f"{Path.home()}"[6:]
file: Path = Path.home() / "/tmp/.log_user"
with open(file, "w", encoding="utf-8") as f:
f.write(log_name)
Path(file).write_text(log_name, encoding="utf-8")
@staticmethod
def clean_files(folder_path: Path = None, file: Path = None) -> None:
@ -156,13 +155,12 @@ class LxTools(tk.Tk):
"""
method that writes in file whether tooltip is displayed or not
"""
with open(path, "r", encoding="utf-8") as set_f2:
lines2 = set_f2.readlines()
if "False\n" in lines2:
tip = False
else:
tip = True
return tip
lines = Path(path).read_text(encoding="utf-8")
if "False\n" in lines:
tip = False
else:
tip = True
return tip
@staticmethod
def msg_window(img_w: str, img_i: str, w_title: str, w_txt: str, txt2: Optional[str] = None,

View File

@ -349,11 +349,9 @@ class FrameWidgets(ttk.Frame):
"""
if self.tk.call("ttk::style", "theme", "use") == "water-dark":
self.tk.call("set_theme", "light")
with open(set_file, "r", encoding="utf-8") as theme_set2:
lines3 = theme_set2.readlines()
lines3[3] = "light\n"
with open(set_file, "w", encoding="utf-8") as theme_set2:
theme_set2.writelines(lines3)
lines = Path(set_file).read_text(encoding="utf-8").splitlines(keepends=True) # (keepends=True) = not changed
lines[3] = 'light\n'
Path(set_file).write_text(''.join(lines), encoding="utf-8")
self.color_label()
def theme_change_dark(self):
@ -362,33 +360,27 @@ class FrameWidgets(ttk.Frame):
"""
if not self.tk.call("ttk::style", "theme", "use") == "water-dark":
self.tk.call("set_theme", "dark")
with open(set_file, "r", encoding="utf-8") as theme_set2:
lines4 = theme_set2.readlines()
lines4[3] = "dark\n"
with open(set_file, "w", encoding="utf-8") as theme_set2:
theme_set2.writelines(lines4)
lines = Path(set_file).read_text(encoding="utf-8").splitlines(keepends=True)
lines[3] = 'dark\n'
Path(set_file).write_text(''.join(lines), encoding="utf-8")
self.color_label()
@staticmethod
def update_setting(update_res):
def update_setting(update_res) -> None:
"""
write off or on in file
Args:
update_res (int): argument that is passed contains 0 or 1
"""
if update_res == 1:
with open(set_file, "r", encoding="utf-8") as set_f2:
lines2 = set_f2.readlines()
lines2[1] = "off\n"
with open(set_file, "w", encoding="utf-8") as set_f2:
set_f2.writelines(lines2)
lines = Path(set_file).read_text(encoding="utf-8").splitlines(keepends=True)
lines[1] = 'off\n'
Path(set_file).write_text(''.join(lines), encoding="utf-8")
else:
with open(set_file, "r", encoding="utf-8") as set_f2:
lines2 = set_f2.readlines()
lines2[1] = "on\n"
with open(set_file, "w", encoding="utf-8") as set_f2:
set_f2.writelines(lines2)
lines = Path(set_file).read_text(encoding="utf-8").splitlines(keepends=True)
lines[1] = 'on\n'
Path(set_file).write_text(''.join(lines), encoding="utf-8")
@staticmethod
def tooltip(tip) -> None:
@ -398,20 +390,16 @@ class FrameWidgets(ttk.Frame):
tip (bool): argument that is passed contains True or False
"""
if tip:
with open(set_file, "r", encoding="utf-8") as set_f2:
lines2 = set_f2.readlines()
lines2[5] = "False\n"
with open(set_file, "w", encoding="utf-8") as set_f2:
set_f2.writelines(lines2)
lines = Path(set_file).read_text(encoding="utf-8").splitlines(keepends=True)
lines[5] = 'False\n'
Path(set_file).write_text(''.join(lines), encoding="utf-8")
else:
with open(set_file, "r", encoding="utf-8") as set_f2:
lines2 = set_f2.readlines()
lines2[5] = "True\n"
with open(set_file, "w", encoding="utf-8") as set_f2:
set_f2.writelines(lines2)
lines = Path(set_file).read_text(encoding="utf-8").splitlines(keepends=True)
lines[5] = 'True\n'
Path(set_file).write_text(''.join(lines), encoding="utf-8")
def enable_check_box(self, _):
def enable_check_box(self, _) -> None:
"""
checkbox for enable autostart Tunnel
"""
@ -422,7 +410,7 @@ class FrameWidgets(ttk.Frame):
self.lb_rename.delete(0, tk.END)
self.btn_rename.config(state="normal")
def delete(self):
def delete(self) -> None:
"""
delete Wireguard Tunnel
"""
@ -541,7 +529,7 @@ class FrameWidgets(ttk.Frame):
except subprocess.CalledProcessError:
pass
def import_sl(self):
def import_sl(self) -> None:
"""
Import Methode for Wireguard config Files.
Before importing, it is checked whether PrivateKey and PublicKey are in the file.
@ -671,7 +659,7 @@ class FrameWidgets(ttk.Frame):
self.show_data()
return data
def box_set(self):
def box_set(self) -> None:
"""
This Method will display the autostarted label which
Tunnel is automatically started regardless of the active tunnel.
@ -705,7 +693,7 @@ class FrameWidgets(ttk.Frame):
self.on_off()
def on_off(self):
def on_off(self) -> None:
"""
Here it is checked whether the path to the file is there, if not, it is created.
Set (on), the selected tunnel is displayed in the label.
@ -732,7 +720,7 @@ class FrameWidgets(ttk.Frame):
self.autoconnect.config(font=("Ubuntu", 11))
self.autoconnect.grid(column=1, row=0, sticky="e", pady=19)
def init_and_report(self, data=None):
def init_and_report(self, data=None) -> None:
"""
Displays the value address, DNS and peer in the labels
or empty it again
@ -755,7 +743,7 @@ class FrameWidgets(ttk.Frame):
for field in fields:
field.set("")
def show_data(self):
def show_data(self) -> None:
"""
shows data in the label
"""
@ -775,7 +763,7 @@ class FrameWidgets(ttk.Frame):
self.endpoint.grid(column=0, row=8, sticky="w", padx=10, pady=20)
self.endpoint.config(font=("Ubuntu", 9))
def stop(self):
def stop(self) -> None:
"""
Stop Button
"""
@ -785,7 +773,7 @@ class FrameWidgets(ttk.Frame):
Tooltip(self.btn_stst, _("Click to stop selected Wireguard Tunnel"), tips)
def start(self):
def start(self) -> None:
"""
Start Button
"""
@ -799,7 +787,7 @@ class FrameWidgets(ttk.Frame):
else:
Tooltip(self.btn_stst, _("Click to start selected Wireguard Tunnel"), tips)
def color_label(self):
def color_label(self) -> None:
"""
View activ Tunnel in the color green or yellow
"""