2012-12-21 08:51:59 +01:00
|
|
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
|
|
|
|
from aqt.qt import *
|
|
|
|
import os, time
|
2017-01-13 08:36:26 +01:00
|
|
|
from aqt.utils import saveGeom, restoreGeom, maybeHideClose, addCloseShortcut, \
|
|
|
|
tooltip
|
2012-12-21 08:51:59 +01:00
|
|
|
import aqt
|
|
|
|
|
|
|
|
# Deck Stats
|
|
|
|
######################################################################
|
|
|
|
|
|
|
|
class DeckStats(QDialog):
|
|
|
|
|
|
|
|
def __init__(self, mw):
|
|
|
|
QDialog.__init__(self, mw, Qt.Window)
|
2016-07-04 05:22:35 +02:00
|
|
|
mw.setupDialogGC(self)
|
2012-12-21 08:51:59 +01:00
|
|
|
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
|
|
|
|
f.setupUi(self)
|
|
|
|
restoreGeom(self, self.name)
|
2017-01-13 08:36:26 +01:00
|
|
|
b = f.buttonBox.addButton(_("Save PDF"),
|
2012-12-21 08:51:59 +01:00
|
|
|
QDialogButtonBox.ActionRole)
|
2017-01-13 08:36:26 +01:00
|
|
|
b.clicked.connect(self.saveImage)
|
2012-12-21 08:51:59 +01:00
|
|
|
b.setAutoDefault(False)
|
2016-05-31 10:51:40 +02:00
|
|
|
f.groups.clicked.connect(lambda: self.changeScope("deck"))
|
2012-12-21 08:51:59 +01:00
|
|
|
f.groups.setShortcut("g")
|
2016-05-31 10:51:40 +02:00
|
|
|
f.all.clicked.connect(lambda: self.changeScope("collection"))
|
|
|
|
f.month.clicked.connect(lambda: self.changePeriod(0))
|
|
|
|
f.year.clicked.connect(lambda: self.changePeriod(1))
|
|
|
|
f.life.clicked.connect(lambda: self.changePeriod(2))
|
2012-12-21 08:51:59 +01:00
|
|
|
maybeHideClose(self.form.buttonBox)
|
2012-12-22 01:11:29 +01:00
|
|
|
addCloseShortcut(self)
|
2012-12-21 08:51:59 +01:00
|
|
|
self.refresh()
|
2016-05-31 10:51:40 +02:00
|
|
|
self.show()
|
2017-06-06 08:16:00 +02:00
|
|
|
self.activateWindow()
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2017-06-22 08:49:53 +02:00
|
|
|
def canClose(self):
|
|
|
|
return True
|
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
def reject(self):
|
|
|
|
saveGeom(self, self.name)
|
2017-06-22 08:49:53 +02:00
|
|
|
aqt.dialogs.close("DeckStats")
|
2012-12-21 08:51:59 +01:00
|
|
|
QDialog.reject(self)
|
|
|
|
|
2017-01-13 08:36:26 +01:00
|
|
|
def _imagePath(self):
|
|
|
|
name = time.strftime("-%Y-%m-%d@%H-%M-%S.pdf",
|
2012-12-21 08:51:59 +01:00
|
|
|
time.localtime(time.time()))
|
|
|
|
name = "anki-"+_("stats")+name
|
2016-07-05 11:52:26 +02:00
|
|
|
desktopPath = QStandardPaths.writableLocation(
|
|
|
|
QStandardPaths.DesktopLocation)
|
2013-06-01 20:48:24 +02:00
|
|
|
if not os.path.exists(desktopPath):
|
|
|
|
os.mkdir(desktopPath)
|
|
|
|
path = os.path.join(desktopPath, name)
|
2017-01-13 08:36:26 +01:00
|
|
|
return path
|
|
|
|
|
|
|
|
def saveImage(self):
|
|
|
|
path = self._imagePath()
|
|
|
|
self.form.web.page().printToPdf(path)
|
|
|
|
tooltip(_("A PDF file was saved to your desktop."))
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
|
|
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(immediate=True)
|
|
|
|
stats = self.mw.col.stats()
|
|
|
|
stats.wholeCollection = self.wholeCollection
|
|
|
|
self.report = stats.report(type=self.period)
|
2017-07-28 08:19:06 +02:00
|
|
|
self.form.web.stdHtml("<html><body>"+self.report+"</body></html>",
|
|
|
|
js=["jquery.js", "plot.js"])
|
2012-12-21 08:51:59 +01:00
|
|
|
self.mw.progress.finish()
|