-
Notifications
You must be signed in to change notification settings - Fork 0
/
lang_support.py
181 lines (156 loc) · 4.9 KB
/
lang_support.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# Support module generated by PAGE version 5.5
# in conjunction with Tcl version 8.6
# Nov 03, 2020 05:11:06 PM CET platform: Windows NT
# Nov 04, 2020 12:15:22 PM CET platform: Windows NT
# Nov 04, 2020 02:03:01 PM CET platform: Windows NT
import sys
try:
import Tkinter as tk
except ImportError:
import tkinter as tk
try:
import ttk
py3 = False
except ImportError:
import tkinter.ttk as ttk
py3 = True
try:
from Tkinter import *
import tkMessageBox
import tkFont
import tkFileDialog
except ImportError:
from tkinter import *
from tkinter import messagebox
from tkinter import font
from tkinter import filedialog
import configparser
import os
import os.path
from pathlib import Path
import configparser
import gettext
# _ = gettext.gettext
gettext.install('lang_support', 'locales')
cfg = Path(os.getcwd() + '\\config.ini')
if cfg.is_file():
config = configparser.ConfigParser()
config.optionxform = str
try:
config.read(cfg, encoding='utf-8')
except BaseException:
try:
config.read(cfg, encoding='ANSI')
except Exception as e:
messagebox.showerror('Read config file', e)
language = (config['aqconfig']['language'])
print(language)
if language == 'de':
lng1 = gettext.translation('lang_support', \
localedir='locales', \
languages=['de'])
lng1.install()
_ = lng1.gettext
elif language == 'en':
lng2 = gettext.translation('lang_support', \
localedir='locales', \
languages=['en'])
lng2.install()
_ = lng2.gettext
elif language == 'fr':
lng3 = gettext.translation('lang_support', \
localedir='locales', \
languages=['fr'])
lng.install()
_ = lng3.gettext
def set_Tk_var():
global strPathToAqserver
strPathToAqserver = tk.StringVar()
strPathToAqserver.set('')
global strCboLanguage
strCboLanguage = tk.StringVar()
def set_lng(language):
''' translate the app '''
de = gettext.translation('lang_support',\
localedir='locales',\
languages=['de'])
de.install()
# _ = de.gettext
def fill_label():
global strPathToAqserver
config = configparser.ConfigParser()
fName = os.getcwd() + '\\config.ini'
config.read(fName)
strPathToAqserver.set(config['aqserver'] ['exefile'])
def fill_combo():
global strCboLanguage
config = configparser.ConfigParser()
fName = os.getcwd() + '\\config.ini'
config.read(fName)
languages =['English', 'Deutsch', 'Francais']
lang = ['en', 'de', 'fr']
i=0
for language in lang:
if language == config['aqconfig'] ['language']:
lng = languages[i]
i += 1
for language in languages:
# fill the trigger combobox
w.cboLanguage['values'] = (*w.cboLanguage['values'], language)
strCboLanguage.set(lng)
def set_value_config_file(file_path, section, key, value):
config = configparser.RawConfigParser()
config.read(file_path)
config.set(section,key,value)
cfgfile = open(file_path,'w')
# use following flag in case you need to avoid white space
config.write(cfgfile, space_around_delimiters=False)
cfgfile.close()
def init(top, gui, *args, **kwargs):
global w, top_level, root
w = gui
top_level = top
root = top
root.iconbitmap('./assets/aqconfig.ico')
fill_label()
fill_combo()
def btnCancel_LeftRelease(p1):
destroy_window()
def btnOk_LeftRelease(p1):
global strCboLanguage
languages =['English', 'Deutsch', 'Francais']
lang = ['en', 'de', 'fr']
#save to aqconfig.ini
fName = os.getcwd() + '\\config.ini'
language = strCboLanguage.get()
i=0
for language in languages:
if language == strCboLanguage.get():
lng = lang[i]
i += 1
set_value_config_file(fName, 'aqconfig', 'language',lng)
destroy_window()
def btnPathToExe_LeftRelease(p1):
global strPathToAqserver
if (py3 == 1) or (py3 == True):
myPath = filedialog.askdirectory(title = _("Get path of aqserver.exe"))
else:
myPath = filedialog.askdirectory(title = _("Get path of aqserver.exe"))
myPath = myPath + '/aqserver.exe'
myPath = myPath.replace('/', '\\')
#save to aqconfig.ini
fName = os.getcwd() + '\\config.ini'
set_value_config_file(fName, 'aqserver', 'exefile', myPath)
strPathToAqserver.set(myPath)
def destroy_window():
# Function which closes the window.
global top_level
top_level.destroy()
top_level = None
if __name__ == '__main__':
import lang
set_lng('de')
lang.vp_start_gui()