wx.StaticText content causing a Python crash

Python 2.7.2
wxPython 2.9.4.0
Windows and OS X

If the last character in the string passed by SetLabel() or in the constructor is & (ampersand) then Python immediately exits. I guess because it is trying to set the non-existent following character as a keyboard shortcut. I haven’t made a runnable sample but the situation can easily be created in the Static Text (Core Windows/Controls) demo. If someone can confirm it, I will raise a ticket.

The work around is to use SetLabelText() which doesn’t afford & any special treatment.

It sounds an unlikely scenario I know, but it did happen. A customer entered a recipe name as “Egg-White Omelette with Asparagus &”, presumably in error, but & what, we will never know :wink:

···


Regards
David Hughes
Forestfield Software

David Hughes wrote:

Python 2.7.2
wxPython 2.9.4.0
Windows and OS X

If the last character in the string passed by SetLabel() or in the
constructor is & (ampersand) then Python immediately exits. I guess
because it is trying to set the non-existent following character as a
keyboard shortcut. I haven't made a runnable sample but the situation
can easily be created in the Static Text (Core Windows/Controls) demo.
If someone can confirm it, I will raise a ticket.

Go ahead and create the ticket, I've confirmed it. Here is a backtrace that you can include:

0 libwx_osx_cocoau-2.9.5.0.0.dylib 0x011d439c wxStripMenuCodes(wxString const&, int) + 284
1 libwx_osx_cocoau-2.9.5.0.0.dylib 0x0131fbb1 wxControlBase::RemoveMnemonics(wxString const&) + 33
2 libwx_osx_cocoau-2.9.5.0.0.dylib 0x012430f7 wxStaticText::DoSetLabel(wxString const&) + 39
3 libwx_osx_cocoau-2.9.5.0.0.dylib 0x01243337 wxStaticText::SetLabel(wxString const&) + 295
4 libwx_osx_cocoau-2.9.5.0.0.dylib 0x01242fb7 wxStaticText::Create(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long,

The work around is to use SetLabelText() which doesn't afford & any
special treatment.

Doubling the & to && should work too.

···

--
Robin Dunn
Software Craftsman