small corrections

This commit is contained in:
Désiré Werner Menrath 2024-11-07 17:15:35 +01:00
parent fecbf2ab46
commit 414a36b436
2 changed files with 28 additions and 42 deletions

View File

@ -148,14 +148,6 @@ class Tunnel:
self.lb_tunnel.config(font=('Ubuntu', 11, 'bold'))
self.lb_tunnel.grid(column=2, padx=10, row=1)
self.columnconfigure(2, weight=1)
self.rowconfigure(0, weight=1)
def columnconfigure(self, param, weight):
pass
def rowconfigure(self, param, weight):
pass
"""

View File

@ -12,6 +12,7 @@ from wg_func import (Tunnel, FileHandle, OnOff, msg_window, WirePyUpdate, res, _
tcl_path = Path('/usr/share/TK-Themes')
class MainWindow(tk.Tk):
def __init__(self, *args, **kwargs):
@ -29,7 +30,7 @@ class MainWindow(tk.Tk):
self.geometry('%dx%d+%d+%d' % (self.x_width, self.y_height, self.monitor_center_x, self.monitor_center_y))
self.style = ttk.Style(self)
self.tk.call('source', str(tcl_path) + '/water.tcl')
#self.tk.call('source', 'TK-Themes/water.tcl')
''' self.tk.call('source', 'TK-Themes/water.tcl') '''
with open(path_to_file2, 'r') as read_file:
lines = read_file.readlines()
if 'light\n' in lines:
@ -40,59 +41,58 @@ class MainWindow(tk.Tk):
''' Load the image file from disk. '''
self.wg_icon = tk.PhotoImage(file=r'/usr/share/icons/wp-icons/48/wg_vpn.png')
# Set it as the window icon.
''' Set it as the window icon '''
self.iconphoto(True, self.wg_icon)
#Set on or off in file
''' Set on or off in file '''
def update():
if set_update.get() == 1:
with open(path_to_file2, 'r') as set_file2:
lines2 = set_file2.readlines()
lines2 = set_file2.readlines()
lines2[1] = 'off\n'
with open(path_to_file2, 'w') as set_file2:
set_file2.writelines(lines2)
if set_update.get() == 0:
with open(path_to_file2, 'r') as set_file2:
lines2 = set_file2.readlines()
lines2 = set_file2.readlines()
lines2[1] = 'on\n'
with open(path_to_file2, 'w') as set_file2:
set_file2.writelines(lines2)
#Set on or off in file
''' Set on or off in file '''
def tooltip():
if set_tip.get():
print(set_tip.get())
with open(path_to_file2, 'r') as set_file2:
lines2 = set_file2.readlines()
lines2 = set_file2.readlines()
lines2[5] = 'False\n'
with open(path_to_file2, 'w') as set_file2:
set_file2.writelines(lines2)
else:
with open(path_to_file2, 'r') as set_file2:
lines2 = set_file2.readlines()
lines2 = set_file2.readlines()
lines2[5] = 'True\n'
with open(path_to_file2, 'w') as set_file2:
set_file2.writelines(lines2)
# Set dark or light
''' Set dark or light '''
def theme_change_light():
if self.tk.call("ttk::style", "theme", "use") == "water-dark":
# Set light theme
''' Set light theme '''
self.tk.call('set_theme', 'light')
with open(path_to_file2, 'r') as theme_set2:
lines3 = theme_set2.readlines()
lines3 = theme_set2.readlines()
lines3[3] = 'light\n'
with open(path_to_file2, 'w') as theme_set2:
theme_set2.writelines(lines3)
def theme_change_dark():
if not self.tk.call("ttk::style", "theme", "use") == "water-dark":
# Set dark theme
''' Set dark theme '''
self.tk.call('set_theme', 'dark')
with open(path_to_file2, 'r') as theme_set2:
lines4 = theme_set2.readlines()
lines4 = theme_set2.readlines()
lines4[3] = 'dark\n'
with open(path_to_file2, 'w') as theme_set2:
theme_set2.writelines(lines4)
@ -123,7 +123,7 @@ class MainWindow(tk.Tk):
self.columnconfigure(0, weight=1)
self.rowconfigure(0, weight=1)
# App Menu
''' 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)
@ -303,7 +303,6 @@ class StSt:
self.btn_stst.bind('<Leave>', start_leave)
# noinspection PyTypeChecker
class TLImp:
"""
Import Class for Wireguard config Files.
@ -342,7 +341,7 @@ class TLImp:
path_split1 = path_split[-1]
self.a = Tunnel.active()
if 'PrivateKey = ' in read and 'PublicKey = 'in read and 'Endpoint =' in read:
if 'PrivateKey = ' in read and 'PublicKey = ' in read and 'Endpoint =' in read:
with open(filepath, 'r') as file:
key = Tunnel.con_to_dict(file)
pre_key = key[3]
@ -402,14 +401,14 @@ class TLImp:
window.my_tool_tip.destroy()
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')
""" The mouse moves into the entry widget """
window.my_tool_tip = MyToolTip(event.x_root, event.y_root,
'List of available tunnels')
def list_info_leave(_):
""" The mouse moves from the entry widget """
''' Remove Tool-Tip '''
window.my_tool_tip.destroy()
""" The mouse moves from the entry widget """
''' Remove Tool-Tip '''
window.my_tool_tip.destroy()
def del_enter(event):
""" The mouse moves into the entry widget """
@ -444,7 +443,6 @@ class TLImp:
''' Remove Tool-Tip '''
window.my_tool_tip.destroy()
self.wg_autostart.bind('<Enter>', chk_a_enter)
self.wg_autostart.bind('<Leave>', chk_a_leave)
self.l_box.bind('<Enter>', list_info_enter)
@ -470,7 +468,6 @@ class TLImp:
check_call(['nmcli', 'con', 'mod', self.a, 'connection.autoconnect', 'no'])
Path.chmod(wg_read, 0o600)
if 'PrivateKey = ' and 'Endpoint = ' not in read:
"""img_w, img_i, w_title, w_txt hand over"""
iw = r'/usr/share/icons/wp-icons/64/error.png'
@ -490,7 +487,6 @@ class TLImp:
print('Tunnel exist!')
# noinspection PyTypeChecker
class FrameWidgets(ttk.Frame):
def __init__(self, container, **kwargs):
super().__init__(container, **kwargs)
@ -567,7 +563,6 @@ class FrameWidgets(ttk.Frame):
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', font=('Ubuntu', 12, 'bold'))
self.l_box.grid(column=1, rowspan=4, row=0, sticky='ns')
@ -610,7 +605,6 @@ class FrameWidgets(ttk.Frame):
self.l_box.bind('<Enter>', list_not_empty_enter)
self.l_box.bind('<Leave>', list_not_empty_leave)
''' Button Vpn '''
if self.a != '':
StSt.stop(self)
@ -662,7 +656,7 @@ class FrameWidgets(ttk.Frame):
self.l_box.delete(self.select_tunnel[0])
with open(path_to_file2, 'r') as set_file6:
lines6 = set_file6.readlines()
if select_tl == lines6[7].strip() and not 'off' in lines6[7].strip():
if select_tl == lines6[7].strip() and 'off' not in lines6[7].strip():
lines6[7] = 'off'
with open(path_to_file2, 'w') as set_file7:
set_file7.writelines(lines6)
@ -681,6 +675,7 @@ 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,
@ -775,6 +770,7 @@ class FrameWidgets(ttk.Frame):
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,
@ -834,6 +830,7 @@ class FrameWidgets(ttk.Frame):
else:
self.lb_rename.bind('<Enter>', rename_no_active_enter)
self.lb_rename.bind('<Leave>', rename_no_active_leave)
def tl_rename():
special_characters = ['\\', '/', '{', '}', ' ']
@ -885,7 +882,7 @@ class FrameWidgets(ttk.Frame):
self.StrVar.set(value=self.a)
with open(path_to_file2, 'r') as set_file5:
lines5 = set_file5.readlines()
if select_tl == lines5[7].strip() and not 'off' in lines5[7].strip():
if select_tl == lines5[7].strip() and 'off' not in lines5[7].strip():
lines5[7] = new_a_connect
with open(path_to_file2, 'w') as theme_set5:
theme_set5.writelines(lines5)
@ -907,7 +904,6 @@ 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()
@ -921,6 +917,7 @@ 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_enter(event):
""" The mouse moves into the entry widget """
window.my_tool_tip = MyToolTip(event.x_root, event.y_root,
@ -933,7 +930,6 @@ class FrameWidgets(ttk.Frame):
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,
@ -947,7 +943,6 @@ class FrameWidgets(ttk.Frame):
self.wg_autostart.bind('<Enter>', chk_a_enter)
self.wg_autostart.bind('<Leave>', chk_a_leave)
if self.l_box.size() == 0:
self.wg_autostart.bind('<Enter>', chk_enter)
self.wg_autostart.bind('<Leave>', chk_leave)
@ -965,7 +960,6 @@ class FrameWidgets(ttk.Frame):
self.wg_autostart.bind('<Enter>', chk_a_enter)
self.wg_autostart.bind('<Leave>', chk_a_leave)
OnOff.on_off(self)
def wg_switch(self):