Merge pull request '1.11.0824' (#23) from 1.11.0824 into main
Reviewed-on: https://git.ilunix.de/punix/Wire-Py/pulls/23
This commit is contained in:
commit
03a7e48018
14
Changelog
14
Changelog
@ -11,6 +11,20 @@ My standard System: Linux Mint 22 Cinnamon
|
||||
### Added
|
||||
07-11-2024
|
||||
|
||||
- remove classes and add methods to class FrameWidgets (removed self errors)
|
||||
|
||||
|
||||
### Added
|
||||
08-11-2024
|
||||
|
||||
- methods from class MainWindow move to class FrameWidgets for active color_label when theme change
|
||||
- optimize columnconfigure, rowconfigure in class MainWindow and FrameWidgets
|
||||
- add new Frame for Widgets on Bottom
|
||||
- optimize from tkinter * to from tkinter import filedialog, ttk, TclError
|
||||
|
||||
### Added
|
||||
07-11-2024
|
||||
|
||||
- remove classes and add methods to class FrameWidgets (removed self errors)
|
||||
|
||||
|
||||
|
191
wg_main.py
191
wg_main.py
@ -5,8 +5,7 @@ import subprocess
|
||||
import tkinter as tk
|
||||
from pathlib import Path
|
||||
from subprocess import check_call
|
||||
from tkinter import *
|
||||
from tkinter import filedialog, ttk
|
||||
from tkinter import filedialog, ttk, TclError
|
||||
|
||||
from wg_func import (Tunnel, msg_window, WirePyUpdate, res, _u, version, path_to_file2, tips)
|
||||
|
||||
@ -19,15 +18,16 @@ class MainWindow(tk.Tk):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self.my_tool_tip = None
|
||||
self.switch_on = None
|
||||
self.switch_off = None
|
||||
self.x_width = 600
|
||||
self.y_height = 400
|
||||
self.y_height = 383
|
||||
self.monitor_center_x = self.winfo_screenwidth() / 2 - (self.x_width / 2)
|
||||
self.monitor_center_y = self.winfo_screenheight() / 2 - (self.y_height / 2)
|
||||
self.resizable(width=False, height=False)
|
||||
self.resizable(width=True, height=True)
|
||||
self.title('Wire-Py')
|
||||
self.geometry('%dx%d+%d+%d' % (self.x_width, self.y_height, self.monitor_center_x, self.monitor_center_y))
|
||||
self.columnconfigure(0, weight=1)
|
||||
self.rowconfigure(0, weight=1)
|
||||
|
||||
self.style = ttk.Style(self)
|
||||
self.tk.call('source', str(tcl_path) + '/water.tcl')
|
||||
''' self.tk.call('source', 'TK-Themes/water.tcl') '''
|
||||
@ -44,6 +44,28 @@ class MainWindow(tk.Tk):
|
||||
''' Set it as the window icon '''
|
||||
self.iconphoto(True, self.wg_icon)
|
||||
|
||||
FrameWidgets(self).grid()
|
||||
|
||||
|
||||
class FrameWidgets(ttk.Frame):
|
||||
def __init__(self, container, **kwargs):
|
||||
super().__init__(container, **kwargs)
|
||||
|
||||
self.lb_tunnel = None
|
||||
self.btn_stst = None
|
||||
self.endpoint = None
|
||||
self.dns = None
|
||||
self.address = None
|
||||
self.auto_con = 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')
|
||||
self.imp_pic = tk.PhotoImage(file=r'/usr/share/icons/wp-icons/48/wg_import.png')
|
||||
self.tr_pic = tk.PhotoImage(file=r'/usr/share/icons/wp-icons/48/wg_trash.png')
|
||||
self.exp_pic = tk.PhotoImage(file=r'/usr/share/icons/wp-icons/48/wg_export.png')
|
||||
self.warning_pic = tk.PhotoImage(file=r'/usr/share/icons/wp-icons/64/error.png')
|
||||
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')
|
||||
|
||||
''' Set on or off in file '''
|
||||
|
||||
def update():
|
||||
@ -61,7 +83,7 @@ class MainWindow(tk.Tk):
|
||||
with open(path_to_file2, 'w') as set_file2:
|
||||
set_file2.writelines(lines2)
|
||||
|
||||
''' Set on or off in file '''
|
||||
''' Set True or False in file '''
|
||||
|
||||
def tooltip():
|
||||
if set_tip.get():
|
||||
@ -89,6 +111,7 @@ class MainWindow(tk.Tk):
|
||||
lines3[3] = 'light\n'
|
||||
with open(path_to_file2, 'w') as theme_set2:
|
||||
theme_set2.writelines(lines3)
|
||||
self.color_label()
|
||||
|
||||
def theme_change_dark():
|
||||
if not self.tk.call("ttk::style", "theme", "use") == "water-dark":
|
||||
@ -99,6 +122,7 @@ class MainWindow(tk.Tk):
|
||||
lines4[3] = 'dark\n'
|
||||
with open(path_to_file2, 'w') as theme_set2:
|
||||
theme_set2.writelines(lines4)
|
||||
self.color_label()
|
||||
|
||||
def info():
|
||||
def link_btn():
|
||||
@ -122,14 +146,12 @@ class MainWindow(tk.Tk):
|
||||
''' Frame for Menu '''
|
||||
self.menu_frame = ttk.Frame(self)
|
||||
self.menu_frame.configure(relief='flat')
|
||||
self.menu_frame.grid(column=0, row=0, sticky='w')
|
||||
self.columnconfigure(0, weight=1)
|
||||
self.rowconfigure(0, weight=1)
|
||||
self.menu_frame.grid(column=0, row=0, columnspan=4, sticky='w')
|
||||
|
||||
''' 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, padx=10)
|
||||
self.version_lb.grid(column=0, row=0, rowspan=4, padx=10)
|
||||
|
||||
def version_enter(event):
|
||||
""" The mouse moves into the Version widget """
|
||||
@ -169,13 +191,11 @@ class MainWindow(tk.Tk):
|
||||
''' About BTN Menu / Label '''
|
||||
self.about_btn = ttk.Button(self.menu_frame, text='About', style='Toolbutton', command=info)
|
||||
self.about_btn.grid(column=2, row=0)
|
||||
|
||||
self.readme = tk.Menu(self)
|
||||
|
||||
''' Update and Tooltip Label '''
|
||||
self.updates_lb = ttk.Label(self.menu_frame)
|
||||
self.updates_lb.grid(column=3, row=0, padx=10)
|
||||
|
||||
'''View Checkbox for enable or disable Tooltip '''
|
||||
if tips:
|
||||
set_tip.set(value=False)
|
||||
@ -225,8 +245,7 @@ class MainWindow(tk.Tk):
|
||||
|
||||
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')
|
||||
window.my_tool_tip = MyToolTip(event.x_root, event.y_root, 'Click to download new version')
|
||||
|
||||
def download_leave(_):
|
||||
""" The mouse moves from the entry widget """
|
||||
@ -240,35 +259,6 @@ class MainWindow(tk.Tk):
|
||||
|
||||
self.update_btn.configure(menu=self.download, style='Toolbutton')
|
||||
self.download.add_command(label='Download', command=WirePyUpdate.download)
|
||||
|
||||
FrameWidgets(self).grid()
|
||||
|
||||
|
||||
class FrameWidgets(ttk.Frame):
|
||||
def __init__(self, container, **kwargs):
|
||||
super().__init__(container, **kwargs)
|
||||
|
||||
self.endpoint = None
|
||||
self.dns = None
|
||||
self.address = None
|
||||
self.btn_stst = None
|
||||
self.auto_con = None
|
||||
self.enp = None
|
||||
self.DNS = None
|
||||
self.add = None
|
||||
self.data = None
|
||||
self.peer = None
|
||||
self.lb_tunnel = None
|
||||
self.wg_read = 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')
|
||||
self.imp_pic = tk.PhotoImage(file=r'/usr/share/icons/wp-icons/48/wg_import.png')
|
||||
self.tr_pic = tk.PhotoImage(file=r'/usr/share/icons/wp-icons/48/wg_trash.png')
|
||||
self.exp_pic = tk.PhotoImage(file=r'/usr/share/icons/wp-icons/48/wg_export.png')
|
||||
self.warning_pic = tk.PhotoImage(file=r'/usr/share/icons/wp-icons/64/error.png')
|
||||
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')
|
||||
|
||||
''' Show active Tunnel '''
|
||||
self.a = Tunnel.active()
|
||||
|
||||
@ -276,30 +266,27 @@ class FrameWidgets(ttk.Frame):
|
||||
self.lb_frame_btn_lbox = ttk.Frame(self)
|
||||
self.lb_frame_btn_lbox.configure(relief='flat')
|
||||
self.lb_frame_btn_lbox.grid(column=0, rowspan=3, row=1)
|
||||
self.columnconfigure(0, weight=1)
|
||||
self.rowconfigure(1, weight=1)
|
||||
|
||||
''' Label Frame 2 '''
|
||||
self.lb_frame = ttk.Frame(self)
|
||||
self.lb_frame.configure(relief='solid')
|
||||
self.lb_frame.grid(column=2, row=2, sticky='snew', padx=20, pady=5)
|
||||
self.columnconfigure(2, weight=1)
|
||||
self.rowconfigure(2, weight=1)
|
||||
|
||||
''' Label Frame 3 '''
|
||||
self.lb_frame2 = ttk.Frame(self)
|
||||
self.lb_frame2.configure(relief='solid')
|
||||
self.lb_frame2.grid(column=2, row=3, sticky='snew', padx=20, pady=5)
|
||||
self.columnconfigure(2, weight=1)
|
||||
self.rowconfigure(3, weight=1)
|
||||
|
||||
''' Bottom Frame 4 '''
|
||||
self.lb_frame3 = ttk.Frame(self)
|
||||
self.lb_frame3.configure(relief='flat')
|
||||
self.lb_frame3.grid(column=0, row=5, columnspan=4, sticky='snew', padx=2, pady=2)
|
||||
|
||||
''' Show active Label '''
|
||||
self.select_tunnel = None
|
||||
self.lb = ttk.Label(self, text='Active: ')
|
||||
self.lb.config(font=('Ubuntu', 11, 'bold'))
|
||||
self.lb.grid(column=2, row=1, padx=15, pady=4, sticky='w')
|
||||
self.columnconfigure(2, weight=1)
|
||||
self.rowconfigure(0, weight=1)
|
||||
|
||||
''' Label to Show active Tunnel '''
|
||||
self.StrVar = tk.StringVar(value=self.a)
|
||||
@ -333,7 +320,6 @@ class FrameWidgets(ttk.Frame):
|
||||
self.scrollbar = ttk.Scrollbar(self.lb_frame_btn_lbox, orient='vertical', command=self.l_box.yview)
|
||||
self.scrollbar.grid(column=1, rowspan=4, row=0, sticky='nse')
|
||||
self.l_box.configure(yscrollcommand=self.scrollbar.set)
|
||||
self.rowconfigure(0, weight=1)
|
||||
|
||||
''' Tunnel List '''
|
||||
self.tl = Tunnel.list()
|
||||
@ -388,15 +374,12 @@ class FrameWidgets(ttk.Frame):
|
||||
self.show_data()
|
||||
|
||||
''' Button Import '''
|
||||
self.btn_i = ttk.Button(self.lb_frame_btn_lbox,
|
||||
image=self.imp_pic, command=self.import_sl,
|
||||
padding=0)
|
||||
self.btn_i = ttk.Button(self.lb_frame_btn_lbox, image=self.imp_pic, command=self.import_sl, padding=0)
|
||||
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')
|
||||
window.my_tool_tip = MyToolTip(event.x_root, event.y_root, 'Click to import a Wireguard Tunnel')
|
||||
|
||||
def imp_leave(_):
|
||||
""" The mouse moves from the entry widget """
|
||||
@ -503,8 +486,7 @@ class FrameWidgets(ttk.Frame):
|
||||
|
||||
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')
|
||||
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 from the entry widget """
|
||||
@ -529,14 +511,12 @@ class FrameWidgets(ttk.Frame):
|
||||
self.btn_tr.bind('<Leave>', del_leave)
|
||||
|
||||
''' Button Export '''
|
||||
self.btn_exp = ttk.Button(self.lb_frame_btn_lbox, image=self.exp_pic, command=Tunnel.export,
|
||||
padding=0)
|
||||
self.btn_exp = ttk.Button(self.lb_frame_btn_lbox, image=self.exp_pic, command=Tunnel.export, padding=0)
|
||||
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')
|
||||
window.my_tool_tip = MyToolTip(event.x_root, event.y_root, 'No Tunnels in List for Export')
|
||||
|
||||
def empty_list_leave(_):
|
||||
""" The mouse moves from the entry widget """
|
||||
@ -561,8 +541,8 @@ class FrameWidgets(ttk.Frame):
|
||||
self.btn_exp.bind('<Leave>', exp_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 = ttk.Entry(self.lb_frame3, width=20)
|
||||
self.lb_rename.grid(column=2, row=0, padx=8, pady=10, sticky='ne')
|
||||
self.lb_rename.insert(0, 'Max. 12 characters!')
|
||||
self.lb_rename.config(state='disable')
|
||||
|
||||
@ -662,21 +642,21 @@ class FrameWidgets(ttk.Frame):
|
||||
msg_window(iw, ii, wt, msg_t)
|
||||
|
||||
''' Button Rename '''
|
||||
self.btn_rename = ttk.Button(self, text='Rename', state='disable', command=tl_rename, padding=4,
|
||||
self.btn_rename = ttk.Button(self.lb_frame3, text='Rename', state='disable', command=tl_rename, padding=4,
|
||||
style='RnButton.TButton')
|
||||
self.btn_rename.grid(column=2, row=4, padx=20, pady=15, sticky='ne')
|
||||
self.btn_rename.grid(column=3, row=0, padx=5, pady=10, sticky='ne')
|
||||
|
||||
''' Check Buttons '''
|
||||
self.selected_option = tk.IntVar()
|
||||
self.autoconnect_var = tk.StringVar()
|
||||
self.autoconnect_var.set(self.auto_con)
|
||||
''' Frame for Labels, Entry and Button'''
|
||||
self.autoconnect = ttk.Label(self, textvariable=self.autoconnect_var)
|
||||
self.autoconnect = ttk.Label(self.lb_frame3, textvariable=self.autoconnect_var, width=15)
|
||||
self.autoconnect.config(font=('Ubuntu', 11))
|
||||
self.autoconnect.grid(column=0, row=4, sticky='ne', padx=10, pady=15)
|
||||
self.wg_autostart = ttk.Checkbutton(self, text='Autoconnect on:', variable=self.selected_option,
|
||||
self.autoconnect.grid(column=1, row=0, sticky='e', pady=19)
|
||||
self.wg_autostart = ttk.Checkbutton(self.lb_frame3, text='Autoconnect on:', variable=self.selected_option,
|
||||
command=self.box_set)
|
||||
self.wg_autostart.grid(column=0, row=4, pady=15, padx=15, sticky='nw')
|
||||
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 """
|
||||
@ -722,19 +702,17 @@ class FrameWidgets(ttk.Frame):
|
||||
|
||||
self.on_off()
|
||||
|
||||
"""
|
||||
Import Methode for Wireguard config Files.
|
||||
Before importing, it is checked whether PrivateKey and PublicKey are in the file.
|
||||
If True then it is checked whether the PreSharedKey is already in the key file
|
||||
to avoid an import error so that no double wgconf are imported.
|
||||
Thus, tunnels can be renamed without the problems arise. If False then the key is written into the file.
|
||||
Furthermore, it is checked whether the name is longer than 12 characters.
|
||||
If True then the name is automatically shortened to 12 characters and then imported.
|
||||
If in each case false comes out, a corresponding window comes to inform the user that something is wrong.
|
||||
"""
|
||||
|
||||
def import_sl(self):
|
||||
|
||||
"""
|
||||
Import Methode for Wireguard config Files.
|
||||
Before importing, it is checked whether PrivateKey and PublicKey are in the file.
|
||||
If True then it is checked whether the PreSharedKey is already in the key file
|
||||
to avoid an import error so that no double wgconf are imported.
|
||||
Thus, tunnels can be renamed without the problems arise. If False then the key is written into the file.
|
||||
Furthermore, it is checked whether the name is longer than 12 characters.
|
||||
If True then the name is automatically shortened to 12 characters and then imported.
|
||||
If in each case false comes out, a corresponding window comes to inform the user that something is wrong.
|
||||
"""
|
||||
try:
|
||||
filepath = filedialog.askopenfilename(initialdir=str(_u), title='Select Wireguard config File',
|
||||
filetypes=[('WG config files', '*.conf')], )
|
||||
@ -890,14 +868,12 @@ class FrameWidgets(ttk.Frame):
|
||||
|
||||
print('Tunnel exist!')
|
||||
|
||||
'''
|
||||
This Method will display the autostart label which
|
||||
Tunnel is automatically started regardless of the active tunnel.
|
||||
The selected tunnel is written into a file to read it after the start of the system.
|
||||
'''
|
||||
|
||||
def box_set(self):
|
||||
|
||||
"""
|
||||
This Method will display the autostart label which
|
||||
Tunnel is automatically started regardless of the active tunnel.
|
||||
The selected tunnel is written into a file to read it after the start of the system.
|
||||
"""
|
||||
try:
|
||||
select_tunnel = self.l_box.curselection()
|
||||
select_tl = self.l_box.get(select_tunnel[0])
|
||||
@ -926,13 +902,12 @@ class FrameWidgets(ttk.Frame):
|
||||
|
||||
self.on_off()
|
||||
|
||||
'''
|
||||
Here it is checked whether the path to the file is there if not it is created.
|
||||
Set (on), the selected tunnel is displayed in the label.
|
||||
At (off) the label is first emptied then filled with No Autoconnect
|
||||
'''
|
||||
|
||||
def on_off(self):
|
||||
"""
|
||||
Here it is checked whether the path to the file is there if not it is created.
|
||||
Set (on), the selected tunnel is displayed in the label.
|
||||
At (off) the label is first emptied then filled with No Autoconnect
|
||||
"""
|
||||
with open(path_to_file2, 'r') as set_file4:
|
||||
lines4 = set_file4.readlines()
|
||||
|
||||
@ -949,16 +924,16 @@ class FrameWidgets(ttk.Frame):
|
||||
self.autoconnect_var = tk.StringVar()
|
||||
self.autoconnect_var.set(self.auto_con)
|
||||
|
||||
self.autoconnect = ttk.Label(self, textvariable=self.autoconnect_var, foreground='#0071ff')
|
||||
self.autoconnect = ttk.Label(self.lb_frame3, textvariable=self.autoconnect_var, foreground='#0071ff', width=15)
|
||||
self.autoconnect.config(font=('Ubuntu', 11))
|
||||
self.autoconnect.grid(column=0, row=4, sticky='ne', pady=19)
|
||||
|
||||
"""
|
||||
Displays the value address, DNS and peer in the labels
|
||||
or empty it again
|
||||
"""
|
||||
self.autoconnect.grid(column=1, row=0, sticky='e', pady=19)
|
||||
|
||||
def init_and_report(self, data=None):
|
||||
"""
|
||||
Displays the value address, DNS and peer in the labels
|
||||
or empty it again
|
||||
"""
|
||||
|
||||
""" Address Label """
|
||||
self.add = tk.StringVar()
|
||||
self.add.set('Address: ' + data[0])
|
||||
@ -989,6 +964,7 @@ class FrameWidgets(ttk.Frame):
|
||||
self.endpoint.config(font=('Ubuntu', 9))
|
||||
|
||||
def stop(self):
|
||||
""" Stop Button """
|
||||
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)
|
||||
|
||||
@ -1006,13 +982,13 @@ class FrameWidgets(ttk.Frame):
|
||||
self.btn_stst.bind('<Leave>', stop_leave)
|
||||
|
||||
def start(self):
|
||||
""" Start Button """
|
||||
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_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')
|
||||
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 from the entry widget """
|
||||
@ -1038,6 +1014,8 @@ class FrameWidgets(ttk.Frame):
|
||||
self.btn_stst.bind('<Leave>', start_leave)
|
||||
|
||||
def color_label(self):
|
||||
""" View activ Tunnel in color green or yellow """
|
||||
|
||||
with open(path_to_file2, 'r') as read_file:
|
||||
lines = read_file.readlines()
|
||||
if 'light\n' in lines:
|
||||
@ -1050,6 +1028,7 @@ class FrameWidgets(ttk.Frame):
|
||||
self.lb_tunnel.grid(column=2, padx=10, row=1)
|
||||
|
||||
def wg_switch(self):
|
||||
|
||||
self.a = Tunnel.active()
|
||||
try:
|
||||
if self.a == '':
|
||||
|
Loading…
Reference in New Issue
Block a user