~kevang/mnemosyne-proj/grade-shortcuts-improvements

« back to all changes in this revision

Viewing changes to mnemosyne/mnemosyne/pyqt_ui/review_wdgt.py

  • Committer: Kilian Evang
  • Date: 2015-05-12 13:44:26 UTC
  • Revision ID: noreply@texttheater.net-20150512134426-qla5fmyglw5mfnwk
ReviewWdgt no longer associates shortcuts with grade buttons, instead handles
all key presses in the keyPressEvent method. I think this allows for a more
unified, less error-prone treatment of the keyboard interface.

In addition, it now always avoids reacting to auto-repeated grade key presses.
For example, if you press a number key to show the answer and hold it down for
too long, it would previously immediately grade the card. This is no longer the
case. There was no obvious way to solve this problem with the shortcuts.

Furthermore, it now always avoids grading the current card when the answer is
not showing. Previously, there was a race condition that could lead to two
cards being graded in a row when the user accidentally hit two grade keys at
once, see https://code.launchpad.net/~kevang/mnemosyne-proj/grade_only_if_showing/+merge/235605
for a detailed description.

Show diffs side-by-side

added added

removed removed

Lines of Context:
183
183
 
184
184
    auto_focus_grades = True
185
185
    number_keys_show_answer = True
 
186
 
 
187
    key_to_grade_map = {QtCore.Qt.Key_QuoteLeft: 0, QtCore.Qt.Key_0: 0,
 
188
            QtCore.Qt.Key_1: 1, QtCore.Qt.Key_2: 2, QtCore.Qt.Key_3: 3,
 
189
            QtCore.Qt.Key_4: 4, QtCore.Qt.Key_5: 5}
186
190
     
187
191
    def __init__(self, component_manager):
188
192
        ReviewWidget.__init__(self, component_manager)
229
233
        QtGui.QWidget.changeEvent(self, event)
230
234
 
231
235
    def keyPressEvent(self, event):
232
 
        if not event.isAutoRepeat() and event.key() in \
233
 
            [QtCore.Qt.Key_QuoteLeft, QtCore.Qt.Key_0, QtCore.Qt.Key_1,
234
 
            QtCore.Qt.Key_2, QtCore.Qt.Key_3, QtCore.Qt.Key_4,
235
 
            QtCore.Qt.Key_5] and \
236
 
            self.review_controller().is_question_showing():
237
 
                if self.number_keys_show_answer:
238
 
                    self.show_answer()
 
236
        if event.key() in self.key_to_grade_map:
 
237
            if not event.isAutoRepeat():
 
238
                if self.is_answer_showing:
 
239
                    self.grade_answer(self.key_to_grade_map[event.key()])
 
240
                elif self.review_controller().is_question_showing():
 
241
                    if self.number_keys_show_answer:
 
242
                        self.show_answer()
239
243
        elif not event.isAutoRepeat() and event.key() \
240
244
            == QtCore.Qt.Key_QuoteLeft and \
241
245
            not self.review_controller().is_question_showing():