wire-py-reformat-14-08-2024 #1

Merged
punix merged 3 commits from wire-py-reformat-14-08-2024 into main 2024-08-18 22:39:19 +02:00
7 changed files with 58 additions and 20 deletions
Showing only changes of commit b84b783fa0 - Show all commits

View File

@ -4,7 +4,11 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="940e1630-c825-4d4c-be80-bc11f543c122" name="Changes" comment="wg_import_select in wg_func.py extended"> <list default="true" id="940e1630-c825-4d4c-be80-bc11f543c122" name="Changes" comment="wg_import_select in wg_func.py more extended 17-8-24">
<change afterPath="$PROJECT_DIR$/icons/warning_128.png" afterDir="false" />
<change afterPath="$PROJECT_DIR$/icons/warning_256.png" afterDir="false" />
<change afterPath="$PROJECT_DIR$/icons/warning_32.png" afterDir="false" />
<change afterPath="$PROJECT_DIR$/icons/warning_64.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <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" />
@ -46,7 +50,7 @@
&quot;Python.main.executor&quot;: &quot;Run&quot;, &quot;Python.main.executor&quot;: &quot;Run&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;, &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;wire-py-reformat-14-08-2024&quot;, &quot;git-widget-placeholder&quot;: &quot;wire-py-reformat-14-08-2024&quot;,
&quot;last_opened_file_path&quot;: &quot;/home/punix/Pyapps/wire-py&quot; &quot;last_opened_file_path&quot;: &quot;/home/punix/Downloads/tkinter-bitcoin_price_converter_objectoriented(1).py&quot;
} }
}</component> }</component>
<component name="RunManager"> <component name="RunManager">

BIN
icons/warning_128.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

BIN
icons/warning_256.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
icons/warning_32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
icons/warning_64.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

32
main.py
View File

@ -1,26 +1,24 @@
#!/usr/bin/python3 #!/usr/bin/python3
import os import os
import tkinter as tk import tkinter as tk
from tkinter import ttk
from wg_func import active, tl_list, wg_export, wg_import_select from wg_func import active, tl_list, wg_export, wg_import_select
wg_exp = wg_export() wg_exp = wg_export()
color_default = '#d3ebff'
color_dark = '#2e2e2e'
a = active() a = active()
class MainWindow(tk.Tk): class MainWindow(tk.Tk):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.select_tunnel = None
self.switch_on = None self.switch_on = None
self.switch_off = None self.switch_off = None
self.x_width = 600 self.x_width = 600
self.y_height = 350 self.y_height = 350
self.monitor_center_x = self.winfo_screenwidth() / 2 - (self.x_width / 2) 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.monitor_center_y = self.winfo_screenheight() / 2 - (self.y_height / 2)
self.resizable(width=False, height=False)
self.lb_tunnel = None self.lb_tunnel = None
self.title('Wire-Py') self.title('Wire-Py')
self.configure() self.configure()
@ -30,6 +28,13 @@ class MainWindow(tk.Tk):
# Set it as the window icon. # Set it as the window icon.
self.iconphoto(True, self.wg_icon) self.iconphoto(True, self.wg_icon)
FrameWidgets(self).grid()
class FrameWidgets(ttk.Frame):
def __init__(self, container, **kwargs):
super().__init__(container, **kwargs)
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')
self.wg_vpn_stop = tk.PhotoImage(file=r'icons/wg-vpn-stop-48.png') self.wg_vpn_stop = tk.PhotoImage(file=r'icons/wg-vpn-stop-48.png')
self.wgi_on = tk.PhotoImage(file=r'icons/wire-switch-on-48.png') self.wgi_on = tk.PhotoImage(file=r'icons/wire-switch-on-48.png')
@ -37,8 +42,10 @@ class MainWindow(tk.Tk):
self.imp_pic = tk.PhotoImage(file=r'icons/wg-import.png') self.imp_pic = tk.PhotoImage(file=r'icons/wg-import.png')
self.tr_pic = tk.PhotoImage(file=r'icons/wg-trash-48.png') self.tr_pic = tk.PhotoImage(file=r'icons/wg-trash-48.png')
self.exp_pic = tk.PhotoImage(file=r'icons/wg-export-48.png') self.exp_pic = tk.PhotoImage(file=r'icons/wg-export-48.png')
self.warning_pic = tk.PhotoImage(file=r'icons/warning_64.png')
# Show active Label # Show active Label
self.select_tunnel = None
self.lb = tk.Label(self, text='Active:') self.lb = tk.Label(self, text='Active:')
self.lb.config(font=("Ubuntu", 11, "bold")) self.lb.config(font=("Ubuntu", 11, "bold"))
self.lb.grid(column=2, row=1, padx=10, pady=5, sticky="e") self.lb.grid(column=2, row=1, padx=10, pady=5, sticky="e")
@ -71,8 +78,19 @@ class MainWindow(tk.Tk):
# Button Import # Button Import
self.btn_i = tk.Button(self, image=self.imp_pic, bd=0, command=wg_import_select) self.btn_i = tk.Button(self, image=self.imp_pic, bd=0, command=wg_import_select)
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():
self.select_tunnel = self.l_box.curselection()
select_tl = self.l_box.get(self.select_tunnel[0])
os.system('nmcli connection delete ' + str(select_tl))
self.l_box.delete(self.select_tunnel[0])
if a != '':
self.StrVar.set(value='')
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=15, sticky="s")
# Button Trash # Button Trash
self.btn_tr = tk.Button(self, image=self.tr_pic, bd=0) 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)
# Button Export # Button Export
self.btn_exp = tk.Button(self, image=self.exp_pic, bd=0) self.btn_exp = tk.Button(self, image=self.exp_pic, bd=0)
@ -107,7 +125,7 @@ class MainWindow(tk.Tk):
self.btn_stst.grid(column=0, row=1, padx=15, pady=15, sticky="s") self.btn_stst.grid(column=0, row=1, padx=15, pady=15, sticky="s")
a = active() a = active()
self.StrVar = tk.StringVar() self.StrVar = tk.StringVar()
self.StrVar.set(' ') self.StrVar.set(value=' ')
self.lb_tunnel = tk.Label(self, textvariable=self.StrVar, fg='green') self.lb_tunnel = tk.Label(self, textvariable=self.StrVar, fg='green')
self.lb_tunnel.config(font=("Ubuntu", 11, "bold")) self.lb_tunnel.config(font=("Ubuntu", 11, "bold"))
self.lb_tunnel.grid(column=3, row=1, sticky="w") self.lb_tunnel.grid(column=3, row=1, sticky="w")

View File

@ -3,7 +3,30 @@ import os
import subprocess import subprocess
from tkinter import filedialog from tkinter import filedialog
import tkinter as tk import tkinter as tk
from tkinter import messagebox
class Message(tk.Tk):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.warning_pic = None
self.x_width = 300
self.y_height = 120
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.title('Import error!')
self.configure()
self.geometry('%dx%d+%d+%d' % (self.x_width, self.y_height, self.monitor_center_x, self.monitor_center_y))
self.columnconfigure(0, weight=1)
self.label = tk.Label(self, image=self.warning_pic, text='Oh... no valid Wireguard File!\nPlease select a '
'valid Wireguard File')
self.label.config(font=("Ubuntu", 11), padx=15, pady=15)
self.label.grid(column=0, row=0)
self.button = tk.Button(self, text="OK", command=self.destroy)
self.button.config(padx=15, pady=5)
self.button.grid(column=0, row=1)
def active(): # Shows the active tunnel def active(): # Shows the active tunnel
@ -21,7 +44,7 @@ a = active()
def tl_list(): def tl_list():
wg_s = os.popen('nmcli con show | grep -iPo "(.*)(wireguard)"').read().split() wg_s = os.popen('nmcli con show | grep -iPo "(.*)(wireguard)"').read().split()
tl = wg_s[::3] # tl = Tunnelliste # Hiermit wird jedes 4. Element der Liste gezeigt tl = wg_s[::3] # tl = Tunnel list # Show of 4.Element in list
return tl return tl
@ -48,20 +71,13 @@ def wg_import_select():
os.system('nmcli connection import type wireguard file ' + str(filepath)) os.system('nmcli connection import type wireguard file ' + str(filepath))
os.system('nmcli con mod ' + str(pathsplit1[:-5]) + ' connection.autoconnect no') os.system('nmcli con mod ' + str(pathsplit1[:-5]) + ' connection.autoconnect no')
if "PrivateKey = " not in read: if "PrivateKey = " not in read:
messagebox.showwarning(title="conf error", message=" Oh... no valid Wireguard File!\nPlease select a " Message()
"valid Wireguard File ")
except EOFError: except EOFError:
pass pass
except TypeError: except TypeError:
pass pass
def tl_list():
wg_s = os.popen('nmcli con show | grep -iPo "(.*)(wireguard)"').read().split()
tl = wg_s[::3] # tl = Tunnelliste # Hiermit wird jedes 4. Element der Liste gezeigt
return tl
def wg_export(): def wg_export():
try: try:
wg_exp = os.popen('nmcli con show | grep -iPo "(.*)(wireguard)"').read().split() wg_exp = os.popen('nmcli con show | grep -iPo "(.*)(wireguard)"').read().split()