- Add Options, Help, Update Label and Update Menubutton #19

Merged
punix merged 1 commits from 1.10.2024 into main 2024-10-20 02:15:23 +02:00
4 changed files with 335 additions and 41 deletions
Showing only changes of commit c4a4d328ae - Show all commits

View File

@ -4,7 +4,7 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="940e1630-c825-4d4c-be80-bc11f543c122" name="Changes" comment=" - Theme modify to water-theme&#10; - add ttk.Menubutton vor modern Menu and automatic theme and textvariable for color on font in menu">
<list default="true" id="940e1630-c825-4d4c-be80-bc11f543c122" name="Changes" comment=" - Add Options, Help, Update Label and Update Menubutton &#10; - Theme now separate Light and Dark">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/wg_func.py" beforeDir="false" afterPath="$PROJECT_DIR$/wg_func.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/wg_main.py" beforeDir="false" afterPath="$PROJECT_DIR$/wg_main.py" afterDir="false" />
@ -137,14 +137,6 @@
<option name="presentableId" value="Default" />
<updated>1723279982210</updated>
</task>
<task id="LOCAL-00012" summary="fixed error when active tunnel is deleted,&#10;now also the Address Label is emptied">
<option name="closed" value="true" />
<created>1724400463791</created>
<option name="number" value="00012" />
<option name="presentableId" value="LOCAL-00012" />
<option name="project" value="LOCAL" />
<updated>1724400463791</updated>
</task>
<task id="LOCAL-00013" summary="In FrameWidged Class else Block StrVar, this resorts reference and variable assignment together">
<option name="closed" value="true" />
<created>1724401340512</created>
@ -529,7 +521,15 @@
<option name="project" value="LOCAL" />
<updated>1729283719951</updated>
</task>
<option name="localTasksCounter" value="61" />
<task id="LOCAL-00061" summary=" - Add Options, Help, Update Label and Update Menubutton &#10; - Theme now separate Light and Dark">
<option name="closed" value="true" />
<created>1729353898829</created>
<option name="number" value="00061" />
<option name="presentableId" value="LOCAL-00061" />
<option name="project" value="LOCAL" />
<updated>1729353898830</updated>
</task>
<option name="localTasksCounter" value="62" />
<servers />
</component>
<component name="UnknownFeatures">
@ -570,7 +570,6 @@
</component>
<component name="VcsManagerConfiguration">
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
<MESSAGE value="fix rename in Messagebox warning to error" />
<MESSAGE value="set rights in install and a .conf a import Tunnel Filedialog Part 1 /home when open" />
<MESSAGE value="fix set rights in install and a .conf a import Tunnel Filedialog Part 1 /home when open" />
<MESSAGE value="fix a filedialog for hidden Files work&#10;install rollback to bash for start wirepy and wirepy rollback to bash" />
@ -595,17 +594,7 @@
<MESSAGE value="Fix msg_window and remove x , y argument&#10;Install further adapted and with colored&#10;text if user is not in group sudo or wheel.&#10;Added to install Opensuse for installation" />
<MESSAGE value=" - Menu add &#10; - New Modern Dark and Light(default) Theme" />
<MESSAGE value=" - Theme modify to water-theme&#10; - add ttk.Menubutton vor modern Menu and automatic theme and textvariable for color on font in menu" />
<option name="LAST_COMMIT_MESSAGE" value=" - Theme modify to water-theme&#10; - add ttk.Menubutton vor modern Menu and automatic theme and textvariable for color on font in menu" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/wg_main.py</url>
<line>185</line>
<option name="timeStamp" value="1" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
<MESSAGE value=" - Add Options, Help, Update Label and Update Menubutton &#10; - Theme now separate Light and Dark" />
<option name="LAST_COMMIT_MESSAGE" value=" - Add Options, Help, Update Label and Update Menubutton &#10; - Theme now separate Light and Dark" />
</component>
</project>

View File

@ -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

View File

@ -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()

View File

@ -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('<Enter>', version_mouse_enter)
self.version_lb.bind('<Leave>', version_mouse_leave)
self.options_btn.bind('<Enter>', sets_mouse_enter)
self.options_btn.bind('<Leave>', 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('<Enter>', help_mouse_enter)
self.help_btn.bind('<Leave>', 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('<Enter>', disable_mouse_enter)
self.updates_lb.bind('<Leave>', 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('<Enter>', congratulations_mouse_enter)
self.updates_lb.bind('<Leave>', 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('<Enter>', download_mouse_enter)
self.update_btn.bind('<Leave>', 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('<Enter>', stop_mouse_enter)
self.btn_stst.bind('<Leave>', 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('<Enter>', empty_list_start_mouse_enter)
self.btn_stst.bind('<Leave>', empty_list_start_mouse_leave)
else:
self.btn_stst.bind('<Enter>', start_mouse_enter)
self.btn_stst.bind('<Leave>', 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('<Enter>', box_info_mouse_enter)
self.l_box.bind('<Leave>', box_info_mouse_leave)
self.l_box.event_add('<<ClickEvent>>', '<Button-1>')
self.l_box.bind('<<ClickEvent>>', 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('<Enter>', import_mouse_enter)
self.btn_i.bind('<Leave>', 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('<Enter>', empty_list_del_mouse_enter)
self.btn_tr.bind('<Leave>', empty_list_del_mouse_leave)
else:
self.btn_tr.bind('<Enter>', delete_mouse_enter)
self.btn_tr.bind('<Leave>', 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('<Enter>', empty_list_mouse_enter)
self.btn_exp.bind('<Leave>', empty_list_mouse_leave)
else:
self.btn_exp.bind('<Enter>', export_mouse_enter)
self.btn_exp.bind('<Leave>', 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('<Enter>', rename_mouse_enter)
self.lb_rename.bind('<Leave>', rename_mouse_leave)
else:
self.lb_rename.bind('<Enter>', rename_no_active_mouse_enter)
self.lb_rename.bind('<Leave>', 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('<Enter>', chk_mouse_enter)
self.wg_autostart.bind('<Leave>', 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('<Enter>', chk_a_mouse_enter)
self.wg_autostart.bind('<Leave>', 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()
window.mainloop()