diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index b107e2a08..4af8e9d8d 100644 --- a/qt/aqt/browser.py +++ b/qt/aqt/browser.py @@ -1569,7 +1569,7 @@ where id in %s""" self._previewer.close() self._previewer = None else: - self._previewer = PreviewDialog(self, self.mw) + self._previewer = PreviewDialog(self, self.mw, self._on_preview_closed) self._previewer.open() def _renderPreview(self, cardChanged=False): @@ -1580,6 +1580,9 @@ where id in %s""" if self._previewer: self._previewer.cancel_timer() + def _on_preview_closed(self): + self._previewer = None + # Card deletion ###################################################################### diff --git a/qt/aqt/previewer.py b/qt/aqt/previewer.py index 3d3286a84..184b6aaa0 100644 --- a/qt/aqt/previewer.py +++ b/qt/aqt/previewer.py @@ -5,7 +5,7 @@ import json import re import time -from typing import Any, List, Optional, Union +from typing import Any, Callable, List, Optional, Union from anki.cards import Card from anki.lang import _ @@ -34,10 +34,11 @@ class Previewer(QDialog): _timer = None _show_both_sides = False - def __init__(self, parent: QWidget, mw: AnkiQt): + def __init__(self, parent: QWidget, mw: AnkiQt, on_close: Callable[[], None]): super().__init__(None, Qt.Window) self._open = True self._parent = parent + self._close_callback = on_close self.mw = mw def card(self) -> Optional[Card]: @@ -90,9 +91,9 @@ class Previewer(QDialog): self.mw.reviewer.replayAudio(self) def close(self): - if self: - self.close() - self._on_close() + self._on_close() + super().close() + self._close_callback() def _on_close(self): self._open = False