- Preparation for language translation part 4

This commit is contained in:
Désiré Werner Menrath 2024-11-10 11:05:32 +01:00
parent aab90eec70
commit 6a3a982057
3 changed files with 51 additions and 35 deletions

View File

@ -8,6 +8,15 @@ My standard System: Linux Mint 22 Cinnamon
- for loops with lists replaced by List Comprehensions - for loops with lists replaced by List Comprehensions
- Update search after start of Wire-Py - 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 ### Added
08-11-2024 08-11-2024

View File

@ -19,26 +19,27 @@ gettext.bindtextdomain(APP, LOCALE_DIR)
gettext.textdomain(APP) gettext.textdomain(APP)
_ = gettext.gettext _ = 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')) _u = Path.read_text(Path('/tmp/_u'))
class GiteaUpdate: 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) 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, Calling download requests the download URL of the running script,
the taskbar image for the Download OK window, the taskbar image for the taskbar image for the Download OK window, the taskbar image for the
the Download Error window and the variable res Download error window and the variable res
""" """
@staticmethod @staticmethod
def api_down(update_api_url, version): def api_down(update_api_url, version):
try: try:
response = requests.get(update_api_url) response = requests.get(update_api_url)
response_dict = response.json() response_dict = response.json()
response_dict = response_dict[0] 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() set_file = set_file.read()
if 'on\n' in set_file: if 'on\n' in set_file:
if version[3:] != response_dict['tag_name']: if version[3:] != response_dict['tag_name']:
@ -258,9 +259,15 @@ class Tunnel:
except TypeError: except TypeError:
pass pass
class Tipi:
"""
Class for Tooltip setting write in File
Calling request path to file
"""
@staticmethod @staticmethod
def if_tip(): def if_tip(path):
with open(path_to_file2, 'r') as set_file2: with open(path, 'r') as set_file2:
lines2 = set_file2.readlines() lines2 = set_file2.readlines()
if 'False\n' in lines2: if 'False\n' in lines2:
return False return False
@ -268,4 +275,4 @@ class Tunnel:
return True return True
tips = Tunnel.if_tip() wg_tips = Tipi.if_tip(wg_set)

View File

@ -9,7 +9,7 @@ import tkinter as tk
from pathlib import Path from pathlib import Path
from subprocess import check_call from subprocess import check_call
from tkinter import filedialog, ttk, TclError 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') tcl_path = Path('/usr/share/TK-Themes')
@ -46,7 +46,7 @@ class MainWindow(tk.Tk):
self.style = ttk.Style(self) self.style = ttk.Style(self)
self.tk.call('source', str(tcl_path) + '/water.tcl') self.tk.call('source', str(tcl_path) + '/water.tcl')
''' self.tk.call('source', 'TK-Themes/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() lines = read_file.readlines()
if 'light\n' in lines: if 'light\n' in lines:
self.tk.call('set_theme', 'light') self.tk.call('set_theme', 'light')
@ -85,34 +85,34 @@ class FrameWidgets(ttk.Frame):
def update(): def update():
if set_update.get() == 1: 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 = set_file2.readlines()
lines2[1] = 'off\n' 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) set_file2.writelines(lines2)
if set_update.get() == 0: 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 = set_file2.readlines()
lines2[1] = 'on\n' 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_file2.writelines(lines2)
''' Set True or False in file ''' ''' Set True or False in file '''
def tooltip(): def tooltip():
if set_tip.get(): 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 = set_file2.readlines()
lines2[5] = 'False\n' 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) set_file2.writelines(lines2)
else: else:
with open(path_to_file2, 'r') as set_file2: with open(wg_set, 'r') as set_file2:
lines2 = set_file2.readlines() lines2 = set_file2.readlines()
lines2[5] = 'True\n' 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_file2.writelines(lines2)
''' Set dark or light ''' ''' Set dark or light '''
@ -121,10 +121,10 @@ class FrameWidgets(ttk.Frame):
if self.tk.call("ttk::style", "theme", "use") == "water-dark": if self.tk.call("ttk::style", "theme", "use") == "water-dark":
''' Set light theme ''' ''' Set light theme '''
self.tk.call('set_theme', 'light') 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 = theme_set2.readlines()
lines3[3] = 'light\n' 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) theme_set2.writelines(lines3)
self.color_label() self.color_label()
@ -132,10 +132,10 @@ class FrameWidgets(ttk.Frame):
if not self.tk.call("ttk::style", "theme", "use") == "water-dark": if not self.tk.call("ttk::style", "theme", "use") == "water-dark":
''' Set dark theme ''' ''' Set dark theme '''
self.tk.call('set_theme', 'dark') 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 = theme_set2.readlines()
lines4[3] = 'dark\n' 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) theme_set2.writelines(lines4)
self.color_label() self.color_label()
@ -212,7 +212,7 @@ class FrameWidgets(ttk.Frame):
self.updates_lb = ttk.Label(self.menu_frame) self.updates_lb = ttk.Label(self.menu_frame)
self.updates_lb.grid(column=3, row=0, padx=10) self.updates_lb.grid(column=3, row=0, padx=10)
'''View Checkbox for enable or disable Tooltip ''' '''View Checkbox for enable or disable Tooltip '''
if tips: if wg_tips:
set_tip.set(value=False) set_tip.set(value=False)
else: else:
set_tip.set(value=True) set_tip.set(value=True)
@ -420,11 +420,11 @@ class FrameWidgets(ttk.Frame):
pre_key = key[3] pre_key = key[3]
check_call(['nmcli', 'connection', 'delete', select_tl]) check_call(['nmcli', 'connection', 'delete', select_tl])
self.l_box.delete(self.select_tunnel[0]) 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() lines6 = set_file6.readlines()
if select_tl == lines6[7].strip() and 'off' not in lines6[7].strip(): if select_tl == lines6[7].strip() and 'off' not in lines6[7].strip():
lines6[7] = 'off' lines6[7] = 'off'
with open(path_to_file2, 'w') as set_file7: with open(wg_set, 'w') as set_file7:
set_file7.writelines(lines6) set_file7.writelines(lines6)
self.selected_option.set(0) self.selected_option.set(0)
self.autoconnect_var.set(_('no Autoconnect')) self.autoconnect_var.set(_('no Autoconnect'))
@ -642,11 +642,11 @@ class FrameWidgets(ttk.Frame):
if self.a != '' and self.a == select_tl: if self.a != '' and self.a == select_tl:
self.a = Tunnel.active() self.a = Tunnel.active()
self.StrVar.set(value=self.a) 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() lines5 = set_file5.readlines()
if select_tl == lines5[7].strip() and 'off' not in lines5[7].strip(): if select_tl == lines5[7].strip() and 'off' not in lines5[7].strip():
lines5[7] = new_a_connect 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) theme_set5.writelines(lines5)
self.autoconnect_var.set(value=new_a_connect) 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]) select_tl = self.l_box.get(select_tunnel[0])
if self.selected_option.get() == 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 = set_file3.readlines()
lines3[7] = 'off' lines3[7] = 'off'
with open(path_to_file2, 'w') as set_file3: with open(wg_set, 'w') as set_file3:
set_file3.writelines(lines3) set_file3.writelines(lines3)
tl = Tunnel.list() tl = Tunnel.list()
@ -911,10 +911,10 @@ class FrameWidgets(ttk.Frame):
self.wg_autostart.configure(state='disabled') self.wg_autostart.configure(state='disabled')
if self.selected_option.get() >= 1: 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 = set_file3.readlines()
lines3[7] = select_tl 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) set_file3.writelines(lines3)
except IndexError: except IndexError:
@ -928,7 +928,7 @@ class FrameWidgets(ttk.Frame):
Set (on), the selected tunnel is displayed in the label. Set (on), the selected tunnel is displayed in the label.
At (off) the label is first emptied then filled with No Autoconnect 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() lines4 = set_file4.readlines()
if lines4[7] != 'off': if lines4[7] != 'off':
@ -1034,7 +1034,7 @@ class FrameWidgets(ttk.Frame):
def color_label(self): def color_label(self):
""" View activ Tunnel in color green or yellow """ """ 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() lines = read_file.readlines()
if 'light\n' in lines: if 'light\n' in lines:
self.lb_tunnel = ttk.Label(self, textvariable=self.StrVar, foreground='green') self.lb_tunnel = ttk.Label(self, textvariable=self.StrVar, foreground='green')
@ -1112,7 +1112,7 @@ class FrameWidgets(ttk.Frame):
class MyToolTip(tk.Toplevel): class MyToolTip(tk.Toplevel):
TIP_X_OFFSET = 20 TIP_X_OFFSET = 20
TIP_Y_OFFSET = 20 TIP_Y_OFFSET = 20
if not tips: if not wg_tips:
AUTO_CLEAR_TIME = 0 AUTO_CLEAR_TIME = 0
else: else:
AUTO_CLEAR_TIME = 2000 # Millisecond. (1/200 sec.) AUTO_CLEAR_TIME = 2000 # Millisecond. (1/200 sec.)