add new class LxTools and funktion to methode in new class
This commit is contained in:
parent
c43c12f961
commit
87943b2489
Binary file not shown.
@ -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:
|
||||
|
104
wirepy.py
104
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])
|
||||
|
Loading…
x
Reference in New Issue
Block a user