Look up Kanji at the same time as vocab when scanning text
Former-commit-id: ec14972d8e7d3119ad76389299dc2609a8f8c095
This commit is contained in:
parent
170484fa24
commit
ddfba5a1ca
@ -132,8 +132,7 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
|
|||||||
|
|
||||||
|
|
||||||
def keyPressEvent(self, event):
|
def keyPressEvent(self, event):
|
||||||
visible = self.dockVocab.isVisible() or self.dockKanji.isVisible()
|
if event.key() == QtCore.Qt.Key_Shift:
|
||||||
if visible and event.key() == QtCore.Qt.Key_Shift:
|
|
||||||
self.updateSampleFromPosition()
|
self.updateSampleFromPosition()
|
||||||
|
|
||||||
|
|
||||||
@ -412,9 +411,7 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
|
|||||||
def updateSampleMouseEvent(self, event):
|
def updateSampleMouseEvent(self, event):
|
||||||
cursor = self.textContent.cursorForPosition(event.pos())
|
cursor = self.textContent.cursorForPosition(event.pos())
|
||||||
self.state.scanPosition = cursor.position()
|
self.state.scanPosition = cursor.position()
|
||||||
requested = event.buttons() & QtCore.Qt.MidButton or event.modifiers() & QtCore.Qt.ShiftModifier
|
if event.buttons() & QtCore.Qt.MidButton or event.modifiers() & QtCore.Qt.ShiftModifier:
|
||||||
visible = self.dockVocab.isVisible() or self.dockKanji.isVisible()
|
|
||||||
if visible and requested:
|
|
||||||
self.updateSampleFromPosition()
|
self.updateSampleFromPosition()
|
||||||
|
|
||||||
|
|
||||||
@ -425,29 +422,37 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
|
|||||||
cursor = self.textContent.textCursor()
|
cursor = self.textContent.textCursor()
|
||||||
content = unicode(self.textContent.toPlainText())
|
content = unicode(self.textContent.toPlainText())
|
||||||
contentSample = content[samplePosStart:samplePosEnd]
|
contentSample = content[samplePosStart:samplePosEnd]
|
||||||
|
contentSampleFlat = contentSample.replace(u'\n', unicode())
|
||||||
|
|
||||||
if not contentSample or unicode.isspace(contentSample[0]):
|
if len(contentSampleFlat) == 0:
|
||||||
cursor.clearSelection()
|
cursor.clearSelection()
|
||||||
self.textContent.setTextCursor(cursor)
|
self.textContent.setTextCursor(cursor)
|
||||||
return
|
return
|
||||||
|
|
||||||
contentSampleFlat = contentSample.replace('\n', unicode())
|
lengthMatched = 0
|
||||||
|
if self.dockVocab.isVisible():
|
||||||
self.state.vocabDefs, lengthMatched = self.language.findTerm(contentSampleFlat)
|
self.state.vocabDefs, lengthMatched = self.language.findTerm(contentSampleFlat)
|
||||||
|
|
||||||
sentence = reader_util.findSentence(content, samplePosStart)
|
sentence = reader_util.findSentence(content, samplePosStart)
|
||||||
for definition in self.state.vocabDefs:
|
for definition in self.state.vocabDefs:
|
||||||
definition['sentence'] = sentence
|
definition['sentence'] = sentence
|
||||||
|
|
||||||
self.updateVocabDefs()
|
self.updateVocabDefs()
|
||||||
|
|
||||||
|
if self.dockKanji.isVisible():
|
||||||
|
if lengthMatched == 0:
|
||||||
|
self.state.kanjiDefs = self.language.findCharacters(contentSampleFlat[0])
|
||||||
|
if len(self.state.kanjiDefs) > 0:
|
||||||
|
lengthMatched = 1
|
||||||
|
else:
|
||||||
|
self.state.kanjiDefs = self.language.findCharacters(contentSampleFlat[:lengthMatched])
|
||||||
|
self.updateKanjiDefs()
|
||||||
|
|
||||||
lengthSelect = 0
|
lengthSelect = 0
|
||||||
if lengthMatched:
|
|
||||||
for c in contentSample:
|
for c in contentSample:
|
||||||
lengthSelect += 1
|
|
||||||
if c != '\n':
|
|
||||||
lengthMatched -= 1
|
|
||||||
if lengthMatched <= 0:
|
if lengthMatched <= 0:
|
||||||
break
|
break
|
||||||
|
lengthSelect += 1
|
||||||
|
if c != u'\n':
|
||||||
|
lengthMatched -= 1
|
||||||
|
|
||||||
cursor.setPosition(samplePosStart, QtGui.QTextCursor.MoveAnchor)
|
cursor.setPosition(samplePosStart, QtGui.QTextCursor.MoveAnchor)
|
||||||
cursor.setPosition(samplePosStart + lengthSelect, QtGui.QTextCursor.KeepAnchor)
|
cursor.setPosition(samplePosStart + lengthSelect, QtGui.QTextCursor.KeepAnchor)
|
||||||
|
Loading…
Reference in New Issue
Block a user