Beispiel #1
0
    def ankiAddFact(self, markup):
        if not self.anki:
            return False

        fields = reader_util.replaceMarkupInFields(self.preferences.ankiFields, markup)

        tags = self.anki.cleanupTags(unicode(self.comboTags.currentText()))
        tagIndex = self.comboTags.findText(tags)
        if tagIndex > 0:
            self.comboTags.removeItem(tagIndex)
        if tagIndex != 0:
            self.comboTags.insertItem(0, tags)
        self.preferences.updateFactTags(tags)

        factId = self.anki.addFact(fields, tags)
        if not factId:
            return False

        expression, reading = markup["%e"], markup["%r"]
        summary = expression
        if reading:
            summary = u"{0} [{1}]".format(expression, reading)

        self.addedFacts.append(factId)
        self.listDefinitions.addItem(summary)
        self.listDefinitions.setCurrentRow(self.listDefinitions.count() - 1)
        self.setStatus(u"Added expression {0}; {1} new fact(s) total".format(expression, len(self.addedFacts)))

        self.updateDefinitions()
        return True
Beispiel #2
0
    def ankiIsFactValid(self, markup):
        if not self.anki:
            return False

        fields = reader_util.replaceMarkupInFields(self.preferences.ankiFields, markup)
        return self.anki.canAddFact(fields)