[wxPython-users] Re: wx.Locale mystery
Robin Dunn
robin at alldunn.com
Thu Dec 20 11:51:43 PST 2007
Donn Ingle wrote:
> Well,
> In follow up: I have had some success. With that great tip from Stefano
> things are looking up. Here's the nutshell:
I'd like to add a bit more info here for the record.
1. The reason that you need to keep a reference to the wx.Locale object
is because the former locale is restored when the C++ wx.Locale instance
is destroyed. So if you are setting to a locale other than what is the
system's default you must keep that reference until the end of the
program or until you want to switch or restore locales.
2. If you have already created one wx.Locale, and want to create another
one to switch to a different language, then because of the order that
Python manages garbage collection you have to be careful how you do it.
The problem arises when you have code like this:
self.loc = wx.Locale(FOO1)
...
self.loc = wx.Locale(FOO2)
In this case the first locale object is not destroyed until after the
2nd one is created, but since the C++ object will restore the "former"
locale when the object is destroyed then you end up with no current
locale set, and a bad pointer that will likely cause a crash when the
FOO2 object is eventually destroyed. So instead you need to do
something like this to give the first object a chance to be destroyed
before the 2nd one is created (and make sure you only have the single
reference to the locale object):
self.loc = wx.Locale(FOO1)
...
del self.loc
self.loc = wx.Locale(FOO2)
3. On Linux/Unix there are a few non-obvious things that need to be done
to make it work. First the system locales need to be set up for the
languages that you want to support, otherwise the C runtime library will
refuse to switch to the locale and the init of wx.Locale will fail. You
can run "locale -a" to see what locales the system can support. Second
the message catalogs for GTK need to be installed for the "native"
buttons, dialogs, etc. to get the translated text. (It seems like there
was a 3rd item that I can't remember right now...)
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
More information about the wxpython-users
mailing list