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
This commit is contained in:
Arthur Milchior 2020-03-30 15:10:47 +02:00
parent b76ee6f8e5
commit c722b5bd2c

View File

@ -311,7 +311,15 @@ class BrowserPreviewer(MultipleCardsPreviewer):
class ListCardsPreviewer(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.index = 0
self.cards = cards self.cards = cards
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
@ -319,7 +327,9 @@ class ListCardsPreviewer(MultipleCardsPreviewer):
def card(self): def card(self):
if not self.cards: if not self.cards:
return None 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): def _openPreview(self):
if not self.cards: if not self.cards: