mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
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:
parent
2bf134dc72
commit
863f336d85
2 changed files with 35 additions and 28 deletions
|
@ -44,30 +44,17 @@
|
||||||
<number>8</number>
|
<number>8</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="leftMargin">
|
<property name="leftMargin">
|
||||||
<number>6</number>
|
<number>16</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="topMargin">
|
<property name="topMargin">
|
||||||
<number>6</number>
|
<number>6</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="rightMargin">
|
<property name="rightMargin">
|
||||||
<number>6</number>
|
<number>16</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="bottomMargin">
|
<property name="bottomMargin">
|
||||||
<number>6</number>
|
<number>6</number>
|
||||||
</property>
|
</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>
|
<item>
|
||||||
<widget class="QGroupBox" name="groupBox_2">
|
<widget class="QGroupBox" name="groupBox_2">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
|
@ -128,6 +115,19 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<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">
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
|
@ -140,19 +140,6 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
|
|
@ -8,7 +8,9 @@ from typing import Any
|
||||||
import aqt
|
import aqt
|
||||||
import aqt.forms
|
import aqt.forms
|
||||||
import aqt.main
|
import aqt.main
|
||||||
|
from anki.decks import DeckId
|
||||||
from aqt import gui_hooks
|
from aqt import gui_hooks
|
||||||
|
from aqt.operations.deck import set_current_deck
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
from aqt.theme import theme_manager
|
from aqt.theme import theme_manager
|
||||||
from aqt.utils import (
|
from aqt.utils import (
|
||||||
|
@ -42,12 +44,25 @@ class NewDeckStats(QDialog):
|
||||||
f.setupUi(self)
|
f.setupUi(self)
|
||||||
f.groupBox.setVisible(False)
|
f.groupBox.setVisible(False)
|
||||||
f.groupBox_2.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))
|
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(
|
b = f.buttonBox.addButton(
|
||||||
tr.statistics_save_pdf(), QDialogButtonBox.ButtonRole.ActionRole
|
tr.statistics_save_pdf(), QDialogButtonBox.ButtonRole.ActionRole
|
||||||
)
|
)
|
||||||
qconnect(b.clicked, self.saveImage)
|
qconnect(b.clicked, self.saveImage)
|
||||||
b.setAutoDefault(False)
|
b.setAutoDefault(False)
|
||||||
|
b = f.buttonBox.button(QDialogButtonBox.StandardButton.Close)
|
||||||
|
b.setAutoDefault(False)
|
||||||
maybeHideClose(self.form.buttonBox)
|
maybeHideClose(self.form.buttonBox)
|
||||||
addCloseShortcut(self)
|
addCloseShortcut(self)
|
||||||
gui_hooks.stats_dialog_will_show(self)
|
gui_hooks.stats_dialog_will_show(self)
|
||||||
|
@ -69,6 +84,11 @@ class NewDeckStats(QDialog):
|
||||||
self.reject()
|
self.reject()
|
||||||
callback()
|
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:
|
def _imagePath(self) -> str:
|
||||||
name = time.strftime("-%Y-%m-%d@%H-%M-%S.pdf", time.localtime(time.time()))
|
name = time.strftime("-%Y-%m-%d@%H-%M-%S.pdf", time.localtime(time.time()))
|
||||||
name = f"anki-{tr.statistics_stats()}{name}"
|
name = f"anki-{tr.statistics_stats()}{name}"
|
||||||
|
|
Loading…
Reference in a new issue