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.
This commit is contained in:
yellowjello 2023-03-28 20:32:00 -07:00 committed by GitHub
parent 2bf134dc72
commit 863f336d85
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 28 deletions

View file

@ -44,30 +44,17 @@
<number>8</number>
</property>
<property name="leftMargin">
<number>6</number>
<number>16</number>
</property>
<property name="topMargin">
<number>6</number>
</property>
<property name="rightMargin">
<number>6</number>
<number>16</number>
</property>
<property name="bottomMargin">
<number>6</number>
</property>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
@ -128,6 +115,19 @@
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="topMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item alignment="Qt::AlignLeft">
<widget class="QWidget" name="deckArea" native="true"/>
</item>
</layout>
</item>
<item alignment="Qt::AlignRight">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -140,19 +140,6 @@
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>

View file

@ -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}"