예제 #1
0
 def replayAudio(self):
     clearAudioQueue()
     c = self.card
     if self.state == "question":
         playFromText(c.q())
     elif self.state == "answer":
         playFromText(c.a())
예제 #2
0
    def _showQuestion(self):
        self._reps += 1
        self.state = "question"
        self.typedAnswer = None
        c = self.card
        # grab the question and play audio
        if c.isEmpty():
            q = _("""\
The front of this card is empty. Please run Tools>Empty Cards.""")
        else:
            q = c.q()
        if self.autoplay(c):
            playFromText(q)
        # render & update bottom
        q = self._mungeQA(q)
        q += self._hiddenUpcomingImages()
        klass = "card card%d" % (c.ord+1)
        self.web.eval("_updateQA(%s, false, '%s');" % (json.dumps(q), klass))
        self._toggleStar()
        if self._bottomReady:
            self._showAnswerButton()
        # if we have a type answer field, focus main web
        if self.typeCorrect:
            self.mw.web.setFocus()
        # user hook
        runHook('showQuestion')
예제 #3
0
    def _showQuestion(self):
        self._reps += 1
        self.state = "question"
        self.typedAnswer = None
        c = self.card
        # grab the question and play audio
        if c.isEmpty():
            q = _("""\
The front of this card is empty. Please run Tools>Empty Cards.""")
        else:
            q = c.q()
        if self.autoplay(c):
            playFromText(q)
        # render & update bottom
        q = self._mungeQA(q)
        klass = "card card%d" % (c.ord+1)
        self.web.eval("_updateQA(%s, false, '%s');" % (json.dumps(q), klass))
        self._toggleStar()
        if self._bottomReady:
            self._showAnswerButton()
        # if we have a type answer field, focus main web
        if self.typeCorrect:
            self.mw.web.setFocus()
        # user hook
        runHook('showQuestion')
예제 #4
0
파일: clayout.py 프로젝트: Glutanimate/anki
    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()
예제 #5
0
    def _showQuestion(self):
        self._reps += 1
        self.state = "question"
        self.typedAnswer = None
        c = self.card
        # grab the question and play audio
        if c.isEmpty():
            q = _("""\
The front of this card is empty. Please run Tools>Empty Cards.""")
        else:
            q = c.q()
        if self.autoplay(c):
            playFromText(q)
        # render & update bottom
        q = self._mungeQA(q)
        q = runFilter("prepareQA", q, c, "reviewQuestion")

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

        self.web.eval("_showQuestion(%s,'%s');" % (json.dumps(q), bodyclass))
        self._drawFlag()
        self._drawMark()
        self._showAnswerButton()
        # if we have a type answer field, focus main web
        if self.typeCorrect:
            self.mw.web.setFocus()
        # user hook
        runHook('showQuestion')
예제 #6
0
    def _showQuestion(self):
        self._reps += 1
        self.state = "question"
        self.typedAnswer = None
        baseUrl = getBaseUrl(self.mw.col) + '__reviewer__.html'
        c = self.card
        # grab the question and play audio
        if c.isEmpty():
            q = _("""\
The front of this card is empty. Please run Tools>Empty Cards.""")
        else:
            q = c.q()
        if self.autoplay(c):
            playFromText(q)
        # render & update bottom
        q = self._mungeQA(q)
        klass = "card card%d" % (c.ord+1)
        self.web.stdHtml(self._revHtml % q,self._styles(),klass, baseUrl=baseUrl, js=anki.js.jquery+anki.js.browserSel+self._revScript)
        self.web.eval("_updateQA(false, '%s');" % klass)
        self._toggleStar()
        if self._bottomReady:
            self._showAnswerButton()
        # if we have a type answer field, focus main web
        if self.typeCorrect:
            self.mw.web.setFocus()
        # user hook
        runHook('showQuestion')
예제 #7
0
파일: reviewer.py 프로젝트: bbugyi200/anki
    def _showQuestion(self):
        self._reps += 1
        self.state = "question"
        self.typedAnswer = None
        c = self.card
        # grab the question and play audio
        if c.isEmpty():
            q = _("""\
The front of this card is empty. Please run Tools>Empty Cards.""")
        else:
            q = c.q()
        if self.autoplay(c):
            playFromText(q)
        # render & update bottom
        q = self._mungeQA(q)
        q = runFilter("prepareQA", q, c, "reviewQuestion")

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

        self.web.eval("_showQuestion(%s,'%s');" % (json.dumps(q), bodyclass))
        self._drawFlag()
        self._drawMark()
        self._showAnswerButton()
        # if we have a type answer field, focus main web
        if self.typeCorrect:
            self.mw.web.setFocus()
        # user hook
        runHook('showQuestion')
예제 #8
0
파일: clayout.py 프로젝트: proprietary/anki
    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()
예제 #9
0
 def replayAudio(self):
     clearAudioQueue()
     c = self.card
     if self.state == "question":
         playFromText(c.q())
     elif self.state == "answer":
         playFromText(c.a())
예제 #10
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())
예제 #11
0
파일: reviewer.py 프로젝트: ChYi/ankiqt
 def _showAnswer(self):
     self.state = "answer"
     c = self.card
     a = c.a()
     if self.mw.config['autoplaySounds']:
         playFromText(a)
     # render
     runHook('showAnswer')
예제 #12
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)
예제 #13
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)
예제 #14
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)
예제 #15
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)
예제 #16
0
파일: view.py 프로젝트: scout-zz/ankiqt
 def drawQuestion(self, nosound=False):
     "Show the question."
     if not self.main.config['splitQA']:
         self.write("<br>")
     q = self.main.currentCard.htmlQuestion()
     if self.haveTop:
         height = 35
     else:
         height = 45
     q = runFilter("drawQuestion", q)
     self.write(self.center(self.mungeQA(self.main.deck, q), height))
     if self.state != self.oldState and not nosound:
         playFromText(q)
예제 #17
0
 def _showAnswer(self):
     self.state = "answer"
     c = self.card
     a = c.a()
     # play audio?
     if self.mw.col.decks.confForDid(self.card.did)['autoplay']:
         playFromText(a)
     # render and update bottom
     a = self._mungeQA(a)
     self.web.eval("_updateQA(%s, true);" % simplejson.dumps(a))
     self._showEaseButtons()
     # user hook
     runHook('showAnswer')
예제 #18
0
 def _showAnswer(self):
     self.state = "answer"
     c = self.card
     a = c.a()
     # play audio?
     if self.mw.col.decks.confForDid(self.card.did)['autoplay']:
         playFromText(a)
     # render and update bottom
     a = self._mungeQA(a)
     self.web.eval("_updateQA(%s, true);" % simplejson.dumps(a))
     self._showEaseButtons()
     # user hook
     runHook('showAnswer')
    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)
예제 #20
0
 def updateCard(self):
     c = self.cards[self.currentCard]
     self.dialog.webView.setHtml(
         ("<html><head>%s</head><body>" % getBase(self.deck))
         + "<style>"
         + self.deck.css
         + ("\nhtml { background: %s }" % c.cardModel.lastFontColour)
         + "\ndiv { white-space: pre-wrap; }</style>"
         + mungeQA(self.deck, c.htmlQuestion())
         + "<br><br><hr><br><br>"
         + mungeQA(self.deck, c.htmlAnswer())
         + "</body></html>"
     )
     playFromText(c.question)
     playFromText(c.answer)
예제 #21
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
예제 #22
0
 def drawQuestion(self, nosound=False):
     "Show the question."
     if not self.main.config['splitQA']:
         self.write("<br>")
     q = self.main.currentCard.htmlQuestion()
     if self.haveTop:
         height = 35
     elif self.main.currentCard.cardModel.questionInAnswer:
         height = 40
     else:
         height = 45
     q = runFilter("drawQuestion", q, self.main.currentCard)
     self.write(self.center(self.mungeQA(self.main.deck, q), height))
     if self.state != self.oldState and not nosound:
         playFromText(q)
예제 #23
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
예제 #24
0
파일: reviewer.py 프로젝트: hh24k/anki
 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?
     if self.autoplay(c):
         playFromText(a)
     # render and update bottom
     self.web.eval("_showAnswer(%s);" % json.dumps(''))
     self._showEaseButtons()
     # user hook
     runHook('showAnswer')
예제 #25
0
def drawAnswerCES():
    if not isOn:
        origDrawAnswer()
        return
    a = mw.currentCard.htmlAnswer()
    mainAns = mungeQA(mw.bodyView.main.deck, a)
    mw.bodyView.write('<span id=answer />'+mainAns)
    mw.bodyView.flush()
    currentCard = mw.currentCard
    word = currentCard.fact['Expression']
    exSens = findChar(' '+word.strip()+' ')
    displayableExSens = exSensFormat(exSens,word)
    mw.bodyView.write(displayableExSens)
    if mw.bodyView.state != mw.bodyView.oldState:
        playFromText(a)
예제 #26
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
예제 #27
0
파일: reviewer.py 프로젝트: Afoucaul/anki
 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)
예제 #28
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?
     if self.autoplay(c):
         playFromText(a)
     # render and update bottom
     a = self._mungeQA(a)
     self.web.eval("_updateQA(%s, true);" % json.dumps(a))
     self._showEaseButtons()
     # user hook
     runHook('showAnswer')
예제 #29
0
 def _showQuestion(self):
     self.state = "question"
     c = self.card
     # grab the question and play audio
     q = c.q()
     if self.mw.col.decks.confForDid(self.card.did)['autoplay']:
         playFromText(q)
     # render & update bottom
     q = self._mungeQA(q)
     self.web.eval("_updateQA(%s);" % simplejson.dumps(q))
     self._showAnswerButton()
     # if we have a type answer field, focus main web
     if self.typeField:
         self.mw.web.setFocus()
     # user hook
     runHook('showQuestion')
예제 #30
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)
예제 #31
0
 def renderPreview(self):
     c = self.card
     ti = self.maybeTextInput
     base = getBase(self.mw.col)
     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,
         js=anki.js.browserSel)
     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,
         js=anki.js.browserSel)
     clearAudioQueue()
     if c.id not in self.playedAudio:
         playFromText(c.q())
         playFromText(c.a())
         self.playedAudio[c.id] = True
예제 #32
0
파일: view.py 프로젝트: richtermondt/ankiqt
 def drawAnswer(self):
     "Show the answer."
     a = self.main.currentCard.htmlAnswer()
     a = runFilter("drawAnswer", a, self.main.currentCard)
     if self.main.currentCard.cardModel.typeAnswer:
         try:
             cor = stripMedia(stripHTML(self.main.currentCard.fact[self.main.currentCard.cardModel.typeAnswer]))
         except KeyError:
             self.main.currentCard.cardModel.typeAnswer = ""
             cor = ""
         if cor:
             given = unicode(self.main.typeAnswerField.text())
             res = self.correct(cor, given)
             a = res + "<br>" + a
     self.write(self.center("<span id=answer />" + self.mungeQA(self.main.deck, a)))
     if self.state != self.oldState:
         playFromText(a)
예제 #33
0
파일: reviewer.py 프로젝트: ChYi/ankiqt
 def _showQuestion(self):
     # fixme: timeboxing
     # fixme: timer
     self.state = "question"
     c = self.card
     q = c.q()
     a = c.a()
     if self.mw.config['autoplaySounds']:
         playFromText(q)
     # render
     esc = self.mw.deck.media.escapeImages
     q=esc(mungeQA(q)) + self.typeAnsInput()
     a=esc(mungeQA(a))
     self.web.eval("_updateQA(%s);" % simplejson.dumps(
         [q, a, self._answerButtons(), c.cssClass(),
          c.template()['hideQ']]))
     runHook('showQuestion')
예제 #34
0
파일: clayout.py 프로젝트: leowalkling/anki
 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
예제 #35
0
파일: facteditor.py 프로젝트: sanna/ankiqt
 def updateCard(self):
     c = self.cards[self.currentCard]
     styles = (self.deck.css +
               ("\nhtml { background: %s }" % c.cardModel.lastFontColour) +
               "\ndiv { white-space: pre-wrap; }")
     styles = runFilter("addStyles", styles, c)
     self.dialog.webView.setHtml(
         ('<html><head>%s</head><body>' % getBase(self.deck)) +
         "<style>" + styles + "</style>" +
         runFilter("drawQuestion", mungeQA(self.deck, c.htmlQuestion()),
                   c) +
         "<br><br><hr><br><br>" +
         runFilter("drawAnswer", mungeQA(self.deck, c.htmlAnswer()),
                   c)
         + "</body></html>")
     playFromText(c.question)
     playFromText(c.answer)
예제 #36
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
예제 #37
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
예제 #38
0
파일: reviewer.py 프로젝트: bbugyi200/anki
 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')
예제 #39
0
파일: reviewer.py 프로젝트: Afoucaul/anki
 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')
예제 #40
0
파일: reviewer.py 프로젝트: kchien/ankiqt
 def _showQuestion(self):
     self._reps += 1
     self.state = "question"
     self.typedAnswer = None
     c = self.card
     # grab the question and play audio
     q = c.q()
     if self._autoplay(c):
         playFromText(q)
     # render & update bottom
     q = self._mungeQA(q)
     self.web.eval("_updateQA(%s);" % simplejson.dumps(q))
     if self._bottomReady:
         self._showAnswerButton()
     # if we have a type answer field, focus main web
     if self.typeCorrect:
         self.mw.web.setFocus()
     # user hook
     runHook('showQuestion')
예제 #41
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
예제 #42
0
파일: clayout.py 프로젝트: endrjuskr/anki
 def renderPreview(self):
     c = self.card
     ti = self.maybeTextInput
     base = self.mw.baseHTML()
     jsinc = ["jquery.js","browsersel.js",
              "mathjax/conf.js", "mathjax/MathJax.js",
              "mathjax/queue-typeset.js"]
     self.tab['pform'].frontWeb.stdHtml(
         ti(mungeQA(self.mw.col, c.q(reload=True)))+
         self.tab['pform'].frontWeb.bundledCSS("reviewer.css"),
         bodyClass="card card%d" % (c.ord+1), head=base, js=jsinc),
     self.tab['pform'].backWeb.stdHtml(
         ti(mungeQA(self.mw.col, c.a()), type='a')+
         self.tab['pform'].backWeb.bundledCSS("reviewer.css"),
         bodyClass="card card%d" % (c.ord+1), head=base, js=jsinc),
     clearAudioQueue()
     if c.id not in self.playedAudio:
         playFromText(c.q())
         playFromText(c.a())
         self.playedAudio[c.id] = True
예제 #43
0
 def _showAnswer(self):
     if self.mw.state != "review":
         # showing resetRequired screen; ignore space
         return
     self.state = "answer"
     baseUrl = getBaseUrl(self.mw.col) + '__reviewer__.html'
     c = self.card
     a = c.a()
     # play audio?
     if self.autoplay(c):
         playFromText(a)
     # render and update bottom
     a = self._mungeQA(a)
     klass = "card card%d" % (c.ord+1)
     self.web.stdHtml(self._revHtml % a,self._styles(),klass, baseUrl=baseUrl, js=anki.js.jquery+anki.js.browserSel+self._revScript)
     self.web.eval("_updateQA(true);")
     self._toggleStar()
     self._showEaseButtons()
     # user hook
     runHook('showAnswer')
예제 #44
0
 def autoplayOnQ(self, r, card, _old):
     "adds delay between overlapping sound tracks"
     bool = _old(r, card)
     if bool and r.state=='question' and self.duration and \
     not self.settings.config['use_mplayer_for_audio']:
         delay = self.settings.config['card_autoplay_delay']
         dmax = self.settings.theme['duration_max']
         dur = max(0, min(dmax, self.fb.audio_duration - self.duration))
         mw.progress.timer(dur + delay, lambda: playFromText(card.q()),
                           False)
         return False
     return bool
예제 #45
0
 def drawAnswer(self):
     "Show the answer."
     a = self.main.currentCard.htmlAnswer()
     a = runFilter("drawAnswer", a, self.main.currentCard)
     if self.main.currentCard.cardModel.typeAnswer:
         try:
             cor = stripMedia(
                 stripHTML(self.main.currentCard.fact[
                     self.main.currentCard.cardModel.typeAnswer]))
         except KeyError:
             self.main.currentCard.cardModel.typeAnswer = ""
             cor = ""
         if cor:
             given = unicode(self.main.typeAnswerField.text())
             res = self.correct(cor, given)
             a = res + "<br>" + a
     self.write(
         self.center('<span id=answer />' +
                     self.mungeQA(self.main.deck, a)))
     if self.state != self.oldState:
         playFromText(a)
예제 #46
0
    def _renderPreview(self):
        self.cancelPreviewTimer()

        c = self.card
        ti = self.maybeTextInput
        bodyclass = "card card%d" % (c.ord + 1)
        q = ti(mungeQA(self.mw.col, c.q(reload=True)))
        a = ti(mungeQA(self.mw.col, c.a()), type='a')

        # 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()
예제 #47
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
예제 #48
0
 def renderPreview(self):
     c = self.card
     ti = self.maybeTextInput
     base = self.mw.baseHTML()
     self.tab['pform'].frontWeb.setEnabled(False)
     self.tab['pform'].backWeb.setEnabled(False)
     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),
     self.tab['pform'].frontWeb.setEnabled(True)
     self.tab['pform'].backWeb.setEnabled(True)
     clearAudioQueue()
     if c.id not in self.playedAudio:
         playFromText(c.q())
         playFromText(c.a())
         self.playedAudio[c.id] = True
예제 #49
0
 def create_rows(self, layout):
     play_button_group = QButtonGroup(self)
     old_play_button_group = QButtonGroup(self)
     for num, (source, dest, text, dl_fname, dl_hash, extras, icon)\
             in enumerate(self.list, 3):
         tt_text = self.build_text_help_label(text, source, extras)
         ico_label = QLabel('', self)
         ico_label.setToolTip(tt_text)
         if icon:
             ico_label.setPixmap(QPixmap.fromImage(icon))
         layout.addWidget(ico_label, num, 0)
         tt_label = QLabel(text, self)
         tt_label.setToolTip(tt_text)
         layout.addWidget(tt_label, num, 1)
         if self.hide_text:
             tt_label.hide()
         # Play button.
         t_play_button = QPushButton(self)
         play_button_group.addButton(t_play_button, num - 3)
         t_play_button.setToolTip(self.play_help)
         t_play_button.setIcon(QIcon(os.path.join(icons_dir, 'play.png')))
         layout.addWidget(t_play_button, num, self.play_column)
         if self.note[dest]:
             t_play_old_button = QPushButton(self)
             old_play_button_group.addButton(t_play_old_button, num - 3)
             t_play_old_button.setIcon(
                 QIcon(os.path.join(icons_dir, 'play.png')))
             if not self.hide_text:
                 t_play_old_button.setToolTip(self.note[dest])
             else:
                 t_play_old_button.setToolTip(self.play_old_help_short)
             layout.addWidget(t_play_old_button, num, self.play_old_column)
         else:
             dummy_label = QLabel('', self)
             dummy_label.setToolTip(self.play_old_empty_line_help)
             layout.addWidget(dummy_label, num, self.play_old_column)
         # The group where we later look what to do:
         t_button_group = QButtonGroup(self)
         t_button_group.setExclusive(True)
         # Now the four buttons
         t_add_button = QPushButton(self)
         t_add_button.setCheckable(True)
         t_add_button.setChecked(True)
         t_add_button.setFlat(True)
         t_add_button.setToolTip(self.add_help_text_short)
         t_add_button.setIcon(QIcon(os.path.join(icons_dir, 'add.png')))
         layout.addWidget(t_add_button, num, self.add_column)
         t_button_group.addButton(t_add_button, action['add'])
         t_keep_button = QPushButton(self)
         t_keep_button.setCheckable(True)
         t_keep_button.setFlat(True)
         t_keep_button.setToolTip(self.keep_help_text_short)
         t_keep_button.setIcon(QIcon(os.path.join(icons_dir, 'keep.png')))
         layout.addWidget(t_keep_button, num, self.keep_column)
         t_button_group.addButton(t_keep_button,  action['keep'])
         t_delete_button = QPushButton(self)
         t_delete_button.setCheckable(True)
         t_delete_button.setFlat(True)
         t_delete_button.setToolTip(self.delete_help_text_short)
         t_delete_button.setIcon(QIcon(os.path.join(icons_dir,
                                                    'delete.png')))
         layout.addWidget(t_delete_button, num, self.delete_column)
         t_button_group.addButton(t_delete_button,  action['delete'])
         t_blacklist_button = QPushButton(self)
         t_blacklist_button.setCheckable(True)
         t_blacklist_button.setFlat(True)
         t_blacklist_button.setToolTip(self.blacklist_help_text_short)
         t_blacklist_button.setIcon(QIcon(os.path.join(icons_dir,
                                                       'blacklist.png')))
         if self.show_skull_and_bones:
             layout.addWidget(
                 t_blacklist_button, num, self.blacklist_column)
         else:
             t_blacklist_button.hide()
         t_button_group.addButton(t_blacklist_button,  action['blacklist'])
         self.buttons_groups.append(t_button_group)
     play_button_group.buttonClicked.connect(
         lambda button: play(self.list[play_button_group.id(button)][3]))
     old_play_button_group.buttonClicked.connect(
         lambda button: playFromText(
             self.note[self.list[old_play_button_group.id(button)][1]]))
예제 #50
0
 def create_rows(self, layout):
     u"""Build the rows of the dialog box"""
     play_button_group = QButtonGroup(self)
     old_play_button_group = QButtonGroup(self)
     for num, entry in enumerate(self.entries_list, 3):
         tt_text = self.build_text_help_label(entry)
         ico_label = QLabel('', self)
         ico_label.setToolTip(tt_text)
         if entry.icon:
             ico_label.setPixmap(QPixmap.fromImage(entry.icon))
         layout.addWidget(ico_label, num, 0)
         tt_label = QLabel(entry.display_word, self)
         tt_label.setToolTip(tt_text)
         layout.addWidget(tt_label, num, 1)
         if self.hide_text:
             tt_label.hide()
         # Play button.
         t_play_button = QPushButton(self)
         play_button_group.addButton(t_play_button, num - 3)
         t_play_button.setToolTip(self.play_help)
         t_play_button.setIcon(QIcon(os.path.join(icons_dir, 'play.png')))
         layout.addWidget(t_play_button, num, self.play_column)
         if self.note[entry.audio_field_name]:
             t_play_old_button = QPushButton(self)
             old_play_button_group.addButton(t_play_old_button, num - 3)
             t_play_old_button.setIcon(
                 QIcon(os.path.join(icons_dir, 'play.png')))
             if not self.hide_text:
                 t_play_old_button.setToolTip(
                     self.note[entry.audio_field_name])
             else:
                 t_play_old_button.setToolTip(self.play_old_help_short)
             layout.addWidget(t_play_old_button, num, self.play_old_column)
         else:
             dummy_label = QLabel('', self)
             dummy_label.setToolTip(self.play_old_empty_line_help)
             layout.addWidget(dummy_label, num, self.play_old_column)
         # The group where we later look what to do:
         t_button_group = QButtonGroup(self)
         t_button_group.setExclusive(True)
         # Now the four buttons
         t_add_button = QPushButton(self)
         t_add_button.setCheckable(True)
         t_add_button.setFlat(True)
         t_add_button.setToolTip(self.add_help_text_short)
         t_add_button.setIcon(QIcon(os.path.join(icons_dir, 'add.png')))
         layout.addWidget(t_add_button, num, self.add_column)
         t_button_group.addButton(t_add_button, Action.Add)
         t_keep_button = QPushButton(self)
         t_keep_button.setCheckable(True)
         t_keep_button.setFlat(True)
         t_keep_button.setToolTip(self.keep_help_text_short)
         t_keep_button.setIcon(QIcon(os.path.join(icons_dir, 'keep.png')))
         layout.addWidget(t_keep_button, num, self.keep_column)
         t_button_group.addButton(t_keep_button, Action.Keep)
         t_delete_button = QPushButton(self)
         t_delete_button.setCheckable(True)
         t_delete_button.setFlat(True)
         t_delete_button.setToolTip(self.delete_help_text_short)
         t_delete_button.setIcon(
             QIcon(os.path.join(icons_dir, 'delete.png')))
         layout.addWidget(t_delete_button, num, self.delete_column)
         t_button_group.addButton(t_delete_button,  Action.Delete)
         t_blacklist_button = QPushButton(self)
         t_blacklist_button.setCheckable(True)
         t_blacklist_button.setFlat(True)
         t_blacklist_button.setToolTip(self.blacklist_help_text_short)
         t_blacklist_button.setIcon(
             QIcon(os.path.join(icons_dir, 'blacklist.png')))
         if entry.entry_hash:
             layout.addWidget(
                 t_blacklist_button, num, self.blacklist_column)
         else:
             t_blacklist_button.hide()
             dummy_label_bl = QLabel('', self)
             dummy_label_bl.setToolTip(self.blacklist_empty_line_help)
             layout.addWidget(dummy_label_bl, num, self.blacklist_column)
         t_button_group.button(entry.action).setChecked(True)
         # New: check a button based on how good the downloader is.
         t_button_group.addButton(t_blacklist_button, Action.Blacklist)
         self.buttons_groups.append(t_button_group)
     play_button_group.buttonClicked.connect(
         lambda button: play(
             self.entries_list[play_button_group.id(button)].file_path))
     # N.B.: anki.sound.play() plays files from anywhere, not just
     # from the colection.media folder. We should be good,
     # here. (This behaviour may be a security risk, idk.)
     old_play_button_group.buttonClicked.connect(
         lambda button: playFromText(
             self.note[
                 self.entries_list[
                     old_play_button_group.id(button)].audio_field_name]))
예제 #51
0
 def create_rows(self, layout):
     """Build one row of the dialog box"""
     play_button_group = QButtonGroup(self)
     old_play_button_group = QButtonGroup(self)
     for num, (source, dest, text, dl_fname, dl_hash, extras, icon)\
             in enumerate(self.list, 3):
         tt_text = self.build_text_help_label(text, source, extras)
         ico_label = QLabel('', self)
         ico_label.setToolTip(tt_text)
         if icon:
             ico_label.setPixmap(QPixmap.fromImage(icon))
         layout.addWidget(ico_label, num, 0)
         tt_label = QLabel(text, self)
         tt_label.setToolTip(tt_text)
         layout.addWidget(tt_label, num, 1)
         if self.hide_text:
             tt_label.hide()
         # Play button.
         t_play_button = QPushButton(self)
         play_button_group.addButton(t_play_button, num - 3)
         t_play_button.setToolTip(self.play_help)
         t_play_button.setIcon(QIcon(os.path.join(icons_dir, 'play.png')))
         layout.addWidget(t_play_button, num, self.play_column)
         if self.note[dest]:
             t_play_old_button = QPushButton(self)
             old_play_button_group.addButton(t_play_old_button, num - 3)
             t_play_old_button.setIcon(
                 QIcon(os.path.join(icons_dir, 'play.png')))
             if not self.hide_text:
                 t_play_old_button.setToolTip(self.note[dest])
             else:
                 t_play_old_button.setToolTip(self.play_old_help_short)
             layout.addWidget(t_play_old_button, num, self.play_old_column)
         else:
             dummy_label = QLabel('', self)
             dummy_label.setToolTip(self.play_old_empty_line_help)
             layout.addWidget(dummy_label, num, self.play_old_column)
         # The group where we later look what to do:
         t_button_group = QButtonGroup(self)
         t_button_group.setExclusive(True)
         # Now the four buttons
         t_add_button = QPushButton(self)
         t_add_button.setCheckable(True)
         t_add_button.setChecked(True)
         t_add_button.setFlat(True)
         t_add_button.setToolTip(self.add_help_text_short)
         t_add_button.setIcon(QIcon(os.path.join(icons_dir, 'add.png')))
         layout.addWidget(t_add_button, num, self.add_column)
         t_button_group.addButton(t_add_button, action['add'])
         t_keep_button = QPushButton(self)
         t_keep_button.setCheckable(True)
         t_keep_button.setFlat(True)
         t_keep_button.setToolTip(self.keep_help_text_short)
         t_keep_button.setIcon(QIcon(os.path.join(icons_dir, 'keep.png')))
         layout.addWidget(t_keep_button, num, self.keep_column)
         t_button_group.addButton(t_keep_button,  action['keep'])
         t_delete_button = QPushButton(self)
         t_delete_button.setCheckable(True)
         t_delete_button.setFlat(True)
         t_delete_button.setToolTip(self.delete_help_text_short)
         t_delete_button.setIcon(QIcon(os.path.join(icons_dir,
                                                    'delete.png')))
         layout.addWidget(t_delete_button, num, self.delete_column)
         t_button_group.addButton(t_delete_button,  action['delete'])
         t_blacklist_button = QPushButton(self)
         t_blacklist_button.setCheckable(True)
         t_blacklist_button.setFlat(True)
         t_blacklist_button.setToolTip(self.blacklist_help_text_short)
         t_blacklist_button.setIcon(QIcon(os.path.join(icons_dir,
                                                       'blacklist.png')))
         if self.show_skull_and_bones:
             layout.addWidget(
                 t_blacklist_button, num, self.blacklist_column)
         else:
             t_blacklist_button.hide()
         t_button_group.addButton(t_blacklist_button,  action['blacklist'])
         self.buttons_groups.append(t_button_group)
     play_button_group.buttonClicked.connect(
         lambda button: play(self.list[play_button_group.id(button)][3]))
     old_play_button_group.buttonClicked.connect(
         lambda button: playFromText(
             self.note[self.list[old_play_button_group.id(button)][1]]))
예제 #52
0
    def renderPreview(self, cardChanged=False):
        """
        Generates the preview window content
        """

        oldfocus = None
        cids = self.b.selectedCards()
        nr = len(cids)
        multiple_selected = nr > 1

        if not cids:
            txt = "Please select one or more cards"
            self.web.stdHtml(txt)
            self.updateButtons()
            return

        if cardChanged and not self.both:
            self.state = "question"

        if self.config["rev"][0]:
            # only show review buttons on answer side:
            if self.config["rev"][3] and self.state != "answer":
                self.revArea.hide()
            else:
                self.updateRevArea(self.b.card)

        if cids[0] in self.cards and not multiple_selected:
            # moved focus to another previously selected card
            oldfocus = cids[0]
            cids = self.cards
            nr = len(cids)
            self.multi = nr > 1
            if cardChanged:
                # focus changed without any edits
                if not self.linkClicked and self.multi:
                    # only scroll when coming from browser and multiple cards shown
                    self.scrollToCard(oldfocus)
                self.linkClicked = False
                return
        elif multiple_selected:
            self.multi = True
        else:
            self.multi = False

        if nr >= 200:
            q = ("Are you sure you want to preview <b>{} cards</b> at once? "
                 "This might take a while to render".format(nr))
            ret = askUser(q)
            if not ret:
                return False

        html, css, js = self.renderCards(cids)

        def ti(x):
            return x

        base = getBase(self.mw.col)
        if preview_jsbooster:
            # JS Booster available
            baseUrlText = getBaseUrlText(self.mw.col) + "__previewer__.html"
            stdHtmlWithBaseUrl(self.web,
                               ti(mungeQA(self.mw.col, html)),
                               baseUrlText,
                               css,
                               head=base,
                               js=browserSel + multi_preview_js)
        else:
            # fall back to default
            self.web.stdHtml(ti(mungeQA(self.mw.col, html)),
                             css,
                             head=base,
                             js=js)

        if oldfocus and self.multi:
            self.scrollToCard(oldfocus)

        self.cards = cids

        self.updateButtons()

        clearAudioQueue()

        if not self.multi and self.mw.reviewer.autoplay(self.b.card):
            playFromText(html)