Commit 48cfd6550706bc84faee1ce8e01eea16a9c7e756

Authored by tatiana
1 parent 0a6b0a48

ENH: Organized flags/laguage available, so it is easier to include a new language

invesalius/gui/language_dialog.py
... ... @@ -39,38 +39,30 @@ class LanguageDialog(wx.Dialog):
39 39  
40 40 def __init_combobox_bitmap__(self):
41 41 """Initialize combobox bitmap"""
42   -
43   - self.locales = i18n.GetLocales().values()
44   - self.locales_key = i18n.GetLocales().keys()
  42 +
  43 + dict_locales = i18n.GetLocales()
  44 +
  45 + self.locales = dict_locales.values()
  46 + self.locales.sort()
  47 +
  48 + print "-------------------"
  49 + print self.locales
  50 + self.locales_key = [dict_locales.get_key(value)[0] for value in self.locales]
  51 + print self.locales_key
45 52 self.os_locale = i18n.GetLocaleOS()
46   -
  53 +
  54 + os_lang = self.os_locale[0:2]
  55 + selection = self.locales_key.index('en')
  56 +
47 57 self.bitmapCmb = bitmapCmb = wx.combo.BitmapComboBox(self, style=wx.CB_READONLY)
  58 + for key in self.locales_key:
  59 + filepath = os.path.join(ICON_DIR, "%s.bmp"%(key))
  60 + bmp = wx.Bitmap(filepath, wx.BITMAP_TYPE_BMP)
  61 + bitmapCmb.Append(dict_locales[key], bmp, key)
  62 + if key.startswith(os_lang):
  63 + selection = self.locales_key.index(key)
  64 + bitmapCmb.SetSelection(selection)
48 65  
49   - bmp_french_flag = wx.Bitmap(os.path.join(ICON_DIR, "fr_FR.bmp"), wx.BITMAP_TYPE_BMP)
50   - bmp_english_flag = wx.Bitmap(os.path.join(ICON_DIR, "en_GB.bmp"), wx.BITMAP_TYPE_BMP)
51   - bmp_brazilian_flag = wx.Bitmap(os.path.join(ICON_DIR, "pt_BR.bmp"), wx.BITMAP_TYPE_BMP)
52   - bmp_spanish_flag = wx.Bitmap(os.path.join(ICON_DIR, "es.bmp"), wx.BITMAP_TYPE_BMP)
53   - bmp_greek_flag = wx.Bitmap(os.path.join(ICON_DIR, "el_GR.bmp"), wx.BITMAP_TYPE_BMP)
54   -
55   - bitmapCmb.Append(self.locales[0], bmp_greek_flag, "el_GR")
56   - bitmapCmb.Append(self.locales[1], bmp_french_flag,"fr")
57   - bitmapCmb.Append(self.locales[2], bmp_english_flag,"en_GB")
58   - bitmapCmb.Append(self.locales[3], bmp_brazilian_flag,"pt_BR")
59   - bitmapCmb.Append(self.locales[4], bmp_spanish_flag,"es")
60   -
61   -
62   -
63   - os_lang = self.os_locale[0:2]
64   - if (os_lang == 'pt'):
65   - bitmapCmb.SetSelection(3)
66   - elif (os_lang == 'es'):
67   - bitmapCmb.SetSelection(4)
68   - elif (os_lang == 'fr'):
69   - bitmapCmb.SetSelection(1)
70   - elif (os_lang == 'el'):
71   - bitmapCmb.SetSelection(0)
72   - else:
73   - bitmapCmb.SetSelection(2)
74 66  
75 67 def __init_gui(self):
76 68 self.txtMsg = wx.StaticText(self, -1,
... ...
invesalius/i18n.py
... ... @@ -26,16 +26,20 @@ import gettext
26 26 import os
27 27 import sys
28 28  
  29 +import utils as utl
  30 +
29 31 LANGUAGE_DIR = os.path.abspath(os.path.join('..','locale'))
30 32  
31 33 def GetLocales():
32 34 """Return a dictionary which defines supported languages"""
33   - locale_descriptions = {'en': u'English',
34   - 'es': u'Español',
35   - 'pt_BR': u'Português (Brasil)',
36   - 'fr':u'Français',
37   - 'el_GR':u'Ελληνική'}
38   - return locale_descriptions
  35 + d = utl.TwoWaysDictionary ({'en': u'English',
  36 + 'es': u'Español',
  37 + 'pt_BR': u'Português (Brasil)',
  38 + 'fr':u'Français',
  39 + 'el_GR':u'Ελληνική',
  40 + 'it_IT':'Italiano',
  41 + 'de_DE': 'Deutsch'})
  42 + return d
39 43  
40 44 def GetLocaleOS():
41 45 """Return language of the operating system."""
... ...
invesalius/invesalius.py
... ... @@ -46,7 +46,7 @@ import wx.lib.pubsub as ps
46 46  
47 47 class SplashScreen(wx.SplashScreen):
48 48 def __init__(self):
49   -
  49 + lang = False
50 50 save_session = False
51 51 session = Session()
52 52 if not (session.ReadSession()):
... ... @@ -74,29 +74,30 @@ class SplashScreen(wx.SplashScreen):
74 74 session.SetLanguage(lang)
75 75 session.CreateSessionFile()
76 76  
77   - if (lang.startswith('pt')): #Necessy, pt noted as pt_BR
78   - icon_file = "splash_pt.png"
79   - else:
80   - icon_file = "splash_" + lang + ".png"
  77 + if lang:
  78 + if (lang.startswith('pt')): #Necessy, pt noted as pt_BR
  79 + icon_file = "splash_pt.png"
  80 + else:
  81 + icon_file = "splash_" + lang + ".png"
81 82  
82   - path = os.path.join("..","icons", icon_file)
  83 + path = os.path.join("..","icons", icon_file)
83 84  
84   - bmp = wx.Image(path).ConvertToBitmap()
  85 + bmp = wx.Image(path).ConvertToBitmap()
85 86  
86   - wx.SplashScreen.__init__(self, bitmap=bmp,
  87 + wx.SplashScreen.__init__(self, bitmap=bmp,
87 88 splashStyle=wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT,
88 89 milliseconds=1500, id=-1, parent=None)
89   - self.Bind(wx.EVT_CLOSE, self.OnClose)
  90 + self.Bind(wx.EVT_CLOSE, self.OnClose)
90 91  
91   - from gui.frame import Frame
92   - from control import Controller
93   - from project import Project
  92 + from gui.frame import Frame
  93 + from control import Controller
  94 + from project import Project
94 95  
95 96  
96   - self.main = Frame(None)
97   - self.control = Controller(self.main)
  97 + self.main = Frame(None)
  98 + self.control = Controller(self.main)
98 99  
99   - self.fc = wx.FutureCall(1, self.ShowMain)
  100 + self.fc = wx.FutureCall(1, self.ShowMain)
100 101  
101 102 def OnClose(self, evt):
102 103 # Make sure the default handler runs too so this window gets
... ...