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

View File

@ -14,6 +14,7 @@ from aqt.utils import (
qconnect, qconnect,
restoreGeom, restoreGeom,
saveGeom, saveGeom,
tr,
) )
from aqt.webview import AnkiWebView from aqt.webview import AnkiWebView
@ -116,3 +117,19 @@ class CardInfoManager:
def _on_close(self) -> None: def _on_close(self) -> None:
self._dialog = 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.tags import MARKED_TAG
from anki.utils import stripHTML from anki.utils import stripHTML
from aqt import AnkiQt, gui_hooks 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.deckoptions import confirm_deck_then_display_options
from aqt.operations.card import set_card_flag from aqt.operations.card import set_card_flag
from aqt.operations.note import remove_notes from aqt.operations.note import remove_notes
@ -126,6 +126,8 @@ class Reviewer:
self._v3: V3CardInfo | None = None self._v3: V3CardInfo | None = None
self._state_mutation_key = str(random.randint(0, 2 ** 64 - 1)) self._state_mutation_key = str(random.randint(0, 2 ** 64 - 1))
self.bottom = BottomBar(mw, mw.bottomWeb) 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) hooks.card_did_leech.append(self.onLeech)
def show(self) -> None: def show(self) -> None:
@ -197,6 +199,9 @@ class Reviewer:
else: else:
self._get_next_v3_card() 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: if not self.card:
self.mw.moveToState("overview") self.mw.moveToState("overview")
return return
@ -958,12 +963,10 @@ time = %(time)d;
confirm_deck_then_display_options(self.card) confirm_deck_then_display_options(self.card)
def on_previous_card_info(self) -> None: def on_previous_card_info(self) -> None:
if self.previous_card: self._previous_card_info.toggle()
CardInfoDialog(parent=self.mw, mw=self.mw, card=self.previous_card)
def on_card_info(self) -> None: def on_card_info(self) -> None:
if self.card: self._card_info.toggle()
CardInfoDialog(parent=self.mw, mw=self.mw, card=self.card)
def set_flag_on_current_card(self, desired_flag: int) -> None: def set_flag_on_current_card(self, desired_flag: int) -> None:
def redraw_flag(out: OpChangesWithCount) -> None: def redraw_flag(out: OpChangesWithCount) -> None: