From 47bdfbfb17a5daa6781b98740392315606c591f9 Mon Sep 17 00:00:00 2001 From: punix Date: Mon, 21 Apr 2025 22:25:10 +0200 Subject: [PATCH] new class foe tooltip --- __pycache__/cls_mth_fc.cpython-312.pyc | Bin 18172 -> 18196 bytes cls_mth_fc.py | 23 +- start_wg.py | 2 +- wirepy.py | 624 ++++--------------------- 4 files changed, 113 insertions(+), 536 deletions(-) diff --git a/__pycache__/cls_mth_fc.cpython-312.pyc b/__pycache__/cls_mth_fc.cpython-312.pyc index 18c17c46f804594ebb88a8cfff2db26712b80b78..696d866f41e078768eedd5a2e4e4064a39f40a83 100644 GIT binary patch delta 424 zcmey<%Q&Tvk@qw&FBbz42rXpGP};~VX6vs32vMje)ic@paihcuaF9JE?7E6d{KyWb& zkf|^^$6h6ADkB3!aR`vxz;HuMrh}!2`-X@Fkm9@{r_{l6g+ux#H~$SDfqw5!@9R7= z7kOl6M6O`Du3>pm!}1D`6%LuJJXRlA8F&PWB!LERer+$!%r+Nf&!x#c&YNU!@bFCt znI1VYazXhH#{-Th9KSF#337F?eqdwZWd{GsbwO delta 415 zcmbQz$M~n0k@qw&FBbz4xT&*cFm2=&vrSe5@}@JSGDI<^Fhnt>Fh((_Ftsp5v81r2 zu(U8nu>xsUAk9|EtjT_hJtRLrrzEqW>L`~25G3a$78fg|G2db-PR&Ux`VCZ4 zqyZ#~L5e3=*{eiPW(4wlfV>8V8)7mYEIr&eL?nO|=M6cf4wfq%(lZiIApGJm=#F^4fNaOAkEA+3uONJ$%@XKq-F>$P+6|IP;-O( z3Be12K^G#Ut_VbTu-@R{o&3Rh4kQ2MUKcIK6_ane6BKj8S&7soO<92_;7LPYgf;Y&ih3#B", self.show_tooltip) - self.widget.bind("", self.hide_tooltip) + if TIPS: + self.widget.bind("", self.show_tooltip) + self.widget.bind("", self.hide_tooltip) def show_tooltip(self, event=None): 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 @@ -418,12 +421,12 @@ class Tooltip: tw.wm_overrideredirect(True) tw.wm_geometry(f"+{x}+{y}") - label = tk.Label(tw, text=self.text, relief="solid", borderwidth=1, padx=5, pady=5) + label = tk.Label( + tw, text=self.text, relief="solid", borderwidth=1, padx=5, pady=5 + ) label.grid() def hide_tooltip(self, event=None): if self.tooltip_window: self.tooltip_window.destroy() self.tooltip_window = None - - \ No newline at end of file diff --git a/start_wg.py b/start_wg.py index 8f2636c..52e8184 100755 --- a/start_wg.py +++ b/start_wg.py @@ -8,7 +8,7 @@ from subprocess import check_call path_to_file = Path(Path.home() / ".config/wire_py/settings") with open(path_to_file, "r", encoding="utf-8") as a_con: - + # This funtion is for the independent autostart of the previously selected tunnel lines = a_con.readlines() a_con = lines[7].strip() diff --git a/wirepy.py b/wirepy.py index c073737..bd212e3 100755 --- a/wirepy.py +++ b/wirepy.py @@ -23,7 +23,7 @@ Create.decrypt() tcl_path = Path("/usr/share/TK-Themes") wg_set = Path(Path.home() / ".config/wire_py/settings") -WG_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 @@ -233,48 +233,17 @@ class FrameWidgets(ttk.Frame): self.menu_frame.configure(relief="flat") self.menu_frame.grid(column=0, row=0, columnspan=4, sticky="w") - def version_enter(event): - """ - The mouse moves into the Version widget - """ - window.my_tool_tip = MyToolTip( - event.x_root, event.y_root, f"Version: {VERSION[2:]}" - ) - - def version_leave(_): - """ - The mouse moves from the entry widget - Remove Tool-Tip - """ - window.my_tool_tip.destroy() - # App Menu self.version_lb = ttk.Label(self.menu_frame, text=VERSION) 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) + self.options_btn = ttk.Menubutton(self.menu_frame, text=_("Options")) self.options_btn.grid(column=1, columnspan=1, row=0) - def sets_enter(event): - """ - The mouse moves into the entry widget - """ - window.my_tool_tip = MyToolTip( - event.x_root, event.y_root, _("Click for Settings") - ) - - def sets_leave(_): - """ - The mouse moves from the entry widget - Remove Tool-Tip - """ - window.my_tool_tip.destroy() - - self.version_lb.bind("", version_enter) - self.version_lb.bind("", version_leave) - self.options_btn.bind("", sets_enter) - self.options_btn.bind("", sets_leave) + Tooltip(self.options_btn, _("Click for Settings"), TIPS) set_update = tk.IntVar() set_tip = tk.BooleanVar() @@ -301,7 +270,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 WG_TIPS: + if TIPS: set_tip.set(value=False) else: set_tip.set(value=True) @@ -311,47 +280,15 @@ class FrameWidgets(ttk.Frame): set_update.set(value=1) self.updates_lb.configure(text=_("Update search off")) - def disable_enter(event): - """ - The mouse moves into the entry widget - """ - window.my_tool_tip = MyToolTip( - event.x_root, event.y_root, _("Updates you have disabled") - ) + Tooltip(self.updates_lb, _("Updates you have disabled"), TIPS) - def disable_leave(_): - """ - The mouse moves from the entry widget - Remove Tool-Tip - """ - window.my_tool_tip.destroy() - - self.updates_lb.bind("", disable_enter) - self.updates_lb.bind("", disable_leave) 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")) - def congratulations_enter(event): - """ - The mouse moves into the entry widget - """ - window.my_tool_tip = MyToolTip( - event.x_root, - event.y_root, - _("Congratulations! Wire-Py is up to date"), - ) + Tooltip(self.updates_lb, _("Congratulations! Wire-Py is up to date"), TIPS) - def congratulations_leave(_): - """ - The mouse moves into the entry widget - Remove Tool-Tip - """ - window.my_tool_tip.destroy() - - self.updates_lb.bind("", congratulations_enter) - self.updates_lb.bind("", congratulations_leave) else: set_update.set(value=0) text = f"Update {res} " + _("available!") @@ -360,23 +297,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) - def download_enter(event): - """ - The mouse moves into the entry widget - """ - window.my_tool_tip = MyToolTip( - event.x_root, event.y_root, _("Click to download new version") - ) - - def download_leave(_): - """ - The mouse moves into the entry widget - Remove Tool-Tip - """ - window.my_tool_tip.destroy() - - self.update_btn.bind("", download_enter) - self.update_btn.bind("", download_leave) + Tooltip(self.update_btn, _("Click to download new version"), TIPS) self.download = tk.Menu(self, relief="flat") @@ -470,45 +391,6 @@ class FrameWidgets(ttk.Frame): self.l_box.insert("end", tunnels[:-5]) self.l_box.update() - def list_empty_enter(event): - """ - The mouse moves into the entry widget - """ - window.my_tool_tip = MyToolTip( - event.x_root, - event.y_root, - _("You must first import\na Wireguard tunnel"), - ) - - def list_empty_leave(_): - """ - The mouse moves into the entry widget - Remove Tool-Tip - """ - window.my_tool_tip.destroy() - - def list_not_empty_enter(event): - """ - The mouse moves into the entry widget - """ - window.my_tool_tip = MyToolTip( - event.x_root, event.y_root, _("Select a Tunnel") - ) - - def list_not_empty_leave(_): - """ - The mouse moves into the entry widget - Remove Tool-Tip - """ - window.my_tool_tip.destroy() - - if self.l_box.size() == 0: - self.l_box.bind("", list_empty_enter) - self.l_box.bind("", list_empty_leave) - else: - self.l_box.bind("", list_not_empty_enter) - self.l_box.bind("", list_not_empty_leave) - # Button Vpn if self.a != "": self.stop() @@ -538,23 +420,7 @@ class FrameWidgets(ttk.Frame): ) self.btn_i.grid(column=0, row=1, padx=15, pady=8) - def imp_enter(event): - """ - The mouse moves into the entry widget - """ - window.my_tool_tip = MyToolTip( - event.x_root, event.y_root, _("Click to import a Wireguard Tunnel") - ) - - def imp_leave(_): - """ - The mouse moves into the entry widget - Remove Tool-Tip - """ - window.my_tool_tip.destroy() - - self.btn_i.bind("", imp_enter) - self.btn_i.bind("", imp_leave) + Tooltip(self.btn_i, _("Click to import a Wireguard Tunnel"), TIPS) def delete(): """ @@ -604,36 +470,27 @@ class FrameWidgets(ttk.Frame): self.wg_autostart.configure(state="disabled") # for disable checkbox when Listbox empty - def empty_list_start_enter(event): - """ - The mouse moves into the entry widget - """ - window.my_tool_tip = MyToolTip( - event.x_root, event.y_root, _("No tunnels to start in the list") - ) - - def empty_list_start_leave(_): - """ - The mouse moves into the entry widget - Remove Tool-Tip - """ - window.my_tool_tip.destroy() - if self.l_box.size() == 0: self.wg_autostart.configure(state="disabled") self.lb_rename.configure(state="disabled") - self.l_box.bind("", list_empty_enter) - self.l_box.bind("", list_empty_leave) - self.wg_autostart.bind("", chk_enter) - self.wg_autostart.bind("", chk_leave) - self.btn_tr.bind("", empty_list_enter) - self.btn_tr.bind("", empty_list_leave) - self.btn_exp.bind("", empty_list_enter) - self.btn_exp.bind("", empty_list_leave) - self.btn_stst.bind("", empty_list_start_enter) - self.btn_stst.bind("", empty_list_start_leave) - self.lb_rename.bind("", rename_no_active_enter) - self.lb_rename.bind("", rename_no_active_leave) + 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, + ) + + 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, + ) self.lb_rename.insert(0, _("Max. 12 characters!")) if self.a != "" and self.a == select_tl: @@ -677,44 +534,14 @@ class FrameWidgets(ttk.Frame): ) self.btn_tr.grid(column=0, row=2, padx=15, pady=8) - def empty_list_enter(event): - """ - The mouse moves into the entry widget - """ - window.my_tool_tip = MyToolTip( - event.x_root, event.y_root, _("No tunnels to delete in the list") - ) - - def empty_list_leave(_): - """ - The mouse moves into the entry widget - Remove Tool-Tip - """ - window.my_tool_tip.destroy() - - def del_enter(event): - """ - The mouse moves into the entry widget - """ - window.my_tool_tip = MyToolTip( - event.x_root, - event.y_root, - _("Click to delete a Wireguard Tunnel\nSelect from the list!"), - ) - - def del_leave(_): - """ - The mouse moves into the entry widget - Remove Tool-Tip - """ - window.my_tool_tip.destroy() - if self.l_box.size() == 0: - self.btn_tr.bind("", empty_list_enter) - self.btn_tr.bind("", empty_list_leave) + Tooltip(self.btn_tr, _("No tunnels to delete in the list"), TIPS) else: - self.btn_tr.bind("", del_enter) - self.btn_tr.bind("", del_leave) + Tooltip( + self.btn_tr, + _("Click to delete a Wireguard Tunnel\nSelect from the list!"), + TIPS, + ) # Button Export self.btn_exp = ttk.Button( @@ -722,39 +549,14 @@ class FrameWidgets(ttk.Frame): ) self.btn_exp.grid(column=0, row=3, padx=15, pady=8) - def empty_list_enter(event): - """ - The mouse moves into the entry widget - """ - window.my_tool_tip = MyToolTip( - event.x_root, event.y_root, _("No Tunnels in List for Export") - ) - - empty_list_leave(_) - - def exp_enter(event): - """ - The mouse moves into the entry widget - """ - window.my_tool_tip = MyToolTip( - event.x_root, - event.y_root, - _(" Click to export all\nWireguard Tunnel to Zipfile"), - ) - - def exp_leave(_): - """ - The mouse moves into the entry widget - Remove Tool-Tip - """ - window.my_tool_tip.destroy() - if self.l_box.size() == 0: - self.btn_exp.bind("", empty_list_enter) - self.btn_exp.bind("", empty_list_leave) + Tooltip(self.btn_exp, _("No Tunnels in List for Export"), TIPS) else: - self.btn_exp.bind("", exp_enter) - self.btn_exp.bind("", exp_leave) + Tooltip( + self.btn_exp, + _(" Click to export all\nWireguard Tunnel to Zipfile"), + TIPS, + ) # Label Entry self.lb_rename = ttk.Entry(self.lb_frame4, width=20) @@ -762,46 +564,18 @@ class FrameWidgets(ttk.Frame): self.lb_rename.insert(0, _("Max. 12 characters!")) self.lb_rename.config(state="disable") - def rename_no_active_leave(_): - """ - The mouse moves into the entry widget - Remove Tool-Tip - """ - window.my_tool_tip.destroy() - - def rename_no_active_enter(event): - """ - The mouse moves into the entry widget - """ - window.my_tool_tip = MyToolTip( - event.x_root, - event.y_root, - _("To rename a tunnel, at least one must be in the list"), - ) - - def rename_enter(event): - """ - The mouse moves into the entry widget - """ - window.my_tool_tip = MyToolTip( - event.x_root, - event.y_root, - _("To rename a tunnel, you need to\nselect a tunnel from the list"), - ) - - def rename_leave(_): - """ - The mouse moves into the entry widget - Remove Tool-Tip - """ - window.my_tool_tip.destroy() - if self.l_box.size() != 0: - self.lb_rename.bind("", rename_enter) - self.lb_rename.bind("", rename_leave) + Tooltip( + self.lb_rename, + _("To rename a tunnel, you need to\nselect a tunnel from the list"), + TIPS, + ) else: - self.lb_rename.bind("", rename_no_active_enter) - self.lb_rename.bind("", rename_no_active_leave) + Tooltip( + self.lb_rename, + _("To rename a tunnel, at least one must be in the list"), + TIPS, + ) def tl_rename(): @@ -921,72 +695,28 @@ class FrameWidgets(ttk.Frame): ) self.wg_autostart.grid(column=0, row=0, pady=15, padx=15, sticky="nw") - def chk_enter(event): - """ - The mouse moves into the entry widget - """ - window.my_tool_tip = MyToolTip( - event.x_root, - event.y_root, - _( - "You must have at least one\n" - "tunnel in the list,to use the autostart" - ), - ) - - def chk_leave(_): - """ - The mouse moves into the entry widget - Remove Tool-Tip - """ - window.my_tool_tip.destroy() - if self.l_box.size() >= 1 and len(self.l_box.curselection()) >= 1: - def chk_a_enter(event): - """ - The mouse moves into the entry widget - """ - window.my_tool_tip = MyToolTip( - event.x_root, - event.y_root, - _("To use the autostart, enable this Checkbox"), - ) - - def chk_a_leave(_): - """ - The mouse moves into the entry widget - Remove Tool-Tip - """ - window.my_tool_tip.destroy() - - self.wg_autostart.bind("", chk_a_enter) - self.wg_autostart.bind("", chk_a_leave) + Tooltip( + self.wg_autostart, _("To use the autostart, enable this Checkbox"), TIPS + ) if self.l_box.size() == 0: - self.wg_autostart.bind("", chk_enter) - self.wg_autostart.bind("", chk_leave) + Tooltip( + self.wg_autostart, + _( + "You must have at least one\ntunnel in the list,to use the autostart" + ), + TIPS, + ) + else: - def chk_a_enter(event): - """ - The mouse moves into the entry widget - """ - window.my_tool_tip = MyToolTip( - event.x_root, - event.y_root, - _("To use the autostart, a tunnel must be selected from the list"), - ) - - def chk_a_leave(_): - """ - The mouse moves into the entry widget - Remove Tool-Tip - """ - window.my_tool_tip.destroy() - - self.wg_autostart.bind("", chk_a_enter) - self.wg_autostart.bind("", chk_a_leave) + Tooltip( + self.wg_autostart, + _("To use the autostart, a tunnel must be selected from the list"), + TIPS, + ) self.on_off() @@ -1125,109 +855,41 @@ class FrameWidgets(ttk.Frame): self.l_box.update() self.l_box.selection_set(0) - def chk_a_enter(event): - """The mouse moves into the entry widget""" - window.my_tool_tip = MyToolTip( - event.x_root, - event.y_root, - _( - "To use the autostart, enable this " - "Checkbox" - ), - ) + Tooltip( + self.wg_autostart, + _("To use the autostart, enable this Checkbox"), + TIPS, + ) - def chk_a_leave(_): - """ - The mouse moves into the entry widget - Remove Tool-Tip - """ - window.my_tool_tip.destroy() + # Tooltip(self.l_box, _("List of available tunnels")) - def list_info_enter(event): - """ - The mouse moves into the entry widget - """ - window.my_tool_tip = MyToolTip( - event.x_root, - event.y_root, - _("List of available tunnels"), - ) + Tooltip( + self.btn_tr, + _( + "Click to delete a Wireguard Tunnel\n" + "Select from the list!" + ), + TIPS, + ) - def list_info_leave(_): - """ - The mouse moves into the entry widget - Remove Tool-Tip - """ - window.my_tool_tip.destroy() + Tooltip( + self.btn_exp, + _( + " Click to export all\n" + "Wireguard Tunnel to Zipfile" + ), + TIPS, + ) - def del_enter(event): - """The mouse moves into the entry widget""" - window.my_tool_tip = MyToolTip( - event.x_root, - event.y_root, - _( - "Click to delete a Wireguard " - "Tunnel\nSelect from the list!" - ), - ) + Tooltip( + self.btn_rename, + _( + "To rename a tunnel, you need to\n" + "select a tunnel from the list" + ), + TIPS, + ) - def del_leave(_): - """ - The mouse moves into the entry widget - Remove Tool-Tip - """ - window.my_tool_tip.destroy() - - def exp_enter(event): - """ - The mouse moves into the entry widget - """ - window.my_tool_tip = MyToolTip( - event.x_root, - event.y_root, - _( - " Click to export " - "all\nWireguard Tunnel to Zipfile" - ), - ) - - def exp_leave(_): - """ - The mouse moves into the entry widget - Remove Tool-Tip - """ - window.my_tool_tip.destroy() - - def rename_enter(event): - """ - The mouse moves into the entry widget - """ - window.my_tool_tip = MyToolTip( - event.x_root, - event.y_root, - _( - "To rename a tunnel, you need to\n" - "select a tunnel from the list" - ), - ) - - def rename_leave(_): - """ - The mouse moves into the entry widget - Remove Tool-Tip - """ - window.my_tool_tip.destroy() - - self.wg_autostart.bind("", chk_a_enter) - self.wg_autostart.bind("", chk_a_leave) - self.l_box.bind("", list_info_enter) - self.l_box.bind("", list_info_leave) - self.btn_tr.bind("", del_enter) - self.btn_tr.bind("", del_leave) - self.btn_exp.bind("", exp_enter) - self.btn_exp.bind("", exp_leave) - self.lb_rename.bind("", rename_enter) - self.lb_rename.bind("", rename_leave) self.lb_rename.insert(0, "Max. 12 characters!") self.str_var = tk.StringVar() self.str_var.set(self.a) @@ -1369,7 +1031,7 @@ class FrameWidgets(ttk.Frame): """ shows data in the label """ - + # Address Label self.address = ttk.Label( self.lb_frame, textvariable=self.add, foreground="#0071ff" @@ -1401,23 +1063,7 @@ class FrameWidgets(ttk.Frame): ) self.btn_stst.grid(column=0, row=0, padx=5, pady=8) - def stop_enter(event): - """ - The mouse moves into the entry widget - """ - window.my_tool_tip = MyToolTip( - event.x_root, event.y_root, _("Click to stop selected Wireguard Tunnel") - ) - - def stop_leave(_): - """ - The mouse moves into the entry widget - Remove Tool-Tip - """ - window.my_tool_tip.destroy() - - self.btn_stst.bind("", stop_enter) - self.btn_stst.bind("", stop_leave) + Tooltip(self.btn_stst, _("Click to stop selected Wireguard Tunnel"), TIPS) def start(self): """ @@ -1431,45 +1077,11 @@ class FrameWidgets(ttk.Frame): ) self.btn_stst.grid(column=0, row=0, padx=5, pady=8) - def empty_list_start_enter(event): - """ - The mouse moves into the entry widget - """ - window.my_tool_tip = MyToolTip( - event.x_root, event.y_root, _("No tunnels to start in the list") - ) - - def empty_list_start_leave(_): - """ - The mouse moves into the entry widget - Remove Tool-Tip - """ - window.my_tool_tip.destroy() - - def start_enter(event): - """ - The mouse moves into the entry widget - """ - window.my_tool_tip = MyToolTip( - event.x_root, - event.y_root, - _("Click to start selected Wireguard Tunnel"), - ) - - def start_leave(_): - """ - The mouse moves into the entry widget - Remove Tool-Tip - """ - window.my_tool_tip.destroy() - tl = Tunnel.list() if len(tl) == 0: - self.btn_stst.bind("", empty_list_start_enter) - self.btn_stst.bind("", empty_list_start_leave) + Tooltip(self.btn_stst, _("No tunnels to start in the list"), TIPS) else: - self.btn_stst.bind("", start_enter) - self.btn_stst.bind("", start_leave) + Tooltip(self.btn_stst, _("Click to start selected Wireguard Tunnel"), TIPS) def color_label(self): """ @@ -1557,44 +1169,6 @@ class FrameWidgets(ttk.Frame): msg_window(iw, ii, wt, msg_t) -class MyToolTip(tk.Toplevel): - """ - Tooltip Class to view Tooltips - """ - - TIP_X_OFFSET = 20 - TIP_Y_OFFSET = 20 - if not WG_TIPS: - AUTO_CLEAR_TIME = 0 - else: - AUTO_CLEAR_TIME = 2000 # Millisecond. (1/200 sec.) - - def __init__(self, x_pos, y_pos, message=None, auto_clear=True): - self.x_pos = x_pos - self.y_pos = y_pos - self.message = message - self.auto_clear = auto_clear - - tk.Toplevel.__init__(self) - self.overrideredirect(True) - - self.message_label = ttk.Label( - self, compound="left", text=self.message, padding=6 - ) - self.message_label.pack() - - self.geometry( - f"+{self.x_pos + self.TIP_X_OFFSET}+{self.y_pos + self.TIP_X_OFFSET}" - ) - - if self.auto_clear: - self.after(self.AUTO_CLEAR_TIME, self.clear_tip) - - def clear_tip(self): - """Remove Tool-Tip""" - self.destroy() - - if __name__ == "__main__": window = Wirepy() """