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:
|
else:
|
||||||
print(f"Error with the following code... {process.returncode}")
|
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
|
def theme_change_dark(self):
|
||||||
"""
|
"""
|
||||||
logname = f"{Path.home()}"[6:]
|
Set dark theme
|
||||||
file = Path.home() / "/tmp/.loguser"
|
"""
|
||||||
with open(file, "w", encoding="utf-8") as f:
|
if not self.tk.call("ttk::style", "theme", "use") == "water-dark":
|
||||||
f.write(logname)
|
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:
|
class GiteaUpdate:
|
||||||
@ -161,9 +194,9 @@ class GiteaUpdate:
|
|||||||
response = requests.get(update_api_url, timeout=10)
|
response = requests.get(update_api_url, timeout=10)
|
||||||
response_dict = response.json()
|
response_dict = response.json()
|
||||||
response_dict = response_dict[0]
|
response_dict = response_dict[0]
|
||||||
with open(wg_set, "r", encoding="utf-8") as set_file:
|
with open(wg_set, "r", encoding="utf-8") as set_f:
|
||||||
set_file = set_file.read()
|
set_f = set_f.read()
|
||||||
if "on\n" in set_file:
|
if "on\n" in set_f:
|
||||||
if version[3:] != response_dict["tag_name"]:
|
if version[3:] != response_dict["tag_name"]:
|
||||||
req = response_dict["tag_name"]
|
req = response_dict["tag_name"]
|
||||||
else:
|
else:
|
||||||
@ -425,8 +458,8 @@ def if_tip(path):
|
|||||||
"""
|
"""
|
||||||
method that writes in file whether tooltip is displayed or not
|
method that writes in file whether tooltip is displayed or not
|
||||||
"""
|
"""
|
||||||
with open(path, "r", encoding="utf-8") as set_file2:
|
with open(path, "r", encoding="utf-8") as set_f2:
|
||||||
lines2 = set_file2.readlines()
|
lines2 = set_f2.readlines()
|
||||||
if "False\n" in lines2:
|
if "False\n" in lines2:
|
||||||
tip = False
|
tip = False
|
||||||
else:
|
else:
|
||||||
|
104
wirepy.py
104
wirepy.py
@ -15,9 +15,9 @@ from subprocess import check_call
|
|||||||
from tkinter import TclError, filedialog, ttk
|
from tkinter import TclError, filedialog, ttk
|
||||||
|
|
||||||
from cls_mth_fc import (Create, GiteaUpdate, Tooltip, Tunnel, if_tip,
|
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.dir_and_files()
|
||||||
Create.make_dir()
|
Create.make_dir()
|
||||||
Create.decrypt()
|
Create.decrypt()
|
||||||
@ -120,62 +120,36 @@ class FrameWidgets(ttk.Frame):
|
|||||||
Set on or off in file
|
Set on or off in file
|
||||||
"""
|
"""
|
||||||
if set_update.get() == 1:
|
if set_update.get() == 1:
|
||||||
with open(wg_set, "r", encoding="utf-8") as set_file2:
|
with open(wg_set, "r", encoding="utf-8") as set_f2:
|
||||||
lines2 = set_file2.readlines()
|
lines2 = set_f2.readlines()
|
||||||
lines2[1] = "off\n"
|
lines2[1] = "off\n"
|
||||||
with open(wg_set, "w", encoding="utf-8") as set_file2:
|
with open(wg_set, "w", encoding="utf-8") as set_f2:
|
||||||
set_file2.writelines(lines2)
|
set_f2.writelines(lines2)
|
||||||
|
|
||||||
if set_update.get() == 0:
|
if set_update.get() == 0:
|
||||||
with open(wg_set, "r", encoding="utf-8") as set_file2:
|
with open(wg_set, "r", encoding="utf-8") as set_f2:
|
||||||
lines2 = set_file2.readlines()
|
lines2 = set_f2.readlines()
|
||||||
lines2[1] = "on\n"
|
lines2[1] = "on\n"
|
||||||
with open(wg_set, "w", encoding="utf-8") as set_file2:
|
with open(wg_set, "w", encoding="utf-8") as set_f2:
|
||||||
set_file2.writelines(lines2)
|
set_f2.writelines(lines2)
|
||||||
|
|
||||||
def tooltip():
|
def tooltip():
|
||||||
"""
|
"""
|
||||||
Set True or False in file
|
Set True or False in file
|
||||||
"""
|
"""
|
||||||
if set_tip.get():
|
if set_tip.get():
|
||||||
with open(wg_set, "r", encoding="utf-8") as set_file2:
|
with open(wg_set, "r", encoding="utf-8") as set_f2:
|
||||||
lines2 = set_file2.readlines()
|
lines2 = set_f2.readlines()
|
||||||
lines2[5] = "False\n"
|
lines2[5] = "False\n"
|
||||||
with open(wg_set, "w", encoding="utf-8") as set_file2:
|
with open(wg_set, "w", encoding="utf-8") as set_f2:
|
||||||
set_file2.writelines(lines2)
|
set_f2.writelines(lines2)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
with open(wg_set, "r", encoding="utf-8") as set_file2:
|
with open(wg_set, "r", encoding="utf-8") as set_f2:
|
||||||
lines2 = set_file2.readlines()
|
lines2 = set_f2.readlines()
|
||||||
lines2[5] = "True\n"
|
lines2[5] = "True\n"
|
||||||
with open(wg_set, "w", encoding="utf-8") as set_file2:
|
with open(wg_set, "w", encoding="utf-8") as set_f2:
|
||||||
set_file2.writelines(lines2)
|
set_f2.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()
|
|
||||||
|
|
||||||
def info():
|
def info():
|
||||||
def link_btn():
|
def link_btn():
|
||||||
@ -223,8 +197,8 @@ class FrameWidgets(ttk.Frame):
|
|||||||
self.settings.add_checkbutton(
|
self.settings.add_checkbutton(
|
||||||
label=_("Disable Tooltips"), command=tooltip, variable=set_tip
|
label=_("Disable Tooltips"), command=tooltip, variable=set_tip
|
||||||
)
|
)
|
||||||
self.settings.add_command(label=_("Light"), command=theme_change_light)
|
self.settings.add_command(label=_("Light"), command=lambda: LxTools.theme_change_light(self))
|
||||||
self.settings.add_command(label=_("Dark"), command=theme_change_dark)
|
self.settings.add_command(label=_("Dark"), command=lambda: LxTools.theme_change_dark(self))
|
||||||
|
|
||||||
# About BTN Menu / Label
|
# About BTN Menu / Label
|
||||||
self.about_btn = ttk.Button(
|
self.about_btn = ttk.Button(
|
||||||
@ -398,15 +372,15 @@ class FrameWidgets(ttk.Frame):
|
|||||||
pre_key = key[3]
|
pre_key = key[3]
|
||||||
check_call(["nmcli", "connection", "delete", select_tl])
|
check_call(["nmcli", "connection", "delete", select_tl])
|
||||||
self.l_box.delete(self.select_tunnel[0])
|
self.l_box.delete(self.select_tunnel[0])
|
||||||
with open(wg_set, "r", encoding="utf-8") as set_file6:
|
with open(wg_set, "r", encoding="utf-8") as set_f6:
|
||||||
lines6 = set_file6.readlines()
|
lines6 = set_f6.readlines()
|
||||||
if (
|
if (
|
||||||
select_tl == lines6[7].strip()
|
select_tl == lines6[7].strip()
|
||||||
and "off\n" not in lines6[7].strip()
|
and "off\n" not in lines6[7].strip()
|
||||||
):
|
):
|
||||||
lines6[7] = "off\n"
|
lines6[7] = "off\n"
|
||||||
with open(wg_set, "w", encoding="utf-8") as set_file7:
|
with open(wg_set, "w", encoding="utf-8") as set_f7:
|
||||||
set_file7.writelines(lines6)
|
set_f7.writelines(lines6)
|
||||||
self.selected_option.set(0)
|
self.selected_option.set(0)
|
||||||
self.autoconnect_var.set(_("no Autoconnect"))
|
self.autoconnect_var.set(_("no Autoconnect"))
|
||||||
is_encrypt = Path.home() / f".config/wire_py/{select_tl}.dat"
|
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:
|
if self.l_box.size() == 0:
|
||||||
self.wg_autostart.configure(state="disabled")
|
self.wg_autostart.configure(state="disabled")
|
||||||
self.lb_rename.configure(state="disabled")
|
self.lb_rename.configure(state="disabled")
|
||||||
Tooltip(self.wg_autostart, _("You must have at least one\ntunnel",
|
Tooltip(self.wg_autostart, _("You must have at least one\ntunnel in the list,to use the autostart"), tips)
|
||||||
"in the list,to use the autostart"), tips)
|
|
||||||
|
|
||||||
Tooltip(self.btn_exp, _("No Tunnels in List for Export"), 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.btn_stst, _("No tunnels to start in the list"), tips)
|
||||||
Tooltip(self.lb_rename, _("To rename a tunnel, at least one must",
|
Tooltip(self.lb_rename, _("To rename a tunnel, at least one must be in the list"), tips, )
|
||||||
"be in the list"), tips, )
|
|
||||||
self.lb_rename.insert(0, _("Max. 12 characters!"))
|
self.lb_rename.insert(0, _("Max. 12 characters!"))
|
||||||
|
|
||||||
if self.a != "" and self.a == select_tl:
|
if self.a != "" and self.a == select_tl:
|
||||||
@ -580,8 +552,8 @@ class FrameWidgets(ttk.Frame):
|
|||||||
if self.a != "" and self.a == select_tl:
|
if self.a != "" and self.a == select_tl:
|
||||||
self.a = Tunnel.active()
|
self.a = Tunnel.active()
|
||||||
self.str_var.set(value=self.a)
|
self.str_var.set(value=self.a)
|
||||||
with open(wg_set, "r", encoding="utf-8") as set_file5:
|
with open(wg_set, "r", encoding="utf-8") as set_f5:
|
||||||
lines5 = set_file5.readlines()
|
lines5 = set_f5.readlines()
|
||||||
if (
|
if (
|
||||||
select_tl == lines5[7].strip()
|
select_tl == lines5[7].strip()
|
||||||
and "off\n" not in 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])
|
select_tl = self.l_box.get(select_tunnel[0])
|
||||||
|
|
||||||
if self.selected_option.get() == 0:
|
if self.selected_option.get() == 0:
|
||||||
with open(wg_set, "r", encoding="utf-8") as set_file3:
|
with open(wg_set, "r", encoding="utf-8") as set_f3:
|
||||||
lines3 = set_file3.readlines()
|
lines3 = set_f3.readlines()
|
||||||
lines3[7] = "off\n"
|
lines3[7] = "off\n"
|
||||||
with open(wg_set, "w", encoding="utf-8") as set_file3:
|
with open(wg_set, "w", encoding="utf-8") as set_f3:
|
||||||
set_file3.writelines(lines3)
|
set_f3.writelines(lines3)
|
||||||
|
|
||||||
tl = Tunnel.list()
|
tl = Tunnel.list()
|
||||||
|
|
||||||
@ -889,11 +861,11 @@ class FrameWidgets(ttk.Frame):
|
|||||||
self.wg_autostart.configure(state="disabled")
|
self.wg_autostart.configure(state="disabled")
|
||||||
|
|
||||||
if self.selected_option.get() >= 1:
|
if self.selected_option.get() >= 1:
|
||||||
with open(wg_set, "r", encoding="utf-8") as set_file3:
|
with open(wg_set, "r", encoding="utf-8") as set_f3:
|
||||||
lines3 = set_file3.readlines()
|
lines3 = set_f3.readlines()
|
||||||
lines3[7] = select_tl
|
lines3[7] = select_tl
|
||||||
with open(wg_set, "w", encoding="utf-8") as set_file3:
|
with open(wg_set, "w", encoding="utf-8") as set_f3:
|
||||||
set_file3.writelines(lines3)
|
set_f3.writelines(lines3)
|
||||||
|
|
||||||
except IndexError:
|
except IndexError:
|
||||||
self.selected_option.set(1)
|
self.selected_option.set(1)
|
||||||
@ -906,8 +878,8 @@ class FrameWidgets(ttk.Frame):
|
|||||||
Set (on), the selected tunnel is displayed in the label.
|
Set (on), the selected tunnel is displayed in the label.
|
||||||
At (off) the label is first emptied then filled with No Autoconnect
|
At (off) the label is first emptied then filled with No Autoconnect
|
||||||
"""
|
"""
|
||||||
with open(wg_set, "r", encoding="utf-8") as set_file4:
|
with open(wg_set, "r", encoding="utf-8") as set_f4:
|
||||||
lines4 = set_file4.readlines()
|
lines4 = set_f4.readlines()
|
||||||
|
|
||||||
if lines4[7] != "off\n":
|
if lines4[7] != "off\n":
|
||||||
print(lines4[7])
|
print(lines4[7])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user