From c722b5bd2cd140933ea399511260e5c8e0376a6d Mon Sep 17 00:00:00 2001 From: Arthur Milchior Date: Mon, 30 Mar 2020 15:10:47 +0200 Subject: [PATCH] PreviewerListCards can take cids and class This allow to avoid recomputing a card if it is known, while allowing to compute it until it's actually displayed --- qt/aqt/previewer.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/qt/aqt/previewer.py b/qt/aqt/previewer.py index 796605f20..31d2cc096 100644 --- a/qt/aqt/previewer.py +++ b/qt/aqt/previewer.py @@ -311,7 +311,15 @@ class BrowserPreviewer(MultipleCardsPreviewer): class ListCardsPreviewer(MultipleCardsPreviewer): - def __init__(self, cards: List[Card], *args, **kwargs): + def __init__(self, cards: List[Union[Card, int]], *args, **kwargs): + """A previewer displaying a list of card. + + List can be changed by setting self.cards to a new value. + + self.cards contains both cid and card. So that card is loaded + only when required and is not loaded twice. + + """ self.index = 0 self.cards = cards super().__init__(*args, **kwargs) @@ -319,7 +327,9 @@ class ListCardsPreviewer(MultipleCardsPreviewer): def card(self): if not self.cards: return None - return self.cards[0] + if isinstance(self.cards[self.index], int): + self.cards[self.index] = self.mw.col.getCard(self.cards[self.index]) + return self.cards[self.index] def _openPreview(self): if not self.cards: