fix images in preview, typo in hook code

This commit is contained in:
Damien Elmes 2009-04-28 17:56:01 +09:00
parent fde70d80ce
commit 94dddb6531
3 changed files with 19 additions and 16 deletions

View file

@ -12,7 +12,7 @@ from ankiqt.ui.sound import getAudio
import anki.sound
from ankiqt import ui
import ankiqt
from ankiqt.ui.utils import mungeQA, saveGeom, restoreGeom
from ankiqt.ui.utils import mungeQA, saveGeom, restoreGeom, getBase
from anki.hooks import addHook, removeHook, runHook
from sqlalchemy.exceptions import InvalidRequestError
@ -44,7 +44,7 @@ class FactEditor(object):
def close(self):
removeHook("deckClosed", self.deckClosedHook)
addHook("colourChanged", self.colourChanged)
removeHook("guiReset", self.refresh)
removeHook("colourChanged", self.colourChanged)
def setFact(self, fact, noFocus=False, check=False, scroll=False):
@ -1075,12 +1075,13 @@ class PreviewDialog(QDialog):
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()))
mungeQA(self.deck, c.htmlAnswer()) + "</body></html>")
playFromText(c.question)
playFromText(c.answer)

View file

@ -189,6 +189,19 @@ def mungeQA(deck, txt):
txt = stripSounds(txt)
return txt
def getBase(deck):
if deck and deck.mediaDir():
if sys.platform.startswith("win32"):
prefix = u"file:///"
else:
prefix = u"file://"
base = prefix + unicode(
urllib.quote(deck.mediaDir().encode("utf-8")),
"utf-8")
return '<base href="%s/">' % base
else:
return ""
class ProgressWin(object):
def __init__(self, parent, max=0, min=0, title=None):

View file

@ -11,7 +11,7 @@ from anki.utils import stripHTML
from anki.hooks import runHook
import types, time, re, os, urllib, sys, difflib
from ankiqt import ui
from ankiqt.ui.utils import mungeQA
from ankiqt.ui.utils import mungeQA, getBase
from anki.utils import fmtTimeSpan
from PyQt4.QtWebKit import QWebPage, QWebView
@ -106,19 +106,8 @@ class View(object):
self.buffer = self.addStyles() + self.buffer
# hook for user css
runHook("preFlushHook")
if self.main.deck and self.main.deck.mediaDir():
if sys.platform.startswith("win32"):
prefix = u"file:///"
else:
prefix = u"file://"
base = prefix + unicode(
urllib.quote(self.main.deck.mediaDir().encode("utf-8")),
"utf-8")
base = '<base href="%s/">' % base
else:
base = ""
self.buffer = '''<html><head>%s</head><body>%s</body></html>''' % (
base, self.buffer)
getBase(self.main.deck), self.buffer)
#print self.buffer.encode("utf-8")
self.body.setHtml(self.buffer)