add Class StartStopBTN to wg_func.py #6

Merged
punix merged 1 commits from wire-py-reformat-14-08-2024 into main 2024-08-21 12:52:51 +02:00
4 changed files with 52 additions and 25 deletions

View File

@ -4,8 +4,7 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="940e1630-c825-4d4c-be80-bc11f543c122" name="Changes" comment="add Label Interface and Peer to new FrameWidget one and two. when import Tunnel then add to list works and remove of list when Tunnel delete.(with Label active on and off) &#10;add to class and methods open a avtive Tunnel when Wire-Py open, when import and start a Tunnel">
<change afterPath="$PROJECT_DIR$/dict_to_address" afterDir="false" />
<list default="true" id="940e1630-c825-4d4c-be80-bc11f543c122" name="Changes" comment="add file dict_to_address for &#10;address a active Tunnel. Label green pack in Class.&#10;add Class to convert fileoutput as String to Dictionary">
<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" />
@ -147,7 +146,15 @@
<option name="project" value="LOCAL" />
<updated>1724102937260</updated>
</task>
<option name="localTasksCounter" value="8" />
<task id="LOCAL-00008" summary="add file dict_to_address for &#10;address a active Tunnel. Label green pack in Class.&#10;add Class to convert fileoutput as String to Dictionary">
<option name="closed" value="true" />
<created>1724233806458</created>
<option name="number" value="00008" />
<option name="presentableId" value="LOCAL-00008" />
<option name="project" value="LOCAL" />
<updated>1724233806458</updated>
</task>
<option name="localTasksCounter" value="9" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
@ -181,6 +188,18 @@
<MESSAGE value="add class Frame and class Massage, delete funktion go 100%, add resize window, add warning pic" />
<MESSAGE value="add class ListTunnels and class ImportTunnel, and add class ExportTunnels (ExportTunnels no finish)" />
<MESSAGE value="add Label Interface and Peer to new FrameWidget one and two. when import Tunnel then add to list works and remove of list when Tunnel delete.(with Label active on and off) &#10;add to class and methods open a avtive Tunnel when Wire-Py open, when import and start a Tunnel" />
<option name="LAST_COMMIT_MESSAGE" value="add Label Interface and Peer to new FrameWidget one and two. when import Tunnel then add to list works and remove of list when Tunnel delete.(with Label active on and off) &#10;add to class and methods open a avtive Tunnel when Wire-Py open, when import and start a Tunnel" />
<MESSAGE value="add file dict_to_address for &#10;address a active Tunnel. Label green pack in Class.&#10;add Class to convert fileoutput as String to Dictionary" />
<option name="LAST_COMMIT_MESSAGE" value="add file dict_to_address for &#10;address a active Tunnel. Label green pack in Class.&#10;add Class to convert fileoutput as String to Dictionary" />
</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>116</line>
<option name="timeStamp" value="3" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
</project>

View File

@ -1,3 +1,3 @@
192.168.178.158/24
192.168.178.1,
rj2cexasg9b9oydd.myfritz.net:54775
10.64.1.5/32
10.64.1.1
wg.iunix.dedyn.io:51820

24
main.py
View File

@ -4,7 +4,7 @@ import tkinter as tk
from tkinter import ttk
from wg_func import (TunnelActiv, ListTunnels, ImportTunnel,
ConToDict, GreenLabel, ExportTunnels)
ConToDict, GreenLabel, StartStopBTN, ExportTunnels)
class MainWindow(tk.Tk):
@ -37,8 +37,6 @@ class FrameWidgets(ttk.Frame):
self.wg_read = None
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.wgi_on = tk.PhotoImage(file=r'icons/wire-switch-on-48.png')
self.wgi_off = tk.PhotoImage(file=r'icons/wire-switch-off-48.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.exp_pic = tk.PhotoImage(file=r'icons/wg-export-48.png')
@ -97,15 +95,13 @@ class FrameWidgets(ttk.Frame):
# Button Vpn
if self.a != '':
self.btn_stst = tk.Button(self, image=self.wg_vpn_stop, bd=0, command=self.wg_switch)
self.btn_stst.grid(column=0, row=1, padx=15, pady=15, sticky="s")
StartStopBTN.button_stop(self)
wg_read = os.environ['HOME'] + '/tester/' + str(self.a) + '.conf'
file = open(wg_read, 'r')
ConToDict.covert_to_dict(file)
file.close()
else:
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")
StartStopBTN.button_start(self)
# Button Import
self.btn_i = tk.Button(self, image=self.imp_pic, bd=0, command=lambda: ImportTunnel.wg_import_select(self))
self.btn_i.grid(column=0, row=2, padx=15, pady=15)
@ -118,8 +114,7 @@ class FrameWidgets(ttk.Frame):
os.remove(os.environ['HOME'] + '/tester/' + str(select_tl) + '.conf')
if self.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")
StartStopBTN.button_start(self)
self.l_box.update()
# Button Trash
@ -138,7 +133,7 @@ class FrameWidgets(ttk.Frame):
def wg_switch(self):
self.a = TunnelActiv.active()
if self.a == '':
StartStopBTN.button_start(self)
self.select_tunnel = self.l_box.curselection()
select_tl = self.l_box.get(self.select_tunnel[0])
os.system('nmcli connection up ' + str(select_tl))
@ -147,20 +142,17 @@ class FrameWidgets(ttk.Frame):
ConToDict.covert_to_dict(file)
file.close()
# Button Start/Stop
self.btn_stst = tk.Button(self, image=self.wg_vpn_stop, bd=0, command=self.wg_switch)
self.btn_stst.grid(column=0, row=1, padx=15, pady=15, sticky="s")
StartStopBTN.button_stop(self)
self.a = TunnelActiv.active()
self.StrVar = tk.StringVar()
self.StrVar.set(self.a)
GreenLabel.green_show_label(self)
elif self.a != '':
# Button Start/Stop
self.btn_stst = tk.Button(self, image=self.wg_vpn_stop, bd=0, command=self.wg_switch)
self.btn_stst.grid(column=0, row=1, padx=15, pady=15, sticky="s")
StartStopBTN.button_stop(self)
os.system('nmcli connection down ' + str(self.a))
# Button Start/Stop
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")
StartStopBTN.button_start(self)
self.a = TunnelActiv.active()
self.StrVar = tk.StringVar()
self.StrVar.set(value=' ')

View File

@ -41,6 +41,23 @@ class GreenLabel(tk.Tk):
self.lb_tunnel.grid(column=3, row=1, sticky="w")
class StartStopBTN(tk.Tk):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.wg_switch = None
self.btn_stst = None
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')
def button_stop(self):
self.btn_stst = tk.Button(self, image=self.wg_vpn_stop, bd=0, command=self.wg_switch)
self.btn_stst.grid(column=0, row=1, padx=15, pady=15, sticky="s")
def button_start(self):
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")
class ConToDict:
@classmethod
def covert_to_dict(cls, file):
@ -138,8 +155,7 @@ class ImportTunnel:
self.lb_tunnel = tk.Label(self, textvariable=self.StrVar, fg='green')
self.lb_tunnel.config(font=("Ubuntu", 11, "bold"))
self.lb_tunnel.grid(column=3, row=1, sticky="w")
self.btn_stst = tk.Button(self, image=self.wg_vpn_stop, bd=0, command=self.wg_switch)
self.btn_stst.grid(column=0, row=1, padx=15, pady=15, sticky="s")
StartStopBTN.button_stop(self)
wg_read = os.environ['HOME'] + '/tester/' + str(self.a) + '.conf'
file = open(wg_read, 'r')
ConToDict.covert_to_dict(file)