def webview_message_handler(reviewer: Reviewer, message: str): card = reviewer.card if not card: return _, action = message.split(":", 1) deck_config = get_config_dict_for_deck_id(reviewer.mw.col.decks, card.odid or card.did) if action == "typeans": if local_conf["stopWhenTypingAnswer"]: suspend_timers(reviewer) elif action == "alert": av_player.clear_queue_and_maybe_interrupt() av_player.play_file(ALERT_PATH) timeout = deck_config.get("autoAlert", 0) tooltip( "Wake up! You have been looking at <br>" "the question for <b>{}</b> seconds!".format(timeout), period=1000, ) elif action == "action": action = deck_config.get("autoAction", "again") if action == "again": if reviewer.state == "question": reviewer._showAnswer() reviewer._answerCard(1) elif action == "good": if reviewer.state == "question": reviewer._showAnswer() reviewer._answerCard(reviewer._defaultEase()) elif action == "bury": reviewer.onBuryCard()
def fnameToLink(self, fname: str) -> str: ext = fname.split(".")[-1].lower() if ext in pics: name = urllib.parse.quote(fname.encode("utf8")) return '<img src="%s">' % name else: av_player.play_file(fname) return "[sound:%s]" % html.escape(fname, quote=False)
def fnameToLink(self, fname: str) -> str: ext = fname.split(".")[-1].lower() if ext in pics: name = urllib.parse.quote(fname.encode("utf8")) return f'<img src="{name}">' else: av_player.play_file(fname) return f"[sound:{html.escape(fname, quote=False)}|fileonly]"
def onRecSound(self): try: file = getAudio(self.widget) except Exception as e: showWarning( _("Couldn't record audio. Have you installed 'lame'?") + "\n\n" + repr(str(e)) ) return if file: av_player.play_file(file) self.addMedia(file)
def confirm(image_path: str, audio_path: str, period: int): global _timer, _lab if mw is None: return parent = mw closeConfirm() if Path(image_path).is_file(): lab = QLabel(parent=parent) img = QPixmap(image_path).scaledToWidth(64, mode=Qt.SmoothTransformation) lab.setPixmap(img) lab.setAttribute(Qt.WA_TranslucentBackground, True) lab.setAutoFillBackground(False) lab.setWindowFlags(Qt.ToolTip | Qt.FramelessWindowHint | Qt.NoDropShadowWindowHint # type: ignore ) center = parent.frameGeometry().center() qp = QPoint(img.width() * 0.5, img.height() * 0.5) # type: ignore lab.move(center - qp) lab.show() _timer = mw.progress.timer(period, closeConfirm, False) _lab = lab if Path(audio_path).is_file(): if av_player: # Delay audio playback to prevent reviewer from stopping playback # on showQuestion mw.progress.timer(1, lambda: av_player.play_file(filename=audio_path), False) else: legacy_play(audio_path)
def onReplayRecorded(self) -> None: if not self._recordedAudio: tooltip(_("You haven't recorded your voice yet.")) return av_player.play_file(self._recordedAudio)
def onReplayRecorded(self) -> None: if not self._recordedAudio: tooltip(tr(TR.STUDYING_YOU_HAVENT_RECORDED_YOUR_VOICE_YET)) return av_player.play_file(self._recordedAudio)
def onReplayRecorded(self) -> None: if not self._recordedAudio: tooltip(tr.studying_you_havent_recorded_your_voice_yet()) return av_player.play_file(self._recordedAudio)