fixes on empty Listbox now is disable and now works autoconnect label with read and write, delete works now with read and write

This commit is contained in:
2024-09-04 20:52:44 +02:00
parent aa84a5ad79
commit 2aa9f907b5
4 changed files with 54 additions and 51 deletions

View File

@ -217,7 +217,7 @@ class ImportTunnel:
file.close()
os.system('nmcli con mod ' + str(self.a) + ' connection.autoconnect no')
new_tl = open('wg_py.xml', 'a')
new_tl.write('false ' + str(self.a))
new_tl.write('false ' + str(self.a) + '\n')
new_tl.close()
if 'PrivateKey = ' not in read:
Message()
@ -243,45 +243,51 @@ class FileHandle:
self.select_tunnel = None
def box_set(self):
global replacement
word_replace = ''
try:
self.select_tunnel = self.l_box.curselection()
select_tl = self.l_box.get(self.select_tunnel[0])
if self.selected_option.get() == 0:
set_on = open('wg_py.xml', 'r')
replacement = ""
# using the for loop
for line in set_on:
line = line.strip()
changes = line.replace('true ' + select_tl, 'false ' + select_tl)
for tl in self.tl:
os.system('nmcli con mod ' + str(tl) + ' connection.autoconnect no')
replacement = replacement + changes + "\n"
os.system('nmcli con mod ' + str(self.auto_con) + ' connection.autoconnect no')
word_replace = word_replace + changes + "\n"
set_on.close()
if self.selected_option.get() == 1:
if self.selected_option.get() >= 1:
set_on = open('wg_py.xml', 'r')
replacement = ""
# using the for loop
for line in set_on:
line = line.strip()
changes = line.replace('false ' + select_tl, 'true ' + select_tl)
os.system('nmcli con mod ' + str(select_tl) + ' connection.autoconnect yes')
replacement = replacement + changes + "\n"
word_replace = word_replace + changes + "\n"
set_on.close()
set_off = open('wg_py.xml', 'w')
set_off.write(replacement)
set_off.write(word_replace)
set_off.close()
except IndexError:
self.selected_option.set(1)
OnOff.on_off(self)
class OnOff(tk.Tk, FileHandle):
def __init__(self, container, **kwargs):
super().__init__(container, **kwargs)
def on_off(self):
a_connect = {}
on_or_off = open('wg_py.xml', 'r')
res = on_or_off.read()
if 'true' in res:
for line in on_or_off.readlines():
line_splitted = line.split()
a_connect[line_splitted[0]] = line_splitted[1]
if 'true' in a_connect:
self.selected_option.set(1)
self.auto_con = res
self.auto_con = self.auto_con[5:]
print(self.auto_con)
self.auto_con = a_connect['true']
else:
self.wg_autostart.configure(state='disabled')
self.auto_con = 'no Autoconnect'