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:
parent
aa84a5ad79
commit
2aa9f907b5
@ -4,7 +4,7 @@
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="940e1630-c825-4d4c-be80-bc11f543c122" name="Changes" comment="add class FileHandle, add Label to show autoconnect Tunnel disable checkbox when Listbox is empty or no select Tunnel">
|
||||
<list default="true" id="940e1630-c825-4d4c-be80-bc11f543c122" name="Changes" comment="add delete row in wg_py.xml when Tunnel delete">
|
||||
<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" />
|
||||
@ -268,7 +268,15 @@
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1725391658456</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="23" />
|
||||
<task id="LOCAL-00023" summary="add if question and add autoconnect, autoconnect_var to class Filehandle in box_set no finish!">
|
||||
<option name="closed" value="true" />
|
||||
<created>1725434328731</created>
|
||||
<option name="number" value="00023" />
|
||||
<option name="presentableId" value="LOCAL-00023" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1725434328731</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="24" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
@ -317,6 +325,7 @@
|
||||
<MESSAGE value="columnconfigure on all widgets set" />
|
||||
<MESSAGE value="little fixes a " " to ' '" />
|
||||
<MESSAGE value="add class FileHandle, add Label to show autoconnect Tunnel disable checkbox when Listbox is empty or no select Tunnel" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="add class FileHandle, add Label to show autoconnect Tunnel 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!" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="add if question and add autoconnect, autoconnect_var to class Filehandle in box_set no finish!" />
|
||||
</component>
|
||||
</project>
|
51
main.py
51
main.py
@ -4,7 +4,7 @@ import tkinter as tk
|
||||
from tkinter import ttk
|
||||
|
||||
from wg_func import (TunnelActiv, ListTunnels, ImportTunnel, ConToDict, GreenLabel, StartStopBTN, ShowAddress,
|
||||
FileHandle, ExportTunnels)
|
||||
FileHandle, ExportTunnels, OnOff)
|
||||
|
||||
font_color = '#4011a7'
|
||||
replacement = ''
|
||||
@ -20,7 +20,7 @@ class MainWindow(tk.Tk):
|
||||
self.y_height = 360
|
||||
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.resizable(width=False, height=False)
|
||||
#self.resizable(width=False, height=False)
|
||||
self.title('Wire-Py')
|
||||
self.configure()
|
||||
self.geometry('%dx%d+%d+%d' % (self.x_width, self.y_height, self.monitor_center_x, self.monitor_center_y))
|
||||
@ -136,21 +136,26 @@ class FrameWidgets(ttk.Frame):
|
||||
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')
|
||||
try:
|
||||
with open('wg_py.xml', 'r') as fr:
|
||||
lines = fr.readlines()
|
||||
|
||||
with open('wg_py.xml_2', 'w') as fw:
|
||||
for line in lines:
|
||||
del_tl_read = open('wg_py.xml', 'r')
|
||||
if 'false ' in del_tl_read:
|
||||
first_word = 'false '
|
||||
else:
|
||||
first_word = 'true '
|
||||
|
||||
# strip() is used to remove '\n'
|
||||
# present at the end of each line
|
||||
if line.strip('\n') != select_tl:
|
||||
fw.write(line)
|
||||
print("Deleted")
|
||||
except:
|
||||
print("Oops! someting error")
|
||||
word_replace = ''
|
||||
# using the for loop
|
||||
for line in del_tl_read:
|
||||
line = line.strip()
|
||||
changes = line.replace(first_word + select_tl, '')
|
||||
word_replace = word_replace + changes + "\n"
|
||||
|
||||
del_tl_read.close()
|
||||
del_tl = open('wg_py.xml', 'w')
|
||||
del_tl.write(word_replace)
|
||||
del_tl.close()
|
||||
if len(self.tl) == 0:
|
||||
self.wg_autostart.configure(state='disabled')
|
||||
if self.a != '' and self.a == select_tl:
|
||||
self.StrVar.set(value='')
|
||||
StartStopBTN.button_start(self)
|
||||
@ -182,23 +187,7 @@ class FrameWidgets(ttk.Frame):
|
||||
command=lambda: FileHandle.box_set(self))
|
||||
self.wg_autostart.grid(column=1, row=4, sticky='nw')
|
||||
|
||||
on_or_off = open('wg_py.xml', 'r')
|
||||
res = on_or_off.read()
|
||||
if 'true' in res:
|
||||
self.selected_option.set(1)
|
||||
self.auto_con = res
|
||||
self.auto_con = self.auto_con[5:]
|
||||
print(self.auto_con)
|
||||
else:
|
||||
self.wg_autostart.configure(state='disabled')
|
||||
self.auto_con = 'no Autoconnect'
|
||||
on_or_off.close()
|
||||
|
||||
self.autoconnect_var = tk.StringVar()
|
||||
self.autoconnect_var.set(self.auto_con)
|
||||
self.autoconnect = tk.Label(self, textvariable=self.autoconnect_var, bd=2, fg='blue', padx=5)
|
||||
self.autoconnect.config(font=('Ubuntu', 11))
|
||||
self.autoconnect.grid(column=1, row=4, sticky='we')
|
||||
OnOff.on_off(self)
|
||||
|
||||
#self.wg_update = tk.Checkbutton(self, tex='Search automatically for\nWire-Py updates')
|
||||
#self.wg_update.grid(column=1, rowspan=3, row=5)
|
||||
|
38
wg_func.py
38
wg_func.py
@ -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'
|
||||
|
Loading…
Reference in New Issue
Block a user