Skip to content

Commit

Permalink
TTT Let's try dropping the locale nonsense
Browse files Browse the repository at this point in the history
We're on wxPython 4.2.1 now, 4.2 did yet another rework of all this so
maybe we're finally good?
  • Loading branch information
Infernio committed Nov 7, 2023
1 parent 6a5c60c commit c89593c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 18 deletions.
3 changes: 0 additions & 3 deletions Mopy/bash/bash.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ def MainLoop(self, restore_stdio=True):
rv = _wx.PyApp.MainLoop(self)
if restore_stdio: self.RestoreStdio()
return rv
def InitLocale(self):
if sys.platform.startswith('win') and sys.version_info > (3,8):
locale.setlocale(locale.LC_CTYPE, 'C') # pass?
# Initialize the App instance once
global bash_app
bash_app = _BaseApp(bass.is_standalone)
Expand Down
22 changes: 11 additions & 11 deletions Mopy/bash/localize.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,11 @@
import subprocess
import sys
import time
import warnings

# Minimal local imports - needs to be imported early in bash
from . import bass, bolt

def set_c_locale():
# Hack see: https://discuss.wxpython.org/t/wxpython4-1-1-python3-8-locale-wxassertionerror/35168/3
if sys.platform.startswith('win') and sys.version_info > (3, 8):
for cat in (locale.LC_COLLATE, locale.LC_CTYPE, locale.LC_MONETARY,
locale.LC_TIME): # locale.LC_NUMERIC
locale.setlocale(cat, 'C')

#------------------------------------------------------------------------------
# Locale Detection & Setup
def setup_locale(cli_lang, _wx):
Expand All @@ -70,9 +64,17 @@ def setup_locale(cli_lang, _wx):
target_name = cli_target.CanonicalName
else:
# Fall back on the default language
language_code, enc = locale.getdefaultlocale()
try:
with warnings.catch_warnings():
# Work around https://github.com/python/cpython/issues/82986
warnings.simplefilter('ignore', category=DeprecationWarning)
language_code, enc = locale.getdefaultlocale()
except AttributeError:
bolt.deprint('getdefaultlocale no longer exists, this will '
'probably break on Windows now')
language_code, enc = locale.getlocale()
bolt.deprint(f'{cli_lang=} - {cli_target=} - falling back to '
f'({language_code}, {enc}) from getdefaultlocale')
f'({language_code}, {enc}) from default locale')
lang_info = _wx.Locale.FindLanguageInfo(language_code)
target_name = lang_info and lang_info.CanonicalName
bolt.deprint(f'wx gave back {target_name}')
Expand Down Expand Up @@ -158,8 +160,6 @@ def setup_locale(cli_lang, _wx):
# we ended up with as the final locale
trans.install()
bass.active_locale = target_name
# adieu, user locale
set_c_locale()
return target_locale

def __get_translations_dir():
Expand Down
3 changes: 0 additions & 3 deletions Mopy/bash/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@ def MainLoop(self, restore_stdio=True):
rv = _wx.PyApp.MainLoop(self)
if restore_stdio: self.RestoreStdio()
return rv
def InitLocale(self):
if sys.platform.startswith('win') and sys.version_info > (3,8):
locale.setlocale(locale.LC_CTYPE, 'C')

def _emulate_startup():
"""Emulates a normal Wrye Bash startup, but without launching basher
Expand Down
1 change: 0 additions & 1 deletion Mopy/bash/tests/test_localize.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def _test_locale(self, loc, capsys):
with capsys.disabled():
print(f'\n\n******* Testing {loc=} *******')
print(f'getlocale: {locale.getlocale()}')
print(f'getdefaultlocale: {locale.getdefaultlocale()}')
wx_locale = setup_locale(loc, _wx)
# getlocale = locale.getlocale()
# print(getlocale)
Expand Down

0 comments on commit c89593c

Please sign in to comment.