Hello community, I am trying to make a TimeCtrl have AM/PM in the field. I noticed that in Ubuntu this is added automatically and it also adjusts depending on the time that is set, I was moving the parameters fmt24hr and size but I can’t make it appear, I was reading the source code and in the comment of the size parameter it says something about locale but let’s say I didn’t find anything concrete about how to assign the locale to a WxPython application, I would like to know if it is possible to get the same effect that you have in Ubuntu. I tried to do it with the local library but no change.
Some time ago I had a problem with the date format in a wx.adv.DatePickerCtrl. It was using ‘MM/DD/YYYY’ instead of the preferred ‘DD/MM/YYYY’. I noticed that the example in the wxPython Demo did use the correct format and after a bit of digging in the Demo code, I found that inserting the following line in the OnInit() method fixed my problem:
self.locale = wx.Locale(wx.LANGUAGE_DEFAULT)
I don’t have access to a Windows PC to test it with your code, but might be worth you trying it, or some variation.
Well, evidently the same code behaves differently on the two platforms. Without needing to configure anything, in the 12 hour clock the AM is shown automatically and goes up to 12, as you could see in windows it had the same value as the 24 hour field.
Is there any important difference between TimeCtrl and TimePickerCtrl? I was looking at it and the am/pm displays and adjusts correctly, I would like to know if there is a workaround for TimeCtrl, but I think I will consider using TimePickerCtrl.
Now that is very strange – the date controls are unlikely to
pick up a random instance attribute.
The theory would be that as long as the app holds on to the
attribute the wx.Locale() won’t get __del__eted … and if the del contains a switch back to the “previous” locale …
One might test that theory by doing for once:
self.__some_random_123456 = wx.Locale(....)
and for another run doing
self.__some_random_123456 = wx.Locale(....)
del self.__some_random_123456
4
self.__random_something = wx.Locale(…)
del self.__random_something
Version 1 does not work, which rules out the
init-the-system-for-magic-pickup-later theory (much like it
used to be with InitAllImageFormats()).
Version 2 does work but we don’t know why.
So:
Version 3 and 4 do “the same” – but what ?
And, try this:
5
self.locale = wx.Locale(…)
del self.locale
Does it still work ?
This is 2 and 4 combined to find out whether self.locale is
either a magic attribute being picked up later or else is
being passed to the picker control down the line
(the latter assumption could be checked by perusing the code,
and it might throw a NameError – unless self.locale is
being initialzed to, say, None elsewhere…)