Show flag and mark icons in previewer

This commit is contained in:
hikaru-y 2021-07-26 14:28:38 +09:00
parent 03e76d522a
commit 80e15ff6aa
2 changed files with 15 additions and 2 deletions

View file

@ -151,12 +151,14 @@ class Browser(QMainWindow):
return return
self.editor.set_note(note) self.editor.set_note(note)
self._renderPreview()
if changes.browser_table and changes.card: if changes.browser_table and changes.card:
self.card = self.table.get_current_card() self.card = self.table.get_current_card()
self._update_context_actions() self._update_context_actions()
# changes.card is required for updating flag icon
if changes.note_text or changes.card:
self._renderPreview()
def on_focus_change(self, new: Optional[QWidget], old: Optional[QWidget]) -> None: def on_focus_change(self, new: Optional[QWidget], old: Optional[QWidget]) -> None:
if current_window() == self: if current_window() == self:
self.setUpdatesEnabled(True) self.setUpdatesEnabled(True)

View file

@ -11,6 +11,7 @@ from typing import Any, Callable, Optional, Tuple, Union
import aqt.browser import aqt.browser
from anki.cards import Card from anki.cards import Card
from anki.collection import Config from anki.collection import Config
from anki.tags import MARKED_TAG
from aqt import AnkiQt, gui_hooks from aqt import AnkiQt, gui_hooks
from aqt.qt import ( from aqt.qt import (
QCheckBox, QCheckBox,
@ -140,6 +141,15 @@ class Previewer(QDialog):
if cmd.startswith("play:"): if cmd.startswith("play:"):
play_clicked_audio(cmd, self.card()) play_clicked_audio(cmd, self.card())
def _update_flag_and_mark_icons(self, card: Optional[Card]) -> None:
if card:
flag = card.user_flag()
marked = card.note(reload=True).has_tag(MARKED_TAG)
else:
flag = 0
marked = False
self._web.eval(f"_drawFlag({flag}); _drawMark({json.dumps(marked)});")
def render_card(self) -> None: def render_card(self) -> None:
self.cancel_timer() self.cancel_timer()
# Keep track of whether render() has ever been called # Keep track of whether render() has ever been called
@ -167,6 +177,7 @@ class Previewer(QDialog):
if not self._open: if not self._open:
return return
c = self.card() c = self.card()
self._update_flag_and_mark_icons(c)
func = "_showQuestion" func = "_showQuestion"
ans_txt = "" ans_txt = ""
if not c: if not c: