Cleanup
This commit is contained in:
parent
47905e7808
commit
09b007d5f0
@ -38,7 +38,7 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
|
||||
self.vocabDefs = []
|
||||
|
||||
|
||||
def __init__(self, parent, preferences, language, filename=None, anki=None, remoteApi=None, closed=None):
|
||||
def __init__(self, parent, preferences, language, filename=None, anki=None, closed=None):
|
||||
QtGui.QMainWindow.__init__(self, parent)
|
||||
self.setupUi(self)
|
||||
|
||||
@ -48,7 +48,6 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
|
||||
|
||||
self.facts = []
|
||||
self.anki = anki
|
||||
self.remoteApi = remoteApi
|
||||
self.closed = closed
|
||||
self.language = language
|
||||
self.preferences = preferences
|
||||
@ -104,9 +103,6 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
|
||||
if self.preferences['windowSize'] is not None:
|
||||
self.resize(QtCore.QSize(*self.preferences['windowSize']))
|
||||
|
||||
if self.remoteApi is not None:
|
||||
self.remoteApi.enable(self.preferences['enableRemoteApi'])
|
||||
|
||||
self.comboTags.addItems(self.preferences['tags'])
|
||||
self.applyPreferencesContent()
|
||||
|
||||
@ -385,7 +381,7 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
|
||||
|
||||
def findText(self, text):
|
||||
content = unicode(self.textContent.toPlainText())
|
||||
index = content.find(unicode(text), self.state.searchPosition)
|
||||
index = content.find(unicode(text), self.state.searchPosition)
|
||||
|
||||
if index == -1:
|
||||
wrap = self.state.searchPosition != 0
|
||||
@ -415,8 +411,8 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
|
||||
if profile is None:
|
||||
return False
|
||||
|
||||
fields = reader_util.formatFields(profile['fields'], markup)
|
||||
tagsSplit = reader_util.splitTags(unicode(self.comboTags.currentText()))
|
||||
fields = reader_util.formatFields(profile['fields'], markup)
|
||||
tagsSplit = reader_util.splitTags(unicode(self.comboTags.currentText()))
|
||||
tagsJoined = ' '.join(tagsSplit)
|
||||
|
||||
tagIndex = self.comboTags.findText(tagsJoined)
|
||||
@ -491,12 +487,13 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
|
||||
|
||||
def updateSampleFromPosition(self):
|
||||
samplePosStart = self.state.scanPosition
|
||||
samplePosEnd = self.state.scanPosition + self.preferences['scanLength']
|
||||
samplePosEnd = self.state.scanPosition + self.preferences['scanLength']
|
||||
|
||||
content = unicode(self.textContent.toPlainText())
|
||||
contentSample = content[samplePosStart:samplePosEnd]
|
||||
contentSampleFlat = contentSample.replace(u'\n', unicode())
|
||||
|
||||
cursor = self.textContent.textCursor()
|
||||
content = unicode(self.textContent.toPlainText())
|
||||
contentSample = content[samplePosStart:samplePosEnd]
|
||||
contentSampleFlat = contentSample.replace(u'\n', unicode())
|
||||
|
||||
if len(contentSampleFlat) == 0 or not japanese.util.isJapanese(contentSampleFlat[0]):
|
||||
cursor.clearSelection()
|
||||
@ -565,7 +562,7 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
|
||||
html = builder(defs, self.ankiIsFactValid)
|
||||
|
||||
scrollbar = control.verticalScrollBar()
|
||||
position = scrollbar.sliderPosition()
|
||||
position = scrollbar.sliderPosition()
|
||||
control.setHtml(html)
|
||||
|
||||
if options.get('scroll', False):
|
||||
|
@ -105,10 +105,10 @@ def markupVocabExp(definition):
|
||||
|
||||
return {
|
||||
'expression': definition['expression'],
|
||||
'reading': definition['reading'] or unicode(),
|
||||
'glossary': definition['glossary'],
|
||||
'sentence': definition.get('sentence'),
|
||||
'summary': summary
|
||||
'reading': definition['reading'] or unicode(),
|
||||
'glossary': definition['glossary'],
|
||||
'sentence': definition.get('sentence'),
|
||||
'summary': summary
|
||||
}
|
||||
|
||||
|
||||
@ -116,10 +116,10 @@ def markupVocabReading(definition):
|
||||
if definition['reading']:
|
||||
return {
|
||||
'expression': definition['reading'],
|
||||
'reading': unicode(),
|
||||
'glossary': definition['glossary'],
|
||||
'sentence': definition.get('sentence'),
|
||||
'summary': definition['reading']
|
||||
'reading': unicode(),
|
||||
'glossary': definition['glossary'],
|
||||
'sentence': definition.get('sentence'),
|
||||
'summary': definition['reading']
|
||||
}
|
||||
|
||||
|
||||
@ -135,10 +135,10 @@ def copyVocabDef(definition):
|
||||
def markupKanji(definition):
|
||||
return {
|
||||
'character': definition['character'],
|
||||
'onyomi': definition['onyomi'],
|
||||
'kunyomi': definition['kunyomi'],
|
||||
'glossary': definition['glossary'],
|
||||
'summary': definition['character']
|
||||
'onyomi': definition['onyomi'],
|
||||
'kunyomi': definition['kunyomi'],
|
||||
'glossary': definition['glossary'],
|
||||
'summary': definition['character']
|
||||
}
|
||||
|
||||
|
||||
@ -147,7 +147,7 @@ def copyKanjiDef(definition):
|
||||
|
||||
|
||||
def buildDefHeader():
|
||||
palette = QtGui.QApplication.palette()
|
||||
palette = QtGui.QApplication.palette()
|
||||
toolTipBg = palette.color(QtGui.QPalette.Window).name()
|
||||
toolTipFg = palette.color(QtGui.QPalette.WindowText).name()
|
||||
|
||||
|
@ -38,10 +38,10 @@ class RemoteApi:
|
||||
'getVersion': self.apiGetVersion,
|
||||
}
|
||||
|
||||
self.enable(self.preferences['enableRemoteApi'])
|
||||
|
||||
def advance(self):
|
||||
enabled = self.preferences['enableRemoteApi']
|
||||
|
||||
def enable(self, enabled=True):
|
||||
if self.server is None and enabled:
|
||||
self.server = AjaxServer(self.handler)
|
||||
self.server.listen()
|
||||
@ -49,8 +49,6 @@ class RemoteApi:
|
||||
self.server.close()
|
||||
self.server = None
|
||||
|
||||
|
||||
def advance(self):
|
||||
if self.server is not None:
|
||||
self.server.advance()
|
||||
|
||||
|
@ -65,7 +65,6 @@ class YomichanPlugin(Yomichan):
|
||||
self.language,
|
||||
None,
|
||||
self.anki,
|
||||
self.remoteApi,
|
||||
self.onWindowClose
|
||||
)
|
||||
self.window.show()
|
||||
|
Loading…
Reference in New Issue
Block a user