Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config.DateLocale does not format forecast date and time #141

Open
BertLindeman opened this issue Feb 9, 2019 · 1 comment
Open

Config.DateLocale does not format forecast date and time #141

BertLindeman opened this issue Feb 9, 2019 · 1 comment

Comments

@BertLindeman
Copy link
Contributor

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.

@BertLindeman
Copy link
Contributor Author

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?

BertLindeman added a commit to BertLindeman/PiClock that referenced this issue Mar 16, 2019
Fix n0bel#141 "Config.DateLocale does not format forecast date and time"
Fix part of n0bel#125 "Text layout issues":
1. Put all date/time format strings in the config (with appropriate defaults in the startup area so old configs still work)
Made some records in Config-Example.py shorter than 80 chars.
BertLindeman added a commit to BertLindeman/PiClock that referenced this issue Mar 16, 2019
Fix n0bel#122 "does not work with regional settings"

Fix part of n0bel#125 "Text layout issues":
1. Put all date/time format strings in the config (with appropriate defaults in the startup area so old configs still work)

Fix n0bel#141 "Config.DateLocale does not format forecast date and time"

Made some records in Config-Example.py shorter than 80 chars.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant