From 09b007d5f07f8b3bb81ed6ac1e754838d65aa6bd Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 1 May 2016 20:43:09 -0700 Subject: [PATCH] Cleanup --- yomi_base/reader.py | 23 ++++++++++------------- yomi_base/reader_util.py | 26 +++++++++++++------------- yomi_base/remote_api.py | 6 ++---- yomichan.py | 1 - 4 files changed, 25 insertions(+), 31 deletions(-) diff --git a/yomi_base/reader.py b/yomi_base/reader.py index 0d9af34..48e513b 100644 --- a/yomi_base/reader.py +++ b/yomi_base/reader.py @@ -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): diff --git a/yomi_base/reader_util.py b/yomi_base/reader_util.py index 014263f..f5a6700 100644 --- a/yomi_base/reader_util.py +++ b/yomi_base/reader_util.py @@ -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() diff --git a/yomi_base/remote_api.py b/yomi_base/remote_api.py index d5a20e2..3718000 100644 --- a/yomi_base/remote_api.py +++ b/yomi_base/remote_api.py @@ -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() diff --git a/yomichan.py b/yomichan.py index bd43734..bfbb46a 100755 --- a/yomichan.py +++ b/yomichan.py @@ -65,7 +65,6 @@ class YomichanPlugin(Yomichan): self.language, None, self.anki, - self.remoteApi, self.onWindowClose ) self.window.show()