本文整理汇总了Python中aqt.webview.AnkiWebView.setHtml方法的典型用法代码示例。如果您正苦于以下问题:Python AnkiWebView.setHtml方法的具体用法?Python AnkiWebView.setHtml怎么用?Python AnkiWebView.setHtml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aqt.webview.AnkiWebView
的用法示例。
在下文中一共展示了AnkiWebView.setHtml方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CardStats
# 需要导入模块: from aqt.webview import AnkiWebView [as 别名]
# 或者: from aqt.webview.AnkiWebView import setHtml [as 别名]
class CardStats(object):
def __init__(self, mw):
self.mw = mw
self.shown = False
addHook("showQuestion", self._update)
addHook("deckClosing", self.hide)
addHook("reviewCleanup", self.hide)
def show(self):
if not self.shown:
self.web = AnkiWebView(self.mw)
self.web.setMaximumWidth(400)
self.shown = self.mw.addDockable(_("Card Info"), self.web)
self.shown.connect(self.shown, SIGNAL("visibilityChanged(bool)"),
self._visChange)
self._update()
def hide(self):
if self.shown:
self.mw.rmDockable(self.shown)
self.shown = None
def _visChange(self, vis):
if not vis:
# schedule removal for after evt has finished
self.mw.progress.timer(100, self.hide, False)
def _update(self):
if not self.shown:
return
txt = ""
r = self.mw.reviewer
d = self.mw.deck
if r.card:
txt += _("<h1>Current</h1>")
txt += d.cardStats(r.card)
lc = r.lastCard()
if lc:
txt += _("<h1>Last</h1>")
txt += d.cardStats(lc)
if not txt:
txt = _("No current card or last card.")
self.web.setHtml("""
<html><head>
<style>table { font-size: 12px; } h1 { font-size: 14px; }</style>
</head><body><center>%s</center></body></html>"""%txt)
示例2: VocabularyProfile
# 需要导入模块: from aqt.webview import AnkiWebView [as 别名]
# 或者: from aqt.webview.AnkiWebView import setHtml [as 别名]
class VocabularyProfile(GenericProfile):
name = "vocabulary"
displayedName = "Vocabulary"
descriptor = "VOCABULARY IN THIS TEXT (EXPORT)"
languages = ["japanese","chinese","korean"]
sortIndex = 1
allowedTags = ['expression', 'term', 'source', 'kanji', 'hanja', 'reading', 'glossary', 'sentence','line','filename','summary','traditional','language','goo','defs','refs']
def __init__(self,reader):
GenericProfile.__init__(self,reader)
self.history = []
self.currentIndex = 0
self.dockVocab = QtGui.QDockWidget(reader)
self.dockVocab.setObjectName(fromUtf8("dockVocab"))
self.dockWidgetContents = QtGui.QWidget()
self.dockWidgetContents.setObjectName(fromUtf8("dockWidgetContents"))
self.verticalLayout = QtGui.QVBoxLayout(self.dockWidgetContents)
self.verticalLayout.setObjectName(fromUtf8("verticalLayout"))
self.previousExpression = None
self.textField = AnkiWebView()
self.textField.setAcceptDrops(False)
self.textField.setObjectName("textField")
self.keyFilter = VocabKeyFilter()
self.keyFilter.obj = self
self.keyFilter.textField = self.textField
self.textField.installEventFilter(self.keyFilter)
self.verticalLayout.addWidget(self.textField)
self.dockVocab.setWidget(self.dockWidgetContents)
reader.addDockWidget(QtCore.Qt.DockWidgetArea(2), self.dockVocab)
self.dockVocab.visibilityChanged.connect(self.onVisibilityChanged)
self.dockVocab.setWindowTitle(translate("MainWindowReader", "Vocabulary", None))
self.textField.setLinkHandler(self.onAnchorClicked)
# menu entries to toggle visibility of the vocabulary dock
self.actionToggleVocab = QtGui.QAction(reader)
self.actionToggleVocab.setCheckable(True)
self.actionToggleVocab.setObjectName("actionToggleVocab")
self.actionToggleVocab.setText("&Vocabulary")
self.actionToggleVocab.setToolTip("Toggle vocabulary")
reader.menuView.insertAction(reader.menuView.actions()[2],self.actionToggleVocab)
QtCore.QObject.connect(self.actionToggleVocab, QtCore.SIGNAL("toggled(bool)"), self.dockVocab.setVisible)
self.dockVocab.installEventFilter(self.reader.keyFilter)
def updateSampleFromSelection(self):
d = {
"samplePosStart": 0,
"contentSampleFlat": self.textField.selectedText(),
"content": ""
}
self.onLookup(d,0,sentenceAndLine=False)
def fixHtml(self,html,appendToHistory=True):
if html.find(self.buildEmpty()) == -1 and appendToHistory:
self.history.append((html,list(self.definitions),self.defBody))
back = len(self.history)>1
#self.currentIndex > 0
#forward = self.currentIndex < len(self.history)-1
if back:
backHtml = "<a href='vocabulary_back:0'><<Back</a>" if back else ""
forwardHtml = ""
#"<a href='vocabulary_forward:0'>Forward>></a>" if forward else ""
return u"<div>{1} {2}</div><br>{0}".format(html,backHtml,forwardHtml)
else:
return html
def onVisibilityChanged(self,visible):
self.actionToggleVocab.setChecked(self.dockVocab.isVisible())
def onAnchorClicked(self, url):
command, index = url.split(':')
if command == "jisho":
url = QtCore.QUrl(self.reader.preferences["linkToVocab"].format(index))
QtGui.QDesktopServices().openUrl(url)
elif command == "vocabulary_back":
if len(self.history)>1:
self.history.pop()
html, definitions, body = self.history[-1]
html = self.fixHtml(html,appendToHistory=False)
self.textField.setHtml(html)
self.definitions = definitions
self.defBody = body
elif command == "vocabulary_forward":
self.textField.history().forward()
else:
if not index.startswith("void"):
index = int(index)
commands = command.split("_")
profile = commands.pop(0)
self.runCommand(commands,index)
def onLookup(self,d,lengthMatched,sentenceAndLine=True):
if self.dockVocab.isVisible():
lengthMatched = self.reader.findTerm(d)
if sentenceAndLine:
sentence, sentenceStart = reader_util.findSentence(d['content'], d['samplePosStart'])
line, lineStart = reader_util.findLine(d['content'], d['samplePosStart'])
else:
sentence = line = ""
for definition in self.definitions:
definition['sentence'] = sentence
#.........这里部分代码省略.........