Commit fa05cea1d177448f8dc376f0c31be6be8cec8811
1 parent
30442c8c
Exists in
master
and in
67 other branches
FIX: Fixed selection of language bug, thank's Bruno Lara Bottazzini
Showing
3 changed files
with
62 additions
and
95 deletions
Show diff stats
invesalius/gui/language_dialog.py
@@ -53,7 +53,7 @@ class LanguageDialog(wx.Dialog): | @@ -53,7 +53,7 @@ class LanguageDialog(wx.Dialog): | ||
53 | # Find out OS locale | 53 | # Find out OS locale |
54 | self.os_locale = i18n.GetLocaleOS() | 54 | self.os_locale = i18n.GetLocaleOS() |
55 | 55 | ||
56 | - os_lang = self.os_locale | 56 | + os_lang = self.os_locale[0:2] |
57 | 57 | ||
58 | # Default selection will be English | 58 | # Default selection will be English |
59 | selection = self.locales_key.index('en') | 59 | selection = self.locales_key.index('en') |
invesalius/i18n.py
1 | -#!/usr/bin/env python | ||
2 | -# -*- coding: UTF-8 -*- | ||
3 | - | 1 | +#!/usr/bin/env python |
2 | +# -*- coding: UTF-8 -*- | ||
3 | + | ||
4 | #-------------------------------------------------------------------------- | 4 | #-------------------------------------------------------------------------- |
5 | # Software: InVesalius - Software de Reconstrucao 3D de Imagens Medicas | 5 | # Software: InVesalius - Software de Reconstrucao 3D de Imagens Medicas |
6 | # Copyright: (C) 2001 Centro de Pesquisas Renato Archer | 6 | # Copyright: (C) 2001 Centro de Pesquisas Renato Archer |
@@ -25,50 +25,36 @@ import locale | @@ -25,50 +25,36 @@ import locale | ||
25 | import gettext | 25 | import gettext |
26 | import os | 26 | import os |
27 | import sys | 27 | import sys |
28 | - | ||
29 | -import utils as utl | ||
30 | - | ||
31 | -def GetLocales(): | ||
32 | - """Return a dictionary which defines supported languages""" | ||
33 | - d = utl.TwoWaysDictionary ({'zh_TW': u'中文', | ||
34 | - 'en': u'English', | ||
35 | - 'es': u'Español', | ||
36 | - 'ko': u'조선어', | ||
37 | - 'pt_BR': u'Português (Brasil)', | ||
38 | - 'pt': u'Português (Portugal)', | ||
39 | - 'fr':u'Français', | ||
40 | - 'el_GR':u'Ελληνική', | ||
41 | - 'it_IT':'Italiano', | ||
42 | - 'de_DE': 'Deutsch'}) | ||
43 | - return d | ||
44 | - | ||
45 | -def GetLocaleOS(): | ||
46 | - """Return language of the operating system.""" | ||
47 | - default_locale = 'en' | ||
48 | - locales_dict = GetLocales() | ||
49 | - | ||
50 | - if sys.platform == 'darwin': | ||
51 | - locale.setlocale(locale.LC_ALL, "") | ||
52 | - os_locale = locale.getlocale()[0] | ||
53 | - else: | ||
54 | - os_locale = locale.getdefaultlocale()[0] | ||
55 | - | ||
56 | - if os_locale: | ||
57 | - if os_locale in locales_dict.keys(): | ||
58 | - default_locale = os_locale | ||
59 | - else: | ||
60 | - for l in locales_dict: | ||
61 | - if l.startswith(os_locale): | ||
62 | - default_locale = l | ||
63 | - return default_locale | ||
64 | - | ||
65 | -def InstallLanguage(language): | ||
66 | - language_dir = os.path.abspath(os.path.join('..','locale')) | ||
67 | - if os.path.isdir(language_dir): | ||
68 | - lang = gettext.translation('invesalius', language_dir,\ | ||
69 | - languages=[language], codeset='utf8') | ||
70 | - # Using unicode | ||
71 | - lang.install(unicode=1) | ||
72 | - return lang.ugettext | ||
73 | - else: | ||
74 | - return False | 28 | + |
29 | +import utils as utl | ||
30 | + | ||
31 | +def GetLocales(): | ||
32 | + """Return a dictionary which defines supported languages""" | ||
33 | + d = utl.TwoWaysDictionary ({'zh_TW': u'中文', | ||
34 | + 'en': u'English', | ||
35 | + 'es': u'Español', | ||
36 | + 'pt_BR': u'Português (Brasil)', | ||
37 | + 'fr':u'Français', | ||
38 | + 'el_GR':u'Ελληνική', | ||
39 | + #'it_IT':'Italiano', | ||
40 | + 'de_DE': 'Deutsch'}) | ||
41 | + return d | ||
42 | + | ||
43 | +def GetLocaleOS(): | ||
44 | + """Return language of the operating system.""" | ||
45 | + if sys.platform == 'darwin': | ||
46 | + #The app can't get the location then it has to set | ||
47 | + #it manually returning english | ||
48 | + #locale.setlocale(locale.LC_ALL, "") | ||
49 | + #return locale.getlocale()[0] | ||
50 | + return "en" | ||
51 | + | ||
52 | + return locale.getdefaultlocale()[0] | ||
53 | + | ||
54 | +def InstallLanguage(language): | ||
55 | + language_dir = os.path.abspath(os.path.join('..','locale')) | ||
56 | + lang = gettext.translation('invesalius', language_dir,\ | ||
57 | + languages=[language], codeset='utf8') | ||
58 | + # Using unicode | ||
59 | + lang.install(unicode=1) | ||
60 | + return lang.ugettext |
invesalius/invesalius.py
1 | -#!/usr/bin/env python2.6 | ||
2 | -# NOTE: #!/usr/local/bin/python simply will *not* work if python is not | ||
3 | -# installed in that exact location and, therefore, we're using the code | ||
4 | -# above | 1 | +#!/usr/local/bin/python |
5 | #-------------------------------------------------------------------------- | 2 | #-------------------------------------------------------------------------- |
6 | # Software: InVesalius - Software de Reconstrucao 3D de Imagens Medicas | 3 | # Software: InVesalius - Software de Reconstrucao 3D de Imagens Medicas |
7 | # Copyright: (C) 2001 Centro de Pesquisas Renato Archer | 4 | # Copyright: (C) 2001 Centro de Pesquisas Renato Archer |
@@ -21,25 +18,15 @@ | @@ -21,25 +18,15 @@ | ||
21 | # detalhes. | 18 | # detalhes. |
22 | #------------------------------------------------------------------------- | 19 | #------------------------------------------------------------------------- |
23 | 20 | ||
21 | + | ||
24 | import multiprocessing | 22 | import multiprocessing |
25 | import optparse as op | 23 | import optparse as op |
26 | import os | 24 | import os |
27 | import sys | 25 | import sys |
28 | - | ||
29 | -if sys.platform == 'win32': | ||
30 | - import _winreg | ||
31 | -else: | ||
32 | - import wxversion | ||
33 | - wxversion.ensureMinimal('2.8-unicode', optionsRequired=True) | ||
34 | - wxversion.select('2.8-unicode', optionsRequired=True) | 26 | +import shutil |
35 | 27 | ||
36 | import wx | 28 | import wx |
37 | import wx.lib.pubsub as ps | 29 | import wx.lib.pubsub as ps |
38 | -import wx.lib.agw.advancedsplash as agw | ||
39 | -if sys.platform == 'linux2': | ||
40 | - _SplashScreen = agw.AdvancedSplash | ||
41 | -else: | ||
42 | - _SplashScreen = wx.SplashScreen | ||
43 | 30 | ||
44 | import gui.language_dialog as lang_dlg | 31 | import gui.language_dialog as lang_dlg |
45 | import i18n | 32 | import i18n |
@@ -72,7 +59,7 @@ class InVesalius(wx.App): | @@ -72,7 +59,7 @@ class InVesalius(wx.App): | ||
72 | 59 | ||
73 | # ------------------------------------------------------------------ | 60 | # ------------------------------------------------------------------ |
74 | 61 | ||
75 | -class SplashScreen(_SplashScreen): | 62 | +class SplashScreen(wx.SplashScreen): |
76 | """ | 63 | """ |
77 | Splash screen to be shown in InVesalius initialization. | 64 | Splash screen to be shown in InVesalius initialization. |
78 | """ | 65 | """ |
@@ -88,20 +75,21 @@ class SplashScreen(_SplashScreen): | @@ -88,20 +75,21 @@ class SplashScreen(_SplashScreen): | ||
88 | if not (session.ReadSession()): | 75 | if not (session.ReadSession()): |
89 | create_session = True | 76 | create_session = True |
90 | 77 | ||
78 | + install_lang = 0 | ||
91 | # Check if there is a language set (if session file exists | 79 | # Check if there is a language set (if session file exists |
92 | - language_exist = session.ReadLanguage() | ||
93 | - | ||
94 | - if language_exist: | 80 | + if session.ReadLanguage(): |
95 | lang = session.GetLanguage() | 81 | lang = session.GetLanguage() |
96 | - install = i18n.InstallLanguage(lang) | ||
97 | - if install: | ||
98 | - _ = install | 82 | + if (lang != "False"): |
83 | + _ = i18n.InstallLanguage(lang) | ||
84 | + install_lang = 1 | ||
99 | else: | 85 | else: |
100 | - language_exist = False | 86 | + install_lang = 0 |
87 | + else: | ||
88 | + install_lang = 0 | ||
101 | 89 | ||
102 | # If no language is set into session file, show dialog so | 90 | # If no language is set into session file, show dialog so |
103 | # user can select language | 91 | # user can select language |
104 | - if not language_exist: | 92 | + if install_lang == 0: |
105 | dialog = lang_dlg.LanguageDialog() | 93 | dialog = lang_dlg.LanguageDialog() |
106 | 94 | ||
107 | # FIXME: This works ok in linux2, darwin and win32, | 95 | # FIXME: This works ok in linux2, darwin and win32, |
@@ -115,6 +103,13 @@ class SplashScreen(_SplashScreen): | @@ -115,6 +103,13 @@ class SplashScreen(_SplashScreen): | ||
115 | lang = dialog.GetSelectedLanguage() | 103 | lang = dialog.GetSelectedLanguage() |
116 | session.SetLanguage(lang) | 104 | session.SetLanguage(lang) |
117 | _ = i18n.InstallLanguage(lang) | 105 | _ = i18n.InstallLanguage(lang) |
106 | + else: | ||
107 | + homedir = self.homedir = os.path.expanduser('~') | ||
108 | + invdir = os.path.join(homedir, ".invesalius") | ||
109 | + shutil.rmtree(invdir) | ||
110 | + sys.exit() | ||
111 | + | ||
112 | + | ||
118 | 113 | ||
119 | # Session file should be created... So we set the recent | 114 | # Session file should be created... So we set the recent |
120 | # choosen language | 115 | # choosen language |
@@ -138,24 +133,13 @@ class SplashScreen(_SplashScreen): | @@ -138,24 +133,13 @@ class SplashScreen(_SplashScreen): | ||
138 | 133 | ||
139 | bmp = wx.Image(path).ConvertToBitmap() | 134 | bmp = wx.Image(path).ConvertToBitmap() |
140 | 135 | ||
141 | - style = wx.SPLASH_TIMEOUT | wx.SPLASH_CENTRE_ON_SCREEN |\ | ||
142 | - wx.FRAME_SHAPED | ||
143 | - if sys.platform == 'linux2': | ||
144 | - _SplashScreen.__init__(self, | ||
145 | - bitmap=bmp, | ||
146 | - style=style, | ||
147 | - timeout=5000, | ||
148 | - id=-1, | ||
149 | - parent=None) | ||
150 | - else: | ||
151 | - _SplashScreen.__init__(self, | 136 | + style = wx.SPLASH_TIMEOUT | wx.SPLASH_CENTRE_ON_SCREEN |
137 | + wx.SplashScreen.__init__(self, | ||
152 | bitmap=bmp, | 138 | bitmap=bmp, |
153 | splashStyle=style, | 139 | splashStyle=style, |
154 | - milliseconds=5000, | 140 | + milliseconds=1500, |
155 | id=-1, | 141 | id=-1, |
156 | parent=None) | 142 | parent=None) |
157 | - | ||
158 | - | ||
159 | self.Bind(wx.EVT_CLOSE, self.OnClose) | 143 | self.Bind(wx.EVT_CLOSE, self.OnClose) |
160 | 144 | ||
161 | # Importing takes sometime, therefore it will be done | 145 | # Importing takes sometime, therefore it will be done |
@@ -167,7 +151,7 @@ class SplashScreen(_SplashScreen): | @@ -167,7 +151,7 @@ class SplashScreen(_SplashScreen): | ||
167 | self.main = Frame(None) | 151 | self.main = Frame(None) |
168 | self.control = Controller(self.main) | 152 | self.control = Controller(self.main) |
169 | 153 | ||
170 | - self.fc = wx.FutureCall(2000, self.ShowMain) | 154 | + self.fc = wx.FutureCall(1, self.ShowMain) |
171 | 155 | ||
172 | def OnClose(self, evt): | 156 | def OnClose(self, evt): |
173 | # Make sure the default handler runs too so this window gets | 157 | # Make sure the default handler runs too so this window gets |
@@ -215,10 +199,7 @@ def parse_comand_line(): | @@ -215,10 +199,7 @@ def parse_comand_line(): | ||
215 | 199 | ||
216 | # If debug argument... | 200 | # If debug argument... |
217 | if options.debug: | 201 | if options.debug: |
218 | - try: | ||
219 | - ps.Publisher().subscribe(print_events, ps.ALL_TOPICS) | ||
220 | - except AttributeError: | ||
221 | - ps.Publisher().subscribe(print_events, ps.pub.getStrAllTopics()) | 202 | + ps.Publisher().subscribe(print_events, ps.ALL_TOPICS) |
222 | session.debug = 1 | 203 | session.debug = 1 |
223 | 204 | ||
224 | # If import DICOM argument... | 205 | # If import DICOM argument... |