From f42c164999d35f98035f92aea5a8edec0800b258 Mon Sep 17 00:00:00 2001 From: Arthur Milchior Date: Sun, 29 Mar 2020 23:41:00 +0200 Subject: [PATCH] add a class to preview a single card --- qt/aqt/previewer.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/qt/aqt/previewer.py b/qt/aqt/previewer.py index bd055bda4..9284c9fa1 100644 --- a/qt/aqt/previewer.py +++ b/qt/aqt/previewer.py @@ -282,3 +282,30 @@ class BrowserPreviewer(Previewer): def _renderScheduledPreview(self) -> None: super()._renderScheduledPreview() self._updatePreviewButtons() + + +class SingleCardPreviewer(Previewer): + def __init__(self, card: Card, *args, **kwargs): + self._card = card + super().__init__(*args, **kwargs) + + def card(self) -> Card: + return self._card + + def _create_gui(self): + super()._create_gui() + self._other_side = self.bbox.addButton( + "Other side", QDialogButtonBox.ActionRole + ) + self._other_side.setAutoDefault(False) + self._other_side.setShortcut(QKeySequence("Right")) + self._other_side.setShortcut(QKeySequence("Left")) + self._other_side.setToolTip(_("Shortcut key: Left or Right arrow")) + self._other_side.clicked.connect(self._on_other_side) + + def _on_other_side(self): + if self._previewState == "question": + self._previewState = "answer" + else: + self._previewState = "question" + self._renderPreview()