Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def mapWordToCardButton(self, command):
""" Sends the correct answerCard action based on the number of buttons """
""" displayed on the answer card. """
cnt = mw.col.sched.answerButtons(mw.reviewer.card)
c = lambda x:mw.reviewer._answerCard(x)
if self.anki_state != 'A': return
if command == "AGAIN": c(1)
elif cnt == 2:
if command == "GOOD": c(2)
elif cnt == 3:
if command == "GOOD": c(2)
if command == "EASY": c(3)
elif cnt == 4:
if command == "HARD": c(2)
if command == "GOOD": c(3)
if command == "EASY": c(4)
def take_care_of_night_class(web_object=None):
if not web_object:
web_object = mw.reviewer.web
if nm_state_on:
javascript = """
current_classes = document.body.className;
if(current_classes.indexOf("night_mode") == -1)
{
document.body.className += " night_mode";
}
"""
else:
javascript = """
current_classes = document.body.className;
if(current_classes.indexOf("night_mode") != -1)
{
document.body.className = current_classes.replace("night_mode","");
}
This function changes CSS style of most objects. In basic use,
it only reloads original styles and refreshes interface.
All arguments are expected to be strings with CSS styles.
"""
# Invert images and latex if needed
if nm_invert_image:
body += nm_css_iimage
if nm_invert_latex:
body += nm_css_ilatex
# Apply styles to Python objects or by Qt functions.
mw.setStyleSheet(nm_default_css_menu + menu)
mw.toolbar._css = nm_default_css_top + top
mw.reviewer._bottomCSS = nm_default_css_bottom + bottom
mw.reviewer._css = nm_default_css_body + body
mw.deckBrowser._css = nm_default_css_decks + decks
mw.deckBrowser.bottom._css = nm_default_css_decks_bottom + other_bottoms
mw.overview._css = nm_default_css_overview + overview
mw.overview.bottom._css = nm_default_css_overview_bottom + other_bottoms
mw.sharedCSS = nm_default_css_waiting_screen + waiting_screen
# Reload current screen.
if mw.state == "review":
mw.reviewer._initWeb()
if mw.state == "deckBrowser":
mw.deckBrowser.refresh()
if mw.state == "overview":
mw.overview.refresh()
# Redraw toolbar (should be always visible).
relay=lambda event: reviewer.key_handler(
key_event=event,
state=aqt.mw.reviewer.state,
card=aqt.mw.reviewer.card,
replay_audio=aqt.mw.reviewer.replayAudio,
),
"""Populate context menu, given the context/configuration."""
window = web_view.window()
try: # this works for web views embedded in editor windows
atts_button = web_view.editor.widget.findChild(gui.Button)
except AttributeError:
atts_button = None
say_text = config['presets'] and strip(web_view.selectedText())
tts_card = tts_side = None
tts_shortcuts = False
try: # this works for web views in the reviewer and template dialog
if window is aqt.mw and aqt.mw.state == 'review':
tts_card = aqt.mw.reviewer.card
tts_side = aqt.mw.reviewer.state
tts_shortcuts = True
elif web_view.objectName() == 'mainText': # card template dialog
parent_name = web_view.parentWidget().objectName()
tts_card = window.card
tts_side = ('question' if parent_name == 'groupBox'
else 'answer' if parent_name == 'groupBox_2'
else None)
except Exception: # just in case, pylint:disable=broad-except
pass
tts_question = tts_card and tts_side and \
reviewer.has_tts('question', tts_card)
tts_answer = tts_card and tts_side == 'answer' and \
reviewer.has_tts('answer', tts_card)
def init_actions(self):
""" These map all of the Sphynx 'sentences' to actions. """
""" In order to generate an appropriate language model, """
""" see http://www.speech.cs.cmu.edu/tools/lmtool-new.html """
self.actions = {
'AGAIN': lambda:self.mapWordToCardButton('AGAIN'),
'ANSWER': self.showAnswer,
'BURY CARD': mw.reviewer.onBuryCard,
'BURY NOTE': mw.reviewer.onBuryNote,
'EASY': lambda:self.mapWordToCardButton('EASY'),
'GOOD': lambda:self.mapWordToCardButton('GOOD'),
'HARD': lambda:self.mapWordToCardButton('HARD'),
'MARK': mw.reviewer.onMark,
'PAUSE': self.pause,
'RESUME': self.resume,
'STAR': mw.reviewer.onMark,
'SUSPEND CARD': mw.reviewer.onSuspendCard,
'SUSPEND NOTE': mw.reviewer.onSuspend,
'SYNCHRONIZE': mw.onSync,
'UNDO': mw.onUndo
}
def init_actions(self):
""" These map all of the Sphynx 'sentences' to actions. """
""" In order to generate an appropriate language model, """
""" see http://www.speech.cs.cmu.edu/tools/lmtool-new.html """
self.actions = {
'AGAIN': lambda:self.mapWordToCardButton('AGAIN'),
'ANSWER': self.showAnswer,
'BURY CARD': mw.reviewer.onBuryCard,
'BURY NOTE': mw.reviewer.onBuryNote,
'EASY': lambda:self.mapWordToCardButton('EASY'),
'GOOD': lambda:self.mapWordToCardButton('GOOD'),
'HARD': lambda:self.mapWordToCardButton('HARD'),
'MARK': mw.reviewer.onMark,
'PAUSE': self.pause,
'RESUME': self.resume,
'STAR': mw.reviewer.onMark,
'SUSPEND CARD': mw.reviewer.onSuspendCard,
'SUSPEND NOTE': mw.reviewer.onSuspend,
'SYNCHRONIZE': mw.onSync,
'UNDO': mw.onUndo
}
def sweep_current_note():
try:
sweep_files(mw.reviewer.card.note())
except:
pass
note.flush()
# We have to do different things here, for download during
# review, we should reload the card and replay. When we are in
# the add dialog, we do a field update there.
rnote = None
try:
rnote = mw.reviewer.card.note()
except AttributeError:
# Could not get the note of the reviewer's card. Probably
# not reviewing at all.
return
if note == rnote:
# The note we have is the one we were reviewing, so,
# reload and replay
mw.reviewer.card.load()
mw.reviewer.replayAudio()
def buttonTime(self, i, _old):
if isIrCard(mw.reviewer.card):
return '<div class="spacer"></div>'
return _old(self, i)