| 8 | |
| 9 | |
| 10 | class PyfaApp(wx.App): |
| 11 | def OnInit(self): |
| 12 | """ |
| 13 | Do application initialization work, e.g. define application globals. |
| 14 | """ |
| 15 | |
| 16 | # Name for my application. |
| 17 | self.appName = "pyfa" |
| 18 | |
| 19 | #------------ |
| 20 | |
| 21 | # # Simplified init method. |
| 22 | # self.DoConfig() |
| 23 | # self.Init() # InspectionMixin |
| 24 | # # work around for Python stealing "_". |
| 25 | # sys.displayhook = _displayHook |
| 26 | # |
| 27 | # #------------ |
| 28 | |
| 29 | |
| 30 | # Return locale folder. |
| 31 | localeDir = os.path.join(config.pyfaPath, "locale") |
| 32 | |
| 33 | # Set language stuff and update to last used language. |
| 34 | self.locale = None |
| 35 | wx.Locale.AddCatalogLookupPathPrefix(localeDir) |
| 36 | # Set language stuff and update to last used language. |
| 37 | self.UpdateLanguage(config.language) |
| 38 | |
| 39 | return True |
| 40 | |
| 41 | #----------------------------------------------------------------------- |
| 42 | |
| 43 | def UpdateLanguage(self, lang=None): |
| 44 | """ |
| 45 | Update the language to the requested one. |
| 46 | |
| 47 | Make *sure* any existing locale is deleted before the new |
| 48 | one is created. The old C++ object needs to be deleted |
| 49 | before the new one is created, and if we just assign a new |
| 50 | instance to the old Python variable, the old C++ locale will |
| 51 | not be destroyed soon enough, likely causing a crash. |
| 52 | |
| 53 | :param string `lang`: one of the supported language codes. |
| 54 | """ |
| 55 | |
| 56 | # Language domain. |
| 57 | langDomain = config.CATALOG |
| 58 | |
| 59 | # If an unsupported language is requested default to English. |
| 60 | |
| 61 | if self.locale: |
| 62 | assert sys.getrefcount(self.locale) <= 2 |
| 63 | del self.locale |
| 64 | |
| 65 | # Create a locale object for this language. |
| 66 | langInfo = wx.Locale.FindLanguageInfo(lang) |
| 67 | if langInfo is not None: |