mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 06:52:21 -04:00
fix images in preview, typo in hook code
This commit is contained in:
parent
fde70d80ce
commit
94dddb6531
3 changed files with 19 additions and 16 deletions
|
@ -12,7 +12,7 @@ from ankiqt.ui.sound import getAudio
|
||||||
import anki.sound
|
import anki.sound
|
||||||
from ankiqt import ui
|
from ankiqt import ui
|
||||||
import ankiqt
|
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 anki.hooks import addHook, removeHook, runHook
|
||||||
from sqlalchemy.exceptions import InvalidRequestError
|
from sqlalchemy.exceptions import InvalidRequestError
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ class FactEditor(object):
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
removeHook("deckClosed", self.deckClosedHook)
|
removeHook("deckClosed", self.deckClosedHook)
|
||||||
addHook("colourChanged", self.colourChanged)
|
removeHook("guiReset", self.refresh)
|
||||||
removeHook("colourChanged", self.colourChanged)
|
removeHook("colourChanged", self.colourChanged)
|
||||||
|
|
||||||
def setFact(self, fact, noFocus=False, check=False, scroll=False):
|
def setFact(self, fact, noFocus=False, check=False, scroll=False):
|
||||||
|
@ -1075,12 +1075,13 @@ class PreviewDialog(QDialog):
|
||||||
def updateCard(self):
|
def updateCard(self):
|
||||||
c = self.cards[self.currentCard]
|
c = self.cards[self.currentCard]
|
||||||
self.dialog.webView.setHtml(
|
self.dialog.webView.setHtml(
|
||||||
|
('<html><head>%s</head><body>' % getBase(self.deck)) +
|
||||||
"<style>" + self.deck.css +
|
"<style>" + self.deck.css +
|
||||||
("\nhtml { background: %s }" % c.cardModel.lastFontColour) +
|
("\nhtml { background: %s }" % c.cardModel.lastFontColour) +
|
||||||
"\ndiv { white-space: pre-wrap; }</style>" +
|
"\ndiv { white-space: pre-wrap; }</style>" +
|
||||||
mungeQA(self.deck, c.htmlQuestion()) +
|
mungeQA(self.deck, c.htmlQuestion()) +
|
||||||
"<br><br><hr><br><br>" +
|
"<br><br><hr><br><br>" +
|
||||||
mungeQA(self.deck, c.htmlAnswer()))
|
mungeQA(self.deck, c.htmlAnswer()) + "</body></html>")
|
||||||
playFromText(c.question)
|
playFromText(c.question)
|
||||||
playFromText(c.answer)
|
playFromText(c.answer)
|
||||||
|
|
||||||
|
|
|
@ -189,6 +189,19 @@ def mungeQA(deck, txt):
|
||||||
txt = stripSounds(txt)
|
txt = stripSounds(txt)
|
||||||
return 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):
|
class ProgressWin(object):
|
||||||
|
|
||||||
def __init__(self, parent, max=0, min=0, title=None):
|
def __init__(self, parent, max=0, min=0, title=None):
|
||||||
|
|
|
@ -11,7 +11,7 @@ from anki.utils import stripHTML
|
||||||
from anki.hooks import runHook
|
from anki.hooks import runHook
|
||||||
import types, time, re, os, urllib, sys, difflib
|
import types, time, re, os, urllib, sys, difflib
|
||||||
from ankiqt import ui
|
from ankiqt import ui
|
||||||
from ankiqt.ui.utils import mungeQA
|
from ankiqt.ui.utils import mungeQA, getBase
|
||||||
from anki.utils import fmtTimeSpan
|
from anki.utils import fmtTimeSpan
|
||||||
from PyQt4.QtWebKit import QWebPage, QWebView
|
from PyQt4.QtWebKit import QWebPage, QWebView
|
||||||
|
|
||||||
|
@ -106,19 +106,8 @@ class View(object):
|
||||||
self.buffer = self.addStyles() + self.buffer
|
self.buffer = self.addStyles() + self.buffer
|
||||||
# hook for user css
|
# hook for user css
|
||||||
runHook("preFlushHook")
|
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>''' % (
|
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")
|
#print self.buffer.encode("utf-8")
|
||||||
self.body.setHtml(self.buffer)
|
self.body.setHtml(self.buffer)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue