-
Notifications
You must be signed in to change notification settings - Fork 0
/
lang.py
186 lines (160 loc) · 6.31 KB
/
lang.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
177
178
179
180
181
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# GUI module generated by PAGE version 5.5
# in conjunction with Tcl version 8.6
# Nov 04, 2020 02:02:54 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
from pathlib import Path
import os
import configparser
import gettext
# _ = gettext.gettext
gettext.install('lang', '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'])
if language == 'de':
lng1 = gettext.translation('lang', \
localedir='locales', \
languages=['de'])
lng1.install()
_ = lng1.gettext
elif language == 'en':
lng2 = gettext.translation('lang', \
localedir='locales', \
languages=['en'])
lng2.install()
_ = lng2.gettext
elif language == 'fr':
lng3 = gettext.translation('lang', \
localedir='locales', \
languages=['fr'])
lng.install()
_ = lng3.gettext
import os.path
from pathlib import Path
import lang_support
def vp_start_gui():
'''Starting point when module is the main routine.'''
global val, w, root
root = tk.Tk()
lang_support.set_Tk_var()
top = frmGetLang (root)
lang_support.init(root, top)
root.mainloop()
def set_lng(language):
''' translate the app '''
lng = gettext.translation('lang_support',\
localedir='locales',\
languages=['de'])
lng.install()
# _ = lng.gettext
w = None
def create_frmGetLang(rt, *args, **kwargs):
'''Starting point when module is imported by another module.
Correct form of call: 'create_frmGetLang(root, *args, **kwargs)' .'''
global w, w_win, root
#rt = root
root = rt
w = tk.Toplevel (root)
lang_support.set_Tk_var()
top = frmGetLang (w)
lang_support.init(w, top, *args, **kwargs)
return (w, top)
def destroy_frmGetLang():
global w
w.destroy()
w = None
class frmGetLang:
def __init__(self, top=None):
'''This class configures and populates the toplevel window.
top is the toplevel containing window.'''
_bgcolor = '#d9d9d9' # X11 color: 'gray85'
_fgcolor = '#000000' # X11 color: 'black'
_compcolor = '#d9d9d9' # X11 color: 'gray85'
_ana1color = '#d9d9d9' # X11 color: 'gray85'
_ana2color = '#ececec' # Closest X11 color: 'gray92'
self.style = ttk.Style()
if sys.platform == "win32":
self.style.theme_use('winnative')
self.style.configure('.',background=_bgcolor)
self.style.configure('.',foreground=_fgcolor)
self.style.configure('.',font="TkDefaultFont")
self.style.map('.',background=
[('selected', _compcolor), ('active',_ana2color)])
top.geometry("300x220+660+210")
top.minsize(120, 1)
top.maxsize(1924, 1061)
top.resizable(0, 0)
top.title(_("Settings"))
top.configure(background="#d9d9d9")
top.configure(highlightbackground="#d9d9d9")
top.configure(highlightcolor="black")
self.btnOk = ttk.Button(top)
self.btnOk.place(x=30, y=180, height=25, width=75)
self.btnOk.configure(takefocus="")
self.btnOk.configure(text=_('''Ok'''))
self.btnOk.bind('<ButtonRelease-1>',lambda e:lang_support.btnOk_LeftRelease(e))
self.btnCancel = ttk.Button(top)
self.btnCancel.place(x=110, y=180, height=25, width=75)
self.btnCancel.configure(takefocus="")
self.btnCancel.configure(text=_('''Cancel'''))
self.btnCancel.bind('<ButtonRelease-1>',lambda e:lang_support.btnCancel_LeftRelease(e))
self.fraSelLanguage = ttk.Labelframe(top)
self.fraSelLanguage.place(x=30, y=80, height=100, width=260)
self.fraSelLanguage.configure(relief='groove')
self.fraSelLanguage.configure(text=_('''Language'''))
self.fraSelLanguage.configure(borderwidth="2")
self.fraSelLanguage.configure(relief="groove")
self.lblSelLanguage = ttk.Label(self.fraSelLanguage)
self.lblSelLanguage.place(x=30, y=30, height=19, width=200
, bordermode='ignore')
self.lblSelLanguage.configure(background="#d9d9d9")
self.lblSelLanguage.configure(foreground="#000000")
self.lblSelLanguage.configure(font="TkDefaultFont")
self.lblSelLanguage.configure(relief="flat")
self.lblSelLanguage.configure(anchor='w')
self.lblSelLanguage.configure(justify='left')
self.lblSelLanguage.configure(text=_('''Select language from below:'''))
self.cboLanguage = ttk.Combobox(self.fraSelLanguage)
self.cboLanguage.place(x=30, y=60, height=25, width=160
, bordermode='ignore')
self.cboLanguage.configure(textvariable=lang_support.strCboLanguage)
self.cboLanguage.configure(takefocus="")
self.btnPathToExe = ttk.Button(top)
self.btnPathToExe.place(x=30, y=10, height=25, width=118)
self.btnPathToExe.configure(takefocus="")
self.btnPathToExe.configure(text=_('''Path to Aqserver.exe'''))
self.btnPathToExe.bind('<ButtonRelease-1>',lambda e:lang_support.btnPathToExe_LeftRelease(e))
self.lblPathToExe = ttk.Label(top)
self.lblPathToExe.place(x=10, y=40, height=25, width=280)
self.lblPathToExe.configure(background="#d9d9d9")
self.lblPathToExe.configure(foreground="#000000")
self.lblPathToExe.configure(font="TkDefaultFont")
self.lblPathToExe.configure(relief="sunken")
self.lblPathToExe.configure(anchor='w')
self.lblPathToExe.configure(justify='left')
self.lblPathToExe.configure(textvariable=lang_support.strPathToAqserver)
if __name__ == '__main__':
set_lng('de')
vp_start_gui()