From 3dfa077e08d4687703803ccdf03cbf5a6e4214f7 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 7 May 2016 20:24:59 -0700 Subject: [PATCH] Cleanup, remove maxResults --- ui/preferences.ui | 25 ++++--------------------- yomi_base/defaults.json | 13 ++++++------- yomi_base/japanese/dictionary.py | 17 ++++++++--------- yomi_base/japanese/translate.py | 22 +++++++++++----------- yomi_base/preference_data.py | 4 ++-- yomi_base/preferences.py | 2 -- yomi_base/reader.py | 14 ++++++-------- 7 files changed, 37 insertions(+), 60 deletions(-) diff --git a/ui/preferences.ui b/ui/preferences.ui index bb61f98..a19cc28 100644 --- a/ui/preferences.ui +++ b/ui/preferences.ui @@ -54,34 +54,17 @@ + + QFormLayout::AllNonFixedFieldsGrow + - - - Max search results - - - - - - - - 0 - 0 - - - - 1 - - - - Text scan length - + diff --git a/yomi_base/defaults.json b/yomi_base/defaults.json index a716fe1..a685d07 100644 --- a/yomi_base/defaults.json +++ b/yomi_base/defaults.json @@ -1,20 +1,19 @@ { + "allowEditing": false, "bgColor": 4294967295, "checkForUpdates": true, + "enableAnkiConnect": false, "fgColor": 4278190080, + "firstRun": true, "fontFamily": "Arial", "fontSize": 12, - "rememberTextContent": false, "loadRecentFile": false, - "maxResults": 20, "profiles": {}, "recentFiles": [], - "textContent": "", + "rememberTextContent": false, "scanLength": 16, "stripReadings": false, "tags": [], - "wordWrap": false, - "allowEditing": true, - "enableAnkiConnect": false, - "firstRun": true + "textContent": "", + "wordWrap": false } diff --git a/yomi_base/japanese/dictionary.py b/yomi_base/japanese/dictionary.py index d7a9966..df7c8c0 100644 --- a/yomi_base/japanese/dictionary.py +++ b/yomi_base/japanese/dictionary.py @@ -16,7 +16,6 @@ # along with this program. If not, see . -import operator import sqlite3 @@ -31,15 +30,15 @@ class Dictionary: self.requireIndex('Terms', 'reading') cursor = self.db.cursor() - cursor.execute('SELECT * FROM Terms WHERE expression {0} ? OR reading=? LIMIT 100'.format('LIKE' if wildcards else '='), (word, word)) + cursor.execute('SELECT * FROM Terms WHERE expression {0} ? OR reading=?'.format('LIKE' if wildcards else '='), (word, word)) - results = list() + results = [] for expression, reading, glossary, tags in cursor.fetchall(): results.append({ 'expression': expression, - 'reading': reading, - 'glossary': glossary, - 'tags': tags.split() + 'glossary': glossary, + 'reading': reading, + 'tags': tags.split() }) return results @@ -57,9 +56,9 @@ class Dictionary: character, kunyomi, onyomi, glossary = query return { 'character': character, - 'kunyomi': kunyomi, - 'onyomi': onyomi, - 'glossary': glossary + 'glossary': glossary, + 'kunyomi': kunyomi, + 'onyomi': onyomi } diff --git a/yomi_base/japanese/translate.py b/yomi_base/japanese/translate.py index 202706d..9348195 100644 --- a/yomi_base/japanese/translate.py +++ b/yomi_base/japanese/translate.py @@ -24,13 +24,13 @@ import util class Translator: def __init__(self, deinflector, dictionary): self.deinflector = deinflector - self.dictionary = dictionary + self.dictionary = dictionary def findTerm(self, text, wildcards=False): - text = util.sanitize(text, wildcards=wildcards) + text = util.sanitize(text, wildcards=wildcards) + groups = {} - groups = dict() for i in xrange(len(text), 0, -1): term = text[:i] deinflections = self.deinflector.deinflect(term, self.validator) @@ -52,10 +52,10 @@ class Translator: def findCharacters(self, text): - text = util.sanitize(text, kana=False) - results = list() + text = util.sanitize(text, kana=False) + processed = {} + results = [] - processed = dict() for c in text: if c not in processed: match = self.dictionary.findCharacter(c) @@ -79,11 +79,11 @@ class Translator: (expression, reading, glossary), (tags, source, rules) = group return { 'expression': expression, - 'reading': reading, - 'glossary': glossary, - 'rules': rules, - 'source': source, - 'tags': tags + 'glossary': glossary, + 'reading': reading, + 'rules': rules, + 'source': source, + 'tags': tags } diff --git a/yomi_base/preference_data.py b/yomi_base/preference_data.py index edeef79..59737a3 100644 --- a/yomi_base/preference_data.py +++ b/yomi_base/preference_data.py @@ -26,7 +26,7 @@ class Preferences(object): def __init__(self): self.filename = os.path.expanduser('~/.yomichan.json') self.defaults = os.path.join(os.path.dirname(__file__), 'defaults.json') - self.settings = dict() + self.settings = {} def __getitem__(self, name): @@ -75,4 +75,4 @@ class Preferences(object): def clearRecentFiles(self): - self['recentFiles'] = list() + self['recentFiles'] = [] diff --git a/yomi_base/preferences.py b/yomi_base/preferences.py index 8779410..f749567 100644 --- a/yomi_base/preferences.py +++ b/yomi_base/preferences.py @@ -49,7 +49,6 @@ class DialogPreferences(QtGui.QDialog, gen.preferences_ui.Ui_DialogPreferences): self.checkAllowEditing.setChecked(self.preferences['allowEditing']) self.checkLoadRecentFile.setChecked(self.preferences['loadRecentFile']) self.checkStripReadings.setChecked(self.preferences['stripReadings']) - self.spinMaxResults.setValue(self.preferences['maxResults']) self.spinScanLength.setValue(self.preferences['scanLength']) self.checkEnableAnkiConnect.setChecked(self.preferences['enableAnkiConnect']) @@ -69,7 +68,6 @@ class DialogPreferences(QtGui.QDialog, gen.preferences_ui.Ui_DialogPreferences): self.preferences['rememberTextContent'] = self.checkRememberTextContent.isChecked() self.preferences['allowEditing'] = self.checkAllowEditing.isChecked() self.preferences['loadRecentFile'] = self.checkLoadRecentFile.isChecked() - self.preferences['maxResults'] = self.spinMaxResults.value() self.preferences['scanLength'] = self.spinScanLength.value() self.preferences['stripReadings'] = self.checkStripReadings.isChecked() self.preferences['enableAnkiConnect'] = self.checkEnableAnkiConnect.isChecked() diff --git a/yomi_base/reader.py b/yomi_base/reader.py index 522c1d5..24da26c 100644 --- a/yomi_base/reader.py +++ b/yomi_base/reader.py @@ -31,11 +31,11 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader): class State: def __init__(self): self.filename = unicode() + self.searchText = unicode() self.kanjiDefs = [] + self.vocabDefs = [] self.scanPosition = 0 self.searchPosition = 0 - self.searchText = unicode() - self.vocabDefs = [] def __init__(self, parent, preferences, language, filename=None, anki=None, closed=None): @@ -110,7 +110,8 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader): QtGui.QMessageBox.information( self, 'Yomichan', - 'This may be the first time you are running Yomichan.\nPlease take some time to configure this extension.' + 'This may be the first time you are running Yomichan.\n' \ + 'Please take some time to configure this extension.' ) self.onActionPreferences() @@ -557,9 +558,6 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader): def updateDefs(self, defs, builder, control, **options): - if options.get('trim', True): - defs = defs[:self.preferences['maxResults']] - scrollbar = control.verticalScrollBar() position = scrollbar.sliderPosition() @@ -599,8 +597,8 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader): if self.dockKanji.isVisible(): self.state.kanjiDefs += self.language.findCharacters(word) - self.updateVocabDefs(trim=False, scroll=True) - self.updateKanjiDefs(trim=False, scroll=True) + self.updateVocabDefs(scroll=True) + self.updateKanjiDefs(scroll=True) def setStatus(self, status):