PiClock
PiClock copied to clipboard
Config.DateLocale does not format forecast date and time
Have been busy trying to debug #122. Conclusion sofar: date and time in the forecast boxes are formatted using the locale that is active at the start of the clock. The Config.DateLocale has no grip on this.
Added a few debug lines to the clock to see the locale being used.
Running host with LC_TIME="en_US.UTF-8"
Started the clock thus as dutch locale:
LC_TIME=nl_NL.utf8 python PyQtPiClock.py Config-xenon462
In Config-xenon462.py:
DateLocale = 'ru_RU.utf8'
Part of the output:
DEBUG in mainline: setlocale(2, ru_RU.utf8)
.......
getting current and forecast:Sat Feb 9 17:32:07 2019
https://api.darksky.net/forecast/xxxxxxxxx/69.008562,33.089993?units=auto&lang=ru&r=0.576085599256
wxstart for radar1
wxstart for radar2
DEBUG in range(0, 3) DBGday fmt:{0:%A %H:%M} time:1549735200 value:zaterdag 19:00
('DEBUG in range(0, 3) locale LC_TIME:%s', "('nl_NL', 'UTF-8')")
DEBUG in range(0, 3) DBGday fmt:{0:%A %H:%M} time:1549746000 value:zaterdag 22:00
('DEBUG in range(0, 3) locale LC_TIME:%s', "('nl_NL', 'UTF-8')")
DEBUG in range(0, 3) DBGday fmt:{0:%A %H:%M} time:1549756800 value:zondag 01:00
('DEBUG in range(0, 3) locale LC_TIME:%s', "('nl_NL', 'UTF-8')")
DEBUG in tick() setlocale(2, ru_RU.utf8)
I do not have enough python background to understand apparently. In the mainline we see ru_RU.utf8 being set as LC_TIME (shown as 2).
And yet nl_NL is used for the forecasts. So I do not understand. . . . .
Secondary thought. is the locale set too many times? My thought would be ONCE should be enough.
Found an issue QT backend changes locale That issue made me test with: test_locale_sub0.py
#!/usr/bin/env python2
# -*- coding: UTF-8 -*-
import locale
DateLocale = 'ru_RU.utf8'
def setlocale():
try:
locale.setlocale(locale.LC_TIME, DateLocale)
except Exception as e:
print("FAIL setlocale(%s, %s) ERR:%s" % (locale.LC_TIME, DateLocale, e))
print("Before SETlocale LC_TIME:%s" % str(locale.getlocale(locale.LC_TIME)))
setlocale()
print("getlocale LC_TIME:%s" % str(locale.getlocale(locale.LC_TIME)))
from PyQt4 import QtGui
print("after import \tgetlocale LC_TIME:%s" % str(locale.getlocale(locale.LC_TIME)))
a = QtGui.QApplication([])
print("after QtGui.Qapplication\tgetlocale LC_TIME:%s" % str(locale.getlocale(locale.LC_TIME)))
w = QtGui.QWidget()
print("after QtGui.QWidget \tgetlocale LC_TIME:%s" % str(locale.getlocale(locale.LC_TIME)))
w.show()
print("after w.show() \tgetlocale LC_TIME:%s" % str(locale.getlocale(locale.LC_TIME)))
That shows that the locale has been reset after the definition of the Qapplication:
Before SETlocale LC_TIME:(None, None)
getlocale LC_TIME:('ru_RU', 'UTF-8')
after import getlocale LC_TIME:('ru_RU', 'UTF-8')
after QtGui.Qapplication getlocale LC_TIME:('en_US', 'UTF-8')
after QtGui.QWidget getlocale LC_TIME:('en_US', 'UTF-8')
after w.show() getlocale LC_TIME:('en_US', 'UTF-8')
Added a setlocale after QtGui.QApplication and then the locale does not change back to en_US anymore:
after import getlocale LC_TIME:('ru_RU', 'UTF-8')
after QtGui.Qapplication getlocale LC_TIME:('en_US', 'UTF-8')
setlocale AGAIN getlocale LC_TIME:('ru_RU', 'UTF-8')
after QtGui.QWidget getlocale LC_TIME:('ru_RU', 'UTF-8')
after w.show() getlocale LC_TIME:('ru_RU', 'UTF-8')
As I have no experience with QT: does anyone know a way to tell QApplication to use the current locale on the definition?