fix label when laat Tunnel delete and fix Tuple error in delete and Start/Stop when listbox empty

This commit is contained in:
Désiré Werner Menrath 2024-08-24 12:34:44 +02:00
parent bc8dd7fe6d
commit 4574f1416e
3 changed files with 52 additions and 55 deletions

View File

@ -5,7 +5,6 @@
</component>
<component name="ChangeListManager">
<list default="true" id="940e1630-c825-4d4c-be80-bc11f543c122" name="Changes" comment="little fixes in Class Import">
<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" />
</list>

90
main.py
View File

@ -119,18 +119,21 @@ class FrameWidgets(ttk.Frame):
self.btn_i.grid(column=0, row=2, padx=15, pady=15)
def delete():
self.select_tunnel = self.l_box.curselection()
select_tl = self.l_box.get(self.select_tunnel[0])
os.system('nmcli connection delete ' + str(select_tl))
self.l_box.delete(self.select_tunnel[0])
os.remove(os.environ['HOME'] + '/tester/' + str(select_tl) + '.conf')
if self.a != '' and self.a == select_tl:
self.StrVar.set(value='')
StartStopBTN.button_start(self)
self.l_box.update()
# Address Label
ShowAddress.label_empty(self)
ShowAddress.show_data(self)
try:
self.select_tunnel = self.l_box.curselection()
select_tl = self.l_box.get(self.select_tunnel[0])
os.system('nmcli connection delete ' + str(select_tl))
self.l_box.delete(self.select_tunnel[0])
os.remove(os.environ['HOME'] + '/tester/' + str(select_tl) + '.conf')
if self.a != '' and self.a == select_tl:
self.StrVar.set(value='')
StartStopBTN.button_start(self)
self.l_box.update()
# Address Label
ShowAddress.label_empty(self)
except IndexError:
pass
# Button Trash
self.btn_tr = tk.Button(self, image=self.tr_pic, bd=0, command=delete)
self.btn_tr.grid(column=0, row=3, padx=15, pady=15)
@ -145,36 +148,39 @@ class FrameWidgets(ttk.Frame):
def wg_switch(self):
self.a = TunnelActiv.active()
if self.a == '':
StartStopBTN.button_start(self)
self.select_tunnel = self.l_box.curselection()
select_tl = self.l_box.get(self.select_tunnel[0])
os.system('nmcli connection up ' + str(select_tl))
wg_read = os.environ['HOME'] + '/tester/' + str(select_tl) + '.conf'
file = open(wg_read, 'r')
data = ConToDict.covert_to_dict(file)
# Address Label
ShowAddress.init_and_report(self, data)
ShowAddress.show_data(self)
file.close()
# Button Start/Stop
StartStopBTN.button_stop(self)
self.a = TunnelActiv.active()
self.StrVar = tk.StringVar()
self.StrVar.set(self.a)
GreenLabel.green_show_label(self)
elif self.a != '':
# Button Start/Stop
StartStopBTN.button_stop(self)
os.system('nmcli connection down ' + str(self.a))
# Button Start/Stop
StartStopBTN.button_start(self)
self.a = TunnelActiv.active()
self.StrVar.set('')
GreenLabel.green_show_label(self)
# Address Label
ShowAddress.label_empty(self)
ShowAddress.show_data(self)
try:
if self.a == '':
StartStopBTN.button_start(self)
self.select_tunnel = self.l_box.curselection()
select_tl = self.l_box.get(self.select_tunnel[0])
os.system('nmcli connection up ' + str(select_tl))
wg_read = os.environ['HOME'] + '/tester/' + str(select_tl) + '.conf'
file = open(wg_read, 'r')
data = ConToDict.covert_to_dict(file)
# Address Label
ShowAddress.init_and_report(self, data)
ShowAddress.show_data(self)
file.close()
# Button Start/Stop
StartStopBTN.button_stop(self)
self.a = TunnelActiv.active()
self.StrVar = tk.StringVar()
self.StrVar.set(self.a)
GreenLabel.green_show_label(self)
elif self.a != '':
# Button Start/Stop
StartStopBTN.button_stop(self)
os.system('nmcli connection down ' + str(self.a))
# Button Start/Stop
StartStopBTN.button_start(self)
self.a = TunnelActiv.active()
self.StrVar.set('')
GreenLabel.green_show_label(self)
# Address Label
ShowAddress.label_empty(self)
ShowAddress.show_data(self)
except IndexError:
pass
if __name__ == '__main__':

View File

@ -46,7 +46,6 @@ class GreenLabel(tk.Tk):
class StartStopBTN(tk.Tk):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.tl = None
self.wg_switch = None
self.btn_stst = None
self.wg_vpn_start = tk.PhotoImage(file=r'icons/wg-vpn-start-48.png')
@ -58,17 +57,9 @@ class StartStopBTN(tk.Tk):
self.rowconfigure(0, weight=1)
def button_start(self):
self.tl = ListTunnels.tl_list()
print(len(self.tl))
if len(self.tl) == 0:
self.btn_stst = tk.Button(self, image=self.wg_vpn_start, bd=0, command=self.wg_switch)
self.btn_stst.config(state=tk.DISABLED)
self.btn_stst.grid(column=0, row=1, padx=15, pady=10, sticky="s")
self.rowconfigure(0, weight=1)
else:
self.btn_stst = tk.Button(self, 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.rowconfigure(0, weight=1)
self.btn_stst = tk.Button(self, 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.rowconfigure(0, weight=1)
class ConToDict:
@ -96,6 +87,7 @@ class ConToDict:
finaldict = {}
for elements in newlist:
finaldict[elements[0]] = elements[1]
# end... result a Dictionary
address = finaldict['Address']
dns = finaldict['DNS']