mirror of
https://github.com/ankitects/anki.git
synced 2025-09-22 07:52:24 -04:00
add card stats
This commit is contained in:
parent
3c8763602c
commit
437da036ea
3 changed files with 109 additions and 32 deletions
|
@ -19,7 +19,7 @@ class DeckBrowser(object):
|
||||||
self.web = mw.web
|
self.web = mw.web
|
||||||
self._browserLastRefreshed = 0
|
self._browserLastRefreshed = 0
|
||||||
self._decks = []
|
self._decks = []
|
||||||
addHook("deckClosing", self.onClose)
|
addHook("deckClosing", self._onClose)
|
||||||
|
|
||||||
def show(self, _init=True):
|
def show(self, _init=True):
|
||||||
if _init:
|
if _init:
|
||||||
|
@ -37,7 +37,7 @@ class DeckBrowser(object):
|
||||||
# show
|
# show
|
||||||
self._renderPage()
|
self._renderPage()
|
||||||
|
|
||||||
def onClose(self, deck):
|
def _onClose(self):
|
||||||
print "onClose"
|
print "onClose"
|
||||||
return
|
return
|
||||||
if deck.finishScheduler:
|
if deck.finishScheduler:
|
||||||
|
|
60
aqt/main.py
60
aqt/main.py
|
@ -17,7 +17,7 @@ from anki.utils import addTags, parseTags, canonifyTags, stripHTML, checksum
|
||||||
from anki.hooks import runHook, addHook, removeHook
|
from anki.hooks import runHook, addHook, removeHook
|
||||||
import anki.consts
|
import anki.consts
|
||||||
|
|
||||||
import aqt, aqt.dockable, aqt.facteditor, aqt.progress, aqt.webview
|
import aqt, aqt.facteditor, aqt.progress, aqt.webview, aqt.stats
|
||||||
from aqt.utils import saveGeom, restoreGeom, showInfo, showWarning, \
|
from aqt.utils import saveGeom, restoreGeom, showInfo, showWarning, \
|
||||||
saveState, restoreState, getOnlyText, askUser, GetTextDialog, \
|
saveState, restoreState, getOnlyText, askUser, GetTextDialog, \
|
||||||
askUserDialog, applyStyles, getText, showText
|
askUserDialog, applyStyles, getText, showText
|
||||||
|
@ -76,6 +76,7 @@ class AnkiQt(QMainWindow):
|
||||||
self.setupVersion()
|
self.setupVersion()
|
||||||
self.setupMisc()
|
self.setupMisc()
|
||||||
self.setupAutoUpdate()
|
self.setupAutoUpdate()
|
||||||
|
self.setupCardStats()
|
||||||
# screens
|
# screens
|
||||||
self.setupDeckBrowser()
|
self.setupDeckBrowser()
|
||||||
self.setupOverview()
|
self.setupOverview()
|
||||||
|
@ -106,10 +107,6 @@ class AnkiQt(QMainWindow):
|
||||||
runHook("deckLoading", self.deck)
|
runHook("deckLoading", self.deck)
|
||||||
self.moveToState("overview")
|
self.moveToState("overview")
|
||||||
|
|
||||||
def _deckClosingState(self, oldState):
|
|
||||||
"Run once, before a deck is closed."
|
|
||||||
runHook("deckClosing", self.deck)
|
|
||||||
|
|
||||||
def _overviewState(self, oldState):
|
def _overviewState(self, oldState):
|
||||||
self.overview.show()
|
self.overview.show()
|
||||||
|
|
||||||
|
@ -331,7 +328,8 @@ Please do not file a bug report with Anki.<br>""")
|
||||||
self.resize(500, 500)
|
self.resize(500, 500)
|
||||||
|
|
||||||
def closeAllDeckWindows(self):
|
def closeAllDeckWindows(self):
|
||||||
aqt.dialogs.closeAll()
|
print "closealldeckwindows()"
|
||||||
|
#aqt.dialogs.closeAll()
|
||||||
|
|
||||||
# to port
|
# to port
|
||||||
# elif self.state == "studyScreen":
|
# elif self.state == "studyScreen":
|
||||||
|
@ -554,8 +552,8 @@ Debug info:\n%s""") % traceback.format_exc(), help="DeckErrors")
|
||||||
"(Auto)save and close. Prompt if necessary. True if okay to proceed."
|
"(Auto)save and close. Prompt if necessary. True if okay to proceed."
|
||||||
if not self.deck:
|
if not self.deck:
|
||||||
return
|
return
|
||||||
# allow any focusOut()s to run first
|
runHook("deckClosing")
|
||||||
self.setFocus()
|
print "focusOut() should be handled with deckClosing now"
|
||||||
self.closeAllDeckWindows()
|
self.closeAllDeckWindows()
|
||||||
self.deck.close()
|
self.deck.close()
|
||||||
self.deck = None
|
self.deck = None
|
||||||
|
@ -1169,33 +1167,35 @@ learnt today")
|
||||||
tb = self.form.toolBar
|
tb = self.form.toolBar
|
||||||
self.config['showToolbar'] = tb.isVisible()
|
self.config['showToolbar'] = tb.isVisible()
|
||||||
|
|
||||||
# Tools - statistics
|
# Dockable widgets
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
def onDeckStats(self):
|
def addDockable(self, title, w):
|
||||||
txt = anki.stats.DeckStats(self.deck).report()
|
dock = QDockWidget(title, self)
|
||||||
self.help.showText(txt)
|
dock.setObjectName(title)
|
||||||
|
dock.setAllowedAreas(Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea)
|
||||||
|
dock.setFeatures(QDockWidget.DockWidgetClosable)
|
||||||
|
dock.setWidget(w)
|
||||||
|
self.addDockWidget(Qt.RightDockWidgetArea, dock)
|
||||||
|
return dock
|
||||||
|
|
||||||
|
def rmDockable(self, dock):
|
||||||
|
self.removeDockWidget(dock)
|
||||||
|
|
||||||
|
# Card & deck stats
|
||||||
|
##########################################################################
|
||||||
|
|
||||||
|
def setupCardStats(self):
|
||||||
|
self.cardStats = aqt.stats.CardStats(self)
|
||||||
|
|
||||||
def onCardStats(self):
|
def onCardStats(self):
|
||||||
addHook("showQuestion", self.onCardStats)
|
self.cardStats.show()
|
||||||
addHook("deckFinished", self.onCardStats)
|
|
||||||
txt = ""
|
|
||||||
if self.reviewer.card:
|
|
||||||
txt += _("<h1>Current card</h1>")
|
|
||||||
txt += self.deck.cardStats(self.reviewer.card)
|
|
||||||
lc = self.reviewer.lastCard()
|
|
||||||
if lc:
|
|
||||||
txt += _("<h1>Last card</h1>")
|
|
||||||
txt += self.deck.cardStats(lc)
|
|
||||||
if not txt:
|
|
||||||
txt = _("No current card or last card.")
|
|
||||||
print txt
|
|
||||||
#self.help.showText(txt, py={'hide': self.removeCardStatsHook})
|
|
||||||
|
|
||||||
def removeCardStatsHook(self):
|
def onDeckStats(self):
|
||||||
"Remove the update hook if the help menu was changed."
|
aqt.stats.DeckStats(self)
|
||||||
removeHook("showQuestion", self.onCardStats)
|
|
||||||
removeHook("deckFinished", self.onCardStats)
|
# Graphs
|
||||||
|
##########################################################################
|
||||||
|
|
||||||
def onShowGraph(self):
|
def onShowGraph(self):
|
||||||
self.setStatus(_("Loading graphs (may take time)..."))
|
self.setStatus(_("Loading graphs (may take time)..."))
|
||||||
|
|
77
aqt/stats.py
Normal file
77
aqt/stats.py
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
||||||
|
|
||||||
|
from PyQt4.QtGui import *
|
||||||
|
from PyQt4.QtCore import *
|
||||||
|
from aqt.webview import AnkiWebView
|
||||||
|
from anki.hooks import addHook
|
||||||
|
|
||||||
|
# Card stats
|
||||||
|
######################################################################
|
||||||
|
|
||||||
|
class CardStats(object):
|
||||||
|
def __init__(self, mw):
|
||||||
|
self.mw = mw
|
||||||
|
self.shown = False
|
||||||
|
addHook("showQuestion", self._update)
|
||||||
|
addHook("deckClosing", self.hide)
|
||||||
|
|
||||||
|
def show(self):
|
||||||
|
if not self.shown:
|
||||||
|
self.web = AnkiWebView(self.mw)
|
||||||
|
self.web.setMaximumWidth(400)
|
||||||
|
self.shown = self.mw.addDockable(_("Card Statistics"), self.web)
|
||||||
|
self.shown.connect(self.shown, SIGNAL("visibilityChanged(bool)"),
|
||||||
|
self._visChange)
|
||||||
|
self._update()
|
||||||
|
|
||||||
|
def hide(self):
|
||||||
|
if self.shown:
|
||||||
|
self.mw.rmDockable(self.shown)
|
||||||
|
self.shown = None
|
||||||
|
|
||||||
|
def _visChange(self, vis):
|
||||||
|
if not vis:
|
||||||
|
# schedule removal for after evt has finished
|
||||||
|
self.mw.progress.timer(100, self.hide, False)
|
||||||
|
|
||||||
|
def _update(self):
|
||||||
|
if not self.shown:
|
||||||
|
return
|
||||||
|
txt = ""
|
||||||
|
r = self.mw.reviewer
|
||||||
|
d = self.mw.deck
|
||||||
|
if r.card:
|
||||||
|
txt += _("<h1>Current card</h1>")
|
||||||
|
txt += d.cardStats(r.card)
|
||||||
|
lc = r.lastCard()
|
||||||
|
if lc:
|
||||||
|
txt += _("<h1>Last card</h1>")
|
||||||
|
txt += d.cardStats(lc)
|
||||||
|
if not txt:
|
||||||
|
txt = _("No current card or last card.")
|
||||||
|
print txt
|
||||||
|
self.web.setHtml("""
|
||||||
|
<html><head>
|
||||||
|
<style>table { font-size: 12px; } h1 { font-size: 14px; }</style>
|
||||||
|
</head><body><center>%s</center></body></html>"""%txt)
|
||||||
|
|
||||||
|
# Deck stats
|
||||||
|
######################################################################
|
||||||
|
|
||||||
|
class DeckStats(QDialog):
|
||||||
|
|
||||||
|
def __init__(self, mw):
|
||||||
|
self.mw = mw
|
||||||
|
QDialog.__init__(self, mw)
|
||||||
|
self.setModal(True)
|
||||||
|
self.mw.progress.start()
|
||||||
|
self.web = AnkiWebView(self)
|
||||||
|
stats = self.mw.deck.deckStats()
|
||||||
|
l = QVBoxLayout(self)
|
||||||
|
l.addWidget(self.web)
|
||||||
|
self.setLayout(l)
|
||||||
|
self.web.setHtml(stats)
|
||||||
|
self.mw.progress.finish()
|
||||||
|
self.exec_()
|
Loading…
Reference in a new issue