Update wx.App.InitLocale to be MSW-only, simpler, and maybe better

This commit is contained in:
Robin Dunn
2020-06-26 12:45:18 -07:00
parent 1e92a83dfa
commit f67f588fb9

View File

@@ -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