language_dialog.py
3.96 KB
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
#--------------------------------------------------------------------------
# Software: InVesalius - Software de Reconstrucao 3D de Imagens Medicas
# Copyright: (C) 2001 Centro de Pesquisas Renato Archer
# Homepage: http://www.softwarepublico.gov.br
# Contact: invesalius@cti.gov.br
# License: GNU - GPL 2 (LICENSE.txt/LICENCA.txt)
#--------------------------------------------------------------------------
# Este programa e software livre; voce pode redistribui-lo e/ou
# modifica-lo sob os termos da Licenca Publica Geral GNU, conforme
# publicada pela Free Software Foundation; de acordo com a versao 2
# da Licenca.
#
# Este programa eh distribuido na expectativa de ser util, mas SEM
# QUALQUER GARANTIA; sem mesmo a garantia implicita de
# COMERCIALIZACAO ou de ADEQUACAO A QUALQUER PROPOSITO EM
# PARTICULAR. Consulte a Licenca Publica Geral GNU para obter mais
# detalhes.
#--------------------------------------------------------------------------
import os
import wx
import wx.combo
import i18n
ICON_DIR = os.path.abspath(os.path.join('..', 'icons'))
class LanguageDialog(wx.Dialog):
"""Class define the language to be used in the InVesalius,
exist chcLanguage that list language EN and PT. The language
selected is writing in the config.ini"""
def __init__(self, parent=None, startApp=None):
super(LanguageDialog, self).__init__(parent, title="")
self.__TranslateMessage__()
self.SetTitle(_('Language selection'))
self.__init_gui()
self.Centre()
def __init_combobox_bitmap__(self):
"""Initialize combobox bitmap"""
dict_locales = i18n.GetLocales()
self.locales = dict_locales.values()
self.locales.sort()
print "-------------------"
print self.locales
self.locales_key = [dict_locales.get_key(value)[0] for value in self.locales]
print self.locales_key
self.os_locale = i18n.GetLocaleOS()
os_lang = self.os_locale[0:2]
selection = self.locales_key.index('en')
self.bitmapCmb = bitmapCmb = wx.combo.BitmapComboBox(self, style=wx.CB_READONLY)
for key in self.locales_key:
filepath = os.path.join(ICON_DIR, "%s.bmp"%(key))
bmp = wx.Bitmap(filepath, wx.BITMAP_TYPE_BMP)
bitmapCmb.Append(dict_locales[key], bmp, key)
if key.startswith(os_lang):
selection = self.locales_key.index(key)
bitmapCmb.SetSelection(selection)
def __init_gui(self):
self.txtMsg = wx.StaticText(self, -1,
label=_('Choose user interface language'))
btnsizer = wx.StdDialogButtonSizer()
btn = wx.Button(self, wx.ID_OK)
btn.SetDefault()
btnsizer.AddButton(btn)
btn = wx.Button(self, wx.ID_CANCEL)
btnsizer.AddButton(btn)
btnsizer.Realize()
self.__init_combobox_bitmap__()
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.txtMsg, 0, wx.EXPAND | wx.ALL, 5)
sizer.Add(self.bitmapCmb, 0, wx.EXPAND | wx.ALL, 5)
sizer.Add(btnsizer, 0, wx.EXPAND | wx.ALL, 5)
sizer.Fit(self)
self.SetSizer(sizer)
self.Layout()
self.Update()
self.SetAutoLayout(1)
def GetSelectedLanguage(self):
"""Return String with Selected Language"""
return self.locales_key[self.bitmapCmb.GetSelection()]
def __TranslateMessage__(self):
"""Translate Messages of the Window"""
os_language = i18n.GetLocaleOS()
if(os_language[0:2] == 'pt'):
_ = i18n.InstallLanguage('pt_BR')
elif(os_language[0:2] == 'es'):
_ = i18n.InstallLanguage('es')
else:
_ = i18n.InstallLanguage('en')
def Cancel(self, event):
"""Close Frm_Language"""
self.Close()
event.Skip()