本文整理汇总了Python中aqt.webview.AnkiWebView.installEventFilter方法的典型用法代码示例。如果您正苦于以下问题:Python AnkiWebView.installEventFilter方法的具体用法?Python AnkiWebView.installEventFilter怎么用?Python AnkiWebView.installEventFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aqt.webview.AnkiWebView
的用法示例。
在下文中一共展示了AnkiWebView.installEventFilter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: VocabularyProfile
# 需要导入模块: from aqt.webview import AnkiWebView [as 别名]
# 或者: from aqt.webview.AnkiWebView import installEventFilter [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
#.........这里部分代码省略.........