本文整理汇总了Python中aqt.webview.AnkiWebView.setObjectName方法的典型用法代码示例。如果您正苦于以下问题:Python AnkiWebView.setObjectName方法的具体用法?Python AnkiWebView.setObjectName怎么用?Python AnkiWebView.setObjectName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aqt.webview.AnkiWebView
的用法示例。
在下文中一共展示了AnkiWebView.setObjectName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: VocabularyProfile
# 需要导入模块: from aqt.webview import AnkiWebView [as 别名]
# 或者: from aqt.webview.AnkiWebView import setObjectName [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
#.........这里部分代码省略.........
示例2: KanjiProfile
# 需要导入模块: from aqt.webview import AnkiWebView [as 别名]
# 或者: from aqt.webview.AnkiWebView import setObjectName [as 别名]
class KanjiProfile(GenericProfile):
name = "kanji"
descriptor = "KANJI IN THIS TEXT"
displayedName = "Kanji"
languages = ["japanese"]
sortIndex = 2
allowedTags = ['character', 'onyomi', 'kunyomi', 'glossary','ongroup','words']
def __init__(self,reader):
GenericProfile.__init__(self,reader)
self.dockKanji = QtGui.QDockWidget(reader)
self.dockKanji.setObjectName(fromUtf8("dockKanji"))
self.dockWidgetContents = QtGui.QWidget()
self.dockWidgetContents.setObjectName(fromUtf8("dockWidgetContents"))
self.verticalLayout = QtGui.QVBoxLayout(self.dockWidgetContents)
self.verticalLayout.setObjectName(fromUtf8("verticalLayout"))
self.textField = AnkiWebView()
self.textField.setAcceptDrops(False)
self.textField.setObjectName("textField")
self.verticalLayout.addWidget(self.textField)
self.horizontalLayout_3 = QtGui.QHBoxLayout()
self.horizontalLayout_3.setObjectName(fromUtf8("horizontalLayout_3"))
self.verticalLayout.addLayout(self.horizontalLayout_3)
self.dockKanji.setWidget(self.dockWidgetContents)
reader.addDockWidget(QtCore.Qt.DockWidgetArea(2), self.dockKanji)
self.dockKanji.visibilityChanged.connect(self.onVisibilityChanged)
self.dockKanji.setWindowTitle(translate("MainWindowReader", "Kanji", None))
self.textField.setLinkHandler(self.onAnchorClicked)
# menu entries to toggle visibility of the Kanji dock
self.actionToggleKanji = QtGui.QAction(reader)
self.actionToggleKanji.setCheckable(True)
self.actionToggleKanji.setObjectName("actionToggleKanji")
self.actionToggleKanji.setText("&Kanji")
self.actionToggleKanji.setToolTip("Toggle Kanji")
reader.menuView.insertAction(reader.menuView.actions()[2],self.actionToggleKanji)
QtCore.QObject.connect(self.actionToggleKanji, QtCore.SIGNAL("toggled(bool)"), self.dockKanji.setVisible)
def onVisibilityChanged(self,visible):
self.actionToggleKanji.setChecked(self.dockKanji.isVisible())
def onAnchorClicked(self, url):
command, index = url.split(':')
if command == "jisho":
self.reader.profiles["vocabulary"].onQuery([index])
#url = QtCore.QUrl(self.reader.preferences["linkToKanji"].format(index))
#QtGui.QDesktopServices().openUrl(url)
else:
index = int(index)
commands = command.split("_")
profile = commands.pop(0)
self.runCommand(commands,self.definitions[index])
def onLookup(self,d,lengthMatched):
if self.dockKanji.isVisible():
if 'japanese' in self.reader.languages:
if lengthMatched == 0:
self.definitions = self.reader.languages['japanese'].findCharacters(d['contentSample'][0])
if len(self.definitions) > 0:
lengthMatched = 1
else:
self.definitions = self.reader.languages['japanese'].findCharacters(d['contentSample'][:lengthMatched])
self.updateDefinitions()
self.reader.updateVocabDefs('kanji')
return lengthMatched
def onShowDialogPreferences(self,dialog):
GenericProfile.onShowDialogPreferences(self,dialog)
def runCommand(self,cmd,definition):
if cmd[0] == "copy":
QtGui.QApplication.clipboard().setText(u'{character}\t{kunyomi}\t{onyomi}\t{glossary}'.format(**definition))
elif cmd[0] =="add":
self.addFact(definition)
elif cmd[0] == "addgroup":
kanjigroups = os.path.join(self.reader.anki.collection().media.dir(),"Yomichan","KanjiGroups")
if os.path.exists(kanjigroups):
filename = os.path.join(kanjigroups,definition['ongroup']+".txt")
with open(filename,'w') as fp:
content = u"""### REGEXP ###
.*[{0}]###v###
### SHUFFLE THIS TEXT ###""".format(definition['ongroup'])
fp.write(content.encode('utf-8'))
fp.close()
d = dict()
d['contentSample'] = definition['ongroup']
self.onLookup(d,len(d['contentSample']))
self.reader.profiles["vocabulary"].onQuery(list(definition['ongroup']))
def markup(self, definition):
allCards = self.reader.plugin.fetchAllCards()
words = u",".join([x for x in allCards["vocabulary"].keys() if definition['character'] in x])
return {
'character': definition['character'],
'onyomi': definition['onyomi'],
'kunyomi': definition['kunyomi'],
'glossary': definition['glossary'],
#.........这里部分代码省略.........