make sure the pop-up is closed when the main window is hidden

This commit is contained in:
dries.k
2022-08-28 16:06:46 +02:00
parent 5127951302
commit 2f0d389be4
2 changed files with 7 additions and 1 deletions

View File

@@ -313,11 +313,14 @@ class MainApplication(QtWidgets.QApplication):
def image_popup_callback(self, link: str, pos: QtCore.QPoint): def image_popup_callback(self, link: str, pos: QtCore.QPoint):
if (filename := self.cache.lookup(link)) or (filename := self.downloader.get_filename(link)): # TODO: preload links if (filename := self.cache.lookup(link)) or (filename := self.downloader.get_filename(link)): # TODO: preload links
self.image_popup = ImagePopup(filename, pos, link) self.image_popup = ImagePopup(filename, pos, link)
self.image_popup.show()
else: else:
# TODO # TODO
logger.warning(f"Image {link} is not in the cache") logger.warning(f"Image {link} is not in the cache")
def main_window_hidden_callback(self):
if image_popup := getattr(self, "image_popup", None):
image_popup.close()
def refresh_callback(self): def refresh_callback(self):
# Manual refresh -> also reset the image cache # Manual refresh -> also reset the image cache
Cache().clear() Cache().clear()
@@ -368,6 +371,7 @@ class MainApplication(QtWidgets.QApplication):
) )
self.main_window.delete_message.connect(self.delete_message_callback) self.main_window.delete_message.connect(self.delete_message_callback)
self.main_window.image_popup.connect(self.image_popup_callback) self.main_window.image_popup.connect(self.image_popup_callback)
self.main_window.hidden.connect(self.main_window_hidden_callback)
self.watchdog.closed.connect(lambda: self.listener_closed_callback(None, None)) self.watchdog.closed.connect(lambda: self.listener_closed_callback(None, None))

View File

@@ -22,6 +22,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
delete_message = QtCore.pyqtSignal(MessagesModelItem) delete_message = QtCore.pyqtSignal(MessagesModelItem)
application_selection_changed = QtCore.pyqtSignal(QtGui.QStandardItem) application_selection_changed = QtCore.pyqtSignal(QtGui.QStandardItem)
image_popup = QtCore.pyqtSignal(str, QtCore.QPoint) image_popup = QtCore.pyqtSignal(str, QtCore.QPoint)
hidden = QtCore.pyqtSignal()
def __init__( def __init__(
self, application_model: ApplicationModel, messages_model: MessagesModel self, application_model: ApplicationModel, messages_model: MessagesModel
@@ -175,3 +176,4 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
def closeEvent(self, e: QtGui.QCloseEvent) -> None: def closeEvent(self, e: QtGui.QCloseEvent) -> None:
self.hide() self.hide()
self.hidden.emit()