Beispiel #1
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()
Beispiel #2
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")))
Beispiel #3
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
Beispiel #4
0
 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
Beispiel #5
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", 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
Beispiel #6
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
Beispiel #7
0
 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')
Beispiel #8
0
 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
Beispiel #9
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
Beispiel #10
0
def onPrint():
    path = os.path.join(QStandardPaths.writableLocation(
        QStandardPaths.DesktopLocation), "print.html")
    ids = sortFieldOrderCids(mw.col.decks.selected())
    def esc(s):
        # strip off the repeated question in answer if exists
        #s = re.sub("(?si)^.*<hr id=answer>\n*", "", s)
        # remove type answer
        s = re.sub(r"\[\[type:[^]]+\]\]", "", s)
        return s
    buf = open(path, "w", encoding="utf8")
    buf.write("<html><head>" +
              '<meta charset="utf-8">'
              + mw.baseHTML() + "</head><body>")
    buf.write("""<style>
img { max-width: 100%; }
tr { page-break-inside:avoid; page-break-after:auto }
td { page-break-after:auto; }
td { border: 1px solid #ccc; padding: 1em; }
</style><table cellspacing=10 width=100%>""")
    first = True

    mw.progress.start(immediate=True)
    for j, cid in enumerate(ids):
        if j % config['cardsPerRow'] == 0:
            if not first:
                buf.write("</tr>")
            else:
                first = False
            buf.write("<tr>")
        c = mw.col.getCard(cid)
        qatxt = c._getQA(True, False)['a']
        qatxt = mungeQA(mw.col, qatxt)
        cont = u'<td width="{1}%"><center>{0}</center></td>'.format(
            esc(qatxt), 100/config['cardsPerRow'])
        buf.write(cont)
        if j % 50 == 0:
            mw.progress.update("Cards exported: %d" % (j+1))
    buf.write("</tr>")
    buf.write("</table></body></html>")
    mw.progress.finish()
    buf.close()
    openLink(QUrl.fromLocalFile(path))
Beispiel #11
0
 def _mungeQA(self, buf):
     return self.typeAnsFilter(mungeQA(self.mw.col, buf))
Beispiel #12
0
 def _mungeQA(self, buf):
     return self.mw.col.media.escapeImages(
         self.typeAnsFilter(mungeQA(buf)))
Beispiel #13
0
 def _mungeQA(self, buf):
     return self.typeAnsFilter(mungeQA(self.mw.col, buf))