wire-py-reformat-14-08-2024 #13

Merged
punix merged 2 commits from wire-py-reformat-14-08-2024 into main 2024-09-05 22:22:00 +02:00
4 changed files with 90 additions and 48 deletions

View File

@ -4,12 +4,7 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="940e1630-c825-4d4c-be80-bc11f543c122" name="Changes" comment="add delete row in wg_py.xml when Tunnel delete"> <list default="true" id="940e1630-c825-4d4c-be80-bc11f543c122" name="Changes" comment="add Frame widget 3&#10;for Buttons and Listbox with Scrollbar.&#10;all Widgets new format&#10;delete works now of disable checkbox when Listbox empty (part two)" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/wg_func.py" beforeDir="false" afterPath="$PROJECT_DIR$/wg_func.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/wg_py.xml" beforeDir="false" afterPath="$PROJECT_DIR$/wg_py.xml" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@ -276,7 +271,23 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1725434328731</updated> <updated>1725434328731</updated>
</task> </task>
<option name="localTasksCounter" value="24" /> <task id="LOCAL-00024" summary="fixes on empty Listbox now is disable and now works autoconnect label with read and write, delete works now with read and write">
<option name="closed" value="true" />
<created>1725475967338</created>
<option name="number" value="00024" />
<option name="presentableId" value="LOCAL-00024" />
<option name="project" value="LOCAL" />
<updated>1725475967338</updated>
</task>
<task id="LOCAL-00025" summary="add Frame widget 3&#10;for Buttons and Listbox with Scrollbar.&#10;all Widgets new format&#10;delete works now of disable checkbox when Listbox empty (part two)">
<option name="closed" value="true" />
<created>1725567453540</created>
<option name="number" value="00025" />
<option name="presentableId" value="LOCAL-00025" />
<option name="project" value="LOCAL" />
<updated>1725567453540</updated>
</task>
<option name="localTasksCounter" value="26" />
<servers /> <servers />
</component> </component>
<component name="Vcs.Log.Tabs.Properties"> <component name="Vcs.Log.Tabs.Properties">
@ -326,6 +337,8 @@
<MESSAGE value="little fixes a &quot; &quot; to ' '" /> <MESSAGE value="little fixes a &quot; &quot; to ' '" />
<MESSAGE value="add class FileHandle,&#10;add Label to show autoconnect Tunnel&#10;disable checkbox when Listbox is empty or no select Tunnel" /> <MESSAGE value="add class FileHandle,&#10;add Label to show autoconnect Tunnel&#10;disable checkbox when Listbox is empty or no select Tunnel" />
<MESSAGE value="add if question and add autoconnect, autoconnect_var to class Filehandle in box_set no finish!" /> <MESSAGE value="add if question and add autoconnect, autoconnect_var to class Filehandle in box_set no finish!" />
<option name="LAST_COMMIT_MESSAGE" value="add if question and add autoconnect, autoconnect_var to class Filehandle in box_set no finish!" /> <MESSAGE value="fixes on empty Listbox now is disable and now works autoconnect label with read and write, delete works now with read and write" />
<MESSAGE value="add Frame widget 3&#10;for Buttons and Listbox with Scrollbar.&#10;all Widgets new format&#10;delete works now of disable checkbox when Listbox empty (part two)" />
<option name="LAST_COMMIT_MESSAGE" value="add Frame widget 3&#10;for Buttons and Listbox with Scrollbar.&#10;all Widgets new format&#10;delete works now of disable checkbox when Listbox empty (part two)" />
</component> </component>
</project> </project>

71
main.py
View File

@ -17,10 +17,10 @@ class MainWindow(tk.Tk):
self.switch_on = None self.switch_on = None
self.switch_off = None self.switch_off = None
self.x_width = 600 self.x_width = 600
self.y_height = 360 self.y_height = 340
self.monitor_center_x = self.winfo_screenwidth() / 2 - (self.x_width / 2) 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.monitor_center_y = self.winfo_screenheight() / 2 - (self.y_height / 2)
#self.resizable(width=False, height=False) self.resizable(width=False, height=False)
self.title('Wire-Py') self.title('Wire-Py')
self.configure() self.configure()
self.geometry('%dx%d+%d+%d' % (self.x_width, self.y_height, self.monitor_center_x, self.monitor_center_y)) self.geometry('%dx%d+%d+%d' % (self.x_width, self.y_height, self.monitor_center_x, self.monitor_center_y))
@ -33,6 +33,13 @@ class MainWindow(tk.Tk):
# Set it as the window icon. # Set it as the window icon.
self.iconphoto(True, self.wg_icon) self.iconphoto(True, self.wg_icon)
# App Menu
self.app_menu = tk.Menu(self, borderwidth=0)
for item in self.app_menu.keys():
print(item, ': ', self.app_menu[item])
self.configure(menu=self.app_menu)
self.app_menu.add_cascade(label='?')
FrameWidgets(self).grid() FrameWidgets(self).grid()
@ -53,38 +60,46 @@ class FrameWidgets(ttk.Frame):
self.tr_pic = tk.PhotoImage(file=r'icons/wg-trash-48.png') self.tr_pic = tk.PhotoImage(file=r'icons/wg-trash-48.png')
self.exp_pic = tk.PhotoImage(file=r'icons/wg-export-48.png') self.exp_pic = tk.PhotoImage(file=r'icons/wg-export-48.png')
self.warning_pic = tk.PhotoImage(file=r'icons/warning_64.png') self.warning_pic = tk.PhotoImage(file=r'icons/warning_64.png')
self.configure()
# Show active Tunnel # Show active Tunnel
self.a = TunnelActiv.active() self.a = TunnelActiv.active()
# Label Frame 1 # Label Frame 1
self.lb_frame = ttk.Frame(self) self.lb_frame = ttk.Frame(self)
self.lb_frame.configure(relief='solid') self.lb_frame.configure(relief='solid')
self.lb_frame.grid(column=2, row=2, sticky='snew', padx=20, pady=5) self.lb_frame.grid(column=2, row=1, sticky='snew', padx=20, pady=5)
self.columnconfigure(2, weight=1)
self.rowconfigure(1, weight=1)
# Label Frame 2 # Label Frame 2
self.lb_frame2 = ttk.Frame(self) self.lb_frame2 = ttk.Frame(self)
self.lb_frame2.configure(relief='solid') self.lb_frame2.configure(relief='solid')
self.lb_frame2.grid(column=2, row=3, sticky='snew', padx=20, pady=5) self.lb_frame2.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_frame_buttons = ttk.Frame(self)
self.lb_frame_buttons.configure(relief='flat')
self.lb_frame_buttons.grid(column=0, rowspan=4, row=0)
self.columnconfigure(0, weight=1)
self.rowconfigure(0, weight=1)
# Show active Label # Show active Label
self.select_tunnel = None self.select_tunnel = None
self.lb = tk.Label(self, text='Active: ') self.lb = tk.Label(self, text='Active: ')
self.lb.config(font=('Ubuntu', 11, 'bold')) self.lb.config(font=('Ubuntu', 11, 'bold'))
self.lb.grid(column=2, row=1, padx=15, sticky='w') self.lb.grid(column=2, row=0, padx=15, sticky='w')
self.columnconfigure(2, weight=1)
self.rowconfigure(0, weight=1)
# Label to Show active Tunnel # Label to Show active Tunnel
self.StrVar = tk.StringVar(value=self.a) self.StrVar = tk.StringVar(value=self.a)
GreenLabel.green_show_label(self) GreenLabel.green_show_label(self)
# Interface Label # Interface Label
self.interface = tk.Label(self.lb_frame, text='Interface', fg=font_color) self.interface = tk.Label(self.lb_frame, text='Interface', fg=font_color)
self.interface.grid(column=0, row=4, sticky='we', padx=120) self.interface.grid(column=0, row=2, sticky='we', padx=120)
self.interface.config(font=('Ubuntu', 9)) self.interface.config(font=('Ubuntu', 9))
# Peer Label # Peer Label
self.peer = tk.Label(self.lb_frame2, text='Peer', fg=font_color) self.peer = tk.Label(self.lb_frame2, text='Peer', fg=font_color)
self.peer.config(font=('Ubuntu', 9)) self.peer.config(font=('Ubuntu', 9))
self.peer.grid(column=0, row=7, sticky='we', padx=130) self.peer.grid(column=0, row=3, sticky='we', padx=130)
# Listbox with Scrollbar # Listbox with Scrollbar
def enable_check_box(event): def enable_check_box(event):
@ -93,14 +108,16 @@ class FrameWidgets(ttk.Frame):
if len(tl) != 0: if len(tl) != 0:
self.wg_autostart.configure(state='normal') self.wg_autostart.configure(state='normal')
self.scrollbar = ttk.Scrollbar(self) self.l_box = tk.Listbox(self.lb_frame_buttons, fg='#606060', selectmode='single')
self.l_box = tk.Listbox(self, fg='#606060', selectmode='single') self.l_box.config(highlightthickness=0, relief='ridge')
self.l_box.config(highlightthickness=0, relief='flat')
self.scrollbar.config(command=self.l_box.yview)
self.l_box.config(font=('Ubuntu', 12, 'bold')) self.l_box.config(font=('Ubuntu', 12, 'bold'))
self.l_box.grid(column=1, rowspan=3, row=1) self.l_box.grid(column=1, rowspan=4, row=0, sticky='ns')
self.l_box.event_add('<<ClickEvent>>', '<Button-1>') self.l_box.event_add('<<ClickEvent>>', '<Button-1>')
self.l_box.bind('<<ClickEvent>>', enable_check_box) self.l_box.bind('<<ClickEvent>>', enable_check_box)
self.scrollbar = ttk.Scrollbar(self.lb_frame_buttons, 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 # Tunnel List
self.tl = ListTunnels.tl_list() self.tl = ListTunnels.tl_list()
@ -126,8 +143,10 @@ class FrameWidgets(ttk.Frame):
ShowAddress.label_empty(self) ShowAddress.label_empty(self)
ShowAddress.show_data(self) ShowAddress.show_data(self)
# Button Import # Button Import
self.btn_i = tk.Button(self, image=self.imp_pic, bd=0, command=lambda: ImportTunnel.wg_import_select(self)) self.btn_i = tk.Button(self.lb_frame_buttons,
self.btn_i.grid(column=0, row=2, padx=15, pady=15) image=self.imp_pic, bd=0,
command=lambda: ImportTunnel.wg_import_select(self))
self.btn_i.grid(column=0, row=1, padx=15, pady=8)
def delete(): def delete():
try: try:
@ -154,25 +173,29 @@ class FrameWidgets(ttk.Frame):
del_tl = open('wg_py.xml', 'w') del_tl = open('wg_py.xml', 'w')
del_tl.write(word_replace) del_tl.write(word_replace)
del_tl.close() del_tl.close()
if len(self.tl) == 0: # for disable checkbox when Listbox empty
tl = ListTunnels.tl_list()
if len(tl) == 0:
self.wg_autostart.configure(state='disabled') self.wg_autostart.configure(state='disabled')
if self.a != '' and self.a == select_tl: if self.a != '' and self.a == select_tl:
self.StrVar.set(value='') self.StrVar.set(value='')
StartStopBTN.button_start(self) StartStopBTN.button_start(self)
self.l_box.update() self.l_box.update()
# Address Label # Address Label
ShowAddress.label_empty(self) ShowAddress.label_empty(self)
return select_tl return select_tl
except IndexError: except IndexError:
pass pass
# Button Trash # Button Trash
self.btn_tr = tk.Button(self, image=self.tr_pic, bd=0, command=delete) self.btn_tr = tk.Button(self.lb_frame_buttons, image=self.tr_pic, bd=0, command=delete)
self.btn_tr.grid(column=0, row=3, padx=15, pady=15) self.btn_tr.grid(column=0, row=2, padx=15, pady=8)
# Button Export # Button Export
self.btn_exp = tk.Button(self, image=self.exp_pic, bd=0, command=ExportTunnels.wg_export) self.btn_exp = tk.Button(self.lb_frame_buttons, image=self.exp_pic, bd=0, command=ExportTunnels.wg_export)
self.btn_exp.grid(column=0, row=4, padx=15, pady=15) self.btn_exp.grid(column=0, row=3, padx=15, pady=8)
# Button Rename # Button Rename
self.btn_rename = ttk.Button(self, text='Rename') self.btn_rename = ttk.Button(self, text='Rename')
@ -185,7 +208,7 @@ class FrameWidgets(ttk.Frame):
text='Autoconnect on:', text='Autoconnect on:',
variable=self.selected_option, variable=self.selected_option,
command=lambda: FileHandle.box_set(self)) command=lambda: FileHandle.box_set(self))
self.wg_autostart.grid(column=1, row=4, sticky='nw') self.wg_autostart.grid(column=0, row=4, pady=19, padx=15, sticky='nw')
OnOff.on_off(self) OnOff.on_off(self)

View File

@ -2,7 +2,7 @@
import os import os
import shutil import shutil
from datetime import datetime from datetime import datetime
from tkinter import filedialog from tkinter import filedialog, ttk
import tkinter as tk import tkinter as tk
font_color = '#4011a7' font_color = '#4011a7'
@ -41,30 +41,31 @@ class GreenLabel(tk.Tk):
def green_show_label(self): def green_show_label(self):
self.lb_tunnel = tk.Label(self, textvariable=self.StrVar, fg='green') self.lb_tunnel = tk.Label(self, textvariable=self.StrVar, fg='green')
self.lb_tunnel.config(font=('Ubuntu', 11, 'bold')) self.lb_tunnel.config(font=('Ubuntu', 11, 'bold'))
self.lb_tunnel.grid(column=2, padx=10, row=1) self.lb_tunnel.grid(column=2, padx=10, row=0)
self.columnconfigure(2, weight=1) self.columnconfigure(2, weight=1)
self.rowconfigure(1, weight=1) self.rowconfigure(0, weight=1)
class StartStopBTN(tk.Tk): class StartStopBTN(tk.Tk):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.lb_frame_buttons = None
self.wg_switch = None self.wg_switch = None
self.btn_stst = None self.btn_stst = None
self.wg_vpn_start = tk.PhotoImage(file=r'icons/wg-vpn-start-48.png') self.wg_vpn_start = tk.PhotoImage(file=r'icons/wg-vpn-start-48.png')
self.wg_vpn_stop = tk.PhotoImage(file=r'icons/wg-vpn-stop-48.png') self.wg_vpn_stop = tk.PhotoImage(file=r'icons/wg-vpn-stop-48.png')
def button_stop(self): def button_stop(self):
self.btn_stst = tk.Button(self, image=self.wg_vpn_stop, bd=0, command=self.wg_switch) self.btn_stst = tk.Button(self.lb_frame_buttons, image=self.wg_vpn_stop, bd=0, command=self.wg_switch)
self.btn_stst.grid(column=0, row=1, padx=15, pady=10, sticky="s") self.btn_stst.grid(column=0, row=0, padx=15, pady=8)
self.columnconfigure(0, weight=1) #self.columnconfigure(0, weight=1)
self.rowconfigure(1, weight=1) #self.rowconfigure(0, weight=1)
def button_start(self): def button_start(self):
self.btn_stst = tk.Button(self, image=self.wg_vpn_start, bd=0, command=self.wg_switch) self.btn_stst = tk.Button(self.lb_frame_buttons, image=self.wg_vpn_start, bd=0, command=self.wg_switch)
self.btn_stst.grid(column=0, row=1, padx=15, pady=10, sticky="s") self.btn_stst.grid(column=0, row=0, padx=15, pady=8)
self.columnconfigure(0, weight=1) #self.columnconfigure(0, weight=1)
self.rowconfigure(1, weight=1) #self.rowconfigure(0, weight=1)
class ConToDict: class ConToDict:
@ -143,15 +144,15 @@ class ShowAddress(tk.Tk):
def show_data(self): def show_data(self):
# Address Label # Address Label
self.address = tk.Label(self.lb_frame, textvariable=self.add, fg='blue') self.address = tk.Label(self.lb_frame, textvariable=self.add, fg='blue')
self.address.grid(column=0, row=5, sticky='w', padx=10) self.address.grid(column=0, row=4, sticky='w', padx=10, pady=6)
self.address.config(font=('Ubuntu', 9)) self.address.config(font=('Ubuntu', 9))
# DNS Label # DNS Label
self.dns = tk.Label(self.lb_frame, textvariable=self.DNS, fg='blue') self.dns = tk.Label(self.lb_frame, textvariable=self.DNS, fg='blue')
self.dns.grid(column=0, row=6, sticky='w', padx=10, pady=3) self.dns.grid(column=0, row=6, sticky='w', padx=10, pady=6)
self.dns.config(font=('Ubuntu', 9)) self.dns.config(font=('Ubuntu', 9))
# Endpoint Label # Endpoint Label
self.endpoint = tk.Label(self.lb_frame2, textvariable=self.enp, fg='blue') self.endpoint = tk.Label(self.lb_frame2, textvariable=self.enp, fg='blue')
self.endpoint.grid(column=0, row=8, sticky='w', padx=10, pady=5) self.endpoint.grid(column=0, row=7, sticky='w', padx=10, pady=10)
self.endpoint.config(font=('Ubuntu', 9)) self.endpoint.config(font=('Ubuntu', 9))
@ -268,6 +269,7 @@ class FileHandle:
set_off = open('wg_py.xml', 'w') set_off = open('wg_py.xml', 'w')
set_off.write(word_replace) set_off.write(word_replace)
set_off.close() set_off.close()
except IndexError: except IndexError:
self.selected_option.set(1) self.selected_option.set(1)
@ -277,6 +279,7 @@ class FileHandle:
class OnOff(tk.Tk, FileHandle): class OnOff(tk.Tk, FileHandle):
def __init__(self, container, **kwargs): def __init__(self, container, **kwargs):
super().__init__(container, **kwargs) super().__init__(container, **kwargs)
self.lb_frame_buttons = None
def on_off(self): def on_off(self):
a_connect = {} a_connect = {}
@ -286,6 +289,7 @@ class OnOff(tk.Tk, FileHandle):
a_connect[line_splitted[0]] = line_splitted[1] a_connect[line_splitted[0]] = line_splitted[1]
if 'true' in a_connect: if 'true' in a_connect:
self.selected_option.set(1) self.selected_option.set(1)
self.autoconnect_var.set('')
self.auto_con = a_connect['true'] self.auto_con = a_connect['true']
else: else:
@ -295,9 +299,9 @@ class OnOff(tk.Tk, FileHandle):
self.autoconnect_var = tk.StringVar() self.autoconnect_var = tk.StringVar()
self.autoconnect_var.set(self.auto_con) self.autoconnect_var.set(self.auto_con)
self.autoconnect = tk.Label(self, textvariable=self.autoconnect_var, bd=2, fg='blue', padx=5) self.autoconnect = tk.Label(self, textvariable=self.autoconnect_var, fg='blue', padx=5)
self.autoconnect.config(font=('Ubuntu', 11)) self.autoconnect.config(font=('Ubuntu', 11))
self.autoconnect.grid(column=1, row=4, sticky='we') self.autoconnect.grid(column=0, row=4, sticky='ne', pady=20)
class ExportTunnels: class ExportTunnels:

View File

@ -0,0 +1,2 @@
false peer_iasus
false rverEppingen