mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 15:02:21 -04:00
add the ability to open deck stats in the browser
This commit is contained in:
parent
1f98ef588f
commit
1b20f948f3
2 changed files with 48 additions and 13 deletions
|
@ -144,7 +144,8 @@ class AnkiQt(QMainWindow):
|
||||||
body {
|
body {
|
||||||
/*background: -webkit-gradient(linear, left top, left bottom, from(#eee), to(#bbb));*/
|
/*background: -webkit-gradient(linear, left top, left bottom, from(#eee), to(#bbb));*/
|
||||||
background: #eee;
|
background: #eee;
|
||||||
margin: 2em; }
|
margin: 2em;
|
||||||
|
}
|
||||||
a:hover { background-color: #aaa; }
|
a:hover { background-color: #aaa; }
|
||||||
.but {
|
.but {
|
||||||
-webkit-box-shadow: 2px 2px 6px rgba(0,0,0,0.6);
|
-webkit-box-shadow: 2px 2px 6px rgba(0,0,0,0.6);
|
||||||
|
@ -1193,7 +1194,7 @@ learnt today")
|
||||||
self.cardStats.show()
|
self.cardStats.show()
|
||||||
|
|
||||||
def onDeckStats(self):
|
def onDeckStats(self):
|
||||||
aqt.stats.DeckStats(self)
|
aqt.stats.deckStats(self)
|
||||||
|
|
||||||
# Graphs
|
# Graphs
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
56
aqt/stats.py
56
aqt/stats.py
|
@ -4,7 +4,9 @@
|
||||||
|
|
||||||
from PyQt4.QtGui import *
|
from PyQt4.QtGui import *
|
||||||
from PyQt4.QtCore import *
|
from PyQt4.QtCore import *
|
||||||
|
import os, tempfile
|
||||||
from aqt.webview import AnkiWebView
|
from aqt.webview import AnkiWebView
|
||||||
|
from aqt.utils import saveGeom, restoreGeom
|
||||||
from anki.hooks import addHook
|
from anki.hooks import addHook
|
||||||
|
|
||||||
# Card stats
|
# Card stats
|
||||||
|
@ -60,26 +62,58 @@ class CardStats(object):
|
||||||
# Deck stats
|
# Deck stats
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
class DeckStats(QDialog):
|
class PrintableReport(QDialog):
|
||||||
|
|
||||||
def __init__(self, mw):
|
def __init__(self, mw, type, title, func, css):
|
||||||
self.mw = mw
|
self.mw = mw
|
||||||
QDialog.__init__(self, mw)
|
QDialog.__init__(self, mw)
|
||||||
self.setWindowTitle(_("Deck Statistics"))
|
restoreGeom(self, type)
|
||||||
|
self.type = type
|
||||||
|
self.setWindowTitle(title)
|
||||||
self.setModal(True)
|
self.setModal(True)
|
||||||
self.mw.progress.start()
|
self.mw.progress.start()
|
||||||
self.web = AnkiWebView(self)
|
self.web = AnkiWebView(self)
|
||||||
stats = self.mw.deck.deckStats()
|
stats = func()
|
||||||
l = QVBoxLayout(self)
|
l = QVBoxLayout(self)
|
||||||
l.setContentsMargins(0,0,0,0)
|
l.setContentsMargins(0,0,0,0)
|
||||||
l.addWidget(self.web)
|
l.addWidget(self.web)
|
||||||
self.setLayout(l)
|
self.setLayout(l)
|
||||||
self.web.stdHtml(stats, css=self.mw.sharedCSS+"""
|
self.report = func()
|
||||||
body { margin: 2em; }
|
self.css = css
|
||||||
h1 { font-size: 18px; border-bottom: 1px solid #000; margin-top: 1em;
|
self.web.stdHtml(self.report, css=css)
|
||||||
clear: both; }
|
box = QDialogButtonBox(QDialogButtonBox.Close)
|
||||||
.info {float:right; padding: 10px; max-width: 300px; border-radius: 5px;
|
b = box.addButton(_("Open In Browser"), QDialogButtonBox.AcceptRole)
|
||||||
background: #ddd; font-size: 14px; }
|
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.mw.progress.finish()
|
||||||
self.exec_()
|
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("""
|
||||||
|
<html><head><style>%s</style></head><body>%s</body></html>""" % (
|
||||||
|
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)
|
||||||
|
|
Loading…
Reference in a new issue