diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index e671b91..5ea76c3 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,7 +4,7 @@
-
+
@@ -137,14 +137,6 @@
1723279982210
-
-
- 1724400463791
-
-
-
- 1724400463791
-
1724401340512
@@ -529,7 +521,15 @@
1729283719951
-
+
+
+ 1729353898829
+
+
+
+ 1729353898830
+
+
@@ -570,7 +570,6 @@
-
@@ -595,17 +594,7 @@
-
-
-
-
-
-
- file://$PROJECT_DIR$/wg_main.py
- 185
-
-
-
-
+
+
\ No newline at end of file
diff --git a/Changelog b/Changelog
index 884b39a..d8c605c 100644
--- a/Changelog
+++ b/Changelog
@@ -16,6 +16,7 @@ My standard System: Linux Mint 22 Cinnamon
- Add Options, Help, Update Label and Update Menubutton
- Theme now separate Light and Dark
+ - Add Own Tooltip (Class and def's) Part One
### Added
16-10-2024
diff --git a/wg_func.py b/wg_func.py
index d373362..1218632 100755
--- a/wg_func.py
+++ b/wg_func.py
@@ -11,6 +11,7 @@ from subprocess import check_call
from tkinter import filedialog, ttk
import requests
+
''' 1 = 1. Year, 09 = Month of the Year, 2924 = Day and Year of the Year '''
version = 'v. 1.10.1924'
@@ -74,6 +75,7 @@ class WirePyUpdate:
res = WirePyUpdate.api_down()
+
def msg_window(img_w, img_i, w_title, w_txt):
"""
Function for different message windows for the user. with 4 arguments to be passed.
@@ -133,7 +135,6 @@ class GreenLabel:
def rowconfigure(self, param, weight):
pass
-
class StartStopBTN:
"""
Show Start and Stop Button in Label
@@ -154,7 +155,6 @@ class StartStopBTN:
self.btn_stst = ttk.Button(self.lb_frame_btn_lbox, image=self.wg_vpn_start, command=self.wg_switch, padding=0)
self.btn_stst.grid(column=0, row=0, padx=5, pady=8)
-
class ConToDict:
"""
The config file is packed into a dictionary,
@@ -525,3 +525,31 @@ class ExportTunnels:
except TypeError:
pass
+
+
+class MyToolTip(tk.Toplevel):
+ TIP_X_OFFSET = 8
+ TIP_Y_OFFSET = 8
+ AUTO_CLEAR_TIME = 10 # Millisecond. (1/100 sec.)
+
+ def __init__(self, x_pos, y_pos, message=None, auto_clear=False):
+ 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=4)
+ self.message_label.pack()
+
+ self.geometry("+%d+%d" % (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()
diff --git a/wg_main.py b/wg_main.py
index 25715c3..337c69a 100755
--- a/wg_main.py
+++ b/wg_main.py
@@ -1,21 +1,24 @@
#!/usr/bin/python3
import tkinter as tk
+from select import select
from subprocess import check_call
from tkinter import *
from pathlib import Path
from tkinter import ttk
-from wg_func import (TunnelActiv, ListTunnels, ImportTunnel, ConToDict, GreenLabel, StartStopBTN, ShowAddress,
- FileHandle, ExportTunnels, OnOff, msg_window, WirePyUpdate, res, version, path_to_file2,
- path_to_file3)
+from wg_func import (TunnelActiv, ListTunnels, ImportTunnel, ConToDict, GreenLabel, ShowAddress, FileHandle,
+ ExportTunnels, OnOff, msg_window, WirePyUpdate, res, version, path_to_file2,
+ path_to_file3, MyToolTip)
tcl_path = Path('/usr/share/TK-Themes')
class MainWindow(tk.Tk):
+
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
+ self.my_tool_tip = None
self.switch_on = None
self.switch_off = None
self.x_width = 600
@@ -57,6 +60,7 @@ class MainWindow(tk.Tk):
self.tk.call('set_theme', 'light')
with open(path_to_file3, 'w') as theme_set2:
theme_set2.write('light')
+
def theme_change_dark():
if not self.tk.call("ttk::style", "theme", "use") == "water-dark":
# Set dark theme
@@ -64,15 +68,14 @@ class MainWindow(tk.Tk):
with open(path_to_file3, 'w') as theme_set2:
theme_set2.write('dark')
- def readme():
+ def instruction():
"""img_w, img_i, w_title, w_txt hand over"""
- iw = r'/usr/share/icons/wp-icons/64/info.png'
+ iw = r'/usr/share/icons/wp-icons/48/wg_vpn.png'
ii = r'/usr/share/icons/wp-icons/48/wg_msg.png'
- wt = 'Select tunnel'
- msg_t = 'Here comes the instructions for Wire-Py .'
+ wt = 'Instruction'
+ msg_t = 'Here comes the instructions for Wire-Py'
msg_window(iw, ii, wt, msg_t)
-
''' Frame for Menu '''
self.menu_frame = ttk.Frame(self)
self.menu_frame.configure(relief='flat')
@@ -84,9 +87,33 @@ class MainWindow(tk.Tk):
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, padx=10)
+
+ def version_mouse_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_mouse_leave(event):
+ """ The mouse moves from the entry widget """
+ ''' Remove Tool-Tip '''
+ window.my_tool_tip.destroy()
+
self.options_btn = ttk.Menubutton(self.menu_frame, text='Options')
self.options_btn.grid(column=1, row=0)
+ def sets_mouse_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_mouse_leave(event):
+ """ The mouse moves from the entry widget """
+ ''' Remove Tool-Tip '''
+ window.my_tool_tip.destroy()
+
+ self.version_lb.bind('', version_mouse_enter)
+ self.version_lb.bind('', version_mouse_leave)
+ self.options_btn.bind('', sets_mouse_enter)
+ self.options_btn.bind('', sets_mouse_leave)
+
set_option = tk.IntVar()
self.settings = tk.Menu(self)
@@ -98,9 +125,21 @@ class MainWindow(tk.Tk):
''' Help BTN Menu / Label '''
self.help_btn = ttk.Menubutton(self.menu_frame, text='Help')
self.help_btn.grid(column=2, row=0)
+
+ def help_mouse_enter(event):
+ """ The mouse moves into the entry widget """
+ window.my_tool_tip = MyToolTip(event.x_root, event.y_root, 'Click for Help')
+
+ def help_mouse_leave(event):
+ """ The mouse moves from the entry widget """
+ ''' Remove Tool-Tip '''
+ window.my_tool_tip.destroy()
+
+ self.help_btn.bind('', help_mouse_enter)
+ self.help_btn.bind('', help_mouse_leave)
self.readme = tk.Menu(self)
self.help_btn.configure(menu=self.readme, style='Toolbutton')
- self.readme.add_command(label='Readme', command=readme)
+ self.readme.add_command(label='Instruction', command=instruction)
''' Update Label '''
self.updates_lb = ttk.Label(self.menu_frame)
@@ -109,18 +148,57 @@ class MainWindow(tk.Tk):
if res == 'False':
set_option.set(value=1)
self.updates_lb.configure(text='Update search off')
+
+ def disable_mouse_enter(event):
+ """ The mouse moves into the entry widget """
+ window.my_tool_tip = MyToolTip(event.x_root, event.y_root, 'Updates you have disabled')
+
+ def disable_mouse_leave(event):
+ """ The mouse moves from the entry widget """
+ ''' Remove Tool-Tip '''
+ window.my_tool_tip.destroy()
+
+ self.updates_lb.bind('', disable_mouse_enter)
+ self.updates_lb.bind('', disable_mouse_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_mouse_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')
+
+ def congratulations_mouse_leave(event):
+ """ The mouse moves from the entry widget """
+ ''' Remove Tool-Tip '''
+ window.my_tool_tip.destroy()
+
+ self.updates_lb.bind('', congratulations_mouse_enter)
+ self.updates_lb.bind('', congratulations_mouse_leave)
else:
set_option.set(value=0)
text = f'Update {res} available!'
''' Update BTN Menu'''
- self.update_btn = ttk.Menubutton(self.menu_frame, text=text, )
+ self.update_btn = ttk.Menubutton(self.menu_frame, text=text)
self.update_btn.grid(column=4, row=0, padx=0)
+
+ def download_mouse_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_mouse_leave(event):
+ """ The mouse moves from the entry widget """
+ ''' Remove Tool-Tip '''
+ window.my_tool_tip.destroy()
+
+ self.update_btn.bind('', download_mouse_enter)
+ self.update_btn.bind('', download_mouse_leave)
+
self.download = tk.Menu(self)
self.update_btn.configure(menu=self.download, style='Toolbutton')
@@ -129,9 +207,73 @@ class MainWindow(tk.Tk):
FrameWidgets(self).grid()
+class StartStopBTN:
+ """
+ Show Start and Stop Button in Label
+ """
+
+ def __init__(self):
+ self.lb_frame_btn_lbox = None
+ self.wg_switch = None
+ self.btn_stst = None
+ self.wg_vpn_start = tk.PhotoImage(file=r'/usr/share/icons/wp-icons/48/wg_vpn-start.png')
+ self.wg_vpn_stop = tk.PhotoImage(file=r'/usr/share/icons/wp-icons/48/wg_vpn-stop.png')
+
+ def button_stop(self):
+ self.btn_stst = ttk.Button(self.lb_frame_btn_lbox, image=self.wg_vpn_stop, command=self.wg_switch, padding=0)
+ self.btn_stst.grid(column=0, row=0, padx=5, pady=8)
+
+ def stop_mouse_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_mouse_leave(event):
+ """ The mouse moves from the entry widget """
+ ''' Remove Tool-Tip '''
+ window.my_tool_tip.destroy()
+
+ self.btn_stst.bind('', stop_mouse_enter)
+ self.btn_stst.bind('', stop_mouse_leave)
+
+ def button_start(self):
+ self.btn_stst = ttk.Button(self.lb_frame_btn_lbox, image=self.wg_vpn_start, command=self.wg_switch, padding=0)
+ self.btn_stst.grid(column=0, row=0, padx=5, pady=8)
+
+ def empty_list_start_mouse_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_mouse_leave(event):
+ """ The mouse moves from the entry widget """
+ ''' Remove Tool-Tip '''
+ window.my_tool_tip.destroy()
+
+ def start_mouse_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_mouse_leave(event):
+ """ The mouse moves from the entry widget """
+ ''' Remove Tool-Tip '''
+ window.my_tool_tip.destroy()
+
+ tl = ListTunnels.tl_list()
+ if len(tl) == 0:
+ self.btn_stst.bind('', empty_list_start_mouse_enter)
+ self.btn_stst.bind('', empty_list_start_mouse_leave)
+ else:
+ self.btn_stst.bind('', start_mouse_enter)
+ self.btn_stst.bind('', start_mouse_leave)
+
+
class FrameWidgets(ttk.Frame):
def __init__(self, container, **kwargs):
super().__init__(container, **kwargs)
+
+ self.btn_stst = None
self.auto_con = None
self.enp = None
self.DNS = None
@@ -195,18 +337,34 @@ class FrameWidgets(ttk.Frame):
''' Listbox with Scrollbar '''
+
+ def box_info_mouse_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 box_info_mouse_leave(event):
+ """ The mouse moves from the entry widget """
+ ''' Remove Tool-Tip '''
+ window.my_tool_tip.destroy()
+
+
def enable_check_box(event):
- tl = ListTunnels.tl_list()
+
if len(tl) != 0:
self.wg_autostart.configure(state='normal')
self.lb_rename.config(state='normal')
self.lb_rename.delete(0, tk.END)
self.btn_rename.config(state='normal')
+
self.l_box = tk.Listbox(self.lb_frame_btn_lbox, selectmode='single')
- self.l_box.config(relief='ridge')
- self.l_box.config(font=('Ubuntu', 12, 'bold'))
+ self.l_box.config(relief='ridge', font=('Ubuntu', 12, 'bold'))
self.l_box.grid(column=1, rowspan=4, row=0, sticky='ns')
+ tl = ListTunnels.tl_list()
+ if len(tl) == 0:
+ self.l_box.bind('', box_info_mouse_enter)
+ self.l_box.bind('', box_info_mouse_leave)
self.l_box.event_add('<>', '')
self.l_box.bind('<>', enable_check_box)
self.scrollbar = ttk.Scrollbar(self.lb_frame_btn_lbox, orient='vertical', command=self.l_box.yview)
@@ -246,6 +404,19 @@ class FrameWidgets(ttk.Frame):
padding=0)
self.btn_i.grid(column=0, row=1, padx=15, pady=8)
+ def import_mouse_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 import_mouse_leave(event):
+ """ The mouse moves from the entry widget """
+ ''' Remove Tool-Tip '''
+ window.my_tool_tip.destroy()
+
+ self.btn_i.bind('', import_mouse_enter)
+ self.btn_i.bind('', import_mouse_leave)
+
def delete():
try:
@@ -275,7 +446,7 @@ class FrameWidgets(ttk.Frame):
file_one.replace(file_two)
''' for disable checkbox when Listbox empty '''
- tl = ListTunnels.tl_list()
+
if len(tl) == 0:
self.wg_autostart.configure(state='disabled')
if self.a != '' and self.a == select_tl:
@@ -289,7 +460,7 @@ class FrameWidgets(ttk.Frame):
self.enp.set('')
return select_tl
except IndexError:
- tl = ListTunnels.tl_list()
+
if len(tl) != 0:
"""img_w, img_i, w_title, w_txt hand over"""
@@ -313,17 +484,94 @@ class FrameWidgets(ttk.Frame):
style='CButton.TButton')
self.btn_tr.grid(column=0, row=2, padx=15, pady=8)
+ def empty_list_del_mouse_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_del_mouse_leave(event):
+ """ The mouse moves from the entry widget """
+ ''' Remove Tool-Tip '''
+ window.my_tool_tip.destroy()
+
+ def delete_mouse_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 delete_mouse_leave(event):
+ """ The mouse moves from the entry widget """
+ ''' Remove Tool-Tip '''
+ window.my_tool_tip.destroy()
+
+ if len(tl) == 0:
+ self.btn_tr.bind('', empty_list_del_mouse_enter)
+ self.btn_tr.bind('', empty_list_del_mouse_leave)
+ else:
+ self.btn_tr.bind('', delete_mouse_enter)
+ self.btn_tr.bind('', delete_mouse_leave)
+
''' Button Export '''
self.btn_exp = ttk.Button(self.lb_frame_btn_lbox, image=self.exp_pic, command=ExportTunnels.wg_export,
padding=0)
self.btn_exp.grid(column=0, row=3, padx=15, pady=8)
+ def empty_list_mouse_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')
+
+ def empty_list_mouse_leave(event):
+ """ The mouse moves from the entry widget """
+ ''' Remove Tool-Tip '''
+ window.my_tool_tip.destroy()
+
+ def export_mouse_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 export_mouse_leave(event):
+ """ The mouse moves from the entry widget """
+ ''' Remove Tool-Tip '''
+ window.my_tool_tip.destroy()
+
+ if len(tl) == 0:
+ self.btn_exp.bind('', empty_list_mouse_enter)
+ self.btn_exp.bind('', empty_list_mouse_leave)
+ else:
+ self.btn_exp.bind('', export_mouse_enter)
+ self.btn_exp.bind('', export_mouse_leave)
''' Label Entry '''
self.lb_rename = ttk.Entry(self, width=20)
self.lb_rename.grid(column=2, row=4, padx=30, pady=15, sticky='nw')
self.lb_rename.insert(0, 'Max. 12 characters!')
self.lb_rename.config(state='disable')
+ def rename_mouse_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_no_active_mouse_leave(event):
+ """ The mouse moves from the entry widget """
+ ''' Remove Tool-Tip '''
+ window.my_tool_tip.destroy()
+
+ def rename_no_active_mouse_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_mouse_leave(event):
+ """ The mouse moves from the entry widget """
+ ''' Remove Tool-Tip '''
+ window.my_tool_tip.destroy()
+ if len(tl) != 0:
+ self.lb_rename.bind('', rename_mouse_enter)
+ self.lb_rename.bind('', rename_mouse_leave)
+ else:
+ self.lb_rename.bind('', rename_no_active_mouse_enter)
+ self.lb_rename.bind('', rename_no_active_mouse_leave)
def tl_rename():
special_characters = ['\\', '/', '{', '}', ' ']
@@ -395,6 +643,7 @@ class FrameWidgets(ttk.Frame):
style='RnButton.TButton')
self.btn_rename.grid(column=2, row=4, padx=20, pady=15, sticky='ne')
+
''' Check Buttons '''
self.selected_option = tk.IntVar()
self.autoconnect_var = tk.StringVar()
@@ -408,6 +657,33 @@ class FrameWidgets(ttk.Frame):
variable=self.selected_option,
command=lambda: FileHandle.box_set(self))
self.wg_autostart.grid(column=0, row=4, pady=15, padx=15, sticky='nw')
+ def chk_mouse_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_mouse_leave(event):
+ """ The mouse moves from the entry widget """
+ ''' Remove Tool-Tip '''
+ window.my_tool_tip.destroy()
+
+ if len(tl) == 0:
+ self.wg_autostart.bind('', chk_mouse_enter)
+ self.wg_autostart.bind('', chk_mouse_leave)
+ else:
+ def chk_a_mouse_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_mouse_leave(event):
+ """ The mouse moves from the entry widget """
+ ''' Remove Tool-Tip '''
+ window.my_tool_tip.destroy()
+
+ self.wg_autostart.bind('', chk_a_mouse_enter)
+ self.wg_autostart.bind('', chk_a_mouse_leave)
OnOff.on_off(self)
@@ -487,4 +763,4 @@ if __name__ == '__main__':
window.tk.call('set', '::tk::dialog::file::showHiddenBtn', '0')
window.tk.call('set', '::tk::dialog::file::showHiddenVar', '0')
- window.mainloop()
\ No newline at end of file
+ window.mainloop()