mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 06:52:21 -04:00
update invalid/dupe on a timer, don't gen reading on paste
This commit is contained in:
parent
f5234f52eb
commit
dd044f40ab
2 changed files with 39 additions and 25 deletions
|
@ -499,7 +499,6 @@ where id in (%s)""" % ",".join([
|
||||||
self.editor = ui.facteditor.FactEditor(self,
|
self.editor = ui.facteditor.FactEditor(self,
|
||||||
self.dialog.fieldsArea,
|
self.dialog.fieldsArea,
|
||||||
self.deck)
|
self.deck)
|
||||||
self.editor.onChange = self.textChanged
|
|
||||||
self.editor.onFactValid = self.onFactValid
|
self.editor.onFactValid = self.onFactValid
|
||||||
self.editor.onFactInvalid = self.onFactInvalid
|
self.editor.onFactInvalid = self.onFactInvalid
|
||||||
self.connect(self.dialog.tableView.selectionModel(),
|
self.connect(self.dialog.tableView.selectionModel(),
|
||||||
|
@ -596,11 +595,6 @@ where id in (%s)""" % ",".join([
|
||||||
self.currentCard.setModified()
|
self.currentCard.setModified()
|
||||||
self.deck.setModified()
|
self.deck.setModified()
|
||||||
|
|
||||||
def textChanged(self, field):
|
|
||||||
self.updateStaticTags()
|
|
||||||
self.model.emit(SIGNAL("layoutChanged()"))
|
|
||||||
self.deck.setModified()
|
|
||||||
|
|
||||||
def addFactTags(self):
|
def addFactTags(self):
|
||||||
tags = ui.utils.getText(_("Enter tag(s) to add to each fact:"), self)
|
tags = ui.utils.getText(_("Enter tag(s) to add to each fact:"), self)
|
||||||
if tags: self.deck.addFactTags(self.selectedFacts(), tags)
|
if tags: self.deck.addFactTags(self.selectedFacts(), tags)
|
||||||
|
|
|
@ -27,6 +27,7 @@ class FactEditor(object):
|
||||||
self.onFactValid = None
|
self.onFactValid = None
|
||||||
self.onFactInvalid = None
|
self.onFactInvalid = None
|
||||||
self.lastFocusedEdit = None
|
self.lastFocusedEdit = None
|
||||||
|
self.changeTimer = None
|
||||||
|
|
||||||
def setFact(self, fact, noFocus=False, check=False):
|
def setFact(self, fact, noFocus=False, check=False):
|
||||||
"Make FACT the current fact."
|
"Make FACT the current fact."
|
||||||
|
@ -35,7 +36,7 @@ class FactEditor(object):
|
||||||
if self.needToRedraw():
|
if self.needToRedraw():
|
||||||
self.drawFields(noFocus, check)
|
self.drawFields(noFocus, check)
|
||||||
else:
|
else:
|
||||||
self.updateFields(check)
|
self.loadFields(check)
|
||||||
if not noFocus:
|
if not noFocus:
|
||||||
# update focus to first field
|
# update focus to first field
|
||||||
self.fields[self.fact.fields[0].name][1].setFocus()
|
self.fields[self.fact.fields[0].name][1].setFocus()
|
||||||
|
@ -206,7 +207,9 @@ class FactEditor(object):
|
||||||
self.widgets[w] = field
|
self.widgets[w] = field
|
||||||
# catch changes
|
# catch changes
|
||||||
w.connect(w, SIGNAL("lostFocus"),
|
w.connect(w, SIGNAL("lostFocus"),
|
||||||
lambda w=w: self.saveWidget(w))
|
lambda w=w: self.onFocusLost(w))
|
||||||
|
w.connect(w, SIGNAL("textChanged()"),
|
||||||
|
self.onTextChanged)
|
||||||
w.connect(w, SIGNAL("currentCharFormatChanged(QTextCharFormat)"),
|
w.connect(w, SIGNAL("currentCharFormatChanged(QTextCharFormat)"),
|
||||||
lambda w=w: self.formatChanged(w))
|
lambda w=w: self.formatChanged(w))
|
||||||
n += 1
|
n += 1
|
||||||
|
@ -219,7 +222,7 @@ class FactEditor(object):
|
||||||
self.tags.setDeck(self.deck)
|
self.tags.setDeck(self.deck)
|
||||||
self.fieldsGrid.addWidget(self.tags, n, 1)
|
self.fieldsGrid.addWidget(self.tags, n, 1)
|
||||||
# update fields
|
# update fields
|
||||||
self.updateFields(check)
|
self.loadFields(check)
|
||||||
self.parent.setUpdatesEnabled(True)
|
self.parent.setUpdatesEnabled(True)
|
||||||
self.fieldsScroll.setWidget(self.fieldsFrame)
|
self.fieldsScroll.setWidget(self.fieldsFrame)
|
||||||
|
|
||||||
|
@ -231,7 +234,7 @@ class FactEditor(object):
|
||||||
return True
|
return True
|
||||||
return self.fontChanged
|
return self.fontChanged
|
||||||
|
|
||||||
def updateFields(self, check=True, font=True):
|
def loadFields(self, check=True, font=True):
|
||||||
"Update field text (if changed) and font/colours."
|
"Update field text (if changed) and font/colours."
|
||||||
# text
|
# text
|
||||||
for (name, (field, w)) in self.fields.items():
|
for (name, (field, w)) in self.fields.items():
|
||||||
|
@ -260,22 +263,42 @@ class FactEditor(object):
|
||||||
if check:
|
if check:
|
||||||
self.checkValid()
|
self.checkValid()
|
||||||
|
|
||||||
def saveWidget(self, widget):
|
def saveFields(self):
|
||||||
field = self.widgets[widget]
|
"Save field text into fact."
|
||||||
value = tidyHTML(unicode(widget.toHtml()))
|
for (w, f) in self.widgets.items():
|
||||||
if value and not value.strip():
|
v = tidyHTML(unicode(w.toHtml()))
|
||||||
widget.setText("")
|
if not v.strip():
|
||||||
value = u""
|
# strip blank spaces
|
||||||
self.fact[field.name] = value
|
v = u""
|
||||||
|
w.setText(v)
|
||||||
|
self.fact[f.name] = v
|
||||||
self.fact.setModified(textChanged=True)
|
self.fact.setModified(textChanged=True)
|
||||||
self.deck.setModified()
|
self.deck.setModified()
|
||||||
self.fact.onKeyPress(field, value)
|
|
||||||
# the keypress handler may have changed something, so update all
|
def onFocusLost(self, widget):
|
||||||
self.updateFields(font=False)
|
self.saveFields()
|
||||||
|
field = self.widgets[widget]
|
||||||
|
self.fact.onKeyPress(field, field.value)
|
||||||
|
self.loadFields(font=False)
|
||||||
|
|
||||||
|
def onTextChanged(self):
|
||||||
|
interval = 250
|
||||||
|
if self.changeTimer:
|
||||||
|
self.changeTimer.setInterval(interval)
|
||||||
|
else:
|
||||||
|
self.changeTimer = QTimer(self.parent)
|
||||||
|
self.changeTimer.setSingleShot(True)
|
||||||
|
self.changeTimer.start(interval)
|
||||||
|
self.parent.connect(self.changeTimer,
|
||||||
|
SIGNAL("timeout()"),
|
||||||
|
self.onChangeTimer)
|
||||||
|
|
||||||
|
def onChangeTimer(self):
|
||||||
|
self.saveFields()
|
||||||
self.checkValid()
|
self.checkValid()
|
||||||
if self.onChange:
|
if self.onChange:
|
||||||
self.onChange(field)
|
self.onChange()
|
||||||
self.formatChanged(None)
|
self.changeTimer = None
|
||||||
|
|
||||||
def checkValid(self):
|
def checkValid(self):
|
||||||
empty = []
|
empty = []
|
||||||
|
@ -428,7 +451,6 @@ class FactEditor(object):
|
||||||
return
|
return
|
||||||
path = self.deck.addMedia(file)
|
path = self.deck.addMedia(file)
|
||||||
w.insertHtml('<img src="%s">' % path)
|
w.insertHtml('<img src="%s">' % path)
|
||||||
self.saveWidget(w)
|
|
||||||
|
|
||||||
def onAddSound(self):
|
def onAddSound(self):
|
||||||
self.initMedia()
|
self.initMedia()
|
||||||
|
@ -441,7 +463,6 @@ class FactEditor(object):
|
||||||
anki.sound.play(file)
|
anki.sound.play(file)
|
||||||
path = self.deck.addMedia(file)
|
path = self.deck.addMedia(file)
|
||||||
w.insertHtml('[sound:%s]' % path)
|
w.insertHtml('[sound:%s]' % path)
|
||||||
self.saveWidget(w)
|
|
||||||
|
|
||||||
class FactEdit(QTextEdit):
|
class FactEdit(QTextEdit):
|
||||||
|
|
||||||
|
@ -454,7 +475,6 @@ class FactEdit(QTextEdit):
|
||||||
self.insertPlainText(source.text())
|
self.insertPlainText(source.text())
|
||||||
elif source.hasHtml():
|
elif source.hasHtml():
|
||||||
self.insertHtml(self.simplyHTML(unicode(source.html())))
|
self.insertHtml(self.simplyHTML(unicode(source.html())))
|
||||||
self.parent.saveWidget(self)
|
|
||||||
|
|
||||||
def simplifyHTML(self, html):
|
def simplifyHTML(self, html):
|
||||||
"Remove all style information and P tags."
|
"Remove all style information and P tags."
|
||||||
|
|
Loading…
Reference in a new issue