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