fix new tooltip signal now in modul cls_mth_fc.py

This commit is contained in:
2025-04-22 14:22:39 +02:00
parent 47bdfbfb17
commit 5753a35d6c
3 changed files with 90 additions and 74 deletions

110
wirepy.py
View File

@ -7,14 +7,22 @@ import locale
import webbrowser
import os
import sys
import signal
import subprocess
import shutil
import tkinter as tk
from pathlib import Path
from subprocess import check_call
from tkinter import filedialog, ttk, TclError
from cls_mth_fc import Tooltip, Tunnel, Create, msg_window, if_tip, GiteaUpdate, uos
from cls_mth_fc import (
Tooltip,
Tunnel,
Create,
msg_window,
sigi,
if_tip,
GiteaUpdate,
uos,
)
uos()
Create.dir_and_files()
@ -23,7 +31,7 @@ Create.decrypt()
tcl_path = Path("/usr/share/TK-Themes")
wg_set = Path(Path.home() / ".config/wire_py/settings")
TIPS = if_tip(wg_set)
tips = if_tip(wg_set)
dirname = Path("/tmp/tlecdcwg/")
# 1 = 1. Year, 09 = Month of the Year, 2924 = Day and Year of the Year
@ -41,38 +49,7 @@ gettext.bindtextdomain(APP, LOCALE_DIR)
gettext.textdomain(APP)
_ = gettext.gettext
def signal_handler(signum, frame):
"""
Determine clear text names for signal numbers
"""
signals_to_names_dict = dict(
(getattr(signal, n), n)
for n in dir(signal)
if n.startswith("SIG") and "_" not in n
)
signame = signals_to_names_dict.get(signum, f"Unnamed signal: {signum}")
# End program for certain signals, report to others only reception
if signum in (signal.SIGINT, signal.SIGTERM):
exit_code = 1
print(
f"\nSignal {signame} {(signum)} received. => Aborting with exit code {exit_code}."
)
shutil.rmtree(dirname)
Path.unlink("/tmp/.loguser")
print("Breakdown by user...")
sys.exit(exit_code)
else:
print(f"Signal {signum} received and ignored.")
shutil.rmtree(dirname)
Path.unlink("/tmp/.loguser")
print("Process unexpectedly ended...")
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
signal.signal(signal.SIGHUP, signal_handler)
sigi(dirname)
class Wirepy(tk.Tk):
@ -238,12 +215,12 @@ class FrameWidgets(ttk.Frame):
self.version_lb.config(font=("Ubuntu", 11), foreground="#00c4ff")
self.version_lb.grid(column=0, row=0, rowspan=4, padx=10)
Tooltip(self.version_lb, f"Version: {VERSION[2:]}", TIPS)
Tooltip(self.version_lb, f"Version: {VERSION[2:]}", tips)
self.options_btn = ttk.Menubutton(self.menu_frame, text=_("Options"))
self.options_btn.grid(column=1, columnspan=1, row=0)
Tooltip(self.options_btn, _("Click for Settings"), TIPS)
Tooltip(self.options_btn, _("Click for Settings"), tips)
set_update = tk.IntVar()
set_tip = tk.BooleanVar()
@ -270,7 +247,7 @@ class FrameWidgets(ttk.Frame):
self.updates_lb.grid(column=4, columnspan=3, row=0, padx=10)
# View Checkbox for enable or disable Tooltip
if TIPS:
if tips:
set_tip.set(value=False)
else:
set_tip.set(value=True)
@ -280,14 +257,14 @@ class FrameWidgets(ttk.Frame):
set_update.set(value=1)
self.updates_lb.configure(text=_("Update search off"))
Tooltip(self.updates_lb, _("Updates you have disabled"), TIPS)
Tooltip(self.updates_lb, _("Updates you have disabled"), tips)
elif res == "No Internet Connection!":
self.updates_lb.configure(text=_("No Server Connection!"), foreground="red")
elif res == "No Updates":
self.updates_lb.configure(text=_("No Updates"))
Tooltip(self.updates_lb, _("Congratulations! Wire-Py is up to date"), TIPS)
Tooltip(self.updates_lb, _("Congratulations! Wire-Py is up to date"), tips)
else:
set_update.set(value=0)
@ -297,7 +274,7 @@ class FrameWidgets(ttk.Frame):
self.update_btn = ttk.Menubutton(self.menu_frame, text=text)
self.update_btn.grid(column=4, columnspan=3, row=0, padx=0)
Tooltip(self.update_btn, _("Click to download new version"), TIPS)
Tooltip(self.update_btn, _("Click to download new version"), tips)
self.download = tk.Menu(self, relief="flat")
@ -420,7 +397,7 @@ class FrameWidgets(ttk.Frame):
)
self.btn_i.grid(column=0, row=1, padx=15, pady=8)
Tooltip(self.btn_i, _("Click to import a Wireguard Tunnel"), TIPS)
Tooltip(self.btn_i, _("Click to import a Wireguard Tunnel"), tips)
def delete():
"""
@ -473,23 +450,20 @@ class FrameWidgets(ttk.Frame):
if self.l_box.size() == 0:
self.wg_autostart.configure(state="disabled")
self.lb_rename.configure(state="disabled")
Tooltip(
self.l_box, _("You must first import\na Wireguard tunnel"), TIPS
)
Tooltip(
self.wg_autostart,
_(
"You must have at least one\ntunnel in the list,to use the autostart"
),
TIPS,
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_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,
tips,
)
self.lb_rename.insert(0, _("Max. 12 characters!"))
@ -535,12 +509,12 @@ class FrameWidgets(ttk.Frame):
self.btn_tr.grid(column=0, row=2, padx=15, pady=8)
if self.l_box.size() == 0:
Tooltip(self.btn_tr, _("No tunnels to delete in the list"), TIPS)
Tooltip(self.btn_tr, _("No tunnels to delete in the list"), tips)
else:
Tooltip(
self.btn_tr,
_("Click to delete a Wireguard Tunnel\nSelect from the list!"),
TIPS,
tips,
)
# Button Export
@ -550,12 +524,12 @@ class FrameWidgets(ttk.Frame):
self.btn_exp.grid(column=0, row=3, padx=15, pady=8)
if self.l_box.size() == 0:
Tooltip(self.btn_exp, _("No Tunnels in List for Export"), TIPS)
Tooltip(self.btn_exp, _("No Tunnels in List for Export"), tips)
else:
Tooltip(
self.btn_exp,
_(" Click to export all\nWireguard Tunnel to Zipfile"),
TIPS,
tips,
)
# Label Entry
@ -568,13 +542,13 @@ class FrameWidgets(ttk.Frame):
Tooltip(
self.lb_rename,
_("To rename a tunnel, you need to\nselect a tunnel from the list"),
TIPS,
tips,
)
else:
Tooltip(
self.lb_rename,
_("To rename a tunnel, at least one must be in the list"),
TIPS,
tips,
)
def tl_rename():
@ -698,7 +672,7 @@ class FrameWidgets(ttk.Frame):
if self.l_box.size() >= 1 and len(self.l_box.curselection()) >= 1:
Tooltip(
self.wg_autostart, _("To use the autostart, enable this Checkbox"), TIPS
self.wg_autostart, _("To use the autostart, enable this Checkbox"), tips
)
if self.l_box.size() == 0:
@ -707,7 +681,7 @@ class FrameWidgets(ttk.Frame):
_(
"You must have at least one\ntunnel in the list,to use the autostart"
),
TIPS,
tips,
)
else:
@ -715,7 +689,7 @@ class FrameWidgets(ttk.Frame):
Tooltip(
self.wg_autostart,
_("To use the autostart, a tunnel must be selected from the list"),
TIPS,
tips,
)
self.on_off()
@ -858,7 +832,7 @@ class FrameWidgets(ttk.Frame):
Tooltip(
self.wg_autostart,
_("To use the autostart, enable this Checkbox"),
TIPS,
tips,
)
# Tooltip(self.l_box, _("List of available tunnels"))
@ -869,7 +843,7 @@ class FrameWidgets(ttk.Frame):
"Click to delete a Wireguard Tunnel\n"
"Select from the list!"
),
TIPS,
tips,
)
Tooltip(
@ -878,7 +852,7 @@ class FrameWidgets(ttk.Frame):
" Click to export all\n"
"Wireguard Tunnel to Zipfile"
),
TIPS,
tips,
)
Tooltip(
@ -887,7 +861,7 @@ class FrameWidgets(ttk.Frame):
"To rename a tunnel, you need to\n"
"select a tunnel from the list"
),
TIPS,
tips,
)
self.lb_rename.insert(0, "Max. 12 characters!")
@ -932,11 +906,10 @@ class FrameWidgets(ttk.Frame):
except EOFError as e:
print(e)
except TypeError as e:
print(e)
print("File import: abort by user...")
except FileNotFoundError as e:
print(e)
print("File import: abort by user...")
except subprocess.CalledProcessError:
print("Tunnel exist!")
def box_set(self):
@ -1063,7 +1036,7 @@ class FrameWidgets(ttk.Frame):
)
self.btn_stst.grid(column=0, row=0, padx=5, pady=8)
Tooltip(self.btn_stst, _("Click to stop selected Wireguard Tunnel"), TIPS)
Tooltip(self.btn_stst, _("Click to stop selected Wireguard Tunnel"), tips)
def start(self):
"""
@ -1079,9 +1052,9 @@ class FrameWidgets(ttk.Frame):
tl = Tunnel.list()
if len(tl) == 0:
Tooltip(self.btn_stst, _("No tunnels to start in the list"), TIPS)
Tooltip(self.btn_stst, _("No tunnels to start in the list"), tips)
else:
Tooltip(self.btn_stst, _("Click to start selected Wireguard Tunnel"), TIPS)
Tooltip(self.btn_stst, _("Click to start selected Wireguard Tunnel"), tips)
def color_label(self):
"""
@ -1178,7 +1151,6 @@ if __name__ == "__main__":
window.tk.call("tk_getOpenFile", "-foobarbaz")
except TclError:
pass
window.tk.call("set", "::tk::dialog::file::showHiddenBtn", "0")
window.tk.call("set", "::tk::dialog::file::showHiddenVar", "0")
window.mainloop()