def create(self, text, settings): self.highlight(settings['extractBgColor'], settings['extractTextColor']) createIrNote = (settings['modelName'] == self.settings['modelName']) currentCard = mw.reviewer.card currentNote = currentCard.note() model = mw.col.models.byName(settings['modelName']) newNote = Note(mw.col, model) newNote.tags = currentNote.tags setField(newNote, settings['textField'], fixImages(text)) if settings['extractDeck']: did = mw.col.decks.byName(settings['extractDeck'])['id'] else: did = currentCard.did if createIrNote: if settings['copyTitle']: title = getField(currentNote, settings['titleField']) else: title = '' setField(newNote, settings['sourceField'], getField(currentNote, settings['sourceField'])) if settings['editExtract']: setField(newNote, settings['titleField'], title) addCards = AddCards(mw) addCards.editor.setNote(newNote) deckName = mw.col.decks.get(did)['name'] addCards.deckChooser.deck.setText(deckName) addCards.modelChooser.models.setText(settings['modelName']) else: title, accepted = getText('Enter title', title='Extract Text', default=title) if accepted: setField(newNote, settings['titleField'], title) newNote.model()['did'] = did mw.col.addNote(newNote) if settings['scheduleExtract']: cards = newNote.cards() if cards: mw.readingManager.scheduler.answer(cards[0], SCHEDULE_EXTRACT) else: newNote.tags += settings['tags'] mw.col.addNote(newNote) if settings['editSource']: EditCurrent(mw)
def createNote(self, selectedText): self.textManager.highlight(self.currentQuickKey['bgColor'], self.currentQuickKey['textColor']) newModel = mw.col.models.byName(self.currentQuickKey['modelName']) newNote = notes.Note(mw.col, newModel) setField(newNote, self.currentQuickKey['fieldName'], selectedText) card = mw.reviewer.card currentNote = card.note() tags = currentNote.stringTags() # Sets tags for the note, but still have to set them in the editor # if show dialog (see below) newNote.setTagsFromStr(tags) for f in newModel['flds']: if self.settings['sourceField'] == f['name']: setField(newNote, self.settings['sourceField'], getField(currentNote, self.settings['sourceField'])) if self.currentQuickKey['editExtract']: addCards = AddCards(mw) addCards.editor.setNote(newNote) if newNote.stringTags(): addCards.editor.tags.setText(newNote.stringTags().strip()) addCards.modelChooser.models.setText( self.currentQuickKey['modelName']) addCards.deckChooser.deck.setText( self.currentQuickKey['deckName']) else: deckId = mw.col.decks.byName(self.currentQuickKey['deckName'])['id'] newNote.model()['did'] = deckId ret = newNote.dupeOrEmpty() if ret == 1: showWarning(_( 'The first field is empty.'), help='AddItems#AddError') return cards = mw.col.addNote(newNote) if not cards: showWarning(_('''\ The input you have provided would make an empty \ question on all cards.'''), help='AddItems') return clearAudioQueue() mw.col.autosave() tooltip(_('Added')) if self.currentQuickKey['editSource']: EditCurrent(mw)
def extract(self): if not mw.web.selectedText(): showInfo(_('Please select some text to extract.')) return mw.web.triggerPageAction(QWebPage.Copy) mimeData = QApplication.clipboard().mimeData() if self.settings['plainText']: text = mimeData.text() else: text = mimeData.html() self.highlightText(self.settings['extractBgColor'], self.settings['extractTextColor']) currentCard = mw.reviewer.card currentNote = currentCard.note() model = mw.col.models.byName(self.settings['modelName']) newNote = Note(mw.col, model) newNote.tags = currentNote.tags setField(newNote, TEXT_FIELD_NAME, text) setField(newNote, SOURCE_FIELD_NAME, getField(currentNote, SOURCE_FIELD_NAME)) if self.settings['editSource']: EditCurrent(mw) if self.settings['extractDeck']: did = mw.col.decks.byName(self.settings['extractDeck'])['id'] else: did = currentCard.did if self.settings['editExtract']: addCards = AddCards(mw) addCards.editor.setNote(newNote) deckName = mw.col.decks.get(did)['name'] addCards.deckChooser.deck.setText(deckName) addCards.modelChooser.models.setText(self.settings['modelName']) else: setField(newNote, TITLE_FIELD_NAME, self.getNewTitle()) newNote.model()['did'] = did mw.col.addNote(newNote)
def create(self, text, settings): currentCard = mw.reviewer.card currentNote = currentCard.note() model = mw.col.models.byName(settings['modelName']) newNote = Note(mw.col, model) newNote.tags = currentNote.tags setField(newNote, settings['textField'], fixImages(text)) if settings['extractDeck']: deck = mw.col.decks.byName(settings['extractDeck']) if not deck: showWarning('Destination deck no longer exists. ' 'Please update your settings.') return did = deck['id'] else: did = currentCard.did if settings['isQuickKey']: newNote.tags += settings['tags'] if settings['sourceField']: setField(newNote, settings['sourceField'], getField(currentNote, self.settings['sourceField'])) if settings['editExtract']: highlight = self._editExtract(newNote, did, settings) else: highlight = True newNote.model()['did'] = did mw.col.addNote(newNote) else: if settings['copyTitle']: title = getField(currentNote, settings['titleField']) else: title = '' setField(newNote, settings['sourceField'], getField(currentNote, settings['sourceField'])) if settings['prioEnabled']: setField(newNote, settings['prioField'], getField(currentNote, settings['prioField'])) if settings['editExtract']: setField(newNote, settings['titleField'], title) highlight = self._editExtract(newNote, did, settings) else: highlight = self._getTitle(newNote, did, title, settings) if settings['scheduleExtract'] and not settings['prioEnabled']: cards = newNote.cards() if cards: mw.readingManager.scheduler.answer(cards[0], SCHEDULE_EXTRACT) if highlight: self.highlight(settings['extractBgColor'], settings['extractTextColor']) if settings['editSource']: EditCurrent(mw)