mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
add answer button; more display tweaks; fix bold munging
This commit is contained in:
parent
46c14b5efc
commit
d3a77c1c67
3 changed files with 133 additions and 138 deletions
120
aqt/main.py
120
aqt/main.py
|
@ -155,9 +155,12 @@ 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));
|
||||||
margin: 1em; }
|
margin: 1em; }
|
||||||
a:hover { background-color: #aaa; }
|
a:hover { background-color: #aaa; }
|
||||||
.but { font-size: 80%; padding: 3; background-color: #bbb;
|
.but { font-size: 80%; padding: 3; background-color: #ccc;
|
||||||
border-radius: 2px; color: #000; margin: 0 5 0 5; text-decoration:
|
border-radius: 5px; color: #000; margin: 0 5 0 5; text-decoration:
|
||||||
none; display: inline-block; }
|
none; display: inline-block;
|
||||||
|
-webkit-box-shadow: 2px 2px 6px rgba(0,0,0,0.6);
|
||||||
|
border: 1px solid #aaa;
|
||||||
|
}
|
||||||
.but:focus, .but:hover { background-color: #aaa; }
|
.but:focus, .but:hover { background-color: #aaa; }
|
||||||
.gbut { background-color: #7c7; }
|
.gbut { background-color: #7c7; }
|
||||||
.gbut:hover, .gbut:focus { background-color: #5a5; }
|
.gbut:hover, .gbut:focus { background-color: #5a5; }
|
||||||
|
@ -519,117 +522,6 @@ counts are %d %d %d
|
||||||
import aqt.tray
|
import aqt.tray
|
||||||
self.trayIcon = aqt.tray.AnkiTrayIcon(self)
|
self.trayIcon = aqt.tray.AnkiTrayIcon(self)
|
||||||
|
|
||||||
# Buttons
|
|
||||||
##########################################################################
|
|
||||||
|
|
||||||
def setupButtons(self):
|
|
||||||
print "setupbuttons"
|
|
||||||
return
|
|
||||||
# ask
|
|
||||||
self.connect(self.form.showAnswerButton, SIGNAL("clicked()"),
|
|
||||||
lambda: self.moveToState("showAnswer"))
|
|
||||||
if sys.platform.startswith("win32"):
|
|
||||||
self.form.showAnswerButton.setFixedWidth(358)
|
|
||||||
else:
|
|
||||||
self.form.showAnswerButton.setFixedWidth(351)
|
|
||||||
self.form.showAnswerButton.setFixedHeight(41)
|
|
||||||
# answer
|
|
||||||
for i in range(1, 5):
|
|
||||||
b = getattr(self.form, "easeButton%d" % i)
|
|
||||||
b.setFixedWidth(85)
|
|
||||||
self.connect(b, SIGNAL("clicked()"),
|
|
||||||
lambda i=i: self.cardAnswered(i))
|
|
||||||
# type answer
|
|
||||||
outer = QHBoxLayout()
|
|
||||||
outer.setSpacing(0)
|
|
||||||
outer.setContentsMargins(0,0,0,0)
|
|
||||||
outer.addStretch(0)
|
|
||||||
class QLineEditNoUndo(QLineEdit):
|
|
||||||
def __init__(self, parent):
|
|
||||||
self.parent = parent
|
|
||||||
QLineEdit.__init__(self, parent)
|
|
||||||
def keyPressEvent(self, evt):
|
|
||||||
if evt.matches(QKeySequence.Undo):
|
|
||||||
evt.accept()
|
|
||||||
if self.parent.form.actionUndo.isEnabled():
|
|
||||||
self.parent.onUndo()
|
|
||||||
else:
|
|
||||||
return QLineEdit.keyPressEvent(self, evt)
|
|
||||||
self.typeAnswerField = QLineEditNoUndo(self)
|
|
||||||
self.typeAnswerField.setObjectName("typeAnswerField")
|
|
||||||
self.typeAnswerField.setFixedWidth(351)
|
|
||||||
vbox = QVBoxLayout()
|
|
||||||
vbox.setSpacing(0)
|
|
||||||
vbox.setContentsMargins(0,0,0,0)
|
|
||||||
vbox.addWidget(self.typeAnswerField)
|
|
||||||
self.typeAnswerShowButton = QPushButton(_("Show Answer"))
|
|
||||||
hbox = QHBoxLayout()
|
|
||||||
hbox.setContentsMargins(0,0,0,0)
|
|
||||||
hbox.addWidget(self.typeAnswerShowButton)
|
|
||||||
vbox.addLayout(hbox)
|
|
||||||
self.connect(self.typeAnswerShowButton, SIGNAL("clicked()"),
|
|
||||||
lambda: self.moveToState("showAnswer"))
|
|
||||||
outer.addLayout(vbox)
|
|
||||||
outer.addStretch(0)
|
|
||||||
self.form.typeAnswerPage.setLayout(outer)
|
|
||||||
|
|
||||||
def hideButtons(self):
|
|
||||||
self.form.buttonStack.hide()
|
|
||||||
|
|
||||||
def showAnswerButton(self):
|
|
||||||
if self.currentCard.cardModel.typeAnswer:
|
|
||||||
self.form.buttonStack.setCurrentIndex(2)
|
|
||||||
self.typeAnswerField.setFocus()
|
|
||||||
self.typeAnswerField.setText("")
|
|
||||||
else:
|
|
||||||
self.form.buttonStack.setCurrentIndex(0)
|
|
||||||
self.form.showAnswerButton.setFocus()
|
|
||||||
self.form.buttonStack.show()
|
|
||||||
|
|
||||||
def showEaseButtons(self):
|
|
||||||
self.updateEaseButtons()
|
|
||||||
self.form.buttonStack.setCurrentIndex(1)
|
|
||||||
self.form.buttonStack.show()
|
|
||||||
self.form.buttonStack.setLayoutDirection(Qt.LeftToRight)
|
|
||||||
if self.learningButtons():
|
|
||||||
self.form.easeButton2.setText(_("Good"))
|
|
||||||
self.form.easeButton3.setText(_("Easy"))
|
|
||||||
self.form.easeButton4.setText(_("Very Easy"))
|
|
||||||
else:
|
|
||||||
self.form.easeButton2.setText(_("Hard"))
|
|
||||||
self.form.easeButton3.setText(_("Good"))
|
|
||||||
self.form.easeButton4.setText(_("Easy"))
|
|
||||||
getattr(self.form, "easeButton%d" % self.defaultEaseButton()).\
|
|
||||||
setFocus()
|
|
||||||
|
|
||||||
def learningButtons(self):
|
|
||||||
return not self.currentCard.successive
|
|
||||||
|
|
||||||
def defaultEaseButton(self):
|
|
||||||
if not self.currentCard.successive:
|
|
||||||
return 2
|
|
||||||
else:
|
|
||||||
return 3
|
|
||||||
|
|
||||||
def updateEaseButtons(self):
|
|
||||||
nextInts = {}
|
|
||||||
for i in range(1, 5):
|
|
||||||
l = getattr(self.form, "easeLabel%d" % i)
|
|
||||||
if self.config['suppressEstimates']:
|
|
||||||
l.setText("")
|
|
||||||
elif i == 1:
|
|
||||||
txt = _("Soon")
|
|
||||||
if self.config['colourTimes']:
|
|
||||||
txt = '<span style="color: #700"><b>%s</b></span>' % txt
|
|
||||||
l.setText(txt)
|
|
||||||
else:
|
|
||||||
txt = self.deck.nextIntervalStr(
|
|
||||||
self.currentCard, i)
|
|
||||||
txt = "<b>" + txt + "</b>"
|
|
||||||
if i == self.defaultEaseButton() and self.config['colourTimes']:
|
|
||||||
txt = '<span style="color: #070">' + txt + '</span>'
|
|
||||||
l.setText(txt)
|
|
||||||
|
|
||||||
# Deck loading & saving: backend
|
# Deck loading & saving: backend
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
|
135
aqt/reviewer.py
135
aqt/reviewer.py
|
@ -56,10 +56,52 @@ class Reviewer(object):
|
||||||
self.state != "getQuestion"))
|
self.state != "getQuestion"))
|
||||||
self.form.actionRepeatAudio.setEnabled(snd)
|
self.form.actionRepeatAudio.setEnabled(snd)
|
||||||
|
|
||||||
|
# HTML helpers
|
||||||
|
##########################################################################
|
||||||
|
|
||||||
|
_css = """
|
||||||
|
a.ansbut {
|
||||||
|
display: block; position: fixed;
|
||||||
|
bottom: 5px; width: 250px; left: 50%; margin-left: -125px;
|
||||||
|
height: 40px; background-color: #ccc;
|
||||||
|
border-radius: 5px;
|
||||||
|
text-align: center;
|
||||||
|
color: #000; text-decoration: none;
|
||||||
|
-webkit-box-shadow: 2px 2px 6px rgba(0,0,0,0.6);
|
||||||
|
border: 1px solid #aaa;
|
||||||
|
|
||||||
|
}
|
||||||
|
a.ansbut:focus {
|
||||||
|
border: 1px solid #333; border-radius: 5px;
|
||||||
|
}
|
||||||
|
div.ansbut {
|
||||||
|
position: relative; top: 25%;
|
||||||
|
}
|
||||||
|
div#filler {
|
||||||
|
height: 20px;
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
def _renderQA(self, card, text):
|
||||||
|
# we want to include enough space at the bottom to allow for the
|
||||||
|
# answer buttons
|
||||||
|
buf = "<div id=filler></div>"
|
||||||
|
self.web.stdHtml(text+buf, self._styles(), bodyClass=card.bgClass())
|
||||||
|
|
||||||
|
def _styles(self):
|
||||||
|
css = self.mw.sharedCSS
|
||||||
|
css += self.card.model().css
|
||||||
|
css += self._css
|
||||||
|
css = runFilter("addStyles", css)
|
||||||
|
return css
|
||||||
|
|
||||||
# Showing the question
|
# Showing the question
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
_qHtml = """
|
||||||
|
%(q)s
|
||||||
|
%(but)s"""
|
||||||
|
|
||||||
def _showQuestion(self):
|
def _showQuestion(self):
|
||||||
# fixme: timeboxing
|
# fixme: timeboxing
|
||||||
# fixme: q/a separation
|
# fixme: q/a separation
|
||||||
|
@ -70,22 +112,22 @@ class Reviewer(object):
|
||||||
if (#self.state != self.oldState and not nosound
|
if (#self.state != self.oldState and not nosound
|
||||||
self.mw.config['autoplaySounds']):
|
self.mw.config['autoplaySounds']):
|
||||||
playFromText(q)
|
playFromText(q)
|
||||||
q = mungeQA(q)
|
# render
|
||||||
self.handleTypeAnsQ()
|
buf = self._qHtml % dict(
|
||||||
self._renderQA(c, q)
|
q=mungeQA(q),
|
||||||
|
but=self._questionButtons())
|
||||||
|
self._renderQA(c, buf)
|
||||||
|
|
||||||
def _renderQA(self, card, text):
|
# Question buttons
|
||||||
self.web.stdHtml(text, card.model().css, bodyClass=card.bgClass())
|
##########################################################################
|
||||||
|
|
||||||
def addStyles(self):
|
|
||||||
# card styles
|
|
||||||
s = "<style>\n"
|
|
||||||
if self.main.deck:
|
|
||||||
s += self.main.deck.css
|
|
||||||
s = runFilter("addStyles", s, self.card)
|
|
||||||
s += "</style>"
|
|
||||||
return s
|
|
||||||
|
|
||||||
|
def _questionButtons(self):
|
||||||
|
buf = self.typeAnsInput()
|
||||||
|
# make sure to focus
|
||||||
|
buf += """
|
||||||
|
<a href=ans class=ansbut><div class=ansbut>%s</div></a>
|
||||||
|
""" % _("Show Answer")
|
||||||
|
return buf
|
||||||
|
|
||||||
# Q/A support
|
# Q/A support
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
@ -138,6 +180,54 @@ class Reviewer(object):
|
||||||
mf = self.body.page().mainFrame()
|
mf = self.body.page().mainFrame()
|
||||||
mf.evaluateJavaScript("location.hash = 'answer'")
|
mf.evaluateJavaScript("location.hash = 'answer'")
|
||||||
|
|
||||||
|
# Answer buttons
|
||||||
|
##########################################################################
|
||||||
|
|
||||||
|
def _answerButtons(self):
|
||||||
|
# attach to mw.cardAnswered()
|
||||||
|
self.updateEaseButtons()
|
||||||
|
self.form.buttonStack.setCurrentIndex(1)
|
||||||
|
self.form.buttonStack.show()
|
||||||
|
self.form.buttonStack.setLayoutDirection(Qt.LeftToRight)
|
||||||
|
if self.learningButtons():
|
||||||
|
self.form.easeButton2.setText(_("Good"))
|
||||||
|
self.form.easeButton3.setText(_("Easy"))
|
||||||
|
self.form.easeButton4.setText(_("Very Easy"))
|
||||||
|
else:
|
||||||
|
self.form.easeButton2.setText(_("Hard"))
|
||||||
|
self.form.easeButton3.setText(_("Good"))
|
||||||
|
self.form.easeButton4.setText(_("Easy"))
|
||||||
|
getattr(self.form, "easeButton%d" % self.defaultEaseButton()).\
|
||||||
|
setFocus()
|
||||||
|
|
||||||
|
def learningButtons(self):
|
||||||
|
return not self.currentCard.successive
|
||||||
|
|
||||||
|
def defaultEaseButton(self):
|
||||||
|
if not self.currentCard.successive:
|
||||||
|
return 2
|
||||||
|
else:
|
||||||
|
return 3
|
||||||
|
|
||||||
|
def updateEaseButtons(self):
|
||||||
|
nextInts = {}
|
||||||
|
for i in range(1, 5):
|
||||||
|
l = getattr(self.form, "easeLabel%d" % i)
|
||||||
|
if self.config['suppressEstimates']:
|
||||||
|
l.setText("")
|
||||||
|
elif i == 1:
|
||||||
|
txt = _("Soon")
|
||||||
|
if self.config['colourTimes']:
|
||||||
|
txt = '<span style="color: #700"><b>%s</b></span>' % txt
|
||||||
|
l.setText(txt)
|
||||||
|
else:
|
||||||
|
txt = self.deck.nextIntervalStr(
|
||||||
|
self.currentCard, i)
|
||||||
|
txt = "<b>" + txt + "</b>"
|
||||||
|
if i == self.defaultEaseButton() and self.config['colourTimes']:
|
||||||
|
txt = '<span style="color: #070">' + txt + '</span>'
|
||||||
|
l.setText(txt)
|
||||||
|
|
||||||
# Font properties & output
|
# Font properties & output
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
@ -180,8 +270,21 @@ class Reviewer(object):
|
||||||
passedCharColour = "#00FF00"
|
passedCharColour = "#00FF00"
|
||||||
futureWarningColour = "#FF0000"
|
futureWarningColour = "#FF0000"
|
||||||
|
|
||||||
def handleTypeAnsQ(self):
|
# fixme: type answer undo area shouldn't trigger global shortcut
|
||||||
return
|
# class QLineEditNoUndo(QLineEdit):
|
||||||
|
# def __init__(self, parent):
|
||||||
|
# self.parent = parent
|
||||||
|
# QLineEdit.__init__(self, parent)
|
||||||
|
# def keyPressEvent(self, evt):
|
||||||
|
# if evt.matches(QKeySequence.Undo):
|
||||||
|
# evt.accept()
|
||||||
|
# if self.parent.form.actionUndo.isEnabled():
|
||||||
|
# self.parent.onUndo()
|
||||||
|
# else:
|
||||||
|
# return QLineEdit.keyPressEvent(self, evt)
|
||||||
|
|
||||||
|
def typeAnsInput(self):
|
||||||
|
return ""
|
||||||
if self.card.cardModel.typeAnswer:
|
if self.card.cardModel.typeAnswer:
|
||||||
self.adjustInputFont()
|
self.adjustInputFont()
|
||||||
|
|
||||||
|
|
16
aqt/utils.py
16
aqt/utils.py
|
@ -219,13 +219,13 @@ def restoreGeom(widget, key, offset=None):
|
||||||
key += "Geom"
|
key += "Geom"
|
||||||
if aqt.mw.config.get(key):
|
if aqt.mw.config.get(key):
|
||||||
widget.restoreGeometry(aqt.mw.config[key])
|
widget.restoreGeometry(aqt.mw.config[key])
|
||||||
if sys.platform.startswith("darwin") and offset:
|
# if sys.platform.startswith("darwin") and offset:
|
||||||
from aqt.main import QtConfig as q
|
# from aqt.main import QtConfig as q
|
||||||
minor = (q.qt_version & 0x00ff00) >> 8
|
# minor = (q.qt_version & 0x00ff00) >> 8
|
||||||
if minor > 6:
|
# if minor > 6:
|
||||||
# bug in osx toolkit
|
# # bug in osx toolkit
|
||||||
s = widget.size()
|
# s = widget.size()
|
||||||
widget.resize(s.width(), s.height()+offset*2)
|
# widget.resize(s.width(), s.height()+offset*2)
|
||||||
|
|
||||||
def saveState(widget, key):
|
def saveState(widget, key):
|
||||||
key += "State"
|
key += "State"
|
||||||
|
@ -257,7 +257,7 @@ def restoreHeader(widget, key):
|
||||||
def mungeQA(txt):
|
def mungeQA(txt):
|
||||||
txt = stripSounds(txt)
|
txt = stripSounds(txt)
|
||||||
# osx webkit doesn't understand font weight 600
|
# osx webkit doesn't understand font weight 600
|
||||||
#txt = re.sub("font-weight:.+?;", "font-weight: bold;", txt)
|
txt = re.sub("font-weight: *600", "font-weight:bold", txt)
|
||||||
return txt
|
return txt
|
||||||
|
|
||||||
def applyStyles(widget):
|
def applyStyles(widget):
|
||||||
|
|
Loading…
Reference in a new issue