Damien Elmes 2020-04-08 16:19:59 +10:00
parent 55b99511c0
commit 61793f92b8
2 changed files with 10 additions and 6 deletions

View File

@ -1569,7 +1569,7 @@ where id in %s"""
self._previewer.close() self._previewer.close()
self._previewer = None self._previewer = None
else: else:
self._previewer = PreviewDialog(self, self.mw) self._previewer = PreviewDialog(self, self.mw, self._on_preview_closed)
self._previewer.open() self._previewer.open()
def _renderPreview(self, cardChanged=False): def _renderPreview(self, cardChanged=False):
@ -1580,6 +1580,9 @@ where id in %s"""
if self._previewer: if self._previewer:
self._previewer.cancel_timer() self._previewer.cancel_timer()
def _on_preview_closed(self):
self._previewer = None
# Card deletion # Card deletion
###################################################################### ######################################################################

View File

@ -5,7 +5,7 @@
import json import json
import re import re
import time import time
from typing import Any, List, Optional, Union from typing import Any, Callable, List, Optional, Union
from anki.cards import Card from anki.cards import Card
from anki.lang import _ from anki.lang import _
@ -34,10 +34,11 @@ class Previewer(QDialog):
_timer = None _timer = None
_show_both_sides = False _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) super().__init__(None, Qt.Window)
self._open = True self._open = True
self._parent = parent self._parent = parent
self._close_callback = on_close
self.mw = mw self.mw = mw
def card(self) -> Optional[Card]: def card(self) -> Optional[Card]:
@ -90,9 +91,9 @@ class Previewer(QDialog):
self.mw.reviewer.replayAudio(self) self.mw.reviewer.replayAudio(self)
def close(self): def close(self):
if self:
self.close()
self._on_close() self._on_close()
super().close()
self._close_callback()
def _on_close(self): def _on_close(self):
self._open = False self._open = False