1

Cleanup, remove maxResults

This commit is contained in:
Alex Yatskov 2016-05-07 20:24:59 -07:00
parent 2e8734dd79
commit 3dfa077e08
7 changed files with 37 additions and 60 deletions

View File

@ -54,34 +54,17 @@
</item> </item>
<item> <item>
<layout class="QFormLayout" name="formLayout"> <layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Max search results</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="spinMaxResults">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimum">
<number>1</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_14"> <widget class="QLabel" name="label_14">
<property name="text"> <property name="text">
<string>Text scan length</string> <string>Text scan length</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="0" column="1">
<widget class="QSpinBox" name="spinScanLength"> <widget class="QSpinBox" name="spinScanLength">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> <sizepolicy hsizetype="Fixed" vsizetype="Fixed">

View File

@ -1,20 +1,19 @@
{ {
"allowEditing": false,
"bgColor": 4294967295, "bgColor": 4294967295,
"checkForUpdates": true, "checkForUpdates": true,
"enableAnkiConnect": false,
"fgColor": 4278190080, "fgColor": 4278190080,
"firstRun": true,
"fontFamily": "Arial", "fontFamily": "Arial",
"fontSize": 12, "fontSize": 12,
"rememberTextContent": false,
"loadRecentFile": false, "loadRecentFile": false,
"maxResults": 20,
"profiles": {}, "profiles": {},
"recentFiles": [], "recentFiles": [],
"textContent": "", "rememberTextContent": false,
"scanLength": 16, "scanLength": 16,
"stripReadings": false, "stripReadings": false,
"tags": [], "tags": [],
"wordWrap": false, "textContent": "",
"allowEditing": true, "wordWrap": false
"enableAnkiConnect": false,
"firstRun": true
} }

View File

@ -16,7 +16,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import operator
import sqlite3 import sqlite3
@ -31,15 +30,15 @@ class Dictionary:
self.requireIndex('Terms', 'reading') self.requireIndex('Terms', 'reading')
cursor = self.db.cursor() 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(): for expression, reading, glossary, tags in cursor.fetchall():
results.append({ results.append({
'expression': expression, 'expression': expression,
'reading': reading, 'glossary': glossary,
'glossary': glossary, 'reading': reading,
'tags': tags.split() 'tags': tags.split()
}) })
return results return results
@ -57,9 +56,9 @@ class Dictionary:
character, kunyomi, onyomi, glossary = query character, kunyomi, onyomi, glossary = query
return { return {
'character': character, 'character': character,
'kunyomi': kunyomi, 'glossary': glossary,
'onyomi': onyomi, 'kunyomi': kunyomi,
'glossary': glossary 'onyomi': onyomi
} }

View File

@ -24,13 +24,13 @@ import util
class Translator: class Translator:
def __init__(self, deinflector, dictionary): def __init__(self, deinflector, dictionary):
self.deinflector = deinflector self.deinflector = deinflector
self.dictionary = dictionary self.dictionary = dictionary
def findTerm(self, text, wildcards=False): 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): for i in xrange(len(text), 0, -1):
term = text[:i] term = text[:i]
deinflections = self.deinflector.deinflect(term, self.validator) deinflections = self.deinflector.deinflect(term, self.validator)
@ -52,10 +52,10 @@ class Translator:
def findCharacters(self, text): def findCharacters(self, text):
text = util.sanitize(text, kana=False) text = util.sanitize(text, kana=False)
results = list() processed = {}
results = []
processed = dict()
for c in text: for c in text:
if c not in processed: if c not in processed:
match = self.dictionary.findCharacter(c) match = self.dictionary.findCharacter(c)
@ -79,11 +79,11 @@ class Translator:
(expression, reading, glossary), (tags, source, rules) = group (expression, reading, glossary), (tags, source, rules) = group
return { return {
'expression': expression, 'expression': expression,
'reading': reading, 'glossary': glossary,
'glossary': glossary, 'reading': reading,
'rules': rules, 'rules': rules,
'source': source, 'source': source,
'tags': tags 'tags': tags
} }

View File

@ -26,7 +26,7 @@ class Preferences(object):
def __init__(self): def __init__(self):
self.filename = os.path.expanduser('~/.yomichan.json') self.filename = os.path.expanduser('~/.yomichan.json')
self.defaults = os.path.join(os.path.dirname(__file__), 'defaults.json') self.defaults = os.path.join(os.path.dirname(__file__), 'defaults.json')
self.settings = dict() self.settings = {}
def __getitem__(self, name): def __getitem__(self, name):
@ -75,4 +75,4 @@ class Preferences(object):
def clearRecentFiles(self): def clearRecentFiles(self):
self['recentFiles'] = list() self['recentFiles'] = []

View File

@ -49,7 +49,6 @@ class DialogPreferences(QtGui.QDialog, gen.preferences_ui.Ui_DialogPreferences):
self.checkAllowEditing.setChecked(self.preferences['allowEditing']) self.checkAllowEditing.setChecked(self.preferences['allowEditing'])
self.checkLoadRecentFile.setChecked(self.preferences['loadRecentFile']) self.checkLoadRecentFile.setChecked(self.preferences['loadRecentFile'])
self.checkStripReadings.setChecked(self.preferences['stripReadings']) self.checkStripReadings.setChecked(self.preferences['stripReadings'])
self.spinMaxResults.setValue(self.preferences['maxResults'])
self.spinScanLength.setValue(self.preferences['scanLength']) self.spinScanLength.setValue(self.preferences['scanLength'])
self.checkEnableAnkiConnect.setChecked(self.preferences['enableAnkiConnect']) 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['rememberTextContent'] = self.checkRememberTextContent.isChecked()
self.preferences['allowEditing'] = self.checkAllowEditing.isChecked() self.preferences['allowEditing'] = self.checkAllowEditing.isChecked()
self.preferences['loadRecentFile'] = self.checkLoadRecentFile.isChecked() self.preferences['loadRecentFile'] = self.checkLoadRecentFile.isChecked()
self.preferences['maxResults'] = self.spinMaxResults.value()
self.preferences['scanLength'] = self.spinScanLength.value() self.preferences['scanLength'] = self.spinScanLength.value()
self.preferences['stripReadings'] = self.checkStripReadings.isChecked() self.preferences['stripReadings'] = self.checkStripReadings.isChecked()
self.preferences['enableAnkiConnect'] = self.checkEnableAnkiConnect.isChecked() self.preferences['enableAnkiConnect'] = self.checkEnableAnkiConnect.isChecked()

View File

@ -31,11 +31,11 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
class State: class State:
def __init__(self): def __init__(self):
self.filename = unicode() self.filename = unicode()
self.searchText = unicode()
self.kanjiDefs = [] self.kanjiDefs = []
self.vocabDefs = []
self.scanPosition = 0 self.scanPosition = 0
self.searchPosition = 0 self.searchPosition = 0
self.searchText = unicode()
self.vocabDefs = []
def __init__(self, parent, preferences, language, filename=None, anki=None, closed=None): 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( QtGui.QMessageBox.information(
self, self,
'Yomichan', '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() self.onActionPreferences()
@ -557,9 +558,6 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
def updateDefs(self, defs, builder, control, **options): def updateDefs(self, defs, builder, control, **options):
if options.get('trim', True):
defs = defs[:self.preferences['maxResults']]
scrollbar = control.verticalScrollBar() scrollbar = control.verticalScrollBar()
position = scrollbar.sliderPosition() position = scrollbar.sliderPosition()
@ -599,8 +597,8 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
if self.dockKanji.isVisible(): if self.dockKanji.isVisible():
self.state.kanjiDefs += self.language.findCharacters(word) self.state.kanjiDefs += self.language.findCharacters(word)
self.updateVocabDefs(trim=False, scroll=True) self.updateVocabDefs(scroll=True)
self.updateKanjiDefs(trim=False, scroll=True) self.updateKanjiDefs(scroll=True)
def setStatus(self, status): def setStatus(self, status):