Message window optimized

This commit is contained in:
Désiré Werner Menrath 2025-04-26 21:32:35 +02:00
parent cd625d173d
commit 97ea07d34b
3 changed files with 39 additions and 82 deletions

View File

@ -170,8 +170,8 @@ class LxTools(tk.Tk):
""" """
Creates message windows Creates message windows
:argument img_w = Image for Tk Window :argument img_w = Image for TK window which is displayed to the left of the text
:argument img_i = Image for Icon :argument img_i = Image for Task Icon
:argument w_title = Windows Title :argument w_title = Windows Title
:argument w_txt = Text for Tk Window :argument w_txt = Text for Tk Window
:argument txt2 = Text for Button two :argument txt2 = Text for Button two
@ -291,15 +291,17 @@ class GiteaUpdate:
return req return req
@staticmethod @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 Downloads new version of wirepy
Args: Args:
urld: Download URL urld: Download URL
down_ok_image: Path to success image
down_not_ok_image: Path to error image
res: Result filename 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: try:
to_down: str = f"wget -qP {Path.home()} {" "} {urld}" to_down: str = f"wget -qP {Path.home()} {" "} {urld}"
@ -307,30 +309,21 @@ class GiteaUpdate:
if result == 0: if result == 0:
shutil.chown(f"{Path.home()}/{res}.zip", 1000, 1000) 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") wt: str = _("Download Successful")
msg_t: str = _("Your zip file is in home directory") 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: 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") wt: str = _("Download error")
msg_t: str = _("Download failed! Please try again") 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: 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") wt: str = _("Download error")
msg_t: str = _("Download failed! No internet connection!") 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: class Tunnel:
@ -407,11 +400,16 @@ class Tunnel:
return wg_s return wg_s
@staticmethod @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. This will export the tunnels.
A zipfile with the current date and time is created A zipfile with the current date and time is created
in the user's home directory with the correct right 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_time: datetime = datetime.now()
now_datetime: str = now_time.strftime("wg-exp-%m-%d-%Y-%H:%M") 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: with zipfile.ZipFile(f"{wg_tar}.zip", "r") as zf:
if len(zf.namelist()) != 0: 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") wt: str = _("Export Successful")
msg_t: str = _("Your zip file is in home directory") 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: 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") wt: str = _("Export error")
msg_t: str = _("Export failed! Please try again") 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: 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") wt: str = _("Select tunnel")
msg_t: str = _("Please first import 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: except TypeError:
pass pass

View File

@ -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) 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 # Translate
APP = "wirepy" APP = "wirepy"
LOCALE_DIR = "/usr/share/locale/" 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.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.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.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(): def update():
""" """
@ -169,9 +172,6 @@ class FrameWidgets(ttk.Frame):
def link_btn(): def link_btn():
webbrowser.open("https://git.ilunix.de/punix/Wire-Py") 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") wt = _("Info")
msg_t = _("Wire-Py a simple Wireguard Gui for Linux systems.\n\n" msg_t = _("Wire-Py a simple Wireguard Gui for Linux systems.\n\n"
"Wire-Py is open source software written in Python.\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") txt2 = _("Go to Wire-Py git")
com = link_btn 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 # Frame for Menu
self.menu_frame = ttk.Frame(self) self.menu_frame = ttk.Frame(self)
@ -254,9 +254,7 @@ class FrameWidgets(ttk.Frame):
self.update_btn.configure(menu=self.download, style="Toolbutton") self.update_btn.configure(menu=self.download, style="Toolbutton")
self.download.add_command( self.download.add_command(
label=_("Download"), label=_("Download"),
command=lambda: GiteaUpdate.download(f"https://git.ilunix.de/punix/Wire-Py/archive/{res}.zip", command=lambda: GiteaUpdate.download(f"https://git.ilunix.de/punix/Wire-Py/archive/{res}.zip", res, img_w, img_i, img_w2, img_i2))
r"/usr/share/icons/lx-icons/48/wg_vpn.png",
r"/usr/share/icons/lx-icons/48/wg_msg.png", res))
# Show active Tunnel # Show active Tunnel
self.a = Tunnel.active() self.a = Tunnel.active()
@ -422,21 +420,15 @@ class FrameWidgets(ttk.Frame):
if self.l_box.size() != 0: 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") wt = _("Select tunnel")
msg_t = _("Please select a tunnel from the list") 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: 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") wt = _("Select tunnel")
msg_t = _("Please first import 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 # Button Trash
self.btn_tr = ttk.Button(self.lb_frame_btn_lbox, image=self.tr_pic, command=delete, padding=0, 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) Tooltip(self.btn_tr, _("Click to delete a Wireguard Tunnel\nSelect from the list!"), tips)
# Button Export # 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) self.btn_exp.grid(column=0, row=3, padx=15, pady=8)
if self.l_box.size() == 0: if self.l_box.size() == 0:
@ -474,30 +466,21 @@ class FrameWidgets(ttk.Frame):
if len(self.lb_rename.get()) > 12: 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") wt = _("Renaming not possible")
msg_t = _("The new name may contain only 12 characters") 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: 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") wt = _("Renaming not possible")
msg_t = _("At least one character must be entered") 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()): 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") wt = _("Renaming not possible")
msg_t = _("No valid sign. These must not be used.\nBlank, Slash, Backslash and { }\n") 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: else:
@ -532,12 +515,9 @@ class FrameWidgets(ttk.Frame):
except IndexError: 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") wt = _("Renaming not possible")
msg_t = _("Please select a tunnel from the list") 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 # Button Rename
self.btn_rename = ttk.Button(self.lb_frame4, text=_("Rename"), state="disable", command=tl_rename, padding=4, 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() p_key = readfile.readlines()
if pre_key in p_key or f"{pre_key}\n" in p_key: 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") wt = _("Import Error")
msg_t = _("Tunnel already available!\nPlease use another file for import") 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: else:
@ -681,12 +658,9 @@ class FrameWidgets(ttk.Frame):
pass pass
else: 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") wt = _("Import Error")
msg_t = _("Oh... no valid Wireguard File!\nPlease select a valid Wireguard File") 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: except EOFError as e:
print(e) print(e)
@ -741,7 +715,7 @@ class FrameWidgets(ttk.Frame):
lines4 = set_f4.readlines() lines4 = set_f4.readlines()
if lines4[7] != "off\n": if lines4[7] != "off\n":
print(lines4[7]) print(f"{lines4[7]} starts automatically when the system starts.")
self.selected_option.set(1) self.selected_option.set(1)
self.autoconnect_var.set("") self.autoconnect_var.set("")
self.auto_con = lines4[7] self.auto_con = lines4[7]
@ -749,7 +723,7 @@ class FrameWidgets(ttk.Frame):
else: else:
self.selected_option.set(0) self.selected_option.set(0)
self.auto_con = _("no Autoconnect") self.auto_con = _("no Autoconnect")
print("Autostart disabled.")
self.autoconnect_var.set("") self.autoconnect_var.set("")
self.autoconnect_var = tk.StringVar() self.autoconnect_var = tk.StringVar()
self.autoconnect_var.set(self.auto_con) self.autoconnect_var.set(self.auto_con)
@ -887,21 +861,15 @@ class FrameWidgets(ttk.Frame):
if self.l_box.size() != 0: 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") wt = _("Select tunnel")
msg_t = _("Please select a tunnel from the list") 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: 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") wt = _("Select tunnel")
msg_t = _("Please first import 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__": if __name__ == "__main__":