diff --git a/Changelog b/Changelog index 2130019..e6a0253 100644 --- a/Changelog +++ b/Changelog @@ -8,6 +8,15 @@ My standard System: Linux Mint 22 Cinnamon - for loops with lists replaced by List Comprehensions - Update search after start of Wire-Py + ### Added +09-11-2024 + +- Move Tips Method in separate class for Tooltips in another Apps +- Move Version Variable in main script +- Edit Class GiteaUpdate for requests in api_down and download +- Description on Class GiteaUpdate + + ### Added 08-11-2024 diff --git a/cls_mth_fc.py b/cls_mth_fc.py index cc83481..2a57278 100755 --- a/cls_mth_fc.py +++ b/cls_mth_fc.py @@ -19,26 +19,27 @@ gettext.bindtextdomain(APP, LOCALE_DIR) gettext.textdomain(APP) _ = gettext.gettext -path_to_file2 = Path('/etc/wire_py/settings.conf') +wg_set = Path('/etc/wire_py/settings.conf') _u = Path.read_text(Path('/tmp/_u')) class GiteaUpdate: """ - Calling api_down requests the URL and version from the running script. + Calling api_down requests the URL and the version of the running script. Example: version = 'v. 1.1.1.1' GiteaUpdate.api_down(http://example.de, version) - The call to download requests the download URL from the running script, - the taskbar image for the Download OK window, the taskbar image for - the Download Error window and the variable res + Calling download requests the download URL of the running script, + the taskbar image for the “Download OK” window, the taskbar image for the + “Download error” window and the variable res """ + @staticmethod def api_down(update_api_url, version): try: response = requests.get(update_api_url) response_dict = response.json() response_dict = response_dict[0] - with open(path_to_file2, 'r') as set_file: + with open(wg_set, 'r') as set_file: set_file = set_file.read() if 'on\n' in set_file: if version[3:] != response_dict['tag_name']: @@ -258,9 +259,15 @@ class Tunnel: except TypeError: pass + +class Tipi: + """ + Class for Tooltip setting write in File + Calling request path to file + """ @staticmethod - def if_tip(): - with open(path_to_file2, 'r') as set_file2: + def if_tip(path): + with open(path, 'r') as set_file2: lines2 = set_file2.readlines() if 'False\n' in lines2: return False @@ -268,4 +275,4 @@ class Tunnel: return True -tips = Tunnel.if_tip() +wg_tips = Tipi.if_tip(wg_set) diff --git a/wg_main.py b/wg_main.py index 76bea4c..557b0f2 100755 --- a/wg_main.py +++ b/wg_main.py @@ -9,7 +9,7 @@ import tkinter as tk from pathlib import Path from subprocess import check_call from tkinter import filedialog, ttk, TclError -from cls_mth_fc import (Tunnel, msg_window, GiteaUpdate, _u, path_to_file2, tips) +from cls_mth_fc import (Tunnel, msg_window, GiteaUpdate, _u, wg_tips, wg_set) tcl_path = Path('/usr/share/TK-Themes') @@ -46,7 +46,7 @@ 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_file2, 'r') as read_file: + with open(wg_set, 'r') as read_file: lines = read_file.readlines() if 'light\n' in lines: self.tk.call('set_theme', 'light') @@ -85,34 +85,34 @@ class FrameWidgets(ttk.Frame): def update(): if set_update.get() == 1: - with open(path_to_file2, 'r') as set_file2: + with open(wg_set, 'r') as set_file2: lines2 = set_file2.readlines() lines2[1] = 'off\n' - with open(path_to_file2, 'w') as set_file2: + with open(wg_set, 'w') as set_file2: set_file2.writelines(lines2) if set_update.get() == 0: - with open(path_to_file2, 'r') as set_file2: + with open(wg_set, 'r') as set_file2: lines2 = set_file2.readlines() lines2[1] = 'on\n' - with open(path_to_file2, 'w') as set_file2: + with open(wg_set, 'w') as set_file2: set_file2.writelines(lines2) ''' Set True or False in file ''' def tooltip(): if set_tip.get(): - with open(path_to_file2, 'r') as set_file2: + with open(wg_set, 'r') as set_file2: lines2 = set_file2.readlines() lines2[5] = 'False\n' - with open(path_to_file2, 'w') as set_file2: + with open(wg_set, 'w') as set_file2: set_file2.writelines(lines2) else: - with open(path_to_file2, 'r') as set_file2: + with open(wg_set, 'r') as set_file2: lines2 = set_file2.readlines() lines2[5] = 'True\n' - with open(path_to_file2, 'w') as set_file2: + with open(wg_set, 'w') as set_file2: set_file2.writelines(lines2) ''' Set dark or light ''' @@ -121,10 +121,10 @@ class FrameWidgets(ttk.Frame): if self.tk.call("ttk::style", "theme", "use") == "water-dark": ''' Set light theme ''' self.tk.call('set_theme', 'light') - with open(path_to_file2, 'r') as theme_set2: + with open(wg_set, 'r') as theme_set2: lines3 = theme_set2.readlines() lines3[3] = 'light\n' - with open(path_to_file2, 'w') as theme_set2: + with open(wg_set, 'w') as theme_set2: theme_set2.writelines(lines3) self.color_label() @@ -132,10 +132,10 @@ class FrameWidgets(ttk.Frame): if not self.tk.call("ttk::style", "theme", "use") == "water-dark": ''' Set dark theme ''' self.tk.call('set_theme', 'dark') - with open(path_to_file2, 'r') as theme_set2: + with open(wg_set, 'r') as theme_set2: lines4 = theme_set2.readlines() lines4[3] = 'dark\n' - with open(path_to_file2, 'w') as theme_set2: + with open(wg_set, 'w') as theme_set2: theme_set2.writelines(lines4) self.color_label() @@ -212,7 +212,7 @@ class FrameWidgets(ttk.Frame): 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: + if wg_tips: set_tip.set(value=False) else: set_tip.set(value=True) @@ -420,11 +420,11 @@ class FrameWidgets(ttk.Frame): pre_key = key[3] check_call(['nmcli', 'connection', 'delete', select_tl]) self.l_box.delete(self.select_tunnel[0]) - with open(path_to_file2, 'r') as set_file6: + with open(wg_set, 'r') as set_file6: lines6 = set_file6.readlines() if select_tl == lines6[7].strip() and 'off' not in lines6[7].strip(): lines6[7] = 'off' - with open(path_to_file2, 'w') as set_file7: + with open(wg_set, 'w') as set_file7: set_file7.writelines(lines6) self.selected_option.set(0) self.autoconnect_var.set(_('no Autoconnect')) @@ -642,11 +642,11 @@ class FrameWidgets(ttk.Frame): if self.a != '' and self.a == select_tl: self.a = Tunnel.active() self.StrVar.set(value=self.a) - with open(path_to_file2, 'r') as set_file5: + with open(wg_set, 'r') as set_file5: lines5 = set_file5.readlines() if select_tl == lines5[7].strip() and 'off' not in lines5[7].strip(): lines5[7] = new_a_connect - with open(path_to_file2, 'w') as theme_set5: + with open(wg_set, 'w') as theme_set5: theme_set5.writelines(lines5) self.autoconnect_var.set(value=new_a_connect) @@ -899,10 +899,10 @@ class FrameWidgets(ttk.Frame): select_tl = self.l_box.get(select_tunnel[0]) if self.selected_option.get() == 0: - with open(path_to_file2, 'r') as set_file3: + with open(wg_set, 'r') as set_file3: lines3 = set_file3.readlines() lines3[7] = 'off' - with open(path_to_file2, 'w') as set_file3: + with open(wg_set, 'w') as set_file3: set_file3.writelines(lines3) tl = Tunnel.list() @@ -911,10 +911,10 @@ class FrameWidgets(ttk.Frame): self.wg_autostart.configure(state='disabled') if self.selected_option.get() >= 1: - with open(path_to_file2, 'r') as set_file3: + with open(wg_set, 'r') as set_file3: lines3 = set_file3.readlines() lines3[7] = select_tl - with open(path_to_file2, 'w') as set_file3: + with open(wg_set, 'w') as set_file3: set_file3.writelines(lines3) except IndexError: @@ -928,7 +928,7 @@ class FrameWidgets(ttk.Frame): Set (on), the selected tunnel is displayed in the label. At (off) the label is first emptied then filled with No Autoconnect """ - with open(path_to_file2, 'r') as set_file4: + with open(wg_set, 'r') as set_file4: lines4 = set_file4.readlines() if lines4[7] != 'off': @@ -1034,7 +1034,7 @@ class FrameWidgets(ttk.Frame): def color_label(self): """ View activ Tunnel in color green or yellow """ - with open(path_to_file2, 'r') as read_file: + with open(wg_set, 'r') as read_file: lines = read_file.readlines() if 'light\n' in lines: self.lb_tunnel = ttk.Label(self, textvariable=self.StrVar, foreground='green') @@ -1112,7 +1112,7 @@ class FrameWidgets(ttk.Frame): class MyToolTip(tk.Toplevel): TIP_X_OFFSET = 20 TIP_Y_OFFSET = 20 - if not tips: + if not wg_tips: AUTO_CLEAR_TIME = 0 else: AUTO_CLEAR_TIME = 2000 # Millisecond. (1/200 sec.)