Message window optimized2

This commit is contained in:
Désiré Werner Menrath 2025-04-26 22:33:59 +02:00
parent 97ea07d34b
commit 4eb9d6acd4
4 changed files with 45 additions and 66 deletions

3
.idea/workspace.xml generated
View File

@ -5,10 +5,7 @@
</component>
<component name="ChangeListManager">
<list default="true" id="940e1630-c825-4d4c-be80-bc11f543c122" name="Changes" comment=" - Update Translate Files">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cls_mth_fc.py" beforeDir="false" afterPath="$PROJECT_DIR$/cls_mth_fc.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ssl_decrypt.py" beforeDir="false" afterPath="$PROJECT_DIR$/ssl_decrypt.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ssl_encrypt.py" beforeDir="false" afterPath="$PROJECT_DIR$/ssl_encrypt.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/wirepy.py" beforeDir="false" afterPath="$PROJECT_DIR$/wirepy.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />

View File

@ -400,7 +400,7 @@ class Tunnel:
return wg_s
@staticmethod
def export(img_w: str = None, img_i: str = None, img_w2: str = None, img_i2: str = None) -> None:
def export(img_w: str = None, img_i: str = None, img_w2: str = None, img_i2: str = None, sl: str = None, pfit:str = None) -> None:
"""
This will export the tunnels.
A zipfile with the current date and time is created
@ -425,21 +425,17 @@ class Tunnel:
with zipfile.ZipFile(f"{wg_tar}.zip", "r") as zf:
if len(zf.namelist()) != 0:
wt: str = _("Export Successful")
msg_t: str = _("Your zip file is in home directory")
LxTools.msg_window(img_w, img_i, wt, msg_t)
LxTools.msg_window(img_w, img_i, _("Export Successful"), msg_t)
else:
wt: str = _("Export error")
msg_t: str = _("Export failed! Please try again")
LxTools.msg_window(img_w2, img_i2, wt, msg_t)
LxTools.msg_window(img_w2, img_i2, _("Export error"), msg_t)
else:
wt: str = _("Select tunnel")
msg_t: str = _("Please first import tunnel")
LxTools.msg_window(img_w, img_i2, wt, msg_t)
LxTools.msg_window(img_w, img_i2, sl, pfit)
except TypeError:
pass
@ -497,4 +493,4 @@ class Tooltip:
if self.tooltip_window:
self.tooltip_window.destroy()
self.tooltip_window = None

View File

@ -25,18 +25,13 @@ tcl_path: Path = Path("/usr/share/TK-Themes")
set_file: Path = Path(Path.home() / ".config/wire_py/settings")
tips = LxTools.if_tip(set_file)
folder_path: Path = Path("/tmp/tlecdcwg/")
userfile = Path("/tmp/.log_user")
user_file = Path("/tmp/.log_user")
# 1 = 1. Year, 09 = Month of the Year, 2924 = Day and Year of the Year
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/"
@ -45,12 +40,21 @@ gettext.bindtextdomain(APP, LOCALE_DIR)
gettext.textdomain(APP)
_ = gettext.gettext
LxTools.sigi(folder_path, userfile)
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"
sl: str = _("Select tunnel")
rnp: str = _("Renaming not possible")
ie:str = _("Import Error")
pfit: str = _("Please first import tunnel")
pstl: str = _("Please select a tunnel from the list")
LxTools.sigi(folder_path, user_file)
class Wirepy(tk.Tk):
"""
Class Wirepy this is Main Window of wirepy
Class Wirepy this is the Main Window of wirepy
"""
def __init__(self, *args, **kwargs):
@ -76,7 +80,7 @@ class Wirepy(tk.Tk):
else:
self.tk.call("set_theme", "dark")
# Load the image file from disk
# Load the image file from the disk
self.wg_icon = tk.PhotoImage(file=r"/usr/share/icons/lx-icons/48/wg_vpn.png")
# Set it as the window icon
@ -126,7 +130,7 @@ class FrameWidgets(ttk.Frame):
def theme_change_light():
"""
Set light theme
Set a light theme
"""
if self.tk.call("ttk::style", "theme", "use") == "water-dark":
self.tk.call("set_theme", "light")
@ -139,7 +143,7 @@ class FrameWidgets(ttk.Frame):
def theme_change_dark():
"""
Set dark theme
Set a dark theme
"""
if not self.tk.call("ttk::style", "theme", "use") == "water-dark":
self.tk.call("set_theme", "dark")
@ -152,7 +156,7 @@ class FrameWidgets(ttk.Frame):
def tooltip():
"""
Set True or False in file
Set True or False in a file
"""
if set_tip.get():
with open(set_file, "r", encoding="utf-8") as set_f2:
@ -172,15 +176,12 @@ class FrameWidgets(ttk.Frame):
def link_btn():
webbrowser.open("https://git.ilunix.de/punix/Wire-Py")
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"
"Email: polunga40@unity-mail.de also likes for donation.\n\n"
"Use without warranty!\n")
txt2 = _("Go to Wire-Py git")
com = link_btn
LxTools.msg_window(img_i, img_i, wt, msg_t, txt2, com)
LxTools.msg_window(img_i, img_i, _("Info"), msg_t, _("Go to Wire-Py git"), link_btn)
# Frame for Menu
self.menu_frame = ttk.Frame(self)
@ -219,7 +220,7 @@ class FrameWidgets(ttk.Frame):
self.updates_lb = ttk.Label(self.menu_frame)
self.updates_lb.grid(column=4, columnspan=3, row=0, padx=10)
# View Checkbox for enable or disable Tooltip
# View Checkbox to enable or disable Tooltip
if tips:
set_tip.set(value=False)
else:
@ -254,7 +255,8 @@ 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", res, img_w, img_i, img_w2, img_i2))
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()
@ -394,7 +396,7 @@ class FrameWidgets(ttk.Frame):
file_one.replace(file_two)
self.wg_autostart.configure(state="disabled")
# for disable checkbox when Listbox empty
# for disabling checkbox when Listbox empty
if self.l_box.size() == 0:
self.wg_autostart.configure(state="disabled")
self.lb_rename.configure(state="disabled")
@ -420,15 +422,11 @@ class FrameWidgets(ttk.Frame):
if self.l_box.size() != 0:
wt = _("Select tunnel")
msg_t = _("Please select a tunnel from the list")
LxTools.msg_window(img_w, img_i2, wt, msg_t)
LxTools.msg_window(img_w, img_i2, sl, pstl)
else:
wt = _("Select tunnel")
msg_t = _("Please first import tunnel")
LxTools.msg_window(img_w, img_i2, wt, msg_t)
LxTools.msg_window(img_w, img_i2, sl, pfit)
# Button Trash
self.btn_tr = ttk.Button(self.lb_frame_btn_lbox, image=self.tr_pic, command=delete, padding=0,
@ -441,7 +439,8 @@ 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=lambda: Tunnel.export(img_w, img_i, img_w2, img_i2), 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, sl, pfit), padding=0)
self.btn_exp.grid(column=0, row=3, padx=15, pady=8)
if self.l_box.size() == 0:
@ -466,21 +465,16 @@ class FrameWidgets(ttk.Frame):
if len(self.lb_rename.get()) > 12:
wt = _("Renaming not possible")
msg_t = _("The new name may contain only 12 characters")
LxTools.msg_window(img_w, img_i2, wt, msg_t)
LxTools.msg_window(img_w, img_i2, rnp, _("The new name may contain only 12 characters"))
elif len(self.lb_rename.get()) == 0:
wt = _("Renaming not possible")
msg_t = _("At least one character must be entered")
LxTools.msg_window(img_w, img_i2, wt, msg_t)
LxTools.msg_window(img_w, img_i2, rnp, _("At least one character must be entered"))
elif any(ch in special_characters for ch in self.lb_rename.get()):
wt = _("Renaming not possible")
msg_t = _("No valid sign. These must not be used.\nBlank, Slash, Backslash and { }\n")
LxTools.msg_window(img_w, img_i2, wt, msg_t)
LxTools.msg_window(img_w, img_i2, rnp, msg_t)
else:
@ -515,9 +509,7 @@ class FrameWidgets(ttk.Frame):
except IndexError:
wt = _("Renaming not possible")
msg_t = _("Please select a tunnel from the list")
LxTools.msg_window(img_w, img_i2, wt, msg_t)
LxTools.msg_window(img_w, img_i2, rnp, pstl)
# Button Rename
self.btn_rename = ttk.Button(self.lb_frame4, text=_("Rename"), state="disable", command=tl_rename, padding=4,
@ -553,12 +545,12 @@ class FrameWidgets(ttk.Frame):
"""
Import Methode for Wireguard config Files.
Before importing, it is checked whether PrivateKey and PublicKey are in the file.
If True then it is checked whether the PreSharedKey is already in the key file
If True, then it is checked whether the PreSharedKey is already in the key file
to avoid an import error so that no double wgconf are imported.
Thus, tunnels can be renamed without the problems arise.
If False then the key is written into the file.
Thus, tunnels can be renamed without the problems arising.
If False, then the key is written into the file.
Furthermore, it is checked whether the name is longer than 12 characters.
If True then the name is automatically shortened to 12 characters
If True, then the name is automatically shortened to 12 characters
and then imported.
If in each case false comes out, a corresponding window comes to
inform the user that something is wrong.
@ -585,9 +577,8 @@ class FrameWidgets(ttk.Frame):
p_key = readfile.readlines()
if pre_key in p_key or f"{pre_key}\n" in p_key:
wt = _("Import Error")
msg_t = _("Tunnel already available!\nPlease use another file for import")
LxTools.msg_window(img_w2, img_i2, wt, msg_t)
LxTools.msg_window(img_w2, img_i2, ie, msg_t)
else:
@ -658,9 +649,8 @@ class FrameWidgets(ttk.Frame):
pass
else:
wt = _("Import Error")
msg_t = _("Oh... no valid Wireguard File!\nPlease select a valid Wireguard File")
LxTools.msg_window(img_w2, img_i2, wt, msg_t)
LxTools.msg_window(img_w2, img_i2, ie, msg_t)
except EOFError as e:
print(e)
@ -707,7 +697,7 @@ class FrameWidgets(ttk.Frame):
def on_off(self):
"""
Here it is checked whether the path to the file is there if not it is created.
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.
At (off) the label is first emptied then filled with No Autoconnect
"""
@ -798,7 +788,7 @@ class FrameWidgets(ttk.Frame):
def color_label(self):
"""
View activ Tunnel in color green or yellow
View activ Tunnel in the color green or yellow
"""
with open(set_file, "r", encoding="utf-8") as read_file:
@ -861,15 +851,11 @@ class FrameWidgets(ttk.Frame):
if self.l_box.size() != 0:
wt = _("Select tunnel")
msg_t = _("Please select a tunnel from the list")
LxTools.msg_window(img_w, img_i2, wt, msg_t)
LxTools.msg_window(img_w, img_i2, sl, pstl)
else:
wt = _("Select tunnel")
msg_t = _("Please first import tunnel")
LxTools.msg_window(img_w, img_i2, wt, msg_t)
LxTools.msg_window(img_w, img_i2, sl, pfit)
if __name__ == "__main__":
@ -885,5 +871,5 @@ if __name__ == "__main__":
window.tk.call("set", "::tk::dialog::file::showHiddenVar", "0")
window.mainloop()
LxTools.clean_files(folder_path, userfile)
LxTools.clean_files(folder_path, user_file)
sys.exit(0)