fix label when laat Tunnel delete and fix Tuple error in delete and Start/Stop when listbox empty
This commit is contained in:
parent
bc8dd7fe6d
commit
4574f1416e
1
.idea/workspace.xml
generated
1
.idea/workspace.xml
generated
@ -5,7 +5,6 @@
|
|||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="940e1630-c825-4d4c-be80-bc11f543c122" name="Changes" comment="little fixes in Class Import">
|
<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$/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_func.py" beforeDir="false" afterPath="$PROJECT_DIR$/wg_func.py" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
|
90
main.py
90
main.py
@ -119,18 +119,21 @@ class FrameWidgets(ttk.Frame):
|
|||||||
self.btn_i.grid(column=0, row=2, padx=15, pady=15)
|
self.btn_i.grid(column=0, row=2, padx=15, pady=15)
|
||||||
|
|
||||||
def delete():
|
def delete():
|
||||||
self.select_tunnel = self.l_box.curselection()
|
try:
|
||||||
select_tl = self.l_box.get(self.select_tunnel[0])
|
self.select_tunnel = self.l_box.curselection()
|
||||||
os.system('nmcli connection delete ' + str(select_tl))
|
select_tl = self.l_box.get(self.select_tunnel[0])
|
||||||
self.l_box.delete(self.select_tunnel[0])
|
os.system('nmcli connection delete ' + str(select_tl))
|
||||||
os.remove(os.environ['HOME'] + '/tester/' + str(select_tl) + '.conf')
|
self.l_box.delete(self.select_tunnel[0])
|
||||||
if self.a != '' and self.a == select_tl:
|
os.remove(os.environ['HOME'] + '/tester/' + str(select_tl) + '.conf')
|
||||||
self.StrVar.set(value='')
|
if self.a != '' and self.a == select_tl:
|
||||||
StartStopBTN.button_start(self)
|
self.StrVar.set(value='')
|
||||||
self.l_box.update()
|
StartStopBTN.button_start(self)
|
||||||
# Address Label
|
self.l_box.update()
|
||||||
ShowAddress.label_empty(self)
|
# Address Label
|
||||||
ShowAddress.show_data(self)
|
ShowAddress.label_empty(self)
|
||||||
|
except IndexError:
|
||||||
|
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, 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=3, padx=15, pady=15)
|
||||||
@ -145,36 +148,39 @@ class FrameWidgets(ttk.Frame):
|
|||||||
|
|
||||||
def wg_switch(self):
|
def wg_switch(self):
|
||||||
self.a = TunnelActiv.active()
|
self.a = TunnelActiv.active()
|
||||||
if self.a == '':
|
try:
|
||||||
StartStopBTN.button_start(self)
|
if self.a == '':
|
||||||
self.select_tunnel = self.l_box.curselection()
|
StartStopBTN.button_start(self)
|
||||||
select_tl = self.l_box.get(self.select_tunnel[0])
|
self.select_tunnel = self.l_box.curselection()
|
||||||
os.system('nmcli connection up ' + str(select_tl))
|
select_tl = self.l_box.get(self.select_tunnel[0])
|
||||||
wg_read = os.environ['HOME'] + '/tester/' + str(select_tl) + '.conf'
|
os.system('nmcli connection up ' + str(select_tl))
|
||||||
file = open(wg_read, 'r')
|
wg_read = os.environ['HOME'] + '/tester/' + str(select_tl) + '.conf'
|
||||||
data = ConToDict.covert_to_dict(file)
|
file = open(wg_read, 'r')
|
||||||
# Address Label
|
data = ConToDict.covert_to_dict(file)
|
||||||
ShowAddress.init_and_report(self, data)
|
# Address Label
|
||||||
ShowAddress.show_data(self)
|
ShowAddress.init_and_report(self, data)
|
||||||
file.close()
|
ShowAddress.show_data(self)
|
||||||
# Button Start/Stop
|
file.close()
|
||||||
StartStopBTN.button_stop(self)
|
# Button Start/Stop
|
||||||
self.a = TunnelActiv.active()
|
StartStopBTN.button_stop(self)
|
||||||
self.StrVar = tk.StringVar()
|
self.a = TunnelActiv.active()
|
||||||
self.StrVar.set(self.a)
|
self.StrVar = tk.StringVar()
|
||||||
GreenLabel.green_show_label(self)
|
self.StrVar.set(self.a)
|
||||||
elif self.a != '':
|
GreenLabel.green_show_label(self)
|
||||||
# Button Start/Stop
|
elif self.a != '':
|
||||||
StartStopBTN.button_stop(self)
|
# Button Start/Stop
|
||||||
os.system('nmcli connection down ' + str(self.a))
|
StartStopBTN.button_stop(self)
|
||||||
# Button Start/Stop
|
os.system('nmcli connection down ' + str(self.a))
|
||||||
StartStopBTN.button_start(self)
|
# Button Start/Stop
|
||||||
self.a = TunnelActiv.active()
|
StartStopBTN.button_start(self)
|
||||||
self.StrVar.set('')
|
self.a = TunnelActiv.active()
|
||||||
GreenLabel.green_show_label(self)
|
self.StrVar.set('')
|
||||||
# Address Label
|
GreenLabel.green_show_label(self)
|
||||||
ShowAddress.label_empty(self)
|
# Address Label
|
||||||
ShowAddress.show_data(self)
|
ShowAddress.label_empty(self)
|
||||||
|
ShowAddress.show_data(self)
|
||||||
|
except IndexError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
16
wg_func.py
16
wg_func.py
@ -46,7 +46,6 @@ class GreenLabel(tk.Tk):
|
|||||||
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.tl = 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')
|
||||||
@ -58,17 +57,9 @@ class StartStopBTN(tk.Tk):
|
|||||||
self.rowconfigure(0, weight=1)
|
self.rowconfigure(0, weight=1)
|
||||||
|
|
||||||
def button_start(self):
|
def button_start(self):
|
||||||
self.tl = ListTunnels.tl_list()
|
self.btn_stst = tk.Button(self, image=self.wg_vpn_start, bd=0, command=self.wg_switch)
|
||||||
print(len(self.tl))
|
self.btn_stst.grid(column=0, row=1, padx=15, pady=10, sticky="s")
|
||||||
if len(self.tl) == 0:
|
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.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)
|
|
||||||
|
|
||||||
|
|
||||||
class ConToDict:
|
class ConToDict:
|
||||||
@ -96,6 +87,7 @@ class ConToDict:
|
|||||||
finaldict = {}
|
finaldict = {}
|
||||||
for elements in newlist:
|
for elements in newlist:
|
||||||
finaldict[elements[0]] = elements[1]
|
finaldict[elements[0]] = elements[1]
|
||||||
|
|
||||||
# end... result a Dictionary
|
# end... result a Dictionary
|
||||||
address = finaldict['Address']
|
address = finaldict['Address']
|
||||||
dns = finaldict['DNS']
|
dns = finaldict['DNS']
|
||||||
|
Loading…
x
Reference in New Issue
Block a user