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
:argument img_w = Image for Tk Window
:argument img_i = Image for Icon
:argument img_w = Image for TK window which is displayed to the left of the text
:argument img_i = Image for Task Icon
:argument w_title = Windows Title
:argument w_txt = Text for Tk Window
:argument txt2 = Text for Button two
@ -291,15 +291,17 @@ class GiteaUpdate:
return req
@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
Args:
urld: Download URL
down_ok_image: Path to success image
down_not_ok_image: Path to error image
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:
to_down: str = f"wget -qP {Path.home()} {" "} {urld}"
@ -307,30 +309,21 @@ class GiteaUpdate:
if result == 0:
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")
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:
# 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")
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:
# 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")
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:
@ -407,11 +400,16 @@ class Tunnel:
return wg_s
@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.
A zipfile with the current date and time is created
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_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:
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")
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:
# 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")
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:
# 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")
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:
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)
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
APP = "wirepy"
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.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.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():
"""
@ -169,9 +172,6 @@ class FrameWidgets(ttk.Frame):
def link_btn():
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")
msg_t = _("Wire-Py a simple Wireguard Gui for Linux systems.\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")
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
self.menu_frame = ttk.Frame(self)
@ -254,9 +254,7 @@ class FrameWidgets(ttk.Frame):
self.update_btn.configure(menu=self.download, style="Toolbutton")
self.download.add_command(
label=_("Download"),
command=lambda: GiteaUpdate.download(f"https://git.ilunix.de/punix/Wire-Py/archive/{res}.zip",
r"/usr/share/icons/lx-icons/48/wg_vpn.png",
r"/usr/share/icons/lx-icons/48/wg_msg.png", res))
command=lambda: GiteaUpdate.download(f"https://git.ilunix.de/punix/Wire-Py/archive/{res}.zip", res, img_w, img_i, img_w2, img_i2))
# Show active Tunnel
self.a = Tunnel.active()
@ -422,21 +420,15 @@ class FrameWidgets(ttk.Frame):
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")
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:
# 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")
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
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)
# 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)
if self.l_box.size() == 0:
@ -474,30 +466,21 @@ class FrameWidgets(ttk.Frame):
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")
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:
# 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")
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()):
# 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")
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:
@ -532,12 +515,9 @@ class FrameWidgets(ttk.Frame):
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")
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
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()
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")
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:
@ -681,12 +658,9 @@ class FrameWidgets(ttk.Frame):
pass
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")
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:
print(e)
@ -741,7 +715,7 @@ class FrameWidgets(ttk.Frame):
lines4 = set_f4.readlines()
if lines4[7] != "off\n":
print(lines4[7])
print(f"{lines4[7]} starts automatically when the system starts.")
self.selected_option.set(1)
self.autoconnect_var.set("")
self.auto_con = lines4[7]
@ -749,7 +723,7 @@ class FrameWidgets(ttk.Frame):
else:
self.selected_option.set(0)
self.auto_con = _("no Autoconnect")
print("Autostart disabled.")
self.autoconnect_var.set("")
self.autoconnect_var = tk.StringVar()
self.autoconnect_var.set(self.auto_con)
@ -887,21 +861,15 @@ class FrameWidgets(ttk.Frame):
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")
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:
# 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")
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__":