def ankiAddFact(self, profile, markup): if markup is None: return False if self.anki is None: return False profile = self.preferences["profiles"].get(profile) if profile is None: return False fields = reader_util.formatFields(profile["fields"], markup) tagsSplit = reader_util.splitTags(unicode(self.comboTags.currentText())) tagsJoined = " ".join(tagsSplit) tagIndex = self.comboTags.findText(tagsJoined) if tagIndex > 0: self.comboTags.removeItem(tagIndex) if tagIndex != 0: self.comboTags.insertItem(0, tagsJoined) self.preferences.updateFactTags(tagsJoined) factId = self.anki.addNote(profile["deck"], profile["model"], fields, tagsSplit) if factId is None: return False self.facts.append(factId) self.listDefinitions.addItem(markup["summary"]) self.listDefinitions.setCurrentRow(self.listDefinitions.count() - 1) self.setStatus(u"Added fact {0}; {1} new fact(s) total".format(markup["summary"], len(self.facts))) self.updateVocabDefs(scroll=True) self.updateKanjiDefs(scroll=True) return True
def ankiAddFact(self, profile, markup): if markup is None: return False if self.anki is None: return False profile = self.preferences['profiles'].get(profile) if profile is None: return False fields = reader_util.formatFields(profile['fields'], markup) tagsSplit = reader_util.splitTags(unicode(self.comboTags.currentText())) tagsJoined = ' '.join(tagsSplit) tagIndex = self.comboTags.findText(tagsJoined) if tagIndex > 0: self.comboTags.removeItem(tagIndex) if tagIndex != 0: self.comboTags.insertItem(0, tagsJoined) self.preferences.updateFactTags(tagsJoined) factId = self.anki.addNote(profile['deck'], profile['model'], fields, tagsSplit, None) if factId is None: return False self.facts.append(factId) self.listDefinitions.addItem(markup['summary']) self.listDefinitions.setCurrentRow(self.listDefinitions.count() - 1) self.setStatus(u'Added fact {0}; {1} new fact(s) total'.format(markup['summary'], len(self.facts))) self.updateVocabDefs(scroll=True) self.updateKanjiDefs(scroll=True) return True
def ankiIsFactValid(self, profile, markup): if self.anki is None: return False profile = self.preferences['profiles'].get(profile) if profile is None: return False fields = reader_util.formatFields(profile['fields'], markup) return self.anki.canAddNote(profile['deck'], profile['model'], fields)
def ankiAddFact(self, completeProfile, markup, addToList = True): if markup is None: self.add = "markup is None" return False if self.anki is None: self.add = "anki is None" return False profile = self.preferences['profiles'].get(completeProfile) if profile is None: self.add = "profile is None" return False fields = reader_util.formatFields(profile['fields'], markup) if not self.anki.canAddNote(profile['deck'], profile['model'], fields): return self.ankiOverwriteFact(completeProfile, markup) self.fields = (fields,profile['fields'],markup) tagsSplit = reader_util.splitTags(unicode(self.comboTags.currentText())) tagsJoined = ' '.join(tagsSplit) tagIndex = self.comboTags.findText(tagsJoined) if tagIndex > 0: self.comboTags.removeItem(tagIndex) if tagIndex != 0: self.comboTags.insertItem(0, tagsJoined) self.preferences.updateFactTags(tagsJoined) self.addNote = [profile['deck'],profile['model'],fields,tagsSplit] self.factId = self.anki.addNote(profile['deck'], profile['model'], fields, tagsSplit) if self.factId is None: self.add = "factId is None" return False key = self.anki.getModelKey(profile['model']) value = fields[key] # Put the vocabulary out of 'new' state and add it to the vocabulary list self.cardByNote = (profile['model'],key,value) ids = self.anki.getCardsByNote(profile['model'],key,value) if len(ids) == 0: self.add = "len(ids == 0)" return False card = self.anki.collection().getCard(ids[0]) self.currentFile.profiles[completeProfile]['freshlyAdded'].append(value) self.currentFile.addVocabulary(completeProfile,value,card,addToBadListToo = False) self.currentFile.addMarkup(completeProfile,value,markup) if value in self.currentFile.profiles[completeProfile]['wordsNotFound']: self.currentFile.profiles[completeProfile]['wordsNotFound'].remove(value) if self.preferences['unlockVocab']: self.anki.collection().sched.earlyAnswerCard(card,2) if addToList: self.facts.append({'word':value,'profile':completeProfile}) self.listDefinitions.addItem(value) self.listDefinitions.setCurrentRow(self.listDefinitions.count() - 1) self.setStatus(u'Added fact {0}; {1} new fact(s) total'.format(value, len(self.facts))) for profile in self.profiles.values(): profile.updateDefinitions(scroll=True) return True
def ankiIsFactValid(self, profile, markup): if markup is None: return False if self.anki is None: return False profile = self.preferences["profiles"].get(profile) if profile is None: return False fields = reader_util.formatFields(profile["fields"], markup) return self.anki.canAddNote(profile["deck"], profile["model"], fields)
def ankiIsFactValid(self, profile, markup): if markup is None: return False if self.anki is None: return False profile = self.preferences['profiles'].get(profile) if profile is None: return False fields = reader_util.formatFields(profile['fields'], markup) return self.anki.canAddNote(profile['deck'], profile['model'], fields)
def ankiOverwriteFact(self, completeProfile, markup): if markup is None: self.overwrite = "markup is None" return False if self.anki is None: return False profile = self.preferences['profiles'].get(completeProfile) if profile is None: self.overwrite = "profile is None" return False fields = reader_util.formatFields(profile['fields'], markup) tagsSplit = reader_util.splitTags(unicode(self.comboTags.currentText())) tagsJoined = ' '.join(tagsSplit) tagIndex = self.comboTags.findText(tagsJoined) if tagIndex > 0: self.comboTags.removeItem(tagIndex) if tagIndex != 0: self.comboTags.insertItem(0, tagsJoined) self.preferences.updateFactTags(tagsJoined) key = self.anki.getModelKey(profile['model']) value = fields[key] ids = self.anki.getNotes(profile['model'],key,value) if len(ids) == 0: self.overwrite = "len(ids)==0" return False # Overwrite the fields in the note # or add a line, if a + is at the end of field name note = self.anki.collection().getNote(ids[0]) self.overwrite = { "note": note, "fields": fields } for name, v in fields.items(): if name in note: if unicode(name[-1]) == u'+': if not v in note[name].split(u'<br>'): if len(note[name])>0: note[name]+= u'<br>' + v else: note[name] = v else: note[name] = v note.flush() self.currentFile.profiles[completeProfile]['freshlyAdded'].append(value) cids = self.anki.getCardsByNote(profile['model'],key,value) if len(cids) == 0: return False did = self.anki.collection().decks.id(profile['deck']) self.anki.updateCards(cids,did) card = self.anki.collection().getCard(cids[0]) self.currentFile.overwriteVocabulary(completeProfile,value,card) self.currentFile.addMarkup(completeProfile,value,markup) self.facts.append({'word':value,'profile':completeProfile}) self.listDefinitions.addItem(value) self.listDefinitions.setCurrentRow(self.listDefinitions.count() - 1) for profile in self.profiles.values(): profile.updateDefinitions(scroll=True) return True