def _create_gui(self) -> None: self.setWindowTitle(tr.actions_preview()) self.close_shortcut = QShortcut(QKeySequence("Ctrl+Shift+P"), self) qconnect(self.close_shortcut.activated, self.close) qconnect(self.finished, self._on_finished) self.silentlyClose = True self.vbox = QVBoxLayout() self.vbox.setContentsMargins(0, 0, 0, 0) self._web = AnkiWebView(title="previewer") self.vbox.addWidget(self._web) self.bbox = QDialogButtonBox() self._replay = self.bbox.addButton( tr.actions_replay_audio(), QDialogButtonBox.ButtonRole.ActionRole) self._replay.setAutoDefault(False) self._replay.setShortcut(QKeySequence("R")) self._replay.setToolTip(tr.actions_shortcut_key(val="R")) qconnect(self._replay.clicked, self._on_replay_audio) both_sides_button = QCheckBox(tr.qt_misc_back_side_only()) both_sides_button.setShortcut(QKeySequence("B")) both_sides_button.setToolTip(tr.actions_shortcut_key(val="B")) self.bbox.addButton(both_sides_button, QDialogButtonBox.ButtonRole.ActionRole) self._show_both_sides = self.mw.col.get_config_bool( Config.Bool.PREVIEW_BOTH_SIDES) both_sides_button.setChecked(self._show_both_sides) qconnect(both_sides_button.toggled, self._on_show_both_sides) self.vbox.addWidget(self.bbox) self.setLayout(self.vbox) restoreGeom(self, "preview")
def _bottomHTML(self) -> str: return """ <center id=outer> <table id=innertable width=100%% cellspacing=0 cellpadding=0> <tr> <td align=left width=50 valign=top class=stat> <br> <button title="%(editkey)s" onclick="pycmd('edit');">%(edit)s</button></td> <td align=center valign=top id=middle> </td> <td width=50 align=right valign=top class=stat><span id=time class=stattxt> </span><br> <button onclick="pycmd('more');">%(more)s %(downArrow)s</button> </td> </tr> </table> </center> <script> time = %(time)d; </script> """ % dict( rem=self._remaining(), edit=tr.studying_edit(), editkey=tr.actions_shortcut_key(val="E"), more=tr.studying_more(), downArrow=downArrow(), time=self.card.time_taken() // 1000, )
def _create_sync_link(self) -> str: name = tr.qt_misc_sync() title = tr.actions_shortcut_key(val="Y") label = "sync" self.link_handlers[label] = self._syncLinkHandler return f"""
def _drawButtons(self) -> None: buf = "" drawLinks = deepcopy(self.drawLinks) for b in drawLinks: if b[0]: b[0] = tr.actions_shortcut_key(val=shortcut(b[0])) buf += """ <button title='%s' onclick='pycmd(\"%s\");'>%s</button>""" % tuple(b) self.bottom.draw( buf=buf, link_handler=self._linkHandler, web_context=DeckBrowserBottomBar(self), )
def _centerLinks(self) -> str: links = [ self.create_link( "decks", tr.actions_decks(), self._deckLinkHandler, tip=tr.actions_shortcut_key(val="D"), id="decks", ), self.create_link( "add", tr.actions_add(), self._addLinkHandler, tip=tr.actions_shortcut_key(val="A"), id="add", ), self.create_link( "browse", tr.qt_misc_browse(), self._browseLinkHandler, tip=tr.actions_shortcut_key(val="B"), id="browse", ), self.create_link( "stats", tr.qt_misc_stats(), self._statsLinkHandler, tip=tr.actions_shortcut_key(val="T"), id="stats", ), ] links.append(self._create_sync_link()) gui_hooks.top_toolbar_did_init_links(links, self) return "\n".join(links)
def but(i: int, label: str) -> str: if i == default: extra = """id="defease" class="focus" """ else: extra = "" due = self._buttonTime(i, v3_labels=labels) return """ <td align=center>%s<button %s title="%s" data-ease="%s" onclick='pycmd("ease%d");'>\ %s</button></td>""" % ( due, extra, tr.actions_shortcut_key(val=i), i, i, label, )
def _showAnswerButton(self) -> None: middle = """ <span class=stattxt>{}</span><br> <button title="{}" id="ansbut" class="focus" onclick='pycmd("ans");'>{}</button>""".format( self._remaining(), tr.actions_shortcut_key(val=tr.studying_space()), tr.studying_show_answer(), ) # wrap it in a table so it has the same top margin as the ease buttons middle = ( "<table cellpadding=0><tr><td class=stat2 align=center>%s</td></tr></table>" % middle ) if self.card.should_show_timer(): maxTime = self.card.time_limit() / 1000 else: maxTime = 0 self.bottom.web.eval("showQuestion(%s,%d);" % (json.dumps(middle), maxTime)) self.bottom.web.adjustHeightToFit()
def _renderBottom(self) -> None: links = [ ["O", "opts", tr.actions_options()], ] if self.mw.col.decks.current()["dyn"]: links.append(["R", "refresh", tr.actions_rebuild()]) links.append(["E", "empty", tr.studying_empty()]) else: links.append(["C", "studymore", tr.actions_custom_study()]) # links.append(["F", "cram", _("Filter/Cram")]) if self.mw.col.sched.haveBuried(): links.append(["U", "unbury", tr.studying_unbury()]) links.append(["", "description", tr.scheduling_description()]) buf = "" for b in links: if b[0]: b[0] = tr.actions_shortcut_key(val=shortcut(b[0])) buf += """ <button title="%s" onclick='pycmd("%s")'>%s</button>""" % tuple(b) self.bottom.draw(buf=buf, link_handler=self._linkHandler, web_context=OverviewBottomBar(self))