-
Notifications
You must be signed in to change notification settings - Fork 60
/
toggle_hints.py
36 lines (29 loc) · 1.04 KB
/
toggle_hints.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -*- coding: utf-8 -*-
# Original author: Ben Lickly <blickly at berkeley dot edu>
# Copyright © 2013 Roland Sieker <ospalh@gmail.com>
#
# License: GNU GPL, version 3 or later;
# http://www.gnu.org/copyleft/gpl.html
#
""""
Trigger hints through a key press.
Toggle the chint class on a key press. Through this the hints done in
my style are shown or changed to show-on-hover again.
"""
from PyQt4.QtCore import Qt
SHOW_HINT_KEY = Qt.Key_G
######################### End of Settings ##################################
from anki.hooks import wrap
from aqt.reviewer import Reviewer
def newKeyHandler(self, evt, _old):
"""Show hint when the SHOW_HINT_KEY is pressed."""
if (self.state == "question"
and evt.key() == SHOW_HINT_KEY):
self._showHint()
else:
return _old(self, evt)
def toggleHint(self):
"""To show hint, simply click all show hint buttons."""
self.web.eval("""$('.hnt').toggleClass('chint');""")
Reviewer._showHint = _showHint
Reviewer._keyHandler = wrap(Reviewer._keyHandler, newKeyHandler, "around")