From 5753a35d6c3228f3621851216188e50092251dce Mon Sep 17 00:00:00 2001 From: punix Date: Tue, 22 Apr 2025 14:22:39 +0200 Subject: [PATCH] fix new tooltip signal now in modul cls_mth_fc.py --- __pycache__/cls_mth_fc.cpython-312.pyc | Bin 18196 -> 20307 bytes cls_mth_fc.py | 54 ++++++++++-- wirepy.py | 110 +++++++++---------------- 3 files changed, 90 insertions(+), 74 deletions(-) diff --git a/__pycache__/cls_mth_fc.cpython-312.pyc b/__pycache__/cls_mth_fc.cpython-312.pyc index 696d866f41e078768eedd5a2e4e4064a39f40a83..fddcbdbc2cb3697b8b7b79d0d6196dcadb6eb033 100644 GIT binary patch delta 3469 zcmai0du&tJ89(Rx`r5g+6UTWH0=WS}VjhM7h44rSA%u5;@{s0@2FLd%F*w)g+?#}W zrVcb3q#dsvT7nof-9xL2%34|LChd>1b^BwQwgnLeyMS70)z(VW#3RyHGcVZZ7M7pm@XKp>j1 ze>RTzbkhp8z-1xJqofJc=>J!}&wFq#!EiVRn zNlsohAOy>jb25LVuZeVKCM|1m#A1M0)eLYiIo)T#@KVNx`zMDBP zZ3~^*j!K6RRv=74C_~sZ2`9NVy+OimRN}w#6ldzH8YJ4v6SFo~ybN5+wZGReW1Rz* zp!WwI>RxKG-OHa52KqYP(aw!T0b>i1u}Q?nzK^ zXblk)bF-U?ncD3#t;`ZFNoU6ThC*p5{I3aDc`ZAi2rO& zk)XQy=$c|t%>$mRx@L};(IkpxJX1FJ& zYxblw#ncX&iXQ3F40|PvSeG7&D|&BFhsKPY)l+qZ8+b8%5BCFXCKM_uMfT1mCZ-W}1^xW=CFa|XvC7h@?n`;7d1kUSvbEcp|E;jIGysnl?4WZihdj8Wsg z>bFu8PLf}8cF)L;>%OYd!g24+`wlTZOa8*ZIy_ppm?r(Zb(~{W$&R@~VS^w_y5*hO z`DPL9&Q_Qf)!>LyLrO!VvZf=!%$VM#V7iKSC}t|rgsLfzXoxkSesMEy6gAPWD;)z$ zuK`JfLP?kHGaXlwr8$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-cR-Kk zU-zU0JJ?)x04CY_>U?P$GiKPe>IXYA630h5bZc~29gQcFBawtIJQ|=KJm?eX941Vn zHqmL+#}PByQ#D?&4xvVTr%l$*i>@gg&m)3}7g%vaS#bd6a~vx<2s^@ou_J7E!_)SD zE`5c%DXJ#v4)%FNt!I!&bcpD1K!>OfGChXbUF>$lOCV@-{+|Wu35rU2|B^y%b|au z#@*>%!jiq~r3KWlvNwBcwwy%y28S<;68>81qB5o=QaT*gVVoLgEu;?7Gdv@i#Zi&D zG7Wu?FbH@Zr}(_&_uQN&OE#zG3$#OoOptv%lDWpoI5`9Oc#Kj`@hI209d+Sc{OD9v zWY+wP>$E#GJglZ-BmRMytn5o=28)Ckrwb6`=s16CE#NBxJhw=`;YN9 z#t<*!8iicUk{g0WwA^${V*5>(LoE2c!X(yaURF%>3BjPRjJ9&AXFa2&Qp(|!E~&%O zh^o+wJW2-;8w@`+loLy&6iST;dzGE*tAyR`YG2bvqaBU*3}Lzzf!~wNx4?KojTXaR z;RUilu+&=4YvezY{FXf%EOO^wBJNAXu}sRAiFcV)E)&l$?ET>Dc~;23Ra^tLzYz|j G^1lH}&2rlS diff --git a/cls_mth_fc.py b/cls_mth_fc.py index 5a647a7..7d199e9 100755 --- a/cls_mth_fc.py +++ b/cls_mth_fc.py @@ -4,14 +4,15 @@ import gettext import locale import os import shutil +import signal import subprocess +import sys import tkinter as tk import zipfile from datetime import datetime from pathlib import Path from subprocess import check_call from tkinter import ttk - import requests APP = "wirepy" @@ -378,6 +379,43 @@ class Tunnel: pass +def sigi(dirname): + """ + function for clean up after break + """ + + 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) + + def if_tip(path): """ method that writes in file whether tooltip is displayed or not @@ -402,21 +440,24 @@ class Tooltip: info: label and button is parrent. """ - def __init__(self, widget, text, TIPS=None): + def __init__(self, widget, text, tips=None): self.widget = widget self.text = text self.tooltip_window = None - if TIPS: + if tips: self.widget.bind("", self.show_tooltip) self.widget.bind("", self.hide_tooltip) def show_tooltip(self, event=None): + """ + shows the tooltip + """ if self.tooltip_window or not self.text: return x, y, _, _ = self.widget.bbox("insert") - x += self.widget.winfo_rootx() + 25 - y += self.widget.winfo_rooty() + 20 + x += self.widget.winfo_rootx() + 40 + y += self.widget.winfo_rooty() + 40 self.tooltip_window = tw = tk.Toplevel(self.widget) tw.wm_overrideredirect(True) tw.wm_geometry(f"+{x}+{y}") @@ -427,6 +468,9 @@ class Tooltip: label.grid() def hide_tooltip(self, event=None): + """ + hide the tooltip + """ if self.tooltip_window: self.tooltip_window.destroy() self.tooltip_window = None diff --git a/wirepy.py b/wirepy.py index bd212e3..441d173 100755 --- a/wirepy.py +++ b/wirepy.py @@ -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()