- Preparation for language translation part 3

This commit is contained in:
Désiré Werner Menrath 2024-11-10 00:23:49 +01:00
parent 511d5f72df
commit aab90eec70
2 changed files with 34 additions and 16 deletions

View File

@ -1,4 +1,4 @@
""" Wireguard Classes and Method for Wire-Py """ """ Classes Method and functions for lx apps """
import gettext import gettext
import locale import locale
@ -18,16 +18,22 @@ locale.bindtextdomain(APP, LOCALE_DIR)
gettext.bindtextdomain(APP, LOCALE_DIR) gettext.bindtextdomain(APP, LOCALE_DIR)
gettext.textdomain(APP) gettext.textdomain(APP)
_ = gettext.gettext _ = gettext.gettext
''' 1 = 1. Year, 09 = Month of the Year, 2924 = Day and Year of the Year '''
version = 'v. 1.11.0924'
path_to_file2 = Path('/etc/wire_py/settings.conf') path_to_file2 = 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.
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
"""
@staticmethod @staticmethod
def api_down(update_api_url): 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()
@ -45,7 +51,7 @@ class GiteaUpdate:
return 'No Internet Connection!' return 'No Internet Connection!'
@staticmethod @staticmethod
def download(urld): def download(urld, down_ok_image, down_not_ok_image, res):
try: try:
to_down = 'wget -qP ' + str(_u) + ' ' + urld to_down = 'wget -qP ' + str(_u) + ' ' + urld
result = subprocess.call(to_down, shell=True) result = subprocess.call(to_down, shell=True)
@ -53,7 +59,7 @@ class GiteaUpdate:
shutil.chown(str(_u) + f'/{res}.zip', 1000, 1000) shutil.chown(str(_u) + f'/{res}.zip', 1000, 1000)
"""img_w, img_i, w_title, w_txt hand over""" """img_w, img_i, w_title, w_txt hand over"""
iw = r'/usr/share/icons/lx-icons/64/info.png' iw = r'/usr/share/icons/lx-icons/64/info.png'
ii = r'/usr/share/icons/wp-icons/48/wg_vpn.png' ii = down_ok_image
wt = _('Download Successful') wt = _('Download Successful')
msg_t = _('Your zip file is in home directory') msg_t = _('Your zip file is in home directory')
msg_window(iw, ii, wt, msg_t) msg_window(iw, ii, wt, msg_t)
@ -61,22 +67,19 @@ class GiteaUpdate:
else: else:
"""img_w, img_i, w_title, w_txt hand over""" """img_w, img_i, w_title, w_txt hand over"""
iw = r'/usr/share/icons/lx-icons/64/error.png' iw = r'/usr/share/icons/lx-icons/64/error.png'
ii = r'/usr/share/icons/wp-icons/48/wg_msg.png' ii = down_not_ok_image
wt = _('Download error') wt = _('Download error')
msg_t = _('Download failed! Please try again') msg_t = _('Download failed! Please try again')
msg_window(iw, ii, wt, msg_t) msg_window(iw, ii, wt, msg_t)
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
"""img_w, img_i, w_title, w_txt hand over""" """img_w, img_i, w_title, w_txt hand over"""
iw = r'/usr/share/icons/lx-icons/64/error.png' iw = r'/usr/share/icons/lx-icons/64/error.png'
ii = r'/usr/share/icons/wg-icons/48/wg_msg.png' ii = down_not_ok_image
wt = _('Download error') wt = _('Download error')
msg_t = _('Download failed! No internet connection!') msg_t = _('Download failed! No internet connection!')
msg_window(iw, ii, wt, msg_t) msg_window(iw, ii, wt, msg_t)
res = GiteaUpdate.api_down('https://git.ilunix.de/api/v1/repos/punix/Wire-Py/releases')
def msg_window(img_w, img_i, w_title, w_txt, txt2=None, com=None): 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. Function for different message windows for the user. with 4 arguments to be passed.
@ -86,6 +89,8 @@ def msg_window(img_w, img_i, w_title, w_txt, txt2=None, com=None):
img_i = Image for Icon img_i = Image for Icon
w_title = Windows Title w_title = Windows Title
w_txt = Text for Tk Window w_txt = Text for Tk Window
txt2 = Text for Button two
com = function for Button command
""" """
msg = tk.Toplevel() msg = tk.Toplevel()

View File

@ -1,4 +1,5 @@
#!/usr/bin/python3 #!/usr/bin/python3
import gettext import gettext
import locale import locale
import os import os
@ -8,12 +9,17 @@ 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, res, _u, version, path_to_file2, tips)
tcl_path = Path('/usr/share/TK-Themes') tcl_path = Path('/usr/share/TK-Themes')
APP = 'wg_main' ''' 1 = 1. Year, 09 = Month of the Year, 2924 = Day and Year of the Year '''
version = 'v. 1.11.0924'
res = GiteaUpdate.api_down('https://git.ilunix.de/api/v1/repos/punix/Wire-Py/releases', version)
''' Translate '''
APP = 'wirepy'
LOCALE_DIR = "/usr/share/locale/" LOCALE_DIR = "/usr/share/locale/"
locale.bindtextdomain(APP, LOCALE_DIR) locale.bindtextdomain(APP, LOCALE_DIR)
gettext.bindtextdomain(APP, LOCALE_DIR) gettext.bindtextdomain(APP, LOCALE_DIR)
@ -266,8 +272,15 @@ class FrameWidgets(ttk.Frame):
self.download = tk.Menu(self, relief='flat') self.download = tk.Menu(self, relief='flat')
self.update_btn.configure(menu=self.download, style='Toolbutton') self.update_btn.configure(menu=self.download, style='Toolbutton')
self.download.add_command(label=_('Download'), command=GiteaUpdate.download(f'https://git.ilunix.de/punix' self.download.add_command(label=_('Download'),
f'/Wire-Py/archive/{res}.zip')) command=lambda: GiteaUpdate.download(f'https://git.ilunix.de/punix'
f'/Wire-Py/archive/'
f'{res}.zip', r'/usr/'
r'share/icons/wp-icons'
r'/48/wg_vpn.png',
r'/usr/share/icons/wp-icons'
r'/48/wg_msg.png', res))
''' Show active Tunnel ''' ''' Show active Tunnel '''
self.a = Tunnel.active() self.a = Tunnel.active()