mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 22:42:25 -04:00
improved cloze - descriptions, colours
This commit is contained in:
parent
6b0e1982ff
commit
828f9fa5aa
1 changed files with 25 additions and 15 deletions
|
@ -15,6 +15,8 @@ import ankiqt
|
||||||
from ankiqt.ui.utils import mungeQA, saveGeom, restoreGeom
|
from ankiqt.ui.utils import mungeQA, saveGeom, restoreGeom
|
||||||
from anki.hooks import addHook
|
from anki.hooks import addHook
|
||||||
|
|
||||||
|
clozeColour = "#0000ff"
|
||||||
|
|
||||||
class FactEditor(object):
|
class FactEditor(object):
|
||||||
"""An editor for new/existing facts.
|
"""An editor for new/existing facts.
|
||||||
|
|
||||||
|
@ -34,6 +36,7 @@ class FactEditor(object):
|
||||||
self.onFactInvalid = None
|
self.onFactInvalid = None
|
||||||
self.lastFocusedEdit = None
|
self.lastFocusedEdit = None
|
||||||
self.changeTimer = None
|
self.changeTimer = None
|
||||||
|
self.lastCloze = None
|
||||||
addHook("deckClosed", self.deckClosedHook)
|
addHook("deckClosed", self.deckClosedHook)
|
||||||
|
|
||||||
def setFact(self, fact, noFocus=False, check=False):
|
def setFact(self, fact, noFocus=False, check=False):
|
||||||
|
@ -612,27 +615,34 @@ class FactEditor(object):
|
||||||
dst = self.fields.values()[0][1]
|
dst = self.fields.values()[0][1]
|
||||||
if dst == w:
|
if dst == w:
|
||||||
return
|
return
|
||||||
# create
|
|
||||||
s = unicode(src.toHtml())
|
|
||||||
s2 = re.sub("\(.+?\)", "(...)", s)
|
|
||||||
# check if there's alredy something there
|
# check if there's alredy something there
|
||||||
src1 = stripHTML(tidyHTML(unicode(src.toHtml())).strip())
|
oldDst = dst.toHtml()
|
||||||
dst1 = stripHTML(tidyHTML(unicode(dst.toHtml())).strip())
|
if unicode(dst.toPlainText()):
|
||||||
if dst1:
|
if self.lastCloze and self.lastCloze[1] == oldDst:
|
||||||
# is it the cloze we just generated?
|
src.setHtml(self.lastCloze[0])
|
||||||
if (re.sub("\(.+?\)", "", src1) ==
|
|
||||||
re.sub("\(.+?\)", "", dst1)):
|
|
||||||
# then undo
|
|
||||||
src.setHtml(dst.toHtml())
|
|
||||||
dst.setHtml("")
|
dst.setHtml("")
|
||||||
|
self.lastCloze = None
|
||||||
|
self.saveFields()
|
||||||
|
return
|
||||||
else:
|
else:
|
||||||
ui.utils.showInfo(_("Next field must be blank."),
|
ui.utils.showInfo(_("Next field must be blank."),
|
||||||
parent=self.parent)
|
parent=self.parent)
|
||||||
return
|
return
|
||||||
else:
|
# create
|
||||||
# ok to add
|
s = unicode(src.toHtml())
|
||||||
src.setHtml(s2)
|
def repl(match):
|
||||||
dst.setHtml(s)
|
exp = ""
|
||||||
|
if match.group(2):
|
||||||
|
exp = match.group(2)
|
||||||
|
return '<font color="%s"><b>(...%s)</b></font>' % (
|
||||||
|
clozeColour, exp)
|
||||||
|
new = re.sub("\(.+?(:(.+?))?\)", repl, s)
|
||||||
|
old = re.sub("\((.+?)(:.+?)?\)", '<font color="%s"><b>\\1</b></font>'
|
||||||
|
% clozeColour, s)
|
||||||
|
oldSrc = unicode(src.toHtml())
|
||||||
|
src.setHtml(new)
|
||||||
|
dst.setHtml(old)
|
||||||
|
self.lastCloze = (oldSrc, unicode(dst.toHtml()))
|
||||||
self.saveFields()
|
self.saveFields()
|
||||||
|
|
||||||
def onClozeUndo(self):
|
def onClozeUndo(self):
|
||||||
|
|
Loading…
Reference in a new issue