shift+click on the graphs button to access old graphs for now

This commit is contained in:
Damien Elmes 2020-06-30 17:08:10 +10:00
parent 79d04c9db7
commit 40f270c386
3 changed files with 99 additions and 8 deletions

View file

@ -76,6 +76,7 @@ class DialogManager:
"Browser": [browser.Browser, None],
"EditCurrent": [editcurrent.EditCurrent, None],
"DeckStats": [stats.DeckStats, None],
"NewDeckStats": [stats.NewDeckStats, None],
"About": [about.show, None],
"Preferences": [preferences.Preferences, None],
"sync_log": [mediasync.MediaSyncDialog, None],

View file

@ -1060,7 +1060,11 @@ title="%s" %s>%s</button>""" % (
deck = self._selectedDeck()
if not deck:
return
aqt.dialogs.open("DeckStats", self)
want_old = self.app.queryKeyboardModifiers() & Qt.ShiftModifier
if want_old:
aqt.dialogs.open("DeckStats", self)
else:
aqt.dialogs.open("NewDeckStats", self)
def onPrefs(self):
aqt.dialogs.open("Preferences", self)

View file

@ -19,11 +19,10 @@ from aqt.utils import (
tooltip,
)
# Deck Stats
######################################################################
class NewDeckStats(QDialog):
"""New deck stats."""
class DeckStats(QDialog):
def __init__(self, mw: aqt.main.AnkiQt):
QDialog.__init__(self, mw, Qt.Window)
mw.setupDialogGC(self)
@ -36,8 +35,6 @@ class DeckStats(QDialog):
self.setMinimumWidth(700)
f = self.form
f.setupUi(self)
# no night mode support yet
f.web._page.setBackgroundColor(QColor("white"))
f.groupBox.setVisible(False)
f.groupBox_2.setVisible(False)
restoreGeom(self, self.name)
@ -53,7 +50,7 @@ class DeckStats(QDialog):
def reject(self):
self.form.web = None
saveGeom(self, self.name)
aqt.dialogs.markClosed("DeckStats")
aqt.dialogs.markClosed("NewDeckStats")
QDialog.reject(self)
def closeWithCallback(self, callback):
@ -92,4 +89,93 @@ class DeckStats(QDialog):
extra = "#night"
else:
extra = ""
self.form.web.load(QUrl(f"{self.mw.serverURL()}_anki/graphs.html"+extra))
self.form.web.load(QUrl(f"{self.mw.serverURL()}_anki/graphs.html" + extra))
class DeckStats(QDialog):
"""Legacy deck stats, used by some add-ons."""
def __init__(self, mw):
QDialog.__init__(self, mw, Qt.Window)
mw.setupDialogGC(self)
self.mw = mw
self.name = "deckStats"
self.period = 0
self.form = aqt.forms.stats.Ui_Dialog()
self.oldPos = None
self.wholeCollection = False
self.setMinimumWidth(700)
f = self.form
if theme_manager.night_mode and not theme_manager.macos_dark_mode():
# the grouping box renders incorrectly in the fusion theme. 5.9+
# 5.13 behave differently to 5.14, but it looks bad in either case,
# and adjusting the top margin makes the 'save PDF' button show in
# the wrong place, so for now we just disable the border instead
self.setStyleSheet("QGroupBox { border: 0; }")
f.setupUi(self)
restoreGeom(self, self.name)
b = f.buttonBox.addButton(_("Save PDF"), QDialogButtonBox.ActionRole)
qconnect(b.clicked, self.saveImage)
b.setAutoDefault(False)
qconnect(f.groups.clicked, lambda: self.changeScope("deck"))
f.groups.setShortcut("g")
qconnect(f.all.clicked, lambda: self.changeScope("collection"))
qconnect(f.month.clicked, lambda: self.changePeriod(0))
qconnect(f.year.clicked, lambda: self.changePeriod(1))
qconnect(f.life.clicked, lambda: self.changePeriod(2))
maybeHideClose(self.form.buttonBox)
addCloseShortcut(self)
self.show()
self.refresh()
self.activateWindow()
def reject(self):
self.form.web = None
saveGeom(self, self.name)
aqt.dialogs.markClosed("DeckStats")
QDialog.reject(self)
def closeWithCallback(self, callback):
self.reject()
callback()
def _imagePath(self):
name = time.strftime("-%Y-%m-%d@%H-%M-%S.pdf", time.localtime(time.time()))
name = "anki-" + _("stats") + name
file = getSaveFile(
self,
title=_("Save PDF"),
dir_description="stats",
key="stats",
ext=".pdf",
fname=name,
)
return file
def saveImage(self):
path = self._imagePath()
if not path:
return
self.form.web.page().printToPdf(path)
tooltip(_("Saved."))
def changePeriod(self, n):
self.period = n
self.refresh()
def changeScope(self, type):
self.wholeCollection = type == "collection"
self.refresh()
def refresh(self):
self.mw.progress.start(parent=self)
stats = self.mw.col.stats()
stats.wholeCollection = self.wholeCollection
self.report = stats.report(type=self.period)
self.form.web.title = "deck stats"
self.form.web.stdHtml(
"<html><body>" + self.report + "</body></html>",
js=["jquery.js", "plot.js"],
context=self,
)
self.mw.progress.finish()