Re: Re: Getting wx._core.wxAssertionError
Matt Newville <[email protected]> Sun, 12 Dec 2021 09:34:44 -0600
| Newsgroups | gmane.comp.python.wxpython |
|---|---|
| Message-ID | <CA+7ESboRQ5K9sbJ19LYQFWvE_qrnhWPCy-CPV9JQ=y_+ovTetQ@mail.gmail.com> |
--00000000000034dd7405d2f4b43a
Content-Type: text/plain; charset="UTF-8"
I have had many reports of problems with locale, and only on Windows, and
only with recent versions of wxPython (I think only 4.1.1, but I'm not
certain of that).
My solution was to subclass `wxApp` for any application that I distribute:
###
import wx
import locale
import platform
class MyWxApp(wx.App):
"""wrapper for wx apps, with the following arguments and features:
Arguments
----------
with_c_locale bool whether to force C locale [None : see note 1]
Notes
------
By defaut (and if left ast `None`), then `with_c_locale`
will be True for Windows, False for other systems
"""
def __init__(self, with_c_locale=None, **kws):
if with_c_locale is None:
with_c_locale = (platform.system() == 'Windows')
self.with_c_locale = with_c_locale
wx.App.__init__(self, **kws)
def InitLocale(self):
"""over-ride wxPython default initial locale"""
if self.with_c_locale:
self._initial_locale = None
locale.setlocale(locale.LC_ALL, 'C')
else:
lang, enc = locale.getdefaultlocale()
self._initial_locale = wx.Locale(lang, lang[:2], lang)
locale.setlocale(locale.LC_ALL, lang)
def OnInit(self):
self.createApp()
return True
def createApp(self):
return True
def run(self):
self.MainLoop()
###
On Sat, Dec 11, 2021 at 5:20 PM Peter Clarke <[email protected]>
wrote:
> I've seen a similar issue recently in my own code. When I started using
> wx.Locale, an unrelated part of the code started throwing this error. The
> specific line throwing the error creates the first instance of wx.Image.
> The only way I've found to resolve it so far is either (1) get rid of
> wx.Locale usage completely, or (2) get rid of wx.Image usage. Not a
> pleasant choice.
>
> I found the error was coming up on specific Windows machines only. I have
> not seen it on my own Windows or Mac. It first showed up on my colleague's
> Windows PC - she's Indian. As the OP has a .in email address, I wonder if
> it's a particular issue for Indian locale? Maybe (just a guess) because
> India is one of the few locales with a non-integer time difference from UCT?
>
> Peter Clarke
>
> On Saturday, 11 December 2021 at 02:15:15 UTC+9 [email protected]
> wrote:
>
>> Hi,
>>
>> I'm using GRASS GIS 7.8 <https://grass.osgeo.org/>, an application
>> created using wxPython.
>>
>> Every time I try to open a dataset using this application, I get the
>> following error:
>> C:\Users\Ishan Buxy>Traceback (most recent call last):
>> File "C:\Program Files\GRASS GIS 7.8\gui\wxpython\wxgui.py", line 105,
>> in OnInit
>> mainframe = GMFrame(parent=None, id=wx.ID_ANY,
>> File "C:\Program Files\GRASS GIS 7.8\gui\wxpython\lmgr\frame.py", line
>> 141, in __init__
>> self._createMenuBar()
>> File "C:\Program Files\GRASS GIS 7.8\gui\wxpython\lmgr\frame.py", line
>> 268, in _createMenuBar
>> self.menubar = GMenu(
>> File "C:\Program Files\GRASS GIS 7.8\gui\wxpython\gui_core\menu.py",
>> line 47, in __init__
>> self.Append(self._createMenu(child), child.label)
>> File "C:\Program Files\GRASS GIS 7.8\gui\wxpython\gui_core\menu.py",
>> line 61, in _createMenu
>> self._createMenuItem(menu, label=child.label, **data)
>> File "C:\Program Files\GRASS GIS 7.8\gui\wxpython\gui_core\menu.py",
>> line 88, in _createMenuItem
>> menuItem.SetBitmap(MetaIcon(img=icon).GetBitmap(self.bmpsize))
>> File "C:\Program Files\GRASS GIS 7.8\gui\wxpython\icons\icon.py", line
>> 96, in GetBitmap
>> image = wx.Image(name=self.imagepath)
>> wx._core.wxAssertionError: C++ assertion "strcmp(setlocale(0, 0), "C") ==
>> 0" failed at
>> D:\src\osgeo4w\src\wxwidgets\wxwidgets-3.1.5-0df1d81acd6f1be8624022f8eecb51679008ca40\src\common\intl.cpp(1694)
>> in wxLocale::GetInfo(): You probably called setlocale() directly instead of
>> using wxLocale and now there is a mismatch between C/C++ and Windows locale.
>> Things are going to break, please only change locale by creating wxLocale
>> objects to avoid this!
>> OnInit returned false, exiting...
>>
>>
>> Can someone please explain? How do I resolve this?
>>
>> Regards,
>> Ishan
>>
> --
> You received this message because you are subscribed to the Google Groups
> "wxPython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/wxpython-users/c4e68628-42b6-4429-9ca2-4f6a149f6b2cn%40googlegroups.com
> <https://groups.google.com/d/msgid/wxpython-users/c4e68628-42b6-4429-9ca2-4f6a149f6b2cn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
--Matt
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/CA%2B7ESboRQ5K9sbJ19LYQFWvE_qrnhWPCy-CPV9JQ%3Dy_%2BovTetQ%40mail.gmail.com.
--00000000000034dd7405d2f4b43a
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div dir=3D"ltr"><div class=3D"gmail_default" style=3D"fon=
t-family:arial,sans-serif">I have had many reports of problems with locale,=
and only on Windows, and only with recent versions of wxPython (I think on=
ly 4.1.1, but I'm not certain of that).=C2=A0</div><div class=3D"gmail_=
default" style=3D"font-family:arial,sans-serif"><br></div><div class=3D"gma=
il_default" style=3D"font-family:arial,sans-serif">My solution was to subcl=
ass `wxApp` for any application that I distribute:</div><div class=3D"gmail=
_default" style=3D"font-family:arial,sans-serif"><br></div><div class=3D"gm=
ail_default" style=3D"font-family:arial,sans-serif">###</div><div class=3D"=
gmail_default" style=3D"font-family:arial,sans-serif">import wx<br>import l=
ocale<br>import platform<br><br>class MyWxApp(wx.App):<br>=C2=A0 =C2=A0 &qu=
ot;""wrapper for wx apps, with the following arguments and featur=
es:<br>=C2=A0 =C2=A0 Arguments<br>=C2=A0 =C2=A0 ----------<br>=C2=A0 =C2=A0=
=C2=A0 with_c_locale bool =C2=A0whether to force C locale [None : see note=
1]<br><br>=C2=A0 =C2=A0 Notes<br>=C2=A0 =C2=A0 ------<br>=C2=A0 =C2=A0 =C2=
=A0 By defaut (and if left ast `None`), then `with_c_locale`<br>=C2=A0 =C2=
=A0 =C2=A0 will be True for Windows, False for other systems<br><br>=C2=A0 =
=C2=A0 """<br>=C2=A0 =C2=A0 def __init__(self, with_c_locale=
=3DNone, **kws):<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 if with_c_locale is None:<b=
r>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 with_c_locale =3D (platform.sys=
tem() =3D=3D 'Windows')<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.with_c_=
locale =3D with_c_locale<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 wx.App.__init__(sel=
f, **kws)<br><br>=C2=A0 =C2=A0 def InitLocale(self):<br>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 """over-ride wxPython default initial locale"=
;""<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 if self.with_c_locale:<br>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 self._initial_locale =3D None<br>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 locale.setlocale(locale.LC_ALL, '=
;C')<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 else:<br>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 lang, enc =3D locale.getdefaultlocale()<br>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._initial_locale =3D wx.Locale(lang, lang[:=
2], lang)<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 locale.setlocale(loc=
ale.LC_ALL, lang)<br><br>=C2=A0 =C2=A0 def OnInit(self):<br>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 self.createApp()<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 return True<b=
r><br>=C2=A0 =C2=A0 def createApp(self):<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 ret=
urn True<br><br>=C2=A0 =C2=A0 def run(self):<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0=
self.MainLoop()<br></div><div class=3D"gmail_default" style=3D"font-family=
:arial,sans-serif">###</div><div class=3D"gmail_default" style=3D"font-fami=
ly:arial,sans-serif"><br></div><div class=3D"gmail_default" style=3D"font-f=
amily:arial,sans-serif"><br></div><div class=3D"gmail_default" style=3D"fon=
t-family:arial,sans-serif"><br></div></div><br><div class=3D"gmail_quote"><=
div dir=3D"ltr" class=3D"gmail_attr">On Sat, Dec 11, 2021 at 5:20 PM Peter =
Clarke <<a href=3D"mailto:[email protected]">peterslistening@gma=
il.com</a>> wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"m=
argin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left=
:1ex">I've seen a similar issue recently in my own code. When I started=
using wx.Locale, an unrelated part of the code started throwing this error=
. The specific line throwing the error creates the first instance of wx.Ima=
ge. The only way I've found to resolve it so far is either (1) get rid =
of wx.Locale usage completely, or (2) get rid of wx.Image usage. Not a plea=
sant choice.<div><br></div><div>I found the error was coming up on specific=
Windows machines only. I have not seen it on my own Windows or Mac. It fir=
st showed up on my colleague's Windows PC - she's Indian. As the OP=
has a .in email address, I wonder if it's a particular issue for India=
n locale? Maybe (just a guess) because India is one of the few locales with=
a non-integer time difference from UCT?</div><div><br></div><div>Peter Cla=
rke<br><br></div><div class=3D"gmail_quote"><div dir=3D"auto" class=3D"gmai=
l_attr">On Saturday, 11 December 2021 at 02:15:15 UTC+9 <a href=3D"mailto:c=
[email protected]" target=3D"_blank">[email protected]</a> wro=
te:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px =
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>Hi,</di=
v><div><br></div><div>I'm using <a href=3D"https://grass.osgeo.org/" re=
l=3D"nofollow" target=3D"_blank">GRASS GIS 7.8</a>, an application created =
using wxPython.</div><div><br></div><div>Every time I try to open a dataset=
using this application, I get the following error:</div><div>C:\Users\Isha=
n Buxy>Traceback (most recent call last):<br>=C2=A0 File "C:\Progra=
m Files\GRASS GIS 7.8\gui\wxpython\wxgui.py", line 105, in OnInit<br>=
=C2=A0 =C2=A0 mainframe =3D GMFrame(parent=3DNone, id=3Dwx.ID_ANY,<br>=C2=
=A0 File "C:\Program Files\GRASS GIS 7.8\gui\wxpython\lmgr\frame.py&qu=
ot;, line 141, in __init__<br>=C2=A0 =C2=A0 self._createMenuBar()<br>=C2=A0=
File "C:\Program Files\GRASS GIS 7.8\gui\wxpython\lmgr\frame.py"=
, line 268, in _createMenuBar<br>=C2=A0 =C2=A0 self.menubar =3D GMenu(<br>=
=C2=A0 File "C:\Program Files\GRASS GIS 7.8\gui\wxpython\gui_core\menu=
.py", line 47, in __init__<br>=C2=A0 =C2=A0 self.Append(self._createMe=
nu(child), child.label)<br>=C2=A0 File "C:\Program Files\GRASS GIS 7.8=
\gui\wxpython\gui_core\menu.py", line 61, in _createMenu<br>=C2=A0 =C2=
=A0 self._createMenuItem(menu, label=3Dchild.label, **data)<br>=C2=A0 File =
"C:\Program Files\GRASS GIS 7.8\gui\wxpython\gui_core\menu.py", l=
ine 88, in _createMenuItem<br>=C2=A0 =C2=A0 menuItem.SetBitmap(MetaIcon(img=
=3Dicon).GetBitmap(self.bmpsize))<br>=C2=A0 File "C:\Program Files\GRA=
SS GIS 7.8\gui\wxpython\icons\icon.py", line 96, in GetBitmap<br>=C2=
=A0 =C2=A0 image =3D wx.Image(name=3Dself.imagepath)<br>wx._core.wxAssertio=
nError: C++ assertion "strcmp(setlocale(0, 0), "C") =3D=3D 0=
" failed at D:\src\osgeo4w\src\wxwidgets\wxwidgets-3.1.5-0df1d81acd6f1=
be8624022f8eecb51679008ca40\src\common\intl.cpp(1694) in wxLocale::GetInfo(=
): You probably called setlocale() directly instead of using wxLocale and n=
ow there is a mismatch between C/C++ and Windows locale.<br>Things are goin=
g to break, please only change locale by creating wxLocale objects to avoid=
this!<br>OnInit returned false, exiting...</div><div><br></div><div><br></=
div><div>Can someone please explain? How do I resolve this?<br></div><div><=
br></div><div>Regards,</div><div>Ishan<br></div></blockquote></div>
<p></p>
-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;wxPython-users" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:[email protected]" targ=
et=3D"_blank">[email protected]</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/d/msgid/wxpython-users/c4e68628-42b6-4429-9ca2-4f6a149f6b2cn%40googlegro=
ups.com?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank">https=
://groups.google.com/d/msgid/wxpython-users/c4e68628-42b6-4429-9ca2-4f6a149=
f6b2cn%40googlegroups.com</a>.<br>
</blockquote></div><br clear=3D"all"><div><br></div><div dir=3D"ltr" class=
=3D"gmail_signature"><div dir=3D"ltr">--Matt=C2=A0<br></div></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;wxPython-users" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:[email protected]">wxpy=
[email protected]</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/d/msgid/wxpython-users/CA%2B7ESboRQ5K9sbJ19LYQFWvE_qrnhWPCy-CPV9JQ%3Dy_%=
2BovTetQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">https://g=
roups.google.com/d/msgid/wxpython-users/CA%2B7ESboRQ5K9sbJ19LYQFWvE_qrnhWPC=
y-CPV9JQ%3Dy_%2BovTetQ%40mail.gmail.com</a>.<br />
--00000000000034dd7405d2f4b43a--