1

Attempts to make the definition window not jump all over the place when updating

Former-commit-id: c6aa7ecdbc54ae69e75de0c6fd96100a00091c65
This commit is contained in:
Alex Yatskov 2014-12-20 21:15:13 +09:00
parent 3e489b2fbc
commit 26012a5679

View File

@ -412,8 +412,8 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
self.listDefinitions.setCurrentRow(self.listDefinitions.count() - 1) self.listDefinitions.setCurrentRow(self.listDefinitions.count() - 1)
self.setStatus(u'Added fact {0}; {1} new fact(s) total'.format(markup['summary'], len(self.facts))) self.setStatus(u'Added fact {0}; {1} new fact(s) total'.format(markup['summary'], len(self.facts)))
self.updateVocabDefs() self.updateVocabDefs(False)
self.updateKanjiDefs() self.updateKanjiDefs(False)
return True return True
@ -535,23 +535,35 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
self.preferences.updateRecentFile(self.state.filename, self.state.scanPosition) self.preferences.updateRecentFile(self.state.filename, self.state.scanPosition)
def updateVocabDefs(self, trim=True): def updateVocabDefs(self, scroll=True, trim=True):
vocabDefs = self.state.vocabDefs vocabDefs = self.state.vocabDefs
if trim: if trim:
vocabDefs = vocabDefs[:self.preferences['maxResults']] vocabDefs = vocabDefs[:self.preferences['maxResults']]
html = reader_util.buildVocabDefs(vocabDefs, self.ankiIsFactValid) html = reader_util.buildVocabDefs(vocabDefs, self.ankiIsFactValid)
scrollbar = self.textVocabDefs.verticalScrollBar()
position = scrollbar.sliderPosition()
self.textVocabDefs.setHtml(html) self.textVocabDefs.setHtml(html)
if not scroll:
scrollbar.setSliderPosition(position)
def updateKanjiDefs(self, trim=True):
def updateKanjiDefs(self, scroll=True, trim=True):
kanjiDefs = self.state.kanjiDefs kanjiDefs = self.state.kanjiDefs
if trim: if trim:
kanjiDefs = kanjiDefs[:self.preferences['maxResults']] kanjiDefs = kanjiDefs[:self.preferences['maxResults']]
html = reader_util.buildKanjiDefs(kanjiDefs, self.ankiIsFactValid) html = reader_util.buildKanjiDefs(kanjiDefs, self.ankiIsFactValid)
scrollbar = self.textKanjiDefs.verticalScrollBar()
position = scrollbar.sliderPosition()
self.textKanjiDefs.setHtml(html) self.textKanjiDefs.setHtml(html)
if not scroll:
scrollbar.setSliderPosition(position)
def importWordList(self, words): def importWordList(self, words):
self.state.vocabDefs = list() self.state.vocabDefs = list()
@ -564,8 +576,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(False) self.updateVocabDefs(True, False)
self.updateKanjiDefs(False) self.updateKanjiDefs(True, False)
def setStatus(self, status): def setStatus(self, status):