Bug calling wxMenu.SetLabel() to change menu label and keyboard shortcut?

Background info:

···

-------------------------

I have Python/wxPython an application that is internationalized using the
gettext system and that has the ability to change the natural language
dynamically (from user selected option menu). All works fine. The application
currently supports English and French. The user can flip from English to French
and the text changes on every item. There is no limit to the number of time you
can flip the presentation language.

Problem:
-------------

I noticed, however, that the application crashes after 4 flip if one of the menu
has a label with a keyboard shortcut.

The following line works fine:

         self.mnuFile.SetLabel(wxID_WXFRAME1MNUFILEMNU_EXIT,_(u'Exit'))
         #with the translation being: "Quitte"

The following line also works fine:

        self.mnuFile.SetLabel(wxID_WXFRAME1MNUFILEMNU_EXIT,_(u'E&xit\tCtrl-X'))
         #with the translation being: "&Quitte\tCtrl-Q"

The following line also works fine:

        self.mnuFile.SetLabel(wxID_WXFRAME1MNUFILEMNU_EXIT,_(u'E&xit'))
         #with the translation being: "&Quitte"

**But** this line make the program crash on the 5th language flip:

         self.mnuFile.SetLabel(wxID_WXFRAME1MNUFILEMNU_EXIT,_(u'E&xit\tCtrl-X'))
         #with the translation being: "&Quitte\tCtrl-X"

Note that Ctrl-X and Ctrl-Q are not clashing with any other shortcut inside the
program (in either language).
Also note that the first 4 flips work fine.
The program crashes on the 5th flip
The program crashes inside Python.exe, with the note:
     'The instruction "0x009f4383" referenced memort at "0x00000027". The
memory could not be "read".'

My System:
-----------------
     Windows NT SP6
     Python 2.2
     wxPython 2.4.0.7u

Questions:
--------------

- Is this a known limitation/bug?
- What is the best way to hunt bugs like this when using wxPython?
- What are the constraints when setting keyboard shortcuts with
wxMenu.SetLabel()?
- Is it allowed to use two different letters for menu/keyboard shorcuts as in
"&Quitte\tCtrl-X" ? (irrespective to the way that it should be
"&Quitte\tCtrl-Q")
- When re-setting the labels of all menus, there is a possibility that for a
period of time two menus are assigned with the same shortcut. Is this allowed?

Thanks for the help.

--
Pierre Rouleau

Pierre_Rouleau@ImpathNetworks.com wrote:

**But** this line make the program crash on the 5th language flip:

         self.mnuFile.SetLabel(wxID_WXFRAME1MNUFILEMNU_EXIT,_(u'E&xit\tCtrl-X'))
         #with the translation being: "&Quitte\tCtrl-X"

Note that Ctrl-X and Ctrl-Q are not clashing with any other shortcut inside the
program (in either language).
Also note that the first 4 flips work fine.
The program crashes on the 5th flip
The program crashes inside Python.exe, with the note:
     'The instruction "0x009f4383" referenced memort at "0x00000027". The
memory could not be "read".'

Please enter a bug report about this, with a category of wxMSW.

Questions:
--------------

- Is this a known limitation/bug?

Not that I know of.

- What is the best way to hunt bugs like this when using wxPython?
- What are the constraints when setting keyboard shortcuts with
wxMenu.SetLabel()?

There shouldn't be any.

- Is it allowed to use two different letters for menu/keyboard shorcuts as in
"&Quitte\tCtrl-X" ? (irrespective to the way that it should be
"&Quitte\tCtrl-Q")

Yes, that is fine.

- When re-setting the labels of all menus, there is a possibility that for a
period of time two menus are assigned with the same shortcut. Is this allowed?

It should be okay. The only problem is that if there is a chance for the user to use one of the accelerator keys then only the first one found in the table will be used.

Thanks for the help.

One workaround you may want to try is to completly rebuild the menubar when changing languages instead of changing the text and accelerators in the current one. Just build your new menu and call frame.SetMenuBar

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!