in msg_window two further parameters to be added to the pass, so height and wide can also be specified.
In rename, messages come now if new names do not fit Fix Index Error on msg_window()
This commit is contained in:
parent
428854f25a
commit
8cd5fc28e4
@ -4,8 +4,9 @@
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="940e1630-c825-4d4c-be80-bc11f543c122" name="Changes" comment="Descriptions added in wg_func-py">
|
||||
<list default="true" id="940e1630-c825-4d4c-be80-bc11f543c122" name="Changes" comment="fix scrollbar view with set self.y_height = 330 to self.y_height = 340">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/wg_func.py" beforeDir="false" afterPath="$PROJECT_DIR$/wg_func.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/wg_main.py" beforeDir="false" afterPath="$PROJECT_DIR$/wg_main.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
@ -509,7 +510,23 @@
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1727018233930</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="48" />
|
||||
<task id="LOCAL-00048" summary="If tunnel is renamed and this is in the car start, is now renamed the label">
|
||||
<option name="closed" value="true" />
|
||||
<created>1727028762875</created>
|
||||
<option name="number" value="00048" />
|
||||
<option name="presentableId" value="LOCAL-00048" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1727028762875</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00049" summary="fix scrollbar view with set self.y_height = 330 to self.y_height = 340">
|
||||
<option name="closed" value="true" />
|
||||
<created>1727028915701</created>
|
||||
<option name="number" value="00049" />
|
||||
<option name="presentableId" value="LOCAL-00049" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1727028915701</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="50" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="UnknownFeatures">
|
||||
@ -550,8 +567,6 @@
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
|
||||
<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!" />
|
||||
<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 for Buttons and Listbox with Scrollbar. all Widgets new format delete works now of disable checkbox when Listbox empty (part two)" />
|
||||
<MESSAGE value="little fixes" />
|
||||
@ -575,29 +590,31 @@
|
||||
<MESSAGE value="add con_to_dict in import for write PreSharedKey in .key File to warning if tunnel has already been imported and delete that the key is deleted again" />
|
||||
<MESSAGE value="add con_to_dict in import for write PreSharedKey in .key File to warning if tunnel has already been imported and delete that the key is deleted again now works" />
|
||||
<MESSAGE value="Descriptions added in wg_func-py" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="Descriptions added in wg_func-py" />
|
||||
<MESSAGE value="If tunnel is renamed and this is in the car start, is now renamed the label" />
|
||||
<MESSAGE value="fix scrollbar view with set self.y_height = 330 to self.y_height = 340" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="fix scrollbar view with set self.y_height = 330 to self.y_height = 340" />
|
||||
</component>
|
||||
<component name="XDebuggerManager">
|
||||
<breakpoint-manager>
|
||||
<breakpoints>
|
||||
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
|
||||
<url>file://$PROJECT_DIR$/wg_func.py</url>
|
||||
<line>135</line>
|
||||
<line>137</line>
|
||||
<option name="timeStamp" value="1" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
|
||||
<url>file://$PROJECT_DIR$/wg_func.py</url>
|
||||
<line>194</line>
|
||||
<line>196</line>
|
||||
<option name="timeStamp" value="2" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
|
||||
<url>file://$PROJECT_DIR$/wg_func.py</url>
|
||||
<line>72</line>
|
||||
<line>74</line>
|
||||
<option name="timeStamp" value="3" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
|
||||
<url>file://$PROJECT_DIR$/wg_func.py</url>
|
||||
<line>343</line>
|
||||
<line>348</line>
|
||||
<option name="timeStamp" value="4" />
|
||||
</line-breakpoint>
|
||||
</breakpoints>
|
||||
|
27
wg_func.py
27
wg_func.py
@ -14,7 +14,7 @@ path_to_file = Path('/etc/wire_py/wg_py')
|
||||
_u = Path.read_text(Path('/tmp/_u'))
|
||||
|
||||
|
||||
def msg_window(img_w, img_i, w_title, w_txt):
|
||||
def msg_window(img_w, img_i, w_title, w_txt, x, y):
|
||||
"""
|
||||
Function for different message windows for the user. with 4 arguments to be passed.
|
||||
To create messages with your own images, icons, and titles. As an alternative to Python Messagebox.
|
||||
@ -23,11 +23,13 @@ def msg_window(img_w, img_i, w_title, w_txt):
|
||||
img_i = Image for Icon
|
||||
w_title = Windows Title
|
||||
w_txt = Text for Tk Window
|
||||
x = Window width
|
||||
y = Window height
|
||||
"""
|
||||
msg = tk.Toplevel()
|
||||
msg.resizable(width=False, height=False)
|
||||
msg.x_width = 340
|
||||
msg.y_height = 140
|
||||
msg.x_width = x
|
||||
msg.y_height = y
|
||||
msg.title(w_title)
|
||||
msg.monitor_center_x = msg.winfo_screenwidth() / 2 - (msg.x_width / 2)
|
||||
msg.monitor_center_y = msg.winfo_screenheight() / 2 - (msg.y_height / 2)
|
||||
@ -242,14 +244,15 @@ class ImportTunnel:
|
||||
if len(pre_key) != 0:
|
||||
with open('/etc/wire_py/.keys', 'r') as readfile:
|
||||
p_key = readfile.readlines()
|
||||
print(p_key)
|
||||
if pre_key in p_key or pre_key + '\n' in p_key:
|
||||
"""img_w, img_i, w_title, w_txt hand over"""
|
||||
iw = r'/usr/share/icons/wp-icons/64/error.png'
|
||||
ii = r'/usr/share/icons/wp-icons/48/wg_msg.png'
|
||||
wt = 'Import Error'
|
||||
msg_t = 'Tunnel already available!\nPlease use another file for import'
|
||||
msg_window(iw, ii, wt, msg_t)
|
||||
x = 340 # width
|
||||
y = 140 # height
|
||||
msg_window(iw, ii, wt, msg_t, x, y)
|
||||
else:
|
||||
with open('/etc/wire_py/.keys', 'a') as keyfile:
|
||||
keyfile.write(pre_key + '\r')
|
||||
@ -292,12 +295,14 @@ class ImportTunnel:
|
||||
os.chmod(str(wg_read), 0o600)
|
||||
|
||||
if 'PrivateKey = ' not in read:
|
||||
"""img_w, img_i, w_title, w_txt hand over"""
|
||||
"""img_w, img_i, w_title, w_txt x, y hand over"""
|
||||
iw = r'/usr/share/icons/wp-icons/64/error.png'
|
||||
ii = r'/usr/share/icons/wp-icons/48/wg_msg.png'
|
||||
wt = 'Import Error'
|
||||
msg_t = 'Oh... no valid Wireguard File!\nPlease select a valid Wireguard File'
|
||||
msg_window(iw, ii, wt, msg_t)
|
||||
x = 340 # width
|
||||
y = 140 # height
|
||||
msg_window(iw, ii, wt, msg_t, x, y)
|
||||
except EOFError:
|
||||
pass
|
||||
except TypeError:
|
||||
@ -398,14 +403,18 @@ class ExportTunnels:
|
||||
ii = r'/usr/share/icons/wp-icons/48/wg_vpn.png'
|
||||
wt = 'Import Error'
|
||||
msg_t = 'Your zip file is in home directory'
|
||||
msg_window(iw, ii, wt, msg_t)
|
||||
x = 340 # width
|
||||
y = 140 # height
|
||||
msg_window(iw, ii, wt, msg_t, x, y)
|
||||
else:
|
||||
"""img_w, img_i, w_title, w_txt hand over"""
|
||||
iw = r'/usr/share/icons/wp-icons/64/error.png'
|
||||
ii = r'/usr/share/icons/wp-icons/48/wg_msg.png'
|
||||
wt = 'Export error'
|
||||
msg_t = 'Export failed! Please try again'
|
||||
msg_window(iw, ii, wt, msg_t)
|
||||
x = 340 # width
|
||||
y = 140 # height
|
||||
msg_window(iw, ii, wt, msg_t, x, y)
|
||||
|
||||
except TypeError:
|
||||
pass
|
||||
|
108
wg_main.py
108
wg_main.py
@ -7,7 +7,7 @@ from pathlib import Path
|
||||
from tkinter import ttk
|
||||
|
||||
from wg_func import (TunnelActiv, ListTunnels, ImportTunnel, ConToDict, GreenLabel, StartStopBTN, ShowAddress,
|
||||
FileHandle, ExportTunnels, OnOff)
|
||||
FileHandle, ExportTunnels, OnOff, msg_window)
|
||||
|
||||
font_color = '#4011a7'
|
||||
|
||||
@ -191,7 +191,14 @@ class FrameWidgets(ttk.Frame):
|
||||
self.enp.set('')
|
||||
return select_tl
|
||||
except IndexError:
|
||||
pass
|
||||
"""img_w, img_i, w_title, w_txt x, y hand over"""
|
||||
iw = r'/usr/share/icons/wp-icons/64/info.png'
|
||||
ii = r'/usr/share/icons/wp-icons/48/wg_msg.png'
|
||||
wt = 'Renaming not possible'
|
||||
msg_t = 'Please select a tunnel from the list.'
|
||||
x = 340 # width
|
||||
y = 140 # height
|
||||
msg_window(iw, ii, wt, msg_t, x, y)
|
||||
|
||||
# Button Trash
|
||||
self.btn_tr = tk.Button(self.lb_frame_btn_lbox, image=self.tr_pic, bd=0, command=delete)
|
||||
@ -208,31 +215,69 @@ class FrameWidgets(ttk.Frame):
|
||||
self.lb_rename.config(state='disable')
|
||||
|
||||
def tl_rename():
|
||||
try:
|
||||
self.select_tunnel = self.l_box.curselection()
|
||||
select_tl = self.l_box.get(self.select_tunnel[0])
|
||||
# nmcli connection modify old connection.id iphone
|
||||
check_call(['nmcli', 'connection', 'modify', select_tl, 'connection.id', self.lb_rename.get()])
|
||||
source = Path('/etc/wire_py') / str(select_tl + '.conf')
|
||||
destination = source.with_name(str(self.lb_rename.get() + '.conf'))
|
||||
source.replace(destination)
|
||||
self.l_box.delete(self.select_tunnel[0])
|
||||
self.l_box.insert("end", self.lb_rename.get())
|
||||
self.l_box.update()
|
||||
new_a_connect = self.lb_rename.get()
|
||||
self.lb_rename.delete(0, tk.END)
|
||||
if self.a != '' and self.a == select_tl:
|
||||
self.a = TunnelActiv.active()
|
||||
self.StrVar.set(value=self.a)
|
||||
if Path.is_file(Path('/etc/wire_py/wg_py')):
|
||||
path_to_file = Path('/etc/wire_py') / 'wg_py'
|
||||
a_con = Path.read_text(path_to_file)
|
||||
if select_tl == a_con:
|
||||
self.autoconnect_var.set(value=new_a_connect)
|
||||
Path.write_text(path_to_file, new_a_connect)
|
||||
return select_tl
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
if len(self.lb_rename.get()) > 12:
|
||||
"""img_w, img_i, w_title, w_txt hand over"""
|
||||
iw = r'/usr/share/icons/wp-icons/64/info.png'
|
||||
ii = r'/usr/share/icons/wp-icons/48/wg_msg.png'
|
||||
wt = 'Renaming not possible'
|
||||
msg_t = 'The new name may contain only 12 characters.'
|
||||
x = 420 # width
|
||||
y = 140 # height
|
||||
msg_window(iw, ii, wt, msg_t, x, y)
|
||||
|
||||
elif len(self.lb_rename.get()) == 0:
|
||||
"""img_w, img_i, w_title, w_txt x, y hand over"""
|
||||
iw = r'/usr/share/icons/wp-icons/64/info.png'
|
||||
ii = r'/usr/share/icons/wp-icons/48/wg_msg.png'
|
||||
wt = 'Renaming not possible'
|
||||
msg_t = 'At least one character must be entered.'
|
||||
x = 380 # width
|
||||
y = 140 # height
|
||||
msg_window(iw, ii, wt, msg_t, x, y)
|
||||
|
||||
elif ' ' in self.lb_rename.get():
|
||||
"""img_w, img_i, w_title, w_txt x, y hand over"""
|
||||
iw = r'/usr/share/icons/wp-icons/64/info.png'
|
||||
ii = r'/usr/share/icons/wp-icons/48/wg_msg.png'
|
||||
wt = 'Renaming not possible'
|
||||
msg_t = 'Please do not use blanks.'
|
||||
x = 280 # width
|
||||
y = 140 # height
|
||||
msg_window(iw, ii, wt, msg_t, x, y)
|
||||
else:
|
||||
try:
|
||||
self.select_tunnel = self.l_box.curselection()
|
||||
select_tl = self.l_box.get(self.select_tunnel[0])
|
||||
# nmcli connection modify old connection.id iphone
|
||||
check_call(['nmcli', 'connection', 'modify', select_tl, 'connection.id', self.lb_rename.get()])
|
||||
source = Path('/etc/wire_py') / str(select_tl + '.conf')
|
||||
destination = source.with_name(str(self.lb_rename.get() + '.conf'))
|
||||
source.replace(destination)
|
||||
self.l_box.delete(self.select_tunnel[0])
|
||||
self.l_box.insert("end", self.lb_rename.get())
|
||||
self.l_box.update()
|
||||
new_a_connect = self.lb_rename.get()
|
||||
self.lb_rename.delete(0, tk.END)
|
||||
if self.a != '' and self.a == select_tl:
|
||||
self.a = TunnelActiv.active()
|
||||
self.StrVar.set(value=self.a)
|
||||
if Path.is_file(Path('/etc/wire_py/wg_py')):
|
||||
path_to_file = Path('/etc/wire_py') / 'wg_py'
|
||||
a_con = Path.read_text(path_to_file)
|
||||
if select_tl == a_con:
|
||||
self.autoconnect_var.set(value=new_a_connect)
|
||||
Path.write_text(path_to_file, new_a_connect)
|
||||
return select_tl
|
||||
except IndexError:
|
||||
"""img_w, img_i, w_title, w_txt x, y hand over"""
|
||||
iw = r'/usr/share/icons/wp-icons/64/info.png'
|
||||
ii = r'/usr/share/icons/wp-icons/48/wg_msg.png'
|
||||
wt = 'Renaming not possible'
|
||||
msg_t = 'Please select a tunnel from the list.'
|
||||
x = 340 # width
|
||||
y = 140 # height
|
||||
msg_window(iw, ii, wt, msg_t, x, y)
|
||||
|
||||
# Button Rename
|
||||
self.btn_rename = ttk.Button(self, text='Rename', state='disable', command=tl_rename)
|
||||
@ -292,7 +337,14 @@ class FrameWidgets(ttk.Frame):
|
||||
self.enp.set('')
|
||||
ShowAddress.show_data(self)
|
||||
except IndexError:
|
||||
pass
|
||||
"""img_w, img_i, w_title, w_txt x, y hand over"""
|
||||
iw = r'/usr/share/icons/wp-icons/64/info.png'
|
||||
ii = r'/usr/share/icons/wp-icons/48/wg_msg.png'
|
||||
wt = 'Renaming not possible'
|
||||
msg_t = 'Please select a tunnel from the list.'
|
||||
x = 340 # width
|
||||
y = 140 # height
|
||||
msg_window(iw, ii, wt, msg_t, x, y)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
Reference in New Issue
Block a user