Beispiel #1
0
    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)
Beispiel #2
0
    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)
Beispiel #3
0
    def _editExtract(self, note, did, settings):
        def onAdd():
            addCards.rejected.disconnect(self.undo)
            addCards.reject()

        addCards = AddCards(mw)
        addCards.rejected.connect(self.undo)
        addCards.addButton.clicked.connect(onAdd)
        addCards.editor.setNote(note, focusTo=0)
        deckName = mw.col.decks.get(did)['name']
        addCards.deckChooser.setDeckName(deckName)
        addCards.modelChooser.models.setText(settings['modelName'])
        return True
    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)