From 8160a8d9c8553294068bf6d814b04e701ad2a659 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 13 Dec 2020 14:19:37 +0530 Subject: [PATCH] E-book viewer: Fix clock in header/footer not using system time format. Fixes #1907907 [Feature request: 24h clock format in reader](https://bugs.launchpad.net/calibre/+bug/1907907) --- src/calibre/gui2/viewer/web_view.py | 3 ++- src/pyj/read_book/prefs/head_foot.pyj | 5 +++++ src/pyj/viewer-main.pyj | 5 +++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/viewer/web_view.py b/src/calibre/gui2/viewer/web_view.py index 694001d703..aaed12d86c 100644 --- a/src/calibre/gui2/viewer/web_view.py +++ b/src/calibre/gui2/viewer/web_view.py @@ -9,7 +9,7 @@ import sys from itertools import count from PyQt5.Qt import ( QT_VERSION, QApplication, QBuffer, QByteArray, QFontDatabase, QFontInfo, QPalette, - QHBoxLayout, QMimeData, QSize, Qt, QTimer, QUrl, QWidget, pyqtSignal, QIODevice + QHBoxLayout, QMimeData, QSize, Qt, QTimer, QUrl, QWidget, pyqtSignal, QIODevice, QLocale ) from PyQt5.QtWebEngineCore import QWebEngineUrlSchemeHandler from PyQt5.QtWebEngineWidgets import ( @@ -602,6 +602,7 @@ class WebView(RestartingWebEngineView): 'show_home_page_on_ready': self.show_home_page_on_ready, 'system_colors': system_colors(), 'QT_VERSION': QT_VERSION, + 'short_time_fmt': QLocale.system().timeFormat(QLocale.FormatType.ShortFormat), } self.bridge.create_view( vprefs['session_data'], vprefs['local_storage'], field_metadata.all_metadata(), ui_data) diff --git a/src/pyj/read_book/prefs/head_foot.pyj b/src/pyj/read_book/prefs/head_foot.pyj index 95c4bfaa37..d40e52783b 100644 --- a/src/pyj/read_book/prefs/head_foot.pyj +++ b/src/pyj/read_book/prefs/head_foot.pyj @@ -140,6 +140,11 @@ else: } +def set_time_formatter(func): + nonlocal time_formatter + time_formatter = {'format': func} + + def format_time_left(seconds): hours, minutes = divmod(int(seconds / 60), 60) if hours <= 0: diff --git a/src/pyj/viewer-main.pyj b/src/pyj/viewer-main.pyj index 6bf71ed2b8..5c59dc24a9 100644 --- a/src/pyj/viewer-main.pyj +++ b/src/pyj/viewer-main.pyj @@ -5,6 +5,7 @@ from __python__ import bound_methods, hash_literals import traceback from elementmaker import E from gettext import gettext as _, install +from date import format_date import initialize # noqa: unused-import from ajax import ajax, workaround_qt_bug @@ -20,6 +21,7 @@ from read_book.globals import runtime, set_system_colors, ui_operations, default from read_book.iframe import main as iframe_main from read_book.shortcuts import add_standalone_viewer_shortcuts from read_book.view import View +from read_book.prefs.head_foot import set_time_formatter from session import local_storage, session_defaults from utils import debounce, encode_query_with_path, parse_url_params from viewer.constants import FAKE_HOST, FAKE_PROTOCOL, READER_BACKGROUND_URL @@ -177,6 +179,9 @@ def create_view(prefs, local_storage, field_metadata, ui_data): document.documentElement.style.fontFamily = f'"{ui_data.ui_font_family}", sans-serif' document.documentElement.style.fontSize = ui_data.ui_font_sz runtime.QT_VERSION = ui_data.QT_VERSION + set_time_formatter(def (d): + return format_date(d, ui_data.short_time_fmt) + ) if view is None: create_session_data(prefs, local_storage) view = View(document.getElementById('view'))