From 0835129a000e030567114e10429166001390a767 Mon Sep 17 00:00:00 2001 From: Luka Warren Date: Tue, 19 Apr 2022 06:39:32 +0100 Subject: [PATCH] Fix issue #1114 by scrolling the user to the top of the page (#1810) * Scroll stats to top when exporting (#1114) It's obviously a bit of a "hacky" solution, since it's slightly jarring for users to scroll down, click export, then find themselves all the way at the top again, but it's somewhat less confusing than wondering why your PDF is broken :-) * Clarified comment in stats.py (#1114) * Apply scrolling fix to new stats screen, not legacy stats (dae) Also wait for JS callback before saving the PDF, as JS is executed asynchronously. --- CONTRIBUTORS | 1 + qt/aqt/about.py | 1 + qt/aqt/stats.py | 11 +++++++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index f56b75d18..c54faccb2 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -99,6 +99,7 @@ Sachin Govind Bruce Harris Patric Cunha Brayan Oliveira +Luka Warren ******************** diff --git a/qt/aqt/about.py b/qt/aqt/about.py index 116408b1c..79c2e758e 100644 --- a/qt/aqt/about.py +++ b/qt/aqt/about.py @@ -225,6 +225,7 @@ def show(mw: aqt.AnkiQt) -> QDialog: "Sergio Quintero", "Nicholas Flint", "Daniel Vieira Memoria10X", + "Luka Warren", ) ) diff --git a/qt/aqt/stats.py b/qt/aqt/stats.py index 90a3af964..6af03e118 100644 --- a/qt/aqt/stats.py +++ b/qt/aqt/stats.py @@ -83,8 +83,15 @@ class NewDeckStats(QDialog): path = self._imagePath() if not path: return - self.form.web.page().printToPdf(path) - tooltip(tr.statistics_saved()) + # When scrolled down in dark mode, the top of the page in the + # final PDF will have a white background, making the text and graphs + # unreadable. A simple fix for now is to scroll to the top of the + # page first. + def after_scroll(arg: Any) -> None: + self.form.web.page().printToPdf(path) + tooltip(tr.statistics_saved()) + + self.form.web.evalWithCallback("window.scrollTo(0, 0);", after_scroll) # legacy add-ons def changePeriod(self, n: Any) -> None: