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:
Désiré Werner Menrath 2024-09-23 21:09:41 +02:00
parent 428854f25a
commit 8cd5fc28e4
3 changed files with 124 additions and 46 deletions

View File

@ -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,&#10;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,&#10;add Label to show autoconnect Tunnel&#10;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&#10;for Buttons and Listbox with Scrollbar.&#10;all Widgets new format&#10;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&#10;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,&#10;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>

View File

@ -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

View File

@ -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,6 +215,37 @@ class FrameWidgets(ttk.Frame):
self.lb_rename.config(state='disable')
def tl_rename():
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])
@ -232,7 +270,14 @@ class FrameWidgets(ttk.Frame):
Path.write_text(path_to_file, new_a_connect)
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 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__':