From e0376d66e6fcadb0540ac1828fbbeed28347e238 Mon Sep 17 00:00:00 2001 From: paulojamorim Date: Wed, 6 Jan 2010 12:59:35 +0000 Subject: [PATCH] ENH: Beginning of the internationalization, reffer ticket 52 --- .gitattributes | 2 ++ invesalius/gui/language_dialog.py | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ invesalius/i18n.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ invesalius/invesalius.py | 29 ++++++++++++++++++++++++++--- invesalius/session.py | 8 +++++++- 5 files changed, 211 insertions(+), 4 deletions(-) create mode 100644 invesalius/gui/language_dialog.py create mode 100644 invesalius/i18n.py diff --git a/.gitattributes b/.gitattributes index 8f64acc..99c58bc 100644 --- a/.gitattributes +++ b/.gitattributes @@ -127,6 +127,7 @@ invesalius/gui/dicom_preview_panel.py -text invesalius/gui/frame.py -text invesalius/gui/import_data_wizard.py -text invesalius/gui/import_panel.py -text +invesalius/gui/language_dialog.py -text invesalius/gui/task_exporter.py -text invesalius/gui/task_generic.py -text invesalius/gui/task_importer.py -text @@ -139,6 +140,7 @@ invesalius/gui/widgets/foldpanelbar.py -text invesalius/gui/widgets/gradient.py -text invesalius/gui/widgets/listctrl.py -text invesalius/gui/widgets/slice_menu.py -text +invesalius/i18n.py -text invesalius/invesalius.py -text invesalius/presets.py -text invesalius/project.py -text diff --git a/invesalius/gui/language_dialog.py b/invesalius/gui/language_dialog.py new file mode 100644 index 0000000..d5ffe89 --- /dev/null +++ b/invesalius/gui/language_dialog.py @@ -0,0 +1,130 @@ +#-------------------------------------------------------------------------- +# 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 +import constants as const + +def create(parent): + return LanguageDialog(parent) + +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, startApp = None): + + #self.__TranslateMessage__() + + self.pre = pre = wx.PreDialog() + pre.SetExtraStyle(wx.DIALOG_MODAL) + + pre.Create(parent, -1, 'Language selection', size = wx.Size(250, 150), + pos = wx.DefaultPosition, style=wx.DEFAULT_DIALOG_STYLE) + self.PostCreate(pre) + + icon_path = os.path.join(const.ICON_DIR, "invesalius.ico") + pre.SetIcon(wx.Icon(icon_path, wx.BITMAP_TYPE_ICO)) + + self.pnl = wx.Panel(id=-1, name='pnl', + parent=pre, pos=wx.Point(0, 0), size=wx.Size(250, 160), + style=wx.TAB_TRAVERSAL) + + self.txtMsg = wx.StaticText(id=1, + label=('Choose user interface language'), + name='txtMsg', parent=self.pnl, pos=wx.Point(15, + 10), size=wx.Size(200, 13), style=0) + + self.bxSizer = wx.BoxSizer(orient=wx.VERTICAL) + self.bxSizer.AddWindow(self.pnl, 1, wx.GROW|wx.ALIGN_CENTRE) + + btnsizer = wx.StdDialogButtonSizer() + + if wx.Platform != "__WXMSW__": + btn = wx.ContextHelpButton(self) + btnsizer.AddButton(btn) + + btnsizer.SetOrientation(wx.CENTER) + + 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.bxSizer.AddSizer(btnsizer, 1, wx.GROW|wx.ALIGN_CENTRE) + + self.__init_combobox_bitmap__() + + self.SetSizer(self.bxSizer) + + + def __init_combobox_bitmap__(self): + """Initialize combobox bitmap""" + + self.locales = i18n.GetLocales().values() + + self.locales_key = i18n.GetLocales().keys() + self.os_locale = i18n.GetLocaleOS() + + + self.bitmapCmb = bitmapCmb = wx.combo.BitmapComboBox(self.pnl, pos=(32,34), + size=(180,22), style=wx.CB_READONLY) + + bmp_brazilian_flag = wx.Bitmap(os.path.join(const.ICON_DIR, "pt_BR.bmp"), wx.BITMAP_TYPE_BMP) + bmp_english_flag = wx.Bitmap(os.path.join(const.ICON_DIR, "en_GB.bmp"), wx.BITMAP_TYPE_BMP) + bmp_spanish_flag = wx.Bitmap(os.path.join(const.ICON_DIR, "es.bmp"), wx.BITMAP_TYPE_BMP) + + bitmapCmb.Append(self.locales[0], bmp_brazilian_flag,"pt_BR") + bitmapCmb.Append(self.locales[1], bmp_english_flag,"en_GB") + bitmapCmb.Append(self.locales[2], bmp_spanish_flag,"es") + + + if (self.os_locale[0:2] == 'pt'): + bitmapCmb.SetSelection(0) + elif (self.os_locale[0:2] == 'es'): + bitmapCmb.SetSelection(2) + else: + bitmapCmb.SetSelection(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 = ivI18n.GetLocaleOS() + + if(os_language[0:2] == 'pt'): + _ = ivI18n.ParseLang('pt_BR') + elif(os_language[0:2] == 'es'): + _ = ivI18n.ParseLang('es') + else: + _ = ivI18n.ParseLang('en_GB') + + def Cancel(self, event): + """Close Frm_Language""" + self.Close() + event.Skip() diff --git a/invesalius/i18n.py b/invesalius/i18n.py new file mode 100644 index 0000000..f4e4178 --- /dev/null +++ b/invesalius/i18n.py @@ -0,0 +1,46 @@ +#-------------------------------------------------------------------------- +# 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 locale +import sys +import gettext +import os +import ConfigParser + + +def GetLocales(): + """Return a dictionary which defines supported languages""" + locale_descriptions = {'es':'Espa\xf1ol',\ + 'en_GB':'English',\ + 'pt_BR':'Portugu\xeas (Brasil)'} + return locale_descriptions + +def GetLocaleOS(): + """Return language of the operating system.""" + os_language = locale.getdefaultlocale()[0] + return os_language + +def InstallLanguage(lang): + + lang = gettext.translation('invesalius', lang_dir,\ + languages=[language]) + lang.install() + _ = lang.gettext + return _ + diff --git a/invesalius/invesalius.py b/invesalius/invesalius.py index 0611a73..e801cbb 100755 --- a/invesalius/invesalius.py +++ b/invesalius/invesalius.py @@ -21,6 +21,9 @@ import multiprocessing from optparse import OptionParser import os import sys + +import gui.language_dialog as lang_dlg +import i18n from session import Session @@ -68,7 +71,29 @@ class SplashScreen(wx.SplashScreen): # main frame now if self.fc.IsRunning(): self.fc.Stop() - self.ShowMain() + + session = Session() + if not (session.ReadSession()): + session.CreateItens() + + lang = session.GetLanguage() + #TODO: temporary + lang = "pt_BR" + if not(lang): + + ldlg = lang_dlg.create(parent=None) + ldlg.Show() + + if (ldlg.ShowModal() == wx.ID_OK): + lang = ldlg.GetSelectedLanguage() + session.SetLanguage(lang) + i18n.InstallLanguage(lang) + else: + #i18n.InstallLanguage(lang) + self.ShowMain() + + #print "not....." + #self.ShowMain() def ShowMain(self): @@ -107,8 +132,6 @@ def parse_comand_line(): options, args = parser.parse_args() session = Session() - if not (session.ReadSession()): - session.CreateItens() if options.debug: # The user passed the debug option? diff --git a/invesalius/session.py b/invesalius/session.py index f7fd119..ef03671 100644 --- a/invesalius/session.py +++ b/invesalius/session.py @@ -126,7 +126,13 @@ class Session(object): dict = plistlib.readPlist(main_plist) for key in dict: setattr(self, key, dict[key]) - + + def GetLanguage(self): + return self.language + + def SetLanguage(self, language): + self.language = language + def ReadSession(self): config = ConfigParser.ConfigParser() -- libgit2 0.21.2