Hi there!
I’m using wxPython on a Raspberry Pi with the Raspbian “stretch” operating system. To enjoy a Gtk3 experience and work with a more up-to-date version, I compiled wxPython myself following the instructions at BuildWxPythonOnRaspberryPi - wxPyWiki.
Initially this worked fine with the 4.0.7.post2 release. Now I updated to a freshly compiled 4.1.1 version. In my application, printing numbers with locale-aware thousands separators seems to work no longer. I’ve narrowed it down to this simple test case. Both versions were built to a wheel and installed in separate virtual environments.
Python 3.5.3 (default, Apr 5 2021, 09:00:41)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> wx.version()
'4.0.7.post2 gtk3 (phoenix) wxWidgets 3.0.5'
>>> '{:n}'.format(12345)
'12345'
>>> import locale
>>> locale.localeconv()
{'currency_symbol': '', 'n_cs_precedes': 255, 'int_curr_symbol': '', 'n_sign_posn': 255, 'mon_decimal_point': '', 'mon_thousands_sep': '', 'p_cs_precedes': 255, 'negative_sign': '', 'frac_digits': 255, 'p_sign_posn': 255, 'n_sep_by_space': 255, 'positive_sign': '', 'p_sep_by_space': 255, 'mon_grouping': [], 'grouping': [], 'thousands_sep': '', 'decimal_point': '.', 'int_frac_digits': 255}
>>> locale.getlocale()
('en_US', 'UTF-8')
>>> a = wx.App()
>>> '{:n}'.format(12345)
'12,345'
>>>
Apparently the old version 4.0.7 applied the system locale so that Python itself also uses it during initialization of the wx.App
object.
Python 3.5.3 (default, Apr 5 2021, 09:00:41)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> wx.version()
'4.1.1 gtk3 (phoenix) wxWidgets 3.1.5'
>>> '{:n}'.format(12345)
'12345'
>>> import locale
>>> locale.localeconv()
{'frac_digits': 255, 'p_sep_by_space': 255, 'p_sign_posn': 255, 'int_curr_symbol': '', 'p_cs_precedes': 255, 'n_sep_by_space': 255, 'currency_symbol': '', 'mon_thousands_sep': '
int_frac_digits': 255, 'decimal_point': '.', 'negative_sign': '', 'n_sign_posn': 255, 'positive_sign': '', 'n_cs_precedes': 255, 'mon_decimal_point': ''}
>>> locale.getlocale()
('en_US', 'UTF-8')
>>> a = wx.App()
>>> '{:n}'.format(12345)
'12345'
>>>
The same interactive session with wxPython 4.1.1 no longer exhibits this side-effect, even after wx.App
initialization. Also note the differences in localeconv()
output.
Was there a deliberate change in wxPython or wxWidgets that skips loading the system locale? What do I need to do now with the newer version to make locale-aware formatting work again?
Thanks in advance.