Commit e58244f783849d4efecb44f95e13376e19ed563f
1 parent
aa3b6fed
Exists in
master
and in
67 other branches
ENH: Added language change in the preferences window
Showing
4 changed files
with
98 additions
and
26 deletions
Show diff stats
invesalius/constants.py
@@ -508,3 +508,4 @@ STYLE_LEVEL = {SLICE_STATE_EDITOR: 1, | @@ -508,3 +508,4 @@ STYLE_LEVEL = {SLICE_STATE_EDITOR: 1, | ||
508 | #------------ Prefereces options key ------------ | 508 | #------------ Prefereces options key ------------ |
509 | RENDERING = 0 | 509 | RENDERING = 0 |
510 | SURFACE_INTERPOLATION = 1 | 510 | SURFACE_INTERPOLATION = 1 |
511 | +LANGUAGE = 2 |
invesalius/gui/frame.py
@@ -330,10 +330,11 @@ class Frame(wx.Frame): | @@ -330,10 +330,11 @@ class Frame(wx.Frame): | ||
330 | if self.preferences.ShowModal() == wx.ID_OK: | 330 | if self.preferences.ShowModal() == wx.ID_OK: |
331 | values = self.preferences.GetPreferences() | 331 | values = self.preferences.GetPreferences() |
332 | self.preferences.Close() | 332 | self.preferences.Close() |
333 | - | 333 | + |
334 | ses.Session().rendering = values[const.RENDERING] | 334 | ses.Session().rendering = values[const.RENDERING] |
335 | ses.Session().surface_interpolation = values[const.SURFACE_INTERPOLATION] | 335 | ses.Session().surface_interpolation = values[const.SURFACE_INTERPOLATION] |
336 | - | 336 | + ses.Session().language = values[const.LANGUAGE] |
337 | + | ||
337 | ps.Publisher().sendMessage('Remove Volume') | 338 | ps.Publisher().sendMessage('Remove Volume') |
338 | ps.Publisher().sendMessage('Reset Reaycasting') | 339 | ps.Publisher().sendMessage('Reset Reaycasting') |
339 | ps.Publisher().sendMessage('Update Surface Interpolation') | 340 | ps.Publisher().sendMessage('Update Surface Interpolation') |
invesalius/gui/language_dialog.py
@@ -25,19 +25,9 @@ import i18n | @@ -25,19 +25,9 @@ import i18n | ||
25 | 25 | ||
26 | ICON_DIR = os.path.abspath(os.path.join('..', 'icons')) | 26 | ICON_DIR = os.path.abspath(os.path.join('..', 'icons')) |
27 | 27 | ||
28 | -class LanguageDialog(wx.Dialog): | ||
29 | - """Class define the language to be used in the InVesalius, | ||
30 | - exist chcLanguage that list language EN and PT. The language | ||
31 | - selected is writing in the config.ini""" | 28 | +class ComboBoxLanguage: |
32 | 29 | ||
33 | - def __init__(self, parent=None, startApp=None): | ||
34 | - super(LanguageDialog, self).__init__(parent, title="") | ||
35 | - self.__TranslateMessage__() | ||
36 | - self.SetTitle(_('Language selection')) | ||
37 | - self.__init_gui() | ||
38 | - self.Centre() | ||
39 | - | ||
40 | - def __init_combobox_bitmap__(self): | 30 | + def __init__(self, parent): |
41 | """Initialize combobox bitmap""" | 31 | """Initialize combobox bitmap""" |
42 | 32 | ||
43 | # Retrieve locales dictionary | 33 | # Retrieve locales dictionary |
@@ -59,7 +49,7 @@ class LanguageDialog(wx.Dialog): | @@ -59,7 +49,7 @@ class LanguageDialog(wx.Dialog): | ||
59 | selection = self.locales_key.index('en') | 49 | selection = self.locales_key.index('en') |
60 | 50 | ||
61 | # Create bitmap combo | 51 | # Create bitmap combo |
62 | - self.bitmapCmb = bitmapCmb = wx.combo.BitmapComboBox(self, style=wx.CB_READONLY) | 52 | + self.bitmapCmb = bitmapCmb = wx.combo.BitmapComboBox(parent, style=wx.CB_READONLY) |
63 | for key in self.locales_key: | 53 | for key in self.locales_key: |
64 | # Based on composed flag filename, get bitmap | 54 | # Based on composed flag filename, get bitmap |
65 | filepath = os.path.join(ICON_DIR, "%s.bmp"%(key)) | 55 | filepath = os.path.join(ICON_DIR, "%s.bmp"%(key)) |
@@ -71,6 +61,61 @@ class LanguageDialog(wx.Dialog): | @@ -71,6 +61,61 @@ class LanguageDialog(wx.Dialog): | ||
71 | selection = self.locales_key.index(key) | 61 | selection = self.locales_key.index(key) |
72 | bitmapCmb.SetSelection(selection) | 62 | bitmapCmb.SetSelection(selection) |
73 | 63 | ||
64 | + def GetComboBox(self): | ||
65 | + return self.bitmapCmb | ||
66 | + | ||
67 | + def GetLocalesKey(self): | ||
68 | + return self.locales_key | ||
69 | + | ||
70 | +class LanguageDialog(wx.Dialog): | ||
71 | + """Class define the language to be used in the InVesalius, | ||
72 | + exist chcLanguage that list language EN and PT. The language | ||
73 | + selected is writing in the config.ini""" | ||
74 | + | ||
75 | + def __init__(self, parent=None, startApp=None): | ||
76 | + super(LanguageDialog, self).__init__(parent, title="") | ||
77 | + self.__TranslateMessage__() | ||
78 | + self.SetTitle(_('Language selection')) | ||
79 | + self.__init_gui() | ||
80 | + self.Centre() | ||
81 | + | ||
82 | + #def __init_combobox_bitmap__(self): | ||
83 | + # """Initialize combobox bitmap""" | ||
84 | + | ||
85 | + # # Retrieve locales dictionary | ||
86 | + # dict_locales = i18n.GetLocales() | ||
87 | + | ||
88 | + # # Retrieve locales names and sort them | ||
89 | + # self.locales = dict_locales.values() | ||
90 | + # self.locales.sort() | ||
91 | + | ||
92 | + # # Retrieve locales keys (eg: pt_BR for Portuguese(Brazilian)) | ||
93 | + # self.locales_key = [dict_locales.get_key(value)[0] for value in self.locales] | ||
94 | + | ||
95 | + # # Find out OS locale | ||
96 | + # self.os_locale = i18n.GetLocaleOS() | ||
97 | + | ||
98 | + # os_lang = self.os_locale[0:2] | ||
99 | + | ||
100 | + # # Default selection will be English | ||
101 | + # selection = self.locales_key.index('en') | ||
102 | + | ||
103 | + # # Create bitmap combo | ||
104 | + # self.bitmapCmb = bitmapCmb = wx.combo.BitmapComboBox(self, style=wx.CB_READONLY) | ||
105 | + # for key in self.locales_key: | ||
106 | + # # Based on composed flag filename, get bitmap | ||
107 | + # filepath = os.path.join(ICON_DIR, "%s.bmp"%(key)) | ||
108 | + # bmp = wx.Bitmap(filepath, wx.BITMAP_TYPE_BMP) | ||
109 | + # # Add bitmap and info to Combo | ||
110 | + # bitmapCmb.Append(dict_locales[key], bmp, key) | ||
111 | + # # Set default combo item if available on the list | ||
112 | + # if key.startswith(os_lang): | ||
113 | + # selection = self.locales_key.index(key) | ||
114 | + # bitmapCmb.SetSelection(selection) | ||
115 | + | ||
116 | + def GetComboBox(self): | ||
117 | + return self.bitmapCmb | ||
118 | + | ||
74 | 119 | ||
75 | def __init_gui(self): | 120 | def __init_gui(self): |
76 | self.txtMsg = wx.StaticText(self, -1, | 121 | self.txtMsg = wx.StaticText(self, -1, |
@@ -86,7 +131,9 @@ class LanguageDialog(wx.Dialog): | @@ -86,7 +131,9 @@ class LanguageDialog(wx.Dialog): | ||
86 | btnsizer.AddButton(btn) | 131 | btnsizer.AddButton(btn) |
87 | btnsizer.Realize() | 132 | btnsizer.Realize() |
88 | 133 | ||
89 | - self.__init_combobox_bitmap__() | 134 | + #self.__init_combobox_bitmap__() |
135 | + self.cmb = ComboBoxLanguage(self) | ||
136 | + self.bitmapCmb = self.cmb.GetComboBox() | ||
90 | 137 | ||
91 | sizer = wx.BoxSizer(wx.VERTICAL) | 138 | sizer = wx.BoxSizer(wx.VERTICAL) |
92 | sizer.Add(self.txtMsg, 0, wx.EXPAND | wx.ALL, 5) | 139 | sizer.Add(self.txtMsg, 0, wx.EXPAND | wx.ALL, 5) |
@@ -101,6 +148,7 @@ class LanguageDialog(wx.Dialog): | @@ -101,6 +148,7 @@ class LanguageDialog(wx.Dialog): | ||
101 | 148 | ||
102 | def GetSelectedLanguage(self): | 149 | def GetSelectedLanguage(self): |
103 | """Return String with Selected Language""" | 150 | """Return String with Selected Language""" |
151 | + self.locales_key = self.cmb.GetLocalesKey() | ||
104 | return self.locales_key[self.bitmapCmb.GetSelection()] | 152 | return self.locales_key[self.bitmapCmb.GetSelection()] |
105 | 153 | ||
106 | def __TranslateMessage__(self): | 154 | def __TranslateMessage__(self): |
invesalius/gui/preferences.py
@@ -2,6 +2,7 @@ import wx | @@ -2,6 +2,7 @@ import wx | ||
2 | import constants as const | 2 | import constants as const |
3 | import wx.lib.pubsub as ps | 3 | import wx.lib.pubsub as ps |
4 | import session as ses | 4 | import session as ses |
5 | +from language_dialog import ComboBoxLanguage | ||
5 | 6 | ||
6 | ID = wx.NewId() | 7 | ID = wx.NewId() |
7 | 8 | ||
@@ -59,15 +60,22 @@ class Preferences(wx.Dialog): | @@ -59,15 +60,22 @@ class Preferences(wx.Dialog): | ||
59 | 60 | ||
60 | 61 | ||
61 | def GetPreferences(self): | 62 | def GetPreferences(self): |
62 | - | ||
63 | - return self.pnl_viewer3d.GetSelection() | 63 | + values = {} |
64 | + lang = self.pnl_language.GetSelection() | ||
65 | + viewer = self.pnl_viewer3d.GetSelection() | ||
66 | + values.update(lang) | ||
67 | + values.update(viewer) | ||
68 | + return values | ||
64 | 69 | ||
65 | def LoadPreferences(self, pub_evt): | 70 | def LoadPreferences(self, pub_evt): |
66 | - | ||
67 | - values = {const.RENDERING:ses.Session().rendering, | ||
68 | - const.SURFACE_INTERPOLATION:ses.Session().surface_interpolation} | 71 | + se = ses.Session() |
72 | + values = {const.RENDERING:se.rendering, | ||
73 | + const.SURFACE_INTERPOLATION:se.surface_interpolation, | ||
74 | + const.LANGUAGE:se.language | ||
75 | + } | ||
69 | 76 | ||
70 | self.pnl_viewer3d.LoadSelection(values) | 77 | self.pnl_viewer3d.LoadSelection(values) |
78 | + self.pnl_language.LoadSelection(values) | ||
71 | 79 | ||
72 | 80 | ||
73 | 81 | ||
@@ -126,17 +134,31 @@ class Language(wx.Panel): | @@ -126,17 +134,31 @@ class Language(wx.Panel): | ||
126 | def __init__(self, parent): | 134 | def __init__(self, parent): |
127 | 135 | ||
128 | wx.Panel.__init__(self, parent) | 136 | wx.Panel.__init__(self, parent) |
129 | - | ||
130 | 137 | ||
138 | + self.lg = lg = ComboBoxLanguage(self) | ||
139 | + self.cmb_lang = cmb_lang = lg.GetComboBox() | ||
140 | + | ||
131 | box = wx.StaticBox(self, -1, "Language") | 141 | box = wx.StaticBox(self, -1, "Language") |
132 | bsizer = wx.StaticBoxSizer(box, wx.VERTICAL) | 142 | bsizer = wx.StaticBoxSizer(box, wx.VERTICAL) |
133 | - | ||
134 | - t = wx.StaticText(self, -1, "Control Test....") | ||
135 | - bsizer.Add(t, 0, wx.TOP|wx.LEFT, 10) | ||
136 | - | 143 | + |
144 | + text = wx.StaticText(self, -1, "Takes effect the next time you \n open the InVesalius.") | ||
145 | + bsizer.Add(cmb_lang, 0, wx.TOP|wx.CENTER, 20) | ||
146 | + bsizer.Add(text, 0, wx.TOP|wx.CENTER, 10) | ||
137 | 147 | ||
138 | border = wx.BoxSizer() | 148 | border = wx.BoxSizer() |
139 | border.Add(bsizer, 1, wx.EXPAND|wx.ALL, 20) | 149 | border.Add(bsizer, 1, wx.EXPAND|wx.ALL, 20) |
140 | self.SetSizer(border) | 150 | self.SetSizer(border) |
141 | 151 | ||
142 | border.Fit(self) | 152 | border.Fit(self) |
153 | + | ||
154 | + def GetSelection(self): | ||
155 | + selection = self.cmb_lang.GetSelection() | ||
156 | + locales = self.lg.GetLocalesKey() | ||
157 | + options = {const.LANGUAGE:locales[selection]} | ||
158 | + return options | ||
159 | + | ||
160 | + def LoadSelection(self, values): | ||
161 | + language = values[const.LANGUAGE] | ||
162 | + locales = self.lg.GetLocalesKey() | ||
163 | + selection = locales.index(language) | ||
164 | + self.cmb_lang.SetSelection(int(selection)) |