From fa05cea1d177448f8dc376f0c31be6be8cec8811 Mon Sep 17 00:00:00 2001 From: paulojamorim Date: Fri, 25 Feb 2011 18:15:47 +0000 Subject: [PATCH] FIX: Fixed selection of language bug, thank's Bruno Lara Bottazzini --- invesalius/gui/language_dialog.py | 2 +- invesalius/i18n.py | 86 ++++++++++++++++++++++++++++++++++++-------------------------------------------------- invesalius/invesalius.py | 69 +++++++++++++++++++++++++-------------------------------------------- 3 files changed, 62 insertions(+), 95 deletions(-) diff --git a/invesalius/gui/language_dialog.py b/invesalius/gui/language_dialog.py index 5400248..a4f0861 100644 --- a/invesalius/gui/language_dialog.py +++ b/invesalius/gui/language_dialog.py @@ -53,7 +53,7 @@ class LanguageDialog(wx.Dialog): # Find out OS locale self.os_locale = i18n.GetLocaleOS() - os_lang = self.os_locale + os_lang = self.os_locale[0:2] # Default selection will be English selection = self.locales_key.index('en') diff --git a/invesalius/i18n.py b/invesalius/i18n.py index e80470c..38046e7 100644 --- a/invesalius/i18n.py +++ b/invesalius/i18n.py @@ -1,6 +1,6 @@ -#!/usr/bin/env python -# -*- coding: UTF-8 -*- - +#!/usr/bin/env python +# -*- coding: UTF-8 -*- + #-------------------------------------------------------------------------- # Software: InVesalius - Software de Reconstrucao 3D de Imagens Medicas # Copyright: (C) 2001 Centro de Pesquisas Renato Archer @@ -25,50 +25,36 @@ import locale import gettext import os import sys - -import utils as utl - -def GetLocales(): - """Return a dictionary which defines supported languages""" - d = utl.TwoWaysDictionary ({'zh_TW': u'中文', - 'en': u'English', - 'es': u'Español', - 'ko': u'조선어', - 'pt_BR': u'Português (Brasil)', - 'pt': u'Português (Portugal)', - 'fr':u'Français', - 'el_GR':u'Ελληνική', - 'it_IT':'Italiano', - 'de_DE': 'Deutsch'}) - return d - -def GetLocaleOS(): - """Return language of the operating system.""" - default_locale = 'en' - locales_dict = GetLocales() - - if sys.platform == 'darwin': - locale.setlocale(locale.LC_ALL, "") - os_locale = locale.getlocale()[0] - else: - os_locale = locale.getdefaultlocale()[0] - - if os_locale: - if os_locale in locales_dict.keys(): - default_locale = os_locale - else: - for l in locales_dict: - if l.startswith(os_locale): - default_locale = l - return default_locale - -def InstallLanguage(language): - language_dir = os.path.abspath(os.path.join('..','locale')) - if os.path.isdir(language_dir): - lang = gettext.translation('invesalius', language_dir,\ - languages=[language], codeset='utf8') - # Using unicode - lang.install(unicode=1) - return lang.ugettext - else: - return False + +import utils as utl + +def GetLocales(): + """Return a dictionary which defines supported languages""" + d = utl.TwoWaysDictionary ({'zh_TW': u'中文', + 'en': u'English', + 'es': u'Español', + 'pt_BR': u'Português (Brasil)', + 'fr':u'Français', + 'el_GR':u'Ελληνική', + #'it_IT':'Italiano', + 'de_DE': 'Deutsch'}) + return d + +def GetLocaleOS(): + """Return language of the operating system.""" + if sys.platform == 'darwin': + #The app can't get the location then it has to set + #it manually returning english + #locale.setlocale(locale.LC_ALL, "") + #return locale.getlocale()[0] + return "en" + + return locale.getdefaultlocale()[0] + +def InstallLanguage(language): + language_dir = os.path.abspath(os.path.join('..','locale')) + lang = gettext.translation('invesalius', language_dir,\ + languages=[language], codeset='utf8') + # Using unicode + lang.install(unicode=1) + return lang.ugettext diff --git a/invesalius/invesalius.py b/invesalius/invesalius.py index 0e01450..f509402 100755 --- a/invesalius/invesalius.py +++ b/invesalius/invesalius.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python2.6 -# NOTE: #!/usr/local/bin/python simply will *not* work if python is not -# installed in that exact location and, therefore, we're using the code -# above +#!/usr/local/bin/python #-------------------------------------------------------------------------- # Software: InVesalius - Software de Reconstrucao 3D de Imagens Medicas # Copyright: (C) 2001 Centro de Pesquisas Renato Archer @@ -21,25 +18,15 @@ # detalhes. #------------------------------------------------------------------------- + import multiprocessing import optparse as op import os import sys - -if sys.platform == 'win32': - import _winreg -else: - import wxversion - wxversion.ensureMinimal('2.8-unicode', optionsRequired=True) - wxversion.select('2.8-unicode', optionsRequired=True) +import shutil import wx import wx.lib.pubsub as ps -import wx.lib.agw.advancedsplash as agw -if sys.platform == 'linux2': - _SplashScreen = agw.AdvancedSplash -else: - _SplashScreen = wx.SplashScreen import gui.language_dialog as lang_dlg import i18n @@ -72,7 +59,7 @@ class InVesalius(wx.App): # ------------------------------------------------------------------ -class SplashScreen(_SplashScreen): +class SplashScreen(wx.SplashScreen): """ Splash screen to be shown in InVesalius initialization. """ @@ -88,20 +75,21 @@ class SplashScreen(_SplashScreen): if not (session.ReadSession()): create_session = True + install_lang = 0 # Check if there is a language set (if session file exists - language_exist = session.ReadLanguage() - - if language_exist: + if session.ReadLanguage(): lang = session.GetLanguage() - install = i18n.InstallLanguage(lang) - if install: - _ = install + if (lang != "False"): + _ = i18n.InstallLanguage(lang) + install_lang = 1 else: - language_exist = False + install_lang = 0 + else: + install_lang = 0 # If no language is set into session file, show dialog so # user can select language - if not language_exist: + if install_lang == 0: dialog = lang_dlg.LanguageDialog() # FIXME: This works ok in linux2, darwin and win32, @@ -115,6 +103,13 @@ class SplashScreen(_SplashScreen): lang = dialog.GetSelectedLanguage() session.SetLanguage(lang) _ = i18n.InstallLanguage(lang) + else: + homedir = self.homedir = os.path.expanduser('~') + invdir = os.path.join(homedir, ".invesalius") + shutil.rmtree(invdir) + sys.exit() + + # Session file should be created... So we set the recent # choosen language @@ -138,24 +133,13 @@ class SplashScreen(_SplashScreen): bmp = wx.Image(path).ConvertToBitmap() - style = wx.SPLASH_TIMEOUT | wx.SPLASH_CENTRE_ON_SCREEN |\ - wx.FRAME_SHAPED - if sys.platform == 'linux2': - _SplashScreen.__init__(self, - bitmap=bmp, - style=style, - timeout=5000, - id=-1, - parent=None) - else: - _SplashScreen.__init__(self, + style = wx.SPLASH_TIMEOUT | wx.SPLASH_CENTRE_ON_SCREEN + wx.SplashScreen.__init__(self, bitmap=bmp, splashStyle=style, - milliseconds=5000, + milliseconds=1500, id=-1, parent=None) - - self.Bind(wx.EVT_CLOSE, self.OnClose) # Importing takes sometime, therefore it will be done @@ -167,7 +151,7 @@ class SplashScreen(_SplashScreen): self.main = Frame(None) self.control = Controller(self.main) - self.fc = wx.FutureCall(2000, self.ShowMain) + self.fc = wx.FutureCall(1, self.ShowMain) def OnClose(self, evt): # Make sure the default handler runs too so this window gets @@ -215,10 +199,7 @@ def parse_comand_line(): # If debug argument... if options.debug: - try: - ps.Publisher().subscribe(print_events, ps.ALL_TOPICS) - except AttributeError: - ps.Publisher().subscribe(print_events, ps.pub.getStrAllTopics()) + ps.Publisher().subscribe(print_events, ps.ALL_TOPICS) session.debug = 1 # If import DICOM argument... -- libgit2 0.21.2