From e58244f783849d4efecb44f95e13376e19ed563f Mon Sep 17 00:00:00 2001 From: paulojamorim Date: Fri, 27 May 2011 16:48:40 +0000 Subject: [PATCH] ENH: Added language change in the preferences window --- invesalius/constants.py | 1 + invesalius/gui/frame.py | 5 +++-- invesalius/gui/language_dialog.py | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------- invesalius/gui/preferences.py | 42 ++++++++++++++++++++++++++++++++---------- 4 files changed, 98 insertions(+), 26 deletions(-) diff --git a/invesalius/constants.py b/invesalius/constants.py index b666e72..19fbea5 100644 --- a/invesalius/constants.py +++ b/invesalius/constants.py @@ -508,3 +508,4 @@ STYLE_LEVEL = {SLICE_STATE_EDITOR: 1, #------------ Prefereces options key ------------ RENDERING = 0 SURFACE_INTERPOLATION = 1 +LANGUAGE = 2 diff --git a/invesalius/gui/frame.py b/invesalius/gui/frame.py index 22b04f8..69d9e00 100755 --- a/invesalius/gui/frame.py +++ b/invesalius/gui/frame.py @@ -330,10 +330,11 @@ class Frame(wx.Frame): if self.preferences.ShowModal() == wx.ID_OK: values = self.preferences.GetPreferences() self.preferences.Close() - + ses.Session().rendering = values[const.RENDERING] ses.Session().surface_interpolation = values[const.SURFACE_INTERPOLATION] - + ses.Session().language = values[const.LANGUAGE] + ps.Publisher().sendMessage('Remove Volume') ps.Publisher().sendMessage('Reset Reaycasting') ps.Publisher().sendMessage('Update Surface Interpolation') diff --git a/invesalius/gui/language_dialog.py b/invesalius/gui/language_dialog.py index a4f0861..d147e6c 100644 --- a/invesalius/gui/language_dialog.py +++ b/invesalius/gui/language_dialog.py @@ -25,19 +25,9 @@ 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""" +class ComboBoxLanguage: - 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): + def __init__(self, parent): """Initialize combobox bitmap""" # Retrieve locales dictionary @@ -59,7 +49,7 @@ class LanguageDialog(wx.Dialog): selection = self.locales_key.index('en') # Create bitmap combo - self.bitmapCmb = bitmapCmb = wx.combo.BitmapComboBox(self, style=wx.CB_READONLY) + self.bitmapCmb = bitmapCmb = wx.combo.BitmapComboBox(parent, style=wx.CB_READONLY) for key in self.locales_key: # Based on composed flag filename, get bitmap filepath = os.path.join(ICON_DIR, "%s.bmp"%(key)) @@ -71,6 +61,61 @@ class LanguageDialog(wx.Dialog): selection = self.locales_key.index(key) bitmapCmb.SetSelection(selection) + def GetComboBox(self): + return self.bitmapCmb + + def GetLocalesKey(self): + return self.locales_key + +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""" + + # # Retrieve locales dictionary + # dict_locales = i18n.GetLocales() + + # # Retrieve locales names and sort them + # self.locales = dict_locales.values() + # self.locales.sort() + + # # Retrieve locales keys (eg: pt_BR for Portuguese(Brazilian)) + # self.locales_key = [dict_locales.get_key(value)[0] for value in self.locales] + + # # Find out OS locale + # self.os_locale = i18n.GetLocaleOS() + + # os_lang = self.os_locale[0:2] + + # # Default selection will be English + # selection = self.locales_key.index('en') + + # # Create bitmap combo + # self.bitmapCmb = bitmapCmb = wx.combo.BitmapComboBox(self, style=wx.CB_READONLY) + # for key in self.locales_key: + # # Based on composed flag filename, get bitmap + # filepath = os.path.join(ICON_DIR, "%s.bmp"%(key)) + # bmp = wx.Bitmap(filepath, wx.BITMAP_TYPE_BMP) + # # Add bitmap and info to Combo + # bitmapCmb.Append(dict_locales[key], bmp, key) + # # Set default combo item if available on the list + # if key.startswith(os_lang): + # selection = self.locales_key.index(key) + # bitmapCmb.SetSelection(selection) + + def GetComboBox(self): + return self.bitmapCmb + def __init_gui(self): self.txtMsg = wx.StaticText(self, -1, @@ -86,7 +131,9 @@ class LanguageDialog(wx.Dialog): btnsizer.AddButton(btn) btnsizer.Realize() - self.__init_combobox_bitmap__() + #self.__init_combobox_bitmap__() + self.cmb = ComboBoxLanguage(self) + self.bitmapCmb = self.cmb.GetComboBox() sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(self.txtMsg, 0, wx.EXPAND | wx.ALL, 5) @@ -101,6 +148,7 @@ class LanguageDialog(wx.Dialog): def GetSelectedLanguage(self): """Return String with Selected Language""" + self.locales_key = self.cmb.GetLocalesKey() return self.locales_key[self.bitmapCmb.GetSelection()] def __TranslateMessage__(self): diff --git a/invesalius/gui/preferences.py b/invesalius/gui/preferences.py index 5142dc1..25840f5 100644 --- a/invesalius/gui/preferences.py +++ b/invesalius/gui/preferences.py @@ -2,6 +2,7 @@ import wx import constants as const import wx.lib.pubsub as ps import session as ses +from language_dialog import ComboBoxLanguage ID = wx.NewId() @@ -59,15 +60,22 @@ class Preferences(wx.Dialog): def GetPreferences(self): - - return self.pnl_viewer3d.GetSelection() + values = {} + lang = self.pnl_language.GetSelection() + viewer = self.pnl_viewer3d.GetSelection() + values.update(lang) + values.update(viewer) + return values def LoadPreferences(self, pub_evt): - - values = {const.RENDERING:ses.Session().rendering, - const.SURFACE_INTERPOLATION:ses.Session().surface_interpolation} + se = ses.Session() + values = {const.RENDERING:se.rendering, + const.SURFACE_INTERPOLATION:se.surface_interpolation, + const.LANGUAGE:se.language + } self.pnl_viewer3d.LoadSelection(values) + self.pnl_language.LoadSelection(values) @@ -126,17 +134,31 @@ class Language(wx.Panel): def __init__(self, parent): wx.Panel.__init__(self, parent) - + self.lg = lg = ComboBoxLanguage(self) + self.cmb_lang = cmb_lang = lg.GetComboBox() + box = wx.StaticBox(self, -1, "Language") bsizer = wx.StaticBoxSizer(box, wx.VERTICAL) - - t = wx.StaticText(self, -1, "Control Test....") - bsizer.Add(t, 0, wx.TOP|wx.LEFT, 10) - + + text = wx.StaticText(self, -1, "Takes effect the next time you \n open the InVesalius.") + bsizer.Add(cmb_lang, 0, wx.TOP|wx.CENTER, 20) + bsizer.Add(text, 0, wx.TOP|wx.CENTER, 10) border = wx.BoxSizer() border.Add(bsizer, 1, wx.EXPAND|wx.ALL, 20) self.SetSizer(border) border.Fit(self) + + def GetSelection(self): + selection = self.cmb_lang.GetSelection() + locales = self.lg.GetLocalesKey() + options = {const.LANGUAGE:locales[selection]} + return options + + def LoadSelection(self, values): + language = values[const.LANGUAGE] + locales = self.lg.GetLocalesKey() + selection = locales.index(language) + self.cmb_lang.SetSelection(int(selection)) -- libgit2 0.21.2