~ubuntu-branches/ubuntu/lucid/anki/lucid-updates

« back to all changes in this revision

Viewing changes to ankiqt/ui/view.py

  • Committer: Bazaar Package Importer
  • Author(s): Mackenzie Morgan
  • Date: 2010-05-31 15:55:50 UTC
  • mfrom: (7.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100531155550-wj3tag8bvp6fwhpo
Tags: 0.9.9.8.6-2~lucid1
Backport from maverick to fix FTBFS (LP: #550145)

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
from PyQt4.QtGui import *
6
6
from PyQt4.QtCore import *
7
7
import anki, anki.utils
8
 
from anki.sound import playFromText, stripSounds
 
8
from anki.sound import playFromText
9
9
from anki.latex import renderLatex, stripLatex
10
10
from anki.utils import stripHTML
11
 
from anki.hooks import runHook
 
11
from anki.hooks import runHook, runFilter
 
12
from anki.media import stripMedia
12
13
import types, time, re, os, urllib, sys, difflib
13
14
from ankiqt import ui
14
15
from ankiqt.ui.utils import mungeQA, getBase
52
53
        "Idempotently display the current state (prompt for question, etc)"
53
54
        if self.state == "noDeck" or self.state == "studyScreen":
54
55
            return
55
 
        self.clearWindow()
 
56
        self.buffer = ""
56
57
        self.haveTop = (self.main.lastCard and (
57
58
            self.main.config['showLastCardContent'] or
58
59
            self.main.config['showLastCardInterval'])) or (
86
87
        s = "<style>\n"
87
88
        if self.main.deck:
88
89
            s += self.main.deck.css
89
 
        s += "div { white-space: pre-wrap; }"
 
90
        s += "div { white-space: pre-wrap; }\n"
 
91
        s = runFilter("addStyles", s, self.main.currentCard)
90
92
        s += "</style>"
91
93
        return s
92
94
 
107
109
        # hook for user css
108
110
        runHook("preFlushHook")
109
111
        self.buffer = '''<html><head>%s</head><body>%s</body></html>''' % (
110
 
            getBase(self.main.deck), self.buffer)
 
112
            getBase(self.main.deck, self.main.currentCard), self.buffer)
111
113
        #print self.buffer.encode("utf-8")
112
114
        self.body.setHtml(self.buffer)
113
115
 
134
136
        q = self.main.currentCard.htmlQuestion()
135
137
        if self.haveTop:
136
138
            height = 35
 
139
        elif self.main.currentCard.cardModel.questionInAnswer:
 
140
            height = 40
137
141
        else:
138
142
            height = 45
 
143
        q = runFilter("drawQuestion", q, self.main.currentCard)
139
144
        self.write(self.center(self.mungeQA(self.main.deck, q), height))
140
145
        if self.state != self.oldState and not nosound:
141
146
            playFromText(q)
148
153
        s = difflib.SequenceMatcher(None, b, a)
149
154
 
150
155
        sz = self.main.currentCard.cardModel.answerFontSize
151
 
        ok = "background: %s; color: #000; font-size: %dpx" % (
152
 
            passedCharColour, sz)
153
 
        bad = "background: %s; color: #000; font-size: %dpx;" % (
154
 
            failedCharColour, sz)
 
156
        fn = self.main.currentCard.cardModel.answerFontFamily
 
157
        st = "background: %s; color: #000; font-size: %dpx; font-family: %s;"
 
158
        ok = st % (passedCharColour, sz, fn)
 
159
        bad = st % (failedCharColour, sz, fn)
155
160
 
156
161
        for tag, i1, i2, j1, j2 in s.get_opcodes():
157
162
            if tag == "equal":
168
173
    def drawAnswer(self):
169
174
        "Show the answer."
170
175
        a = self.main.currentCard.htmlAnswer()
 
176
        a = runFilter("drawAnswer", a, self.main.currentCard)
171
177
        if self.main.currentCard.cardModel.typeAnswer:
172
178
            try:
173
 
                cor = stripHTML(self.main.currentCard.fact[
174
 
                    self.main.currentCard.cardModel.typeAnswer])
 
179
                cor = stripMedia(stripHTML(self.main.currentCard.fact[
 
180
                    self.main.currentCard.cardModel.typeAnswer]))
175
181
            except KeyError:
 
182
                self.main.currentCard.cardModel.typeAnswer = ""
176
183
                cor = ""
177
184
            if cor:
178
185
                given = unicode(self.main.typeAnswerField.text())
190
197
            txt = txt.replace("</span>", "&#8203;</span>")
191
198
        return txt
192
199
 
193
 
    def onLoadFinished(self):
 
200
    def onLoadFinished(self, bool):
194
201
        if self.state == "showAnswer":
195
202
            if self.main.config['scrollToAnswer']:
196
203
                mf = self.body.page().mainFrame()
220
227
            return
221
228
        self.write("<span style='color: %s'>" % futureWarningColour +
222
229
                   _("This card was due in %s.") % fmtTimeSpan(
223
 
            self.main.currentCard.due - time.time()) +
 
230
            self.main.currentCard.due - time.time(), after=True) +
224
231
                   "</span>")
225
232
 
226
233
    def drawLastCard(self):
273
280
<table>
274
281
 
275
282
<tr>
276
 
<td>
277
 
<a href="welcome:open"><img src=":/icons/document-open.png"></a>
278
 
</td>
279
 
<td valign=middle><h2><a href="welcome:open">%(local)s</a></h2></td>
280
 
</tr>
281
 
 
282
 
<tr>
283
283
<td width=50>
284
 
<a href="welcome:sample"><img src=":/icons/anki.png"></a>
285
 
</td>
286
 
<td valign=middle><h2><a href="welcome:sample">%(dl_shared)s</a></h2></td>
287
 
</tr>
288
 
 
289
 
<tr>
290
 
<td>
291
 
<a href="welcome:openrem"><img src=":/icons/document-open-remote.png"></a>
292
 
</td>
293
 
<td valign=middle><h2><a href="welcome:openrem">%(dl_personal)s</a></h2></td>
 
284
<a href="welcome:back"><img src=":/icons/go-previous.png"></a>
 
285
</td>
 
286
<td valign=middle><h2><a href="welcome:back">%(back)s</a></h2></td>
294
287
</tr>
295
288
 
296
289
</table>""" % \
297
290
        {"welcome":_("Welcome to Anki!"),
298
 
         "add":_("Add material"),
 
291
         "add":_("Add Material"),
299
292
         "start":_("Start adding your own material."),
300
 
         "local":_("Open Local Deck"),
301
 
         "dl_shared":_("Download Shared Deck"),
302
 
         "dl_personal":_("Download Personal Deck")})
 
293
         "back":_("Back to Deck Browser"),
 
294
         })
303
295
 
304
296
    def drawDeckFinishedMessage(self):
305
297
        "Tell the user the deck is finished."