Use updating card infos in browser and reviewer

This commit is contained in:
RumovZ 2021-10-16 23:38:11 +02:00
parent 13024fcccc
commit f0d7e6f4d1
4 changed files with 39 additions and 9 deletions

View File

@ -22,3 +22,9 @@ card-stats-review-log-type-review = Review
card-stats-review-log-type-relearn = Relearn
card-stats-review-log-type-filtered = Filtered
card-stats-review-log-type-manual = Manual
## Window Titles
card-stats-browser-card = Browser Card
card-stats-reviewer-card = Reviewer Card
card-stats-previous-reviewer-card = Previous Reviewer Card

View File

@ -58,7 +58,7 @@ from aqt.utils import (
)
from ..changenotetype import change_notetype_dialog
from .card_info import CardInfoDialog
from .card_info import BrowserCardInfo
from .find_and_replace import FindAndReplaceDialog
from .previewer import BrowserPreviewer as PreviewDialog
from .previewer import Previewer
@ -110,6 +110,7 @@ class Browser(QMainWindow):
self.lastFilter = ""
self.focusTo: int | None = None
self._previewer: Previewer | None = None
self._card_info = BrowserCardInfo(self.mw)
self._closeEventHasCleanedUp = False
self.form = aqt.forms.browser.Ui_Dialog()
self.form.setupUi(self)
@ -155,6 +156,7 @@ class Browser(QMainWindow):
if changes.browser_table and changes.card:
self.card = self.table.get_single_selected_card()
self.current_card = self.table.get_current_card()
self._update_card_info()
self._update_current_actions()
# changes.card is required for updating flag icon
@ -236,6 +238,7 @@ class Browser(QMainWindow):
def _closeWindow(self) -> None:
self._cleanup_preview()
self._card_info.close()
self.editor.cleanup()
self.table.cleanup()
self.sidebar.cleanup()
@ -447,6 +450,7 @@ class Browser(QMainWindow):
return
self.current_card = self.table.get_current_card()
self._update_current_actions()
self._update_card_info()
def _update_row_actions(self) -> None:
has_rows = bool(self.table.len())
@ -545,10 +549,10 @@ class Browser(QMainWindow):
######################################################################
def showCardInfo(self) -> None:
if not self.current_card:
return
self._card_info.toggle()
CardInfoDialog(parent=self, mw=self.mw, card=self.current_card)
def _update_card_info(self) -> None:
self._card_info.set_card(self.current_card)
# Menu helpers
######################################################################

View File

@ -14,6 +14,7 @@ from aqt.utils import (
qconnect,
restoreGeom,
saveGeom,
tr,
)
from aqt.webview import AnkiWebView
@ -116,3 +117,19 @@ class CardInfoManager:
def _on_close(self) -> None:
self._dialog = None
class BrowserCardInfo(CardInfoManager):
def __init__(self, mw: aqt.AnkiQt):
super().__init__(mw, "revlog", tr.card_stats_browser_card())
class ReviewerCardInfo(CardInfoManager):
def __init__(self, mw: aqt.AnkiQt):
super().__init__(mw, "reviewerCardInfo", tr.card_stats_reviewer_card())
class PreviousReviewerCardInfo(CardInfoManager):
def __init__(self, mw: aqt.AnkiQt):
super().__init__(
mw, "previousReviewerCardInfo", tr.card_stats_previous_reviewer_card()
)

View File

@ -21,7 +21,7 @@ from anki.scheduler.v3 import Scheduler as V3Scheduler
from anki.tags import MARKED_TAG
from anki.utils import stripHTML
from aqt import AnkiQt, gui_hooks
from aqt.browser.card_info import CardInfoDialog
from aqt.browser.card_info import PreviousReviewerCardInfo, ReviewerCardInfo
from aqt.deckoptions import confirm_deck_then_display_options
from aqt.operations.card import set_card_flag
from aqt.operations.note import remove_notes
@ -126,6 +126,8 @@ class Reviewer:
self._v3: V3CardInfo | None = None
self._state_mutation_key = str(random.randint(0, 2 ** 64 - 1))
self.bottom = BottomBar(mw, mw.bottomWeb)
self._card_info = ReviewerCardInfo(self.mw)
self._previous_card_info = PreviousReviewerCardInfo(self.mw)
hooks.card_did_leech.append(self.onLeech)
def show(self) -> None:
@ -197,6 +199,9 @@ class Reviewer:
else:
self._get_next_v3_card()
self._previous_card_info.set_card(self.previous_card)
self._card_info.set_card(self.card)
if not self.card:
self.mw.moveToState("overview")
return
@ -958,12 +963,10 @@ time = %(time)d;
confirm_deck_then_display_options(self.card)
def on_previous_card_info(self) -> None:
if self.previous_card:
CardInfoDialog(parent=self.mw, mw=self.mw, card=self.previous_card)
self._previous_card_info.toggle()
def on_card_info(self) -> None:
if self.card:
CardInfoDialog(parent=self.mw, mw=self.mw, card=self.card)
self._card_info.toggle()
def set_flag_on_current_card(self, desired_flag: int) -> None:
def redraw_flag(out: OpChangesWithCount) -> None: