From 863f336d85ee15b9bcefbbd40b7386e92bc896af Mon Sep 17 00:00:00 2001
From: yellowjello <5134058+yellowjello@users.noreply.github.com>
Date: Tue, 28 Mar 2023 20:32:00 -0700
Subject: [PATCH] Add a deck selector to Stats (#2461)
* Add a deck selector to Stats
* Windows/Linux looks more aligned with 0 top margin
* Prevent Close button from becoming default
If user navigates to deck button with shift+tab, two buttons are highlighted
on Windows/Linux.
* Tweak deck change code
- Remove unneeded initiator argument
- Use our window as the parent, so a progress window will pop up
above the correct window if required.
---
qt/aqt/forms/stats.ui | 43 +++++++++++++++----------------------------
qt/aqt/stats.py | 20 ++++++++++++++++++++
2 files changed, 35 insertions(+), 28 deletions(-)
diff --git a/qt/aqt/forms/stats.ui b/qt/aqt/forms/stats.ui
index 5557432b3..f2deb18e0 100644
--- a/qt/aqt/forms/stats.ui
+++ b/qt/aqt/forms/stats.ui
@@ -44,30 +44,17 @@
8
- 6
+ 16
6
- 6
+ 16
6
- -
-
-
- Qt::Horizontal
-
-
-
- 40
- 20
-
-
-
-
-
@@ -128,6 +115,19 @@
-
+
+
+ 4
+
+
+ 0
+
+
-
+
+
+
+
+ -
Qt::Horizontal
@@ -140,19 +140,6 @@
- -
-
-
- Qt::Horizontal
-
-
-
- 40
- 20
-
-
-
-
diff --git a/qt/aqt/stats.py b/qt/aqt/stats.py
index b1d0055ab..e77579410 100644
--- a/qt/aqt/stats.py
+++ b/qt/aqt/stats.py
@@ -8,7 +8,9 @@ from typing import Any
import aqt
import aqt.forms
import aqt.main
+from anki.decks import DeckId
from aqt import gui_hooks
+from aqt.operations.deck import set_current_deck
from aqt.qt import *
from aqt.theme import theme_manager
from aqt.utils import (
@@ -42,12 +44,25 @@ class NewDeckStats(QDialog):
f.setupUi(self)
f.groupBox.setVisible(False)
f.groupBox_2.setVisible(False)
+ if not is_mac:
+ f.horizontalLayout_4.setContentsMargins(0, 0, 0, 0)
restoreGeom(self, self.name, default_size=(800, 800))
+
+ from aqt.deckchooser import DeckChooser
+
+ DeckChooser(
+ self.mw,
+ f.deckArea,
+ on_deck_changed=self.on_deck_changed,
+ )
+
b = f.buttonBox.addButton(
tr.statistics_save_pdf(), QDialogButtonBox.ButtonRole.ActionRole
)
qconnect(b.clicked, self.saveImage)
b.setAutoDefault(False)
+ b = f.buttonBox.button(QDialogButtonBox.StandardButton.Close)
+ b.setAutoDefault(False)
maybeHideClose(self.form.buttonBox)
addCloseShortcut(self)
gui_hooks.stats_dialog_will_show(self)
@@ -69,6 +84,11 @@ class NewDeckStats(QDialog):
self.reject()
callback()
+ def on_deck_changed(self, deck_id: int) -> None:
+ set_current_deck(parent=self, deck_id=DeckId(deck_id)).success(
+ lambda _: self.refresh()
+ ).run_in_background()
+
def _imagePath(self) -> str:
name = time.strftime("-%Y-%m-%d@%H-%M-%S.pdf", time.localtime(time.time()))
name = f"anki-{tr.statistics_stats()}{name}"