diff --git a/aqt/main.py b/aqt/main.py index 9cbcb6a06..ef9b82b57 100755 --- a/aqt/main.py +++ b/aqt/main.py @@ -144,7 +144,8 @@ class AnkiQt(QMainWindow): body { /*background: -webkit-gradient(linear, left top, left bottom, from(#eee), to(#bbb));*/ background: #eee; -margin: 2em; } +margin: 2em; +} a:hover { background-color: #aaa; } .but { -webkit-box-shadow: 2px 2px 6px rgba(0,0,0,0.6); @@ -1193,7 +1194,7 @@ learnt today") self.cardStats.show() def onDeckStats(self): - aqt.stats.DeckStats(self) + aqt.stats.deckStats(self) # Graphs ########################################################################## diff --git a/aqt/stats.py b/aqt/stats.py index 1d5ffdfaf..8ce74ef65 100644 --- a/aqt/stats.py +++ b/aqt/stats.py @@ -4,7 +4,9 @@ from PyQt4.QtGui import * from PyQt4.QtCore import * +import os, tempfile from aqt.webview import AnkiWebView +from aqt.utils import saveGeom, restoreGeom from anki.hooks import addHook # Card stats @@ -60,26 +62,58 @@ class CardStats(object): # Deck stats ###################################################################### -class DeckStats(QDialog): +class PrintableReport(QDialog): - def __init__(self, mw): + def __init__(self, mw, type, title, func, css): self.mw = mw QDialog.__init__(self, mw) - self.setWindowTitle(_("Deck Statistics")) + restoreGeom(self, type) + self.type = type + self.setWindowTitle(title) self.setModal(True) self.mw.progress.start() self.web = AnkiWebView(self) - stats = self.mw.deck.deckStats() + stats = func() l = QVBoxLayout(self) l.setContentsMargins(0,0,0,0) l.addWidget(self.web) self.setLayout(l) - self.web.stdHtml(stats, css=self.mw.sharedCSS+""" -body { margin: 2em; } -h1 { font-size: 18px; border-bottom: 1px solid #000; margin-top: 1em; - clear: both; } -.info {float:right; padding: 10px; max-width: 300px; border-radius: 5px; - background: #ddd; font-size: 14px; } -""") + self.report = func() + self.css = css + self.web.stdHtml(self.report, css=css) + box = QDialogButtonBox(QDialogButtonBox.Close) + b = box.addButton(_("Open In Browser"), QDialogButtonBox.AcceptRole) + box.button(QDialogButtonBox.Close).setDefault(True) + l.addWidget(box) + self.connect(box, SIGNAL("accepted()"), self.browser) + self.connect(box, SIGNAL("rejected()"), self, SLOT("reject()")) self.mw.progress.finish() self.exec_() + + def reject(self): + saveGeom(self, self.type) + QDialog.reject(self) + + def browser(self): + # dump to a temporary file + tmpdir = tempfile.mkdtemp(prefix="anki") + path = os.path.join(tmpdir, "report.html") + open(path, "w").write(""" +
%s""" % ( + self.css, self.report)) + QDesktopServices.openUrl(QUrl("file://" + path)) + +def deckStats(mw): + css=mw.sharedCSS+""" +body { margin: 2em; font-family: arial; } +h1 { font-size: 18px; border-bottom: 1px solid #000; margin-top: 1em; + clear: both; margin-bottom: 0.5em; } +.info {float:right; padding: 10px; max-width: 300px; border-radius: 5px; + background: #ddd; font-size: 14px; } +""" + return PrintableReport( + mw, + "deckstats", + _("Deck Statistics"), + mw.deck.deckStats, + css)