Adding hotkeys for creating vocabulary and Kanji cards
Former-commit-id: 6bdaba37ae3da0ca56785d6e0350bd04e234820d
This commit is contained in:
parent
d9102ad823
commit
bff7b14bc3
@ -135,6 +135,19 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
|
|||||||
def keyPressEvent(self, event):
|
def keyPressEvent(self, event):
|
||||||
if event.key() == QtCore.Qt.Key_Shift:
|
if event.key() == QtCore.Qt.Key_Shift:
|
||||||
self.updateSampleFromPosition()
|
self.updateSampleFromPosition()
|
||||||
|
elif ord('0') <= event.key() <= ord('9'):
|
||||||
|
index = event.key() - ord('0') - 1
|
||||||
|
if index < 0:
|
||||||
|
index = 9
|
||||||
|
|
||||||
|
if event.modifiers() & QtCore.Qt.ShiftModifier:
|
||||||
|
if event.modifiers() & QtCore.Qt.ControlModifier:
|
||||||
|
self.executeKanjiCommand('addKanji', index)
|
||||||
|
else:
|
||||||
|
if event.modifiers() & QtCore.Qt.ControlModifier:
|
||||||
|
self.executeVocabCommand('addVocabExp', index)
|
||||||
|
if event.modifiers() & QtCore.Qt.AltModifier:
|
||||||
|
self.executeVocabCommand('addVocabReading', index)
|
||||||
|
|
||||||
|
|
||||||
def dragEnterEvent(self, event):
|
def dragEnterEvent(self, event):
|
||||||
@ -234,27 +247,12 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
|
|||||||
|
|
||||||
def onVocabDefsAnchorClicked(self, url):
|
def onVocabDefsAnchorClicked(self, url):
|
||||||
command, index = unicode(url.toString()).split(':')
|
command, index = unicode(url.toString()).split(':')
|
||||||
definition = self.state.vocabDefs[int(index)]
|
self.executeVocabCommand(command, int(index))
|
||||||
|
|
||||||
if command == 'addVocabExp':
|
|
||||||
markup = reader_util.markupVocabExp(definition)
|
|
||||||
self.ankiAddFact('vocab', markup)
|
|
||||||
if command == 'addVocabReading':
|
|
||||||
markup = reader_util.markupVocabReading(definition)
|
|
||||||
self.ankiAddFact('vocab', markup)
|
|
||||||
elif command == 'copyVocabDef':
|
|
||||||
reader_util.copyVocabDef(definition)
|
|
||||||
|
|
||||||
|
|
||||||
def onKanjiDefsAnchorClicked(self, url):
|
def onKanjiDefsAnchorClicked(self, url):
|
||||||
command, index = unicode(url.toString()).split(':')
|
command, index = unicode(url.toString()).split(':')
|
||||||
definition = self.state.kanjiDefs[int(index)]
|
self.executeKanjiCommand(command, int(index))
|
||||||
|
|
||||||
if command == 'addKanji':
|
|
||||||
markup = reader_util.markupKanji(definition)
|
|
||||||
self.ankiAddFact('kanji', markup)
|
|
||||||
elif command == 'copyKanjiDef':
|
|
||||||
reader_util.copyKanjiDef(definition)
|
|
||||||
|
|
||||||
|
|
||||||
def onVocabDefSearchReturn(self):
|
def onVocabDefSearchReturn(self):
|
||||||
@ -368,6 +366,9 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
|
|||||||
|
|
||||||
|
|
||||||
def ankiAddFact(self, profile, markup):
|
def ankiAddFact(self, profile, markup):
|
||||||
|
if markup is None:
|
||||||
|
return False
|
||||||
|
|
||||||
if self.anki is None:
|
if self.anki is None:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -415,6 +416,33 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
|
|||||||
return self.anki.canAddNote(profile['deck'], profile['model'], fields)
|
return self.anki.canAddNote(profile['deck'], profile['model'], fields)
|
||||||
|
|
||||||
|
|
||||||
|
def executeVocabCommand(self, command, index):
|
||||||
|
if index >= len(self.state.vocabDefs):
|
||||||
|
return
|
||||||
|
|
||||||
|
definition = self.state.vocabDefs[index]
|
||||||
|
if command == 'addVocabExp':
|
||||||
|
markup = reader_util.markupVocabExp(definition)
|
||||||
|
self.ankiAddFact('vocab', markup)
|
||||||
|
if command == 'addVocabReading':
|
||||||
|
markup = reader_util.markupVocabReading(definition)
|
||||||
|
self.ankiAddFact('vocab', markup)
|
||||||
|
elif command == 'copyVocabDef':
|
||||||
|
reader_util.copyVocabDef(definition)
|
||||||
|
|
||||||
|
|
||||||
|
def executeKanjiCommand(self, command, index):
|
||||||
|
if index >= len(self.state.kanjiDefs):
|
||||||
|
return
|
||||||
|
|
||||||
|
definition = self.state.kanjiDefs[index]
|
||||||
|
if command == 'addKanji':
|
||||||
|
markup = reader_util.markupKanji(definition)
|
||||||
|
self.ankiAddFact('kanji', markup)
|
||||||
|
elif command == 'copyKanjiDef':
|
||||||
|
reader_util.copyKanjiDef(definition)
|
||||||
|
|
||||||
|
|
||||||
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()
|
||||||
|
Loading…
Reference in New Issue
Block a user