From 61793f92b85d5265f5c2eab7fbd273efcb7ec437 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 8 Apr 2020 16:19:59 +1000 Subject: [PATCH] fix preview closing https://anki.tenderapp.com/discussions/beta-testing/1868-anki-2124-beta#comment_48228480 --- qt/aqt/browser.py | 5 ++++- qt/aqt/previewer.py | 11 ++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) 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