Exemplo n.º 1
0
    def _renderPreview(self) -> None:
        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 = gui_hooks.card_will_show(q, c, "clayoutQuestion")

        a = ti(mungeQA(self.mw.col, c.a()), type="a")
        a = gui_hooks.card_will_show(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()
Exemplo n.º 2
0
 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()
Exemplo n.º 3
0
 def _reject(self) -> None:
     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)
Exemplo n.º 4
0
 def _reject(self) -> None:
     gui_hooks.state_did_reset.remove(self.onReset)
     gui_hooks.current_note_type_did_change.remove(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)
Exemplo n.º 5
0
 def reject(self):
     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)
     self.mw.reset()
     saveGeom(self, "CardLayout")
     self.pform.frontWeb = None
     self.pform.backWeb = None
     return QDialog.reject(self)
Exemplo n.º 6
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)
Exemplo n.º 7
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
     gui_hooks.run_reviewer_showing_answer_hook(c)
def answersound(card, ease, early):
    #add sounds for extra buttons here
    if ease == 1:
        clearAudioQueue(
        )  #force feedback to play now. Apparently this has to be within the if to be defined. Or I have to stop using the python console as if it's the addon.
        play(os.path.join(user_files, "again.mp3"))
    if ease == 2:
        clearAudioQueue()
        play(os.path.join(user_files, "hard.mp3"))
    if ease == 3:
        clearAudioQueue()
        play(os.path.join(user_files, "good.mp3"))
    if ease == 4:
        clearAudioQueue()
        play(os.path.join(user_files, "easy.mp3"))
Exemplo n.º 9
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()
     self._showQuestion()
Exemplo n.º 10
0
 def show(self):
     clearAudioQueue()
     self.web.resetHandlers()
     self.web.onBridgeCmd = self._linkHandler
     self._renderPage()
Exemplo n.º 11
0
 def onReplayRecorded(self):
     if not self._recordedAudio:
         return tooltip(_("You haven't recorded your voice yet."))
     clearAudioQueue()
     play(self._recordedAudio)