示例#1
0
文件: reviewer.py 项目: mstange/anki
 def nextCard(self):
     elapsed = self.mw.col.timeboxReached()
     if elapsed:
         part1 = ngettext("%d card studied in", "%d cards studied in", elapsed[1]) % elapsed[1]
         part2 = ngettext("%s minute.", "%s minutes.", elapsed[0]/60) % (elapsed[0]/60)
         tooltip("%s %s" % (part1, part2), period=5000)
         self.mw.col.startTimebox()
     if self.cardQueue:
         # undone/edited cards to show
         c = self.cardQueue.pop()
         c.startTimer()
         self.hadCardQueue = True
     else:
         if self.hadCardQueue:
             # the undone/edited cards may be sitting in the regular queue;
             # need to reset
             self.mw.col.reset()
             self.hadCardQueue = False
         c = self.mw.col.sched.getCard()
     self.card = c
     clearAudioQueue()
     if not c:
         self.mw.moveToState("overview")
         return
     if self._reps is None or self._reps % 100 == 0:
         # we recycle the webview periodically so webkit can free memory
         self._initWeb()
     else:
         self._showQuestion()
示例#2
0
 def nextCard(self):
     elapsed = self.mw.col.timeboxReached()
     if elapsed:
         part1 = ngettext("%d card studied in", "%d cards studied in", elapsed[1]) % elapsed[1]
         mins = int(round(elapsed[0]/60))
         part2 = ngettext("%s minute.", "%s minutes.", mins) % mins
         fin = _("Finish")
         diag = askUserDialog("%s %s" % (part1, part2),
                          [_("Continue"), fin])
         diag.setIcon(QMessageBox.Information)
         if diag.run() == fin:
             return self.mw.moveToState("deckBrowser")
         self.mw.col.startTimebox()
     if self.cardQueue:
         # undone/edited cards to show
         c = self.cardQueue.pop()
         c.startTimer()
         self.hadCardQueue = True
     else:
         if self.hadCardQueue:
             # the undone/edited cards may be sitting in the regular queue;
             # need to reset
             self.mw.col.reset()
             self.hadCardQueue = False
         c = self.mw.col.sched.getCard()
     self.card = c
     clearAudioQueue()
     if not c:
         self.mw.moveToState("overview")
         return
     if self._reps is None or self._reps % 100 == 0:
         # we recycle the webview periodically so webkit can free memory
         self._initWeb()
     else:
         self._showQuestion()
示例#3
0
文件: reviewer.py 项目: Afoucaul/anki
 def nextCard(self):
     elapsed = self.mw.col.timeboxReached()
     if elapsed:
         part1 = ngettext("%d card studied in", "%d cards studied in", elapsed[1]) % elapsed[1]
         mins = int(round(elapsed[0]/60))
         part2 = ngettext("%s minute.", "%s minutes.", mins) % mins
         fin = _("Finish")
         diag = askUserDialog("%s %s" % (part1, part2),
                          [_("Continue"), fin])
         diag.setIcon(QMessageBox.Information)
         if diag.run() == fin:
             return self.mw.moveToState("deckBrowser")
         self.mw.col.startTimebox()
     if self.cardQueue:
         # undone/edited cards to show
         c = self.cardQueue.pop()
         c.startTimer()
         self.hadCardQueue = True
     else:
         if self.hadCardQueue:
             # the undone/edited cards may be sitting in the regular queue;
             # need to reset
             self.mw.col.reset()
             self.hadCardQueue = False
         c = self.mw.col.sched.getCard()
     self.card = c
     clearAudioQueue()
     if not c:
         self.mw.moveToState("overview")
         return
     if self._reps is None or self._reps % 100 == 0:
         # we recycle the webview periodically so webkit can free memory
         self._initWeb()
     self._showQuestion()
示例#4
0
文件: reviewer.py 项目: ChYi/ankiqt
 def replayAudio(self):
     clearAudioQueue()
     c = self.card
     if not c.template()['hideQ'] or self.state == "question":
         playFromText(c.q())
     if self.state == "answer":
         playFromText(c.a())
示例#5
0
 def show(self):
     clearAudioQueue()
     self.web.setLinkHandler(self._linkHandler)
     self.web.setKeyHandler(None)
     self.mw.keyHandler = self._keyHandler
     self.mw.web.setFocus()
     self.refresh()
示例#6
0
    def _showAnswer(self):
        if self.mw.state != "review":
            # showing resetRequired screen; ignore space
            return
        #save ir view on Q side, requires state=Q
        self.mw.viewmanager.flush()

        self.state = "answer"
        c = self.card
        a = c.a()
        # stop audio? No for 2.0, Yes for 2.1
        if self.mw.pm.profile.get("ccbc.stpAudOnShwAns", True):
            clearAudioQueue()
        # play audio?
        if self.autoplay(c):
            playFromText(a)
        # render and update bottom
        a = self._mungeQA(a)
        a = runFilter("prepareQA", a, c, "reviewAnswer")

        self.web.eval("_updateQA(%s, true);" % json.dumps(a))
        self._showEaseButtons()
        self.mw.web.setFocus()
        # user hook
        runHook('showAnswer')
示例#7
0
    def _renderPreview(self):
        self.cancelPreviewTimer()

        c = self.card
        ti = self.maybeTextInput

        bodyclass = bodyClass(self.mw.col, c)

        q = ti(mungeQA(self.mw.col, c.q(reload=True)))
        q = runFilter("prepareQA", q, c, "clayoutQuestion")

        a = ti(mungeQA(self.mw.col, c.a()), type='a')
        a = runFilter("prepareQA", a, c, "clayoutAnswer")

        # use _showAnswer to avoid the longer delay
        self.pform.frontWeb.eval("_showAnswer(%s,'%s');" % (json.dumps(q), bodyclass))
        self.pform.backWeb.eval("_showAnswer(%s, '%s');" % (json.dumps(a), bodyclass))

        clearAudioQueue()
        if c.id not in self.playedAudio:
            playFromText(c.q())
            playFromText(c.a())
            self.playedAudio[c.id] = True

        self.updateCardNames()
示例#8
0
 def nextCard(self):
     if self.cardQueue:
         # undone/edited cards to show
         c = self.cardQueue.pop()
         c.startTimer()
         self.hadCardQueue = True
     else:
         if self.hadCardQueue:
             # the undone/edited cards may be sitting in the regular queue;
             # need to reset
             self.mw.col.reset()
             self.hadCardQueue = False
         c = self.mw.col.sched.getCard()
     self.card = c
     clearAudioQueue()
     if not c:
         self.mw.moveToState("overview")
         return
     if self._reps is None or self._reps % 100 == 0:
         # we recycle the webview periodically so webkit can free memory
         self._initWeb()
     else:
         self._showQuestion()
     elapsed = self.mw.col.timeboxReached()
     if elapsed:
         part1 = ngettext("%d card studied in", "%d cards studied in",
                          elapsed[1]) % elapsed[1]
         part2 = ngettext("%s minute.", "%s minutes.",
                          elapsed[0] / 60) % (elapsed[0] / 60)
         tooltip("%s %s" % (part1, part2), period=5000)
         self.mw.col.startTimebox()
示例#9
0
 def _linkHandler(self, url):
     if url == "ans":
         self._showAnswer()
     elif url == "nxt":
         self.nextCard()
     elif url == "revFocused":
         self.mw.viewmanager.unhover()
     elif url == "showBottombar":
         self.mw.viewmanager.hoverBottom()
     elif url == "showMenubar":
         self.mw.viewmanager.hoverTop()
     elif url == "showCursor":
         self.mw.viewmanager.showCursor()
         self.mw.viewmanager.hideCursor()
     elif url == "ansHack":
         self.mw.progress.timer(100, self._showAnswerHack, False)
     elif url.startswith("ease"):
         self._answerCard(int(url[4:]))
     elif url == "edit":
         self.mw.onEditCurrent()
     elif url == "more":
         self.showContextMenu()
     elif url.startswith("typeans:"):
         (cmd, arg) = url.split(":", 1)
         self.typedAnswer = arg
     elif url.startswith("ankiplay:"):
         (cmd, arg) = url.split(":", 1)
         clearAudioQueue()
         play(arg)
     else:
         openLink(url)
示例#10
0
 def replayAudio(self):
     clearAudioQueue()
     c = self.card
     if self.state == "question":
         playFromText(c.q())
     elif self.state == "answer":
         playFromText(c.a())
示例#11
0
 def show(self):
     clearAudioQueue()
     self.web.setLinkHandler(self._linkHandler)
     self.web.setKeyHandler(None)
     self.mw.keyHandler = self._keyHandler
     self.mw.web.setFocus()
     self.refresh()
示例#12
0
文件: reviewer.py 项目: kchien/ankiqt
 def nextCard(self):
     if self.cardQueue:
         # undone/edited cards to show
         c = self.cardQueue.pop()
         c.startTimer()
         self.hadCardQueue = True
     else:
         if self.hadCardQueue:
             # the undone/edited cards may be sitting in the regular queue;
             # need to reset
             self.mw.col.reset()
             self.hadCardQueue = False
         c = self.mw.col.sched.getCard()
     self.card = c
     clearAudioQueue()
     if not c:
         self.mw.moveToState("overview")
         return
     if self._reps is None or self._reps % 100 == 0:
         # we recycle the webview periodically so webkit can free memory
         self._initWeb()
     else:
         self._showQuestion()
     elapsed = self.mw.col.timeboxReached()
     if elapsed:
         tooltip(_("%(cards)d cards studied in %(mins)s minutes.") %
                 dict(cards=elapsed[1], mins=elapsed[0]/60))
         self.mw.col.startTimebox()
示例#13
0
    def _renderPreview(self):
        """
        change the answer and question side of the preview
        windows. Change the list of name of cards.
        """
        self.cancelPreviewTimer()

        c = self.card
        ti = self.maybeTextInput

        bodyclass = bodyClass(self.mw.col, c)

        # deal with [[type:, image and remove sound of the card's
        # question and answer
        q = ti(mungeQA(self.mw.col, c.q(reload=True)))
        q = runFilter("prepareQA", q, c, "clayoutQuestion")

        a = ti(mungeQA(self.mw.col, c.a()), type='a')
        a = runFilter("prepareQA", a, c, "clayoutAnswer")

        # use _showAnswer to avoid the longer delay
        self.pform.frontWeb.eval("_showAnswer(%s,'%s');" %
                                 (json.dumps(q), bodyclass))
        self.pform.backWeb.eval("_showAnswer(%s, '%s');" %
                                (json.dumps(a), bodyclass))

        clearAudioQueue()
        if c.id not in self.playedAudio:  # this ensure that audio is
            # played only once until a card is selected again
            playFromText(c.q())
            playFromText(c.a())
            self.playedAudio[c.id] = True

        self.updateCardNames()
示例#14
0
def myPopUp(self, ease):
    cnt = self.mw.col.sched.answerButtons(self.card)
    popUp_Chance = config["Pop-Up Chance"]
    show_random = random.choice(range((101 - popUp_Chance)))
    if show_random == 0 and popUp_Chance != 0:
        play_audio = config["Play Audio"]
        if self.state == "answer":
            if cnt == 3:
                if ease == 1:
                    folder = 'again'
                elif ease == 2:
                    folder = 'good'
                else:
                    folder = 'easy'
            else:
                if ease == 1:
                    folder = 'again'
                elif ease == 2:
                    folder = 'hard'
                elif ease == 3:
                    folder = 'good'
                else:
                    folder = 'easy'
            audio_folder = join(addon_path, 'user_files/audio_video', folder)
            audioName_list = os.listdir(audio_folder)
            audio_name = '/{}'.format(random.choice(audioName_list))
            audio_path = audio_folder + audio_name
            if play_audio:
                AVPlayer.play_tags = _play_tags
                clearAudioQueue()
                play(audio_path)
            show_popUp(cnt, ease)
示例#15
0
    def add_as_first_new(self):
        self.editor.saveNow()
        self.editor.saveAddModeVars()
        note = self.editor.note
        note = self.addNote(note)
        if not note:
            return
        tooltip(_("Added as first new"), period=500)
        # stop anything playing
        clearAudioQueue()
        self.onReset(keep=True)
        self.mw.col.autosave()

        nid, txt = self.history[0]
        note = aqt.mw.col.getNote(nid)
        cids = [int(c.id) for c in note.cards()]

        #browser.py -  reposition
        #self.mw.checkpoint(_("Reposition"))
        aqt.mw.col.sched.sortCards(cids,
                                   start=0,
                                   step=1,
                                   shuffle=True,
                                   shift=True)
        aqt.mw.requireReset()
示例#16
0
 def replayAudio(self):
     clearAudioQueue()
     c = self.card
     if self.state == "question":
         playFromText(c.q())
     elif self.state == "answer":
         playFromText(c.a())
示例#17
0
    def _renderPreview(self):
        self.cancelPreviewTimer()

        c = self.card
        ti = self.maybeTextInput

        bodyclass = bodyClass(self.mw.col, c)

        q = ti(mungeQA(self.mw.col, c.q(reload=True)))
        q = runFilter("prepareQA", q, c, "clayoutQuestion")

        a = ti(mungeQA(self.mw.col, c.a()), type="a")
        a = runFilter("prepareQA", a, c, "clayoutAnswer")

        # use _showAnswer to avoid the longer delay
        self.pform.frontWeb.eval("_showAnswer(%s,'%s');" % (json.dumps(q), bodyclass))
        self.pform.backWeb.eval("_showAnswer(%s, '%s');" % (json.dumps(a), bodyclass))

        clearAudioQueue()
        if c.id not in self.playedAudio:
            playFromText(c.q())
            playFromText(c.a())
            self.playedAudio[c.id] = True

        self.updateCardNames()
 def cleanup(self):
     remHook('reset', self.onReset)
     remHook('currentModelChanged', self.onModelChange)
     clearAudioQueue()
     self.removeTempNote(self.editor.note)
     self.editor.cleanup()
     self.modelChooser.cleanup()
     self.deckChooser.cleanup()
     self.mw.maybeReset()
示例#19
0
文件: addcards.py 项目: t3nma/anki
 def _addCards(self):
     self.editor.saveAddModeVars()
     if not self.addNote(self.editor.note):
         return
     tooltip(_("Added"), period=500)
     # stop anything playing
     clearAudioQueue()
     self.onReset(keep=True)
     self.mw.col.autosave()
示例#20
0
 def reject(self):
     remHook('reset', self.onReset)
     remHook('currentModelChanged', self.onReset)
     clearAudioQueue()
     self.editor.setNote(None)
     self.modelChooser.cleanup()
     self.deckChooser.cleanup()
     self.mw.reset()
     QDialog.reject(self)
示例#21
0
 def _play(self, fx, dur=0):
     clearAudioQueue()
     fx.set()
     img, au = fx.get()
     if img: self.ch_image.show(img)
     if au:
         dur = self.ch_audio.play(au)
     self.audio_duration = dur
     return dur
def showMsg():
    clearAudioQueue()
    m=random.choice(MELODY_LIST)
    m=os.path.join(SND_DIR,m)
    play(m)

    mw.requireReset(True)
    mw.bottomWeb.hide()
    mw.web.stdHtml(ASCII_ART, css=CSS)
    reset()
示例#23
0
 def replayAudio(self):
     clearAudioQueue()
     c = self.card
     if self.state == "question":
         playFromText(c.q())
     elif self.state == "answer":
         txt = ""
         if self.mw.col.conf.get("replayBoth", True):
             txt = c.q()
         txt += c.a()
         playFromText(txt)
示例#24
0
文件: reviewer.py 项目: ospalh/ankiqt
 def replayAudio(self):
     clearAudioQueue()
     c = self.card
     if self.state == "question":
         playFromText(c.q())
     elif self.state == "answer":
         txt = ""
         if self.mw.col.conf.get("replayBoth", True):
             txt = c.q()
         txt += c.a()
         playFromText(txt)
示例#25
0
文件: addcards.py 项目: ChYi/ankiqt
 def addCards(self):
     self.editor.saveNow()
     fact = self.editor.fact
     fact = self.addFact(fact)
     if not fact:
         return
     tooltip("Added", period=500)
     # stop anything playing
     clearAudioQueue()
     self.onReset(keep=True)
     self.mw.deck.autosave()
示例#26
0
 def reject(self):
     clearAudioQueue()
     if self.addMode:
         # remove the filler fields we added
         for name in self.emptyFields:
             self.note[name] = ""
         self.mw.col.db.execute("delete from notes where id = ?", self.note.id)
     self.mm.save(self.model, templates=True)
     self.mw.reset()
     saveGeom(self, "CardLayout")
     return QDialog.reject(self)
示例#27
0
 def addCards(self):
     self.editor.saveNow()
     note = self.editor.note
     note = self.addNote(note)
     if not note:
         return
     tooltip("Added", period=500)
     # stop anything playing
     clearAudioQueue()
     self.onReset(keep=True)
     self.mw.col.autosave()
示例#28
0
 def replayAudio(self):
     clearAudioQueue()
     c = self.card
     if self.state == "question":
         playFromText(c.q())
     elif self.state == "answer":
         txt = ""
         if self._replayq(c):
             txt = c.q()
         txt += c.a()
         playFromText(txt)
示例#29
0
文件: addcards.py 项目: ChYi/ankiqt
 def addCards(self):
     self.editor.saveNow()
     fact = self.editor.fact
     fact = self.addFact(fact)
     if not fact:
         return
     tooltip("Added", period=500)
     # stop anything playing
     clearAudioQueue()
     self.onReset(keep=True)
     self.mw.deck.autosave()
示例#30
0
文件: addcards.py 项目: kchien/ankiqt
 def addCards(self):
     self.editor.saveNow()
     note = self.editor.note
     note = self.addNote(note)
     if not note:
         return
     tooltip("Added", period=500)
     # stop anything playing
     clearAudioQueue()
     self.onReset(keep=True)
     self.mw.col.autosave()
示例#31
0
 def replayAudio(self):
     clearAudioQueue()
     c = self.card
     if self.state == "question":
         playFromText(c.q())
     elif self.state == "answer":
         txt = ""
         if self._replayq(c):
             txt = c.q()
         txt += c.a()
         playFromText(txt)
示例#32
0
 def _reject(self):
     remHook('reset', self.onReset)
     remHook('currentModelChanged', self.onModelChange)
     clearAudioQueue()
     self.removeTempNote(self.editor.note)
     self.editor.cleanup()
     self.modelChooser.cleanup()
     self.deckChooser.cleanup()
     self.mw.maybeReset()
     saveGeom(self, "add")
     aqt.dialogs.markClosed("AddCards")
     QDialog.reject(self)
示例#33
0
 def _reject(self):
     remHook('reset', self.onReset)
     remHook('currentModelChanged', self.onModelChange)
     clearAudioQueue()
     self.removeTempNote(self.editor.note)
     self.editor.cleanup()
     self.modelChooser.cleanup()
     self.deckChooser.cleanup()
     self.mw.maybeReset()
     saveGeom(self, "add")
     aqt.dialogs.markClosed("AddCards")
     QDialog.reject(self)
示例#34
0
 def reject(self):
     clearAudioQueue()
     if self.addMode:
         # remove the filler fields we added
         for name in self.emptyFields:
             self.note[name] = ""
         self.mw.col.db.execute("delete from notes where id = ?",
                                self.note.id)
     self.mm.save(self.model, templates=True)
     self.mw.reset()
     saveGeom(self, "CardLayout")
     return QDialog.reject(self)
示例#35
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)
示例#36
0
文件: addcards.py 项目: ChYi/ankiqt
 def reject(self):
     if not self.canClose():
         return
     removeHook('reset', self.onReset)
     removeHook('currentModelChanged', self.onReset)
     clearAudioQueue()
     self.removeTempFact(self.editor.fact)
     self.editor.setFact(None)
     self.modelChooser.cleanup()
     self.mw.maybeReset()
     saveGeom(self, "add")
     aqt.dialogs.close("AddCards")
     QDialog.reject(self)
示例#37
0
文件: addcards.py 项目: kchien/ankiqt
 def reject(self):
     if not self.canClose():
         return
     remHook('reset', self.onReset)
     remHook('currentModelChanged', self.onReset)
     clearAudioQueue()
     self.removeTempNote(self.editor.note)
     self.editor.setNote(None)
     self.modelChooser.cleanup()
     self.mw.maybeReset()
     saveGeom(self, "add")
     aqt.dialogs.close("AddCards")
     QDialog.reject(self)
示例#38
0
文件: addcards.py 项目: lovac42/CCBC
 def addCards(self):
     self.editor.saveNow()
     self.editor.saveAddModeVars()
     note = self.editor.note
     if self.addNote(note):
         tooltip(_("Added"), period=500)
         # stop anything playing
         clearAudioQueue()
         self.onReset(keep=True)
         self.mw.col.autosave()
         runHook("addedNote", note)
         if self.addOnceChkBox.isChecked():
             self.reject()
示例#39
0
 def _reject(self):
     remHook("reset", self.onReset)
     remHook("currentModelChanged", self.onModelChange)
     clearAudioQueue()
     self.removeTempNote(self.editor.note)
     self.editor.cleanup()
     self.modelChooser.cleanup()
     self.deckChooser.cleanup()
     self.mw.maybeReset()
     saveGeom(self, "ankidown")
     aqt.dialogs.markClosed("Ankidown-Importer")
     tooltip("Added {} Notes".format(self.tally), period=1000)
     QDialog.reject(self)
示例#40
0
文件: addcards.py 项目: lovac42/CCBC
 def _reject(self):
     remHook('reset', self.onReset)
     clearAudioQueue()
     self.removeTempNote(self.editor.note)
     self.editor.setNote(None)
     self.modelChooser.cleanup()
     self.deckChooser.cleanup()
     self.mw.maybeReset()
     saveGeom(self, "add")
     aqt.dialogs.close(self._UID)
     if not self.forceClose:  #not shutdown
         del aqt.dialogs._dialogs[self._UID]
     QDialog.reject(self)
示例#41
0
 def linkHandler(self, url):
     """Executed when clicking on a card"""
     if url.startswith("focus"):
         # bring card into focus
         cid = int(url.split()[1])
         self.linkClicked = True
         self.b.focusCid(cid)
     elif url.startswith("ankiplay"):
         # support for 'Replay Buttons on Card' add-on
         clearAudioQueue()  # stop current playback
         play(url[8:])
     else:
         # handle regular links with the default link handler
         openLink(url)
示例#42
0
    def _addCards(self):
        """Adding the content of the fields as a new note.

        Assume that the content of the GUI saved in the model."""
        self.editor.saveAddModeVars()
        note = self.editor.note
        note = self.addNote(note)
        if not note:
            return
        tooltip(_("Added"), period=500)
        # stop anything playing
        clearAudioQueue()
        self.onReset(keep=True)
        self.mw.col.autosave()
    def setCard(self, cid):
        """
        Set title and webview HTML
        """
        try:
            card = self.mw.col.getCard(cid)
        except TypeError:
            tooltip("Could not find linked card with cid:'{}'.".format(cid))
            return False

        # Set previewer title based on note contents
        note = card.note()
        fields = note.fields
        model = note.model()
        fnames = mw.col.models.fieldNames(model)
        idx = 0
        if "Note ID" in note:
            nid_idx = fnames.index("Note ID")
            if nid_idx == idx:
                idx = min(idx+1, len(fields))
        field1 = stripHTML(fields[idx])
        title = self.title.format(cid, field1[:50])
        self.setWindowTitle(title)

        # Set card HTML
        html = card.a()
        html = runFilter("previewerMungeQA", html)

        ti = lambda x: x
        base = getBase(self.mw.col)
        css = self.mw.reviewer._styles()
        if preview_jsbooster:
            # JS Booster available
            baseUrlText = getBaseUrlText(self.mw.col) + "__previewer__.html"
            stdHtmlWithBaseUrl(self.web,
                ti(mungeQA(self.mw.col, html)), baseUrlText, css,
                bodyClass="card card%d" % (card.ord+1), 
                head=base, js=browserSel)
        else:
            # fall back to default
            self.web.stdHtml(
                ti(mungeQA(self.mw.col, html)), css, 
                bodyClass="card card%d" % (card.ord+1), 
                head=base, js=browserSel)

        # Handle audio
        clearAudioQueue()
        if self.mw.reviewer.autoplay(card):
            playFromText(html)
示例#44
0
文件: clayout.py 项目: ospalh/ankiqt
 def renderPreview(self):
     c = self.card
     ti = self.maybeTextInput
     base = getBase(self.mw.col)
     self.tab['pform'].frontWeb.stdHtml(
         ti(mungeQA(c.q(reload=True))), self.mw.reviewer._styles(),
         bodyClass="card", head=base)
     self.tab['pform'].backWeb.stdHtml(
         ti(mungeQA(c.a())), self.mw.reviewer._styles(),
         bodyClass="card", head=base)
     clearAudioQueue()
     if c.id not in self.playedAudio:
         playFromText(c.q())
         playFromText(c.a())
         self.playedAudio[c.id] = True
示例#45
0
文件: clayout.py 项目: Stvad/anki
 def renderPreview(self):
     c = self.card
     ti = self.maybeTextInput
     base = self.mw.baseHTML()
     self.tab['pform'].frontWeb.stdHtml(
         ti(mungeQA(self.mw.col, c.q(reload=True))), self.mw.reviewer._styles(),
         bodyClass="card card%d" % (c.ord+1), head=base),
     self.tab['pform'].backWeb.stdHtml(
         ti(mungeQA(self.mw.col, c.a()), type='a'), self.mw.reviewer._styles(),
         bodyClass="card card%d" % (c.ord+1), head=base),
     clearAudioQueue()
     if c.id not in self.playedAudio:
         playFromText(c.q())
         playFromText(c.a())
         self.playedAudio[c.id] = True
示例#46
0
    def renderPreview(self):
        c = self.card
        html = '''<html><head>%s</head><body class=card>
<style>%s</style>%s</body></html>'''
        ti = self.maybeTextInput
        base = getBase(self.mw.col)
        self.tab['pform'].front.setHtml(
            html % (base, "", ti(mungeQA(c.q(reload=True)))))
        self.tab['pform'].back.setHtml(
            html % (base, "", ti(mungeQA(c.a()), 'a')))
        clearAudioQueue()
        if c.id not in self.playedAudio:
            playFromText(c.q())
            playFromText(c.a())
            self.playedAudio[c.id] = True
示例#47
0
def reject(self):#same as accept
    """ Close the window and save the current version of the model"""
    # only difference is: sending the information we added at initialization to avoid doing recomputation which is useless.
    self.cancelPreviewTimer()
    clearAudioQueue()
    if self.addMode:
        # remove the filler fields we added
        for name in self.emptyFields:
            self.note[name] = ""
        self.mw.col.db.execute("delete from notes where id = ?",
                               self.note.id)
    self.mm.save(self.model, templates=True, oldModel = self.originalModel, newTemplatesData = self.newTemplatesData) # new: adding oldModel, newTemplatesData
    self.mw.reset()
    saveGeom(self, "CardLayout")
    return QDialog.reject(self)
示例#48
0
 def replayAudio(self, previewer=None):
     if previewer:
         state = previewer._previewState
         c = previewer.card
     else:
         state = self.state
         c = self.card
     clearAudioQueue()
     if state == "question":
         playFromText(c.q())
     elif state == "answer":
         txt = ""
         if self._replayq(c, previewer):
             txt = c.q()
         txt += c.a()
         playFromText(txt)
示例#49
0
 def renderPreview(self):
     c = self.card
     ti = self.maybeTextInput
     baseUrl = getBaseUrl(self.mw.col) + '__previewer__.html'
     self.tab['pform'].frontWeb.stdHtml(
         ti(mungeQA(self.mw.col, c.q(reload=True))), self.mw.reviewer._styles(),
         bodyClass="card card%d" % (c.ord+1),
         js=anki.js.browserSel, baseUrl=baseUrl)
     self.tab['pform'].backWeb.stdHtml(
         ti(mungeQA(self.mw.col, c.a()), type='a'), self.mw.reviewer._styles(),
         bodyClass="card card%d" % (c.ord+1),
         js=anki.js.browserSel, baseUrl=baseUrl)
     clearAudioQueue()
     if c.id not in self.playedAudio:
         playFromText(c.q())
         playFromText(c.a())
         self.playedAudio[c.id] = True
示例#50
0
 def onClose(self):
     removeHook('guiReset', self.modelChanged)
     # stop anything playing
     clearAudioQueue()
     if (self.forceClose or self.editor.fieldsAreBlank() or
         ui.utils.askUser(_("Close and lose current input?"),
                         self)):
         self.editor.close()
         ui.dialogs.close("AddCards")
         self.parent.deck.s.flush()
         self.parent.deck.rebuildCSS()
         self.parent.moveToState("auto")
         saveGeom(self, "add")
         saveSplitter(self.dialog.splitter, "add")
         return True
     else:
         return False
示例#51
0
 def _showAnswer(self):
     if self.mw.state != "review":
         # showing resetRequired screen; ignore space
         return
     self.state = "answer"
     c = self.card
     a = c.a()
     # play audio?
     clearAudioQueue()
     if self.autoplay(c):
         playFromText(a)
     a = self._mungeQA(a)
     a = runFilter("prepareQA", a, c, "reviewAnswer")
     # render and update bottom
     self.web.eval("_showAnswer(%s);" % json.dumps(a))
     self._showEaseButtons()
     # user hook
     runHook('showAnswer')
示例#52
0
文件: clayout.py 项目: ChYi/ankiqt
 def renderPreview(self):
     c = self.card
     styles = self.model.genCSS()
     styles += "\n.cloze { font-weight: bold; color: blue; }"
     self.form.preview.setHtml(
         ('<html><head>%s</head><body class="%s">' %
          (getBase(self.deck), c.cssClass())) +
         "<style>" + styles + "</style>" +
         mungeQA(c.q(reload=True)) +
         self.maybeTextInput() +
         "<hr>" +
         mungeQA(c.a())
         + "</body></html>")
     clearAudioQueue()
     if c.id not in self.playedAudio:
         playFromText(c.q())
         playFromText(c.a())
         self.playedAudio[c.id] = True
def myReject(self):
    if not self.canClose():
        return
    remHook('reset', self.onReset)
    clearAudioQueue()
    self.removeTempNote(self.editor.note)
    self.editor.setNote(None)
    self.modelChooser.cleanup()
    self.deckChooser.cleanup()
    self.mw.maybeReset()
    # save geometry of current dialog
    if self.dialogName == "AddCards":
        saveGeom(self, "add")
    else:
        saveGeom(self, "add2")
    # close dialog
    dialogs.close(self.dialogName)
    QDialog.reject(self)
示例#54
0
 def nextCard(self):
     if self.cardQueue:
         # undone/edited cards to show
         c = self.cardQueue.pop()
         self.hadCardQueue = True
     else:
         if self.hadCardQueue:
             # the undone/edited cards may be sitting in the regular queue;
             # need to reset
             self.mw.col.reset()
             self.hadCardQueue = False
         c = self.mw.col.sched.getCard()
     self.card = c
     clearAudioQueue()
     if c:
         self._initWeb()
     else:
         self.mw.moveToState("overview")
示例#55
0
 def renderPreview(self):
     c = self.card
     styles = self.deck.rebuildCSS() + ("\nhtml { background: %s }" % c.cardModel.lastFontColour)
     styles = runFilter("addStyles", styles, c)
     self.form.preview.setHtml(
         ("<html><head>%s</head><body>" % getBase(self.deck, c))
         + "<style>"
         + styles
         + "</style>"
         + runFilter("drawQuestion", mungeQA(self.deck, c.htmlQuestion()), c)
         + "<hr>"
         + runFilter("drawAnswer", mungeQA(self.deck, c.htmlAnswer()), c)
         + "</body></html>"
     )
     clearAudioQueue()
     if c.id not in self.playedAudio:
         playFromText(c.question)
         playFromText(c.answer)
         self.playedAudio[c.id] = True
示例#56
0
    def addCards(self):
        self.editor.saveNow()

        # grab data
        note = self.editor.note

        # sanity check
        if note.dupeOrEmpty():
            showCritical("Note is a dupe or empty; not adding.")
            return

        # check for cloze sanity in case of potential cloze-y notes
        if len(note.fields) == 2:
            # find the highest existing cloze
            highest = note.highestCloze()
            if highest > 0 and not note.isCloze():
                # clozes used, but wrong model, so switch it to cloze
                self.editor.changeToModel("Cloze")
                note = self.editor.note
            elif note.isCloze() and highest == 0:
                # no clozes, switch to basic
                self.editor.changeToModel("Basic")
                note = self.editor.note

        # send data to TCP server in Anki
        data = {
            "model": note.model["name"],
            "deck": self.deckChooser.currentDeck(),
            "fields": note.fields,
            "tags": note.tags,
        }

        ret = sendToAnki("addNote", data)
        if ret == True:
            self.mw.reset()
            # stop anything playing
            clearAudioQueue()
            self.onReset(keep=True)
        else:
            showCritical("Failed to add card. Is Anki ok?")
示例#57
0
文件: addcards.py 项目: zw/ankiqt
    def addCards(self):
        # make sure updated
        self.editor.saveFieldsNow()
        fact = self.editor.fact
        n = _("Add")
        self.parent.deck.setUndoStart(n)

        fact = self.addFact(fact)
        if not fact:
            return

        # stop anything playing
        clearAudioQueue()

        self.parent.deck.setUndoEnd(n)
        self.parent.updateTitleBar()
        self.parent.statusView.redraw()

        # start a new fact
        self.clearOldFact(fact)

        self.maybeSave()
示例#58
0
文件: reviewer.py 项目: ChYi/ankiqt
 def nextCard(self):
     if self.cardQueue:
         # a card has been retrieved from undo
         c = self.cardQueue.pop()
     else:
         c = self.mw.deck.sched.getCard()
     self.card = c
     clearAudioQueue()
     if c:
         self.mw.enableCardMenuItems()
         self._showStatus()
         self._maybeEnableSound()
         #self.updateMarkAction()
         self.state = "question"
         self._initWeb()
     else:
         self._hideStatus()
         self.mw.disableCardMenuItems()
         if self.mw.deck.cardCount():
             self._showCongrats()
         else:
             self._showEmpty()
示例#59
0
 def renderPreview(self):
     c = self.card
     ti = self.maybeTextInput
     base = getBase(self.mw.col)
     self.tab["pform"].frontWeb.stdHtml(
         ti(mungeQA(c.q(reload=True))),
         self.mw.reviewer._styles(),
         bodyClass="card card%d" % (c.ord + 1),
         head=base,
         js=anki.js.browserSel,
     )
     self.tab["pform"].backWeb.stdHtml(
         ti(mungeQA(c.a()), type="a"),
         self.mw.reviewer._styles(),
         bodyClass="card card%d" % (c.ord + 1),
         head=base,
         js=anki.js.browserSel,
     )
     clearAudioQueue()
     if c.id not in self.playedAudio:
         playFromText(c.q())
         playFromText(c.a())
         self.playedAudio[c.id] = True