From f67f588fb9e246c905ec8dd07259aabdf2a4eaeb Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Fri, 26 Jun 2020 12:45:18 -0700 Subject: [PATCH] Update wx.App.InitLocale to be MSW-only, simpler, and maybe better --- etg/app.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/etg/app.py b/etg/app.py index 85a2254e..635c5df1 100644 --- a/etg/app.py +++ b/etg/app.py @@ -506,28 +506,25 @@ def run(): PyFunctionDef('InitLocale', '(self)', doc="""\ - Try to ensure that the C and Python locale is in sync with wxWidgets locale. + Try to ensure that the C and Python locale is in sync with + the wxWidgets locale on Windows. """, body="""\ self.ResetLocale() - import locale - try: - loc, enc = locale.getlocale() - except ValueError: - loc = enc = None - # Try to set it to the same language as what is already set in the C locale - info = wx.Locale.FindLanguageInfo(loc) if loc else None - if info: - self._initial_locale = wx.Locale(info.Language) - else: - # otherwise fall back to the system default - self._initial_locale = wx.Locale(wx.LANGUAGE_DEFAULT) + if 'wxMSW' in PlatformInfo: + import locale + try: + lang, enc = locale.getdefaultlocale() + self._initial_locale = wx.Locale(lang, lang[:2], lang) + locale.setlocale(locale.LC_ALL, lang) + except ValueError: + wx.LogError("Unable to set default locale.") """), PyFunctionDef('ResetLocale', '(self)', doc="""\ Release the wx.Locale object created in :meth:`InitLocale`. - This will reset the application's locale to the previous settings. + This should reset the application's locale to the previous settings. """, body="""\ self._initial_locale = None