basic image pop-up on hover

This commit is contained in:
dries.k
2022-08-28 15:22:41 +02:00
parent 4f6ce0db56
commit 5127951302
9 changed files with 174 additions and 66 deletions

View File

@@ -31,7 +31,7 @@ from .models import (
MessagesModelItem,
MessageItemDataRole,
)
from .widgets import MainWindow, SettingsDialog, Tray
from .widgets import ImagePopup, MainWindow, SettingsDialog, Tray
settings = Settings("gotify-tray")
@@ -65,6 +65,7 @@ class MainApplication(QtWidgets.QApplication):
settings.value("Server/client_token", type=str),
)
self.cache = Cache()
self.downloader = Downloader()
self.messages_model = MessagesModel()
@@ -308,6 +309,14 @@ class MainApplication(QtWidgets.QApplication):
return
self.messages_model.clear()
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
self.image_popup = ImagePopup(filename, pos, link)
self.image_popup.show()
else:
# TODO
logger.warning(f"Image {link} is not in the cache")
def refresh_callback(self):
# Manual refresh -> also reset the image cache
@@ -358,6 +367,7 @@ class MainApplication(QtWidgets.QApplication):
self.application_selection_changed_callback
)
self.main_window.delete_message.connect(self.delete_message_callback)
self.main_window.image_popup.connect(self.image_popup_callback)
self.watchdog.closed.connect(lambda: self.listener_closed_callback(None, None))