Open BertLindeman opened 5 years ago
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?
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:
Part of the output:
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.