Set locale the wxPython way

607 views
Skip to first unread message

Boštjan Mejak

unread,
Jun 30, 2012, 10:38:34 AM6/30/12
to wxPython Mailing List
I prefer wxPython code over Python code. I was wondering how to set a new locale in a script the wxPython way. I know about the Python way of importing the locale module and then using it to set a new locale.

How can I set a new locale using wxPython and not Python?

I was thinking in the terms of wx.Locale(wx.LANGUAGE_GERMAN). Is this piece of code enough to change the current locale to German locale? Or are there more hacks involved?

Steve Barnes

unread,
Jun 30, 2012, 10:41:33 AM6/30/12
to wxPython Mailing List
I think you need to keep a reference to the returned locale object.

-----Original Message-----

Boštjan Mejak

unread,
Jun 30, 2012, 10:44:33 AM6/30/12
to wxpytho...@googlegroups.com
What for?

myLocale = wx.Locale(wx.LANGUAGE_GERMAN)

myLocale.SetLocale()

Something like that perhaps?

Steve Barnes

unread,
Jun 30, 2012, 10:56:13 AM6/30/12
to wxpytho...@googlegroups.com
I think I recall another thread mentioning that once your wx locale goes out of scope the locale reverts to default so self.locale = etc.


-----Original Message-----

From: Boštjan Mejak
--

Boštjan Mejak

unread,
Jul 1, 2012, 4:05:48 AM7/1/12
to wxpytho...@googlegroups.com
Can you be more specific please?

Steve Barnes

unread,
Jul 1, 2012, 1:30:21 PM7/1/12
to wxpytho...@googlegroups.com
If you create a locale object in a function as a local variable assignment then when the function exits the locale will cease to exist....


-----Original Message-----

From: Boštjan Mejak
Sent: 1 Jul 2012 08:05:54 GMT
To: wxpytho...@googlegroups.com
Subject: Re: [wxPython-users] Set locale the wxPython way

--

Boštjan Mejak

unread,
Jul 1, 2012, 3:11:11 PM7/1/12
to wxpytho...@googlegroups.com
What if I put
self.locale = wx.Locale(wx.LANGUAGE_GERMAN)
into the OnInit() method of wx.App class? Would that suffice?

Steve Barnes

unread,
Jul 1, 2012, 3:58:18 PM7/1/12
to wxpytho...@googlegroups.com
Should do while that class object exists of course.


-----Original Message-----

From: Boštjan Mejak
Sent: 1 Jul 2012 19:11:21 GMT
To: wxpytho...@googlegroups.com
Subject: Re: [wxPython-users] Set locale the wxPython way

--

Boštjan Mejak

unread,
Jul 2, 2012, 3:50:05 AM7/2/12
to wxpytho...@googlegroups.com
class MyApplication(wx.App):

    def OnInit(self):
        self.locale = wx.Locale(wx.LANGUAGE_GERMAN)


So something like that might work, no? Is it really necessary that I do the 'self.locale =' thing?

Boštjan Mejak

unread,
Jul 2, 2012, 5:01:35 AM7/2/12
to wxpytho...@googlegroups.com
You said that you think I need to keep a reference to the returned locale object. Anyone knows if I need this reference or not?

Mike Driscoll

unread,
Jul 2, 2012, 10:20:24 AM7/2/12
to wxpytho...@googlegroups.com
Just try it both ways and see which works

Robin Dunn

unread,
Jul 2, 2012, 11:30:18 AM7/2/12
to wxpytho...@googlegroups.com
Yes. Otherwise the locale is reset to the previous settings when the
locale object is garbage collected. From the docs for the destructor:

"""
The destructor, like the constructor, also has global side effects: the
previously set locale is restored and so the changes described in Init()
documentation are rolled back.
"""


--
Robin Dunn
Software Craftsman
http://wxPython.org



Reply all
Reply to author
Forward
0 new messages