diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index f798ee1..0f8ea06 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,10 +4,14 @@
-
+
+
-
+
+
+
+
@@ -47,24 +51,25 @@
- {
+ "keyToString": {
+ "ASKED_ADD_EXTERNAL_FILES": "true",
+ "Python.INSTALL.executor": "Run",
+ "Python.install.executor": "Run",
+ "Python.main.executor": "Run",
+ "Python.messagebox.executor": "Run",
+ "Python.start_wg.executor": "Run",
+ "Python.testtheme.executor": "Run",
+ "Python.wg_func.executor": "Run",
+ "Python.wg_main.executor": "Run",
+ "RunOnceActivity.ShowReadmeOnStart": "true",
+ "Shell Script.install.executor": "Run",
+ "Shell Script.run_as.executor": "Run",
+ "git-widget-placeholder": "main",
+ "last_opened_file_path": "/home/punix/Pyapps/wire-py",
+ "settings.editor.selected.configurable": "reference.settingsdialog.IDE.editor.colors"
}
-}]]>
+}
@@ -143,14 +148,6 @@
1723279982210
-
-
- 1724495688099
-
-
-
- 1724495688099
-
1724576599289
@@ -535,7 +532,15 @@
1729593628908
-
+
+
+ 1729938941026
+
+
+
+ 1729938941027
+
+
@@ -576,7 +581,6 @@
-
@@ -601,6 +605,18 @@
-
+
+
+
+
+
+
+
+ file://$PROJECT_DIR$/start_wg.py
+ 1
+
+
+
+
\ No newline at end of file
diff --git a/Changelog b/Changelog
index 9d8a975..8e3b619 100644
--- a/Changelog
+++ b/Changelog
@@ -4,12 +4,23 @@ My standard System: Linux Mint 22 Cinnamon
## [Unreleased]
- os import in wg_func replaced by other methods
- - Guide to menu '?' with pictures
- - In Gitea Readme enter text, images
- - Own filedialog for import
- If Wire-Py already runs, prevent further start
- for loops with lists replaced by List Comprehensions
- - Keeping Classes Together
+ - Update search after start of Wire-Py
+
+
+ ### Added
+27-10-2024
+
+- Add Autoconnect settings to settings.conf
+
+
+ ### Added
+26-10-2024
+
+- Add run_as Bash script and open_gitea.py python script
+- Add Tooltip disable/enable
+- Rename settings to settings.conf for theme, updates and tooltip enable in one file
### Added
diff --git a/install b/install
index 7a967c4..e6af75c 100755
--- a/install
+++ b/install
@@ -7,8 +7,8 @@ BLUE='\033[30;1;34m'
install_file_with(){
clear
sudo apt install python3-tk && \
- sudo cp -u wg_main.py start_wg.py wg_func.py wirepy.py /usr/bin/ && \
- sudo mkdir -p /etc/wire_py && sudo touch /etc/wire_py/.keys && sudo cp -u settings theme /etc/wire_py/ && \
+ sudo cp -u wg_main.py start_wg.py wg_func.py wirepy.py run_as open_gitea.py /usr/bin/ && \
+ sudo mkdir -p /etc/wire_py && sudo touch /etc/wire_py/.keys && sudo cp -u settings.conf /etc/wire_py/ && \
sudo cp -uR wp-icons /usr/share/icons/ && sudo cp -uR TK-Themes /usr/share/ && \
sudo chown -R root:root /etc/wire_py && sudo chmod 755 /etc/wire_py && \
sudo ln -sf /usr/bin/wirepy.py /usr/local/bin/wirepy && \
@@ -21,8 +21,8 @@ install_file_with(){
install_arch_d(){
clear
sudo pacman -S --noconfirm tk python3 python-requests && \
- sudo cp -u wg_main.py start_wg.py wg_func.py wirepy.py /usr/bin/ && \
- sudo mkdir -p /etc/wire_py && sudo touch /etc/wire_py/.keys && sudo cp -u settings theme /etc/wire_py/ && \
+ sudo cp -u wg_main.py start_wg.py wg_func.py wirepy.py run_as open_gitea.py /usr/bin/ && \
+ sudo mkdir -p /etc/wire_py && sudo touch /etc/wire_py/.keys && sudo cp -u settings.conf /etc/wire_py/ && \
sudo cp -uR wp-icons /usr/share/icons/ && sudo cp -uR TK-Themes /usr/share/ && \
sudo chown -R root:root /etc/wire_py && sudo chmod 755 /etc/wire_py && \
sudo ln -sf /usr/bin/wirepy.py /usr/local/bin/wirepy && \
@@ -89,9 +89,9 @@ elif grep -i 'fedora' /etc/os-release > /dev/null 2>&1
if ! which python3-tkinter &> /dev/null
then sudo dnf install python3-tkinter -y
- sudo cp -u wg_main.py start_wg.py wg_func.py wirepy.py /usr/bin/ && \
+ sudo cp -u wg_main.py start_wg.py wg_func.py wirepy.py run_as open_gitea.py /usr/bin/ && \
sudo mkdir -p /etc/wire_py && sudo touch /etc/wire_py/.keys && \
- sudo cp -u settings theme /etc/wire_py/ && \
+ sudo cp -u settings.conf /etc/wire_py/ && \
sudo cp -uR wp-icons /usr/share/icons/ && sudo cp -uR TK-Themes /usr/share/ && \
sudo chown -R root:root /etc/wire_py && sudo chmod 755 /etc/wire_py && \
sudo ln -sf /usr/bin/wirepy.py /usr/local/bin/wirepy && \
@@ -105,9 +105,9 @@ elif grep -i 'suse' /etc/os-release > /dev/null 2>&1
then
if ! which python311-tk &> /dev/null
then sudo zypper install python311-tk
- sudo cp -u wg_main.py start_wg.py wg_func.py wirepy.py /usr/bin/ && \
+ sudo cp -u wg_main.py start_wg.py wg_func.py wirepy.py run_as open_gitea.py /usr/bin/ && \
sudo mkdir -p /etc/wire_py && sudo touch /etc/wire_py/.keys && \
- sudo cp -u settings theme /etc/wire_py/ && \
+ sudo cp -u settings.conf /etc/wire_py/ && \
sudo cp -uR wp-icons /usr/share/icons/ && sudo cp -uR TK-Themes /usr/share/ && \
sudo chown -R root:root /etc/wire_py && sudo chmod 755 /etc/wire_py && \
sudo ln -sf /usr/bin/wirepy.py /usr/local/bin/wirepy && \
diff --git a/run_as b/run_as
new file mode 100755
index 0000000..d15cff4
--- /dev/null
+++ b/run_as
@@ -0,0 +1,2 @@
+#!/bin/bash
+/usr/bin/./open_gitea.py
\ No newline at end of file
diff --git a/settings b/settings
deleted file mode 100644
index 66cb652..0000000
--- a/settings
+++ /dev/null
@@ -1 +0,0 @@
-Update on
\ No newline at end of file
diff --git a/start_wg.py b/start_wg.py
index 41bb29b..3140e90 100755
--- a/start_wg.py
+++ b/start_wg.py
@@ -2,11 +2,13 @@
from subprocess import check_call
from pathlib import Path
-path_to_file = Path('/etc/wire_py/wg_py')
+path_to_file = Path('/etc/wire_py/settings.conf')
-if Path.exists(path_to_file):
- a_con = Path.read_text(path_to_file)
- check_call(['nmcli', 'connection', 'up', a_con])
-else:
- pass
+with open(path_to_file, 'r') as a_con:
+ lines = a_con.readlines()
+ a_con = lines[7].strip()
+ if a_con != 'off':
+ check_call(['nmcli', 'connection', 'up', a_con])
+ else:
+ pass
diff --git a/theme b/theme
deleted file mode 100644
index b8b4ecb..0000000
--- a/theme
+++ /dev/null
@@ -1 +0,0 @@
-light
\ No newline at end of file
diff --git a/wg_func.py b/wg_func.py
index 01eb6a4..4bd0b2b 100755
--- a/wg_func.py
+++ b/wg_func.py
@@ -16,14 +16,11 @@ import requests
''' 1 = 1. Year, 09 = Month of the Year, 2924 = Day and Year of the Year '''
version = 'v. 1.10.2124'
-path_to_file = Path('/etc/wire_py/wg_py')
-path_to_file2 = Path('/etc/wire_py/settings')
-path_to_file3 = Path('/etc/wire_py/theme')
+path_to_file2 = Path('/etc/wire_py/settings.conf')
_u = Path.read_text(Path('/tmp/_u'))
UPDATE_API_URL = 'https://git.ilunix.de/api/v1/repos/punix/Wire-Py/releases'
-tips = True
class WirePyUpdate:
@staticmethod
@@ -34,7 +31,7 @@ class WirePyUpdate:
response_dict = response_dict[0]
with open(path_to_file2, 'r') as set_file:
set_file = set_file.read()
- if 'Update on' in set_file:
+ if 'on\n' in set_file:
if version[3:] != response_dict['tag_name']:
return response_dict['tag_name']
else:
@@ -78,7 +75,8 @@ class WirePyUpdate:
res = WirePyUpdate.api_down()
-def msg_window(img_w, img_i, w_title, w_txt):
+
+def msg_window(img_w, img_i, w_title, w_txt, txt2=None, com=None):
"""
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.
@@ -95,13 +93,25 @@ def msg_window(img_w, img_i, w_title, w_txt):
msg.configure(pady=15, padx=15)
msg.img = tk.PhotoImage(file=img_w)
msg.i_window = tk.Label(msg, image=msg.img)
- msg.i_window.grid(column=0, row=0)
+
label = tk.Label(msg, text=w_txt)
- label.config(font=('Ubuntu', 11), padx=15)
+
label.grid(column=1, row=0)
- button = ttk.Button(msg, text='OK', command=msg.destroy, padding=4)
- button.config()
- button.grid(column=0, columnspan=2, row=1)
+
+ if txt2 != None and com != None:
+ label.config(font=('Ubuntu', 11), padx=15, justify='left')
+ msg.i_window.grid(column=0, row=0, sticky='nw')
+ button2 = ttk.Button(msg, text=f'{txt2}', command=com, padding=4)
+ button2.grid(column=0, row=1, sticky='e', columnspan=2)
+ button = ttk.Button(msg, text='OK', command=msg.destroy, padding=4)
+ button.grid(column=0, row=1, sticky='w', columnspan=2)
+
+ else:
+ label.config(font=('Ubuntu', 11), padx=15)
+ msg.i_window.grid(column=0, row=0)
+ button = ttk.Button(msg, text='OK', command=msg.destroy, padding=4)
+ button.grid(column=0, columnspan=2, row=1)
+
img_i = tk.PhotoImage(file=img_i)
msg.iconphoto(True, img_i)
msg.columnconfigure(0, weight=1)
@@ -128,8 +138,9 @@ class Tunnel:
self.add = None
def color(self):
- with open(path_to_file3, 'r') as read_file:
- if 'light' in read_file:
+ with open(path_to_file2, 'r') as read_file:
+ lines = read_file.readlines()
+ if 'light\n' in lines:
self.lb_tunnel = ttk.Label(self, textvariable=self.StrVar, foreground='green')
else:
@@ -280,8 +291,7 @@ class Tunnel:
source = Path('/tmp/wire_py')
Path.unlink(Path(source) / 'wg_py', missing_ok=True)
Path.unlink(Path(source) / '.keys', missing_ok=True)
- Path.unlink(Path(source) / 'settings', missing_ok=True)
- Path.unlink(Path(source) / 'theme', missing_ok=True)
+ Path.unlink(Path(source) / 'settings.conf', missing_ok=True)
shutil.make_archive(wg_tar, 'zip', source)
shutil.chown(wg_tar + '.zip', 1000, 1000)
shutil.rmtree(source)
@@ -316,6 +326,16 @@ class Tunnel:
except TypeError:
pass
+ @staticmethod
+ def if_tip():
+ with open(path_to_file2, 'r') as set_file2:
+ lines2 = set_file2.readlines()
+ if 'False\n' in lines2:
+ return False
+ else:
+ return True
+
+tips = Tunnel.if_tip()
class FileHandle:
"""
@@ -341,14 +361,23 @@ class FileHandle:
select_tl = self.l_box.get(select_tunnel[0])
if self.selected_option.get() == 0:
- Path.unlink(path_to_file)
+ with open(path_to_file2, 'r') as set_file3:
+ lines3 = set_file3.readlines()
+ lines3[7] = 'off'
+ with open(path_to_file2, 'w') as set_file3:
+ set_file3.writelines(lines3)
+
tl = Tunnel.list()
if len(tl) == 0:
self.wg_autostart.configure(state='disabled')
if self.selected_option.get() >= 1:
- Path.write_text(path_to_file, select_tl)
+ with open(path_to_file2, 'r') as set_file3:
+ lines3 = set_file3.readlines()
+ lines3[7] = select_tl
+ with open(path_to_file2, 'w') as set_file3:
+ set_file3.writelines(lines3)
except IndexError:
self.selected_option.set(1)
@@ -373,13 +402,13 @@ class OnOff:
self.lb_frame_buttons = None
def on_off(self):
+ with open(path_to_file2, 'r') as set_file4:
+ lines4 = set_file4.readlines()
- if Path.exists(path_to_file):
+ if lines4[7] != 'off':
self.selected_option.set(1)
self.autoconnect_var.set('')
- if not Path.is_dir(Path('/etc/wire_py')):
- Path.mkdir(Path('/etc/wire_py'))
- self.auto_con = Path.read_text(path_to_file)
+ self.auto_con = lines4[7]
else:
diff --git a/wg_main.py b/wg_main.py
index a872a36..02599da 100755
--- a/wg_main.py
+++ b/wg_main.py
@@ -8,8 +8,7 @@ from subprocess import check_call
from tkinter import *
from tkinter import filedialog, ttk
-from wg_func import (Tunnel, FileHandle, OnOff, msg_window, WirePyUpdate, res, _u, version, path_to_file2,
- path_to_file3, tips)
+from wg_func import (Tunnel, FileHandle, OnOff, msg_window, WirePyUpdate, res, _u, version, path_to_file2, tips)
tcl_path = Path('/usr/share/TK-Themes')
@@ -31,8 +30,9 @@ class MainWindow(tk.Tk):
self.style = ttk.Style(self)
self.tk.call('source', str(tcl_path) + '/water.tcl')
#self.tk.call('source', 'TK-Themes/water.tcl')
- with open(path_to_file3, 'r') as read_file:
- if 'light' in read_file:
+ with open(path_to_file2, 'r') as read_file:
+ lines = read_file.readlines()
+ if 'light\n' in lines:
self.tk.call('set_theme', 'light')
else:
self.tk.call('set_theme', 'dark')
@@ -44,42 +44,77 @@ class MainWindow(tk.Tk):
self.iconphoto(True, self.wg_icon)
#Set on or off in file
- def on_off():
- if set_option.get() == 1:
+ def update():
+ if set_update.get() == 1:
+ with open(path_to_file2, 'r') as set_file2:
+ lines2 = set_file2.readlines()
+ lines2[1] = 'off\n'
with open(path_to_file2, 'w') as set_file2:
- set_file2.write('Update off')
+ set_file2.writelines(lines2)
- if set_option.get() == 0:
+ if set_update.get() == 0:
+ with open(path_to_file2, 'r') as set_file2:
+ lines2 = set_file2.readlines()
+ lines2[1] = 'on\n'
with open(path_to_file2, 'w') as set_file2:
- set_file2.write('Update on')
+ set_file2.writelines(lines2)
+
+ #Set on or off in file
+ def tooltip():
+ if set_tip.get():
+ print(set_tip.get())
+ with open(path_to_file2, 'r') as set_file2:
+ lines2 = set_file2.readlines()
+ lines2[5] = 'False\n'
+ with open(path_to_file2, 'w') as set_file2:
+ set_file2.writelines(lines2)
+
+ else:
+ with open(path_to_file2, 'r') as set_file2:
+ lines2 = set_file2.readlines()
+ lines2[5] = 'True\n'
+ with open(path_to_file2, 'w') as set_file2:
+ set_file2.writelines(lines2)
# Set dark or light
def theme_change_light():
if self.tk.call("ttk::style", "theme", "use") == "water-dark":
# Set light theme
self.tk.call('set_theme', 'light')
- with open(path_to_file3, 'w') as theme_set2:
- theme_set2.write('light')
+ with open(path_to_file2, 'r') as theme_set2:
+ lines3 = theme_set2.readlines()
+ lines3[3] = 'light\n'
+ with open(path_to_file2, 'w') as theme_set2:
+ theme_set2.writelines(lines3)
def theme_change_dark():
if not self.tk.call("ttk::style", "theme", "use") == "water-dark":
# Set dark theme
self.tk.call('set_theme', 'dark')
- with open(path_to_file3, 'w') as theme_set2:
- theme_set2.write('dark')
+ with open(path_to_file2, 'r') as theme_set2:
+ lines4 = theme_set2.readlines()
+ lines4[3] = 'dark\n'
+ with open(path_to_file2, 'w') as theme_set2:
+ theme_set2.writelines(lines4)
def info():
- """img_w, img_i, w_title, w_txt hand over"""
+ def link_btn():
+ _u1 = str(_u[6:])
+ path_to_file = Path('/usr/bin/./run_as')
+ check_call(['su', _u1, path_to_file])
+
+ """img_w, img_i, w_title, w_txt , txt2, com hand over"""
iw = r'/usr/share/icons/wp-icons/48/wg_vpn.png'
ii = r'/usr/share/icons/wp-icons/48/wg_msg.png'
- wt = 'Instruction'
- msg_t = ('Wire-Py: Wireguard Gui for Linux systems.\n\n'
+ wt = 'Info'
+ msg_t = ('Wire-Py a simple Wireguard Gui for Linux systems.\n\n'
'Wire-Py is open source software written in Python.\n\n'
'Email: polunga40@unity-mail.de also likes for donation.\n\n'
- 'https://git.ilunix.de/punix/Wire-P\n\n'
'Use without warranty!\n')
+ txt2 = 'Go to Wire-Py git'
+ com = link_btn
- msg_window(iw, ii, wt, msg_t)
+ msg_window(iw, ii, wt, msg_t, txt2, com)
''' Frame for Menu '''
self.menu_frame = ttk.Frame(self)
@@ -119,39 +154,34 @@ class MainWindow(tk.Tk):
self.options_btn.bind('', sets_enter)
self.options_btn.bind('', sets_leave)
- set_option = tk.IntVar()
-
- self.settings = tk.Menu(self)
+ set_update = tk.IntVar()
+ set_tip = tk.BooleanVar()
+ self.settings = tk.Menu(self, relief='flat')
self.options_btn.configure(menu=self.settings, style='Toolbutton')
- self.settings.add_checkbutton(label='Disable updates', command=on_off, variable=set_option)
+ self.settings.add_checkbutton(label='Disable Updates', command=update, variable=set_update)
+ self.settings.add_checkbutton(label='Disable Tooltips', command=tooltip, variable=set_tip)
self.settings.add_command(label='Light', command=theme_change_light)
self.settings.add_command(label='Dark', command=theme_change_dark)
''' About BTN Menu / Label '''
- self.about_btn = ttk.Menubutton(self.menu_frame, text='About')
+ self.about_btn = ttk.Button(self.menu_frame, text='About', style='Toolbutton', command=info)
self.about_btn.grid(column=2, row=0)
- def about_enter(event):
- """ The mouse moves into the entry widget """
- window.my_tool_tip = MyToolTip(event.x_root, event.y_root, 'Click for Info')
-
- def about_leave(_):
- """ The mouse moves from the entry widget """
- ''' Remove Tool-Tip '''
- window.my_tool_tip.destroy()
-
- self.about_btn.bind('', about_enter)
- self.about_btn.bind('', about_leave)
self.readme = tk.Menu(self)
- self.about_btn.configure(menu=self.readme, style='Toolbutton')
- self.readme.add_command(label='Info', command=info)
- ''' Update Label '''
+ ''' Update and Tooltip Label '''
self.updates_lb = ttk.Label(self.menu_frame)
self.updates_lb.grid(column=3, row=0, padx=10)
+ '''View Checkbox for enable or disable Tooltip '''
+ if tips:
+ set_tip.set(value=False)
+ else:
+ set_tip.set(value=True)
+
+ '''View Checkbox for enable or disable Updates '''
if res == 'False':
- set_option.set(value=1)
+ set_update.set(value=1)
self.updates_lb.configure(text='Update search off')
def disable_enter(event):
@@ -183,11 +213,10 @@ class MainWindow(tk.Tk):
self.updates_lb.bind('', congratulations_enter)
self.updates_lb.bind('', congratulations_leave)
else:
- set_option.set(value=0)
+ set_update.set(value=0)
text = f'Update {res} available!'
''' Update BTN Menu'''
-
self.update_btn = ttk.Menubutton(self.menu_frame, text=text)
self.update_btn.grid(column=4, row=0, padx=0)
@@ -204,7 +233,7 @@ class MainWindow(tk.Tk):
self.update_btn.bind('', download_enter)
self.update_btn.bind('', download_leave)
- self.download = tk.Menu(self)
+ self.download = tk.Menu(self, relief='flat')
self.update_btn.configure(menu=self.download, style='Toolbutton')
self.download.add_command(label='Download', command=WirePyUpdate.download)
@@ -631,14 +660,15 @@ class FrameWidgets(ttk.Frame):
pre_key = key[3]
check_call(['nmcli', 'connection', 'delete', select_tl])
self.l_box.delete(self.select_tunnel[0])
- 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:
+ with open(path_to_file2, 'r') as set_file6:
+ lines6 = set_file6.readlines()
+ if select_tl == lines6[7].strip() and not 'off' in lines6[7].strip():
+ lines6[7] = 'off'
+ with open(path_to_file2, 'w') as set_file7:
+ set_file7.writelines(lines6)
self.selected_option.set(0)
self.autoconnect_var.set('no Autoconnect')
- Path.unlink(path_to_file)
Path.unlink(Path('/etc/wire_py') / str(select_tl + '.conf'))
with open('/etc/wire_py/.keys', 'r') as readfile:
with open('/etc/wire_py/.keys2', 'w') as writefile:
@@ -853,12 +883,13 @@ class FrameWidgets(ttk.Frame):
if self.a != '' and self.a == select_tl:
self.a = Tunnel.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:
+ with open(path_to_file2, 'r') as set_file5:
+ lines5 = set_file5.readlines()
+ if select_tl == lines5[7].strip() and not 'off' in lines5[7].strip():
+ lines5[7] = new_a_connect
+ with open(path_to_file2, 'w') as theme_set5:
+ theme_set5.writelines(lines5)
self.autoconnect_var.set(value=new_a_connect)
- Path.write_text(path_to_file, new_a_connect)
return select_tl