On 2/4/15 6:51 AM, Werner wrote:
Hi,

On 2/4/2015 14:30, Ed Leafe wrote:
On Feb 3, 2015, at 8:47 PM, Neil Flowers <njflower...@gmail.com> wrote:
Here’s the relevant snippet from uiApp.OnInit:

    def OnInit(self):
        app = self.dApp
        # As of wx3, locale must be set using wx.Locale; this can
only be created after the wx.App's initialization, so locale
        # is moved here (also note setting locale is no longer
toolkit-agnostic, so other toolkit bindings would need to handle it
internally)
        if dabo.loadUserLocale:
            self.locale = wx.Locale(wx.LANGUAGE_DEFAULT)

This seemed to be fine when placed in __init__ as well, so that’s
another option. I didn’t even see the locale issue manifest until I
started testing on Windows, but the above should work on any platform.
Would this cause a problem if the user has set a locale to something
other than the wx default?
Hhm, didn't think of that but yes it could.  In my app I have this
method to change the language (which is mostly borrowed from the
wxPython demo module I18N):

     def updateLanguage(self, lang):
         """Update language locale."""
         # Make *sure* any existing locale is deleted before the new
         # one is created.  The old C++ object needs to be deleted
         # before the new one is created, and if we just assign a new
         # instance to the old Python variable, the old C++ locale will
         # not be destroyed soon enough, likely causing a crash.
         if self.locale:
             assert sys.getrefcount(self.locale) <= 2
             del self.locale

         # create a locale object for this language
         if lang in supportedLangs:
             self.locale = wx.Locale(supportedLangs[lang])
             if self.locale.IsOk():
                 self.locale.AddCatalog('twcb')
             else:
                 self.locale = None
         else:
             self.locale = wx.Locale(wx.LANGUAGE_DEFAULT)

Just added the last two lines and tested it.  If update language is
called with e.g. 'it' which I don't support the last else is used and
the UI shows up in English.

Not sure how to handle that in Dabo, how/where do we get the user
selected language from?

There's two layers where we need to deal with locale. One is in dLocalize.py, and that stuff gets called before the ui is initialized. The second layer is at the ui. It seems like with code such as the above, we can still have it both ways (dLocalize sets the default, ui can override). There may be trouble in the interim but for all practical purposes if you are running a ui app you are going to initialize that before doing much else, so it's likely not a problem.

I think the code above looks good, we need to hook to it from the ui initialization. Having a supportedLangs attribute seems like a good explicit way to handle it, and that should likely be part of settings.py.

One thing that may bite us is if the existing locale is garbage collected but then the new language isn't supported, perhaps (not sure here) we should just use whatever the existing locale is instead of defaulting to wx's default.

I'm wondering about the rationale of wx taking control of python's locale like this, but we do need to deal with it.

Paul

_______________________________________________
Post Messages to: Dabo-users@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: http://leafe.com/archives/byMID/54d24171.4010...@mcnettware.com

Reply via email to