basic image pop-up on hover
This commit is contained in:
@@ -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))
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ from PyQt6 import QtCore, QtGui, QtWidgets
|
||||
class Ui_Dialog(object):
|
||||
def setupUi(self, Dialog):
|
||||
Dialog.setObjectName("Dialog")
|
||||
Dialog.resize(384, 274)
|
||||
Dialog.resize(384, 272)
|
||||
self.gridLayout = QtWidgets.QGridLayout(Dialog)
|
||||
self.gridLayout.setObjectName("gridLayout")
|
||||
self.buttonBox = QtWidgets.QDialogButtonBox(Dialog)
|
||||
@@ -30,17 +30,6 @@ class Ui_Dialog(object):
|
||||
self.groupBox_notifications.setObjectName("groupBox_notifications")
|
||||
self.gridLayout_4 = QtWidgets.QGridLayout(self.groupBox_notifications)
|
||||
self.gridLayout_4.setObjectName("gridLayout_4")
|
||||
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum)
|
||||
self.gridLayout_4.addItem(spacerItem, 0, 2, 1, 1)
|
||||
self.label_notification_duration_ms = QtWidgets.QLabel(self.groupBox_notifications)
|
||||
self.label_notification_duration_ms.setObjectName("label_notification_duration_ms")
|
||||
self.gridLayout_4.addWidget(self.label_notification_duration_ms, 1, 2, 1, 1)
|
||||
self.label_notification_priority = QtWidgets.QLabel(self.groupBox_notifications)
|
||||
self.label_notification_priority.setObjectName("label_notification_priority")
|
||||
self.gridLayout_4.addWidget(self.label_notification_priority, 0, 0, 1, 1)
|
||||
self.label_notification_duration = QtWidgets.QLabel(self.groupBox_notifications)
|
||||
self.label_notification_duration.setObjectName("label_notification_duration")
|
||||
self.gridLayout_4.addWidget(self.label_notification_duration, 1, 0, 1, 1)
|
||||
self.spin_duration = QtWidgets.QSpinBox(self.groupBox_notifications)
|
||||
self.spin_duration.setMinimum(500)
|
||||
self.spin_duration.setMaximum(30000)
|
||||
@@ -53,6 +42,17 @@ class Ui_Dialog(object):
|
||||
self.spin_priority.setProperty("value", 5)
|
||||
self.spin_priority.setObjectName("spin_priority")
|
||||
self.gridLayout_4.addWidget(self.spin_priority, 0, 1, 1, 1)
|
||||
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum)
|
||||
self.gridLayout_4.addItem(spacerItem, 0, 2, 1, 1)
|
||||
self.label_notification_duration_ms = QtWidgets.QLabel(self.groupBox_notifications)
|
||||
self.label_notification_duration_ms.setObjectName("label_notification_duration_ms")
|
||||
self.gridLayout_4.addWidget(self.label_notification_duration_ms, 1, 2, 1, 1)
|
||||
self.label_notification_duration = QtWidgets.QLabel(self.groupBox_notifications)
|
||||
self.label_notification_duration.setObjectName("label_notification_duration")
|
||||
self.gridLayout_4.addWidget(self.label_notification_duration, 1, 0, 1, 1)
|
||||
self.label_notification_priority = QtWidgets.QLabel(self.groupBox_notifications)
|
||||
self.label_notification_priority.setObjectName("label_notification_priority")
|
||||
self.gridLayout_4.addWidget(self.label_notification_priority, 0, 0, 1, 1)
|
||||
self.cb_notify = QtWidgets.QCheckBox(self.groupBox_notifications)
|
||||
self.cb_notify.setObjectName("cb_notify")
|
||||
self.gridLayout_4.addWidget(self.cb_notify, 2, 0, 1, 3)
|
||||
@@ -102,18 +102,26 @@ class Ui_Dialog(object):
|
||||
self.verticalLayout.setObjectName("verticalLayout")
|
||||
self.groupBox = QtWidgets.QGroupBox(self.tab_advanced)
|
||||
self.groupBox.setObjectName("groupBox")
|
||||
self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.groupBox)
|
||||
self.verticalLayout_2.setObjectName("verticalLayout_2")
|
||||
self.pb_export = QtWidgets.QPushButton(self.groupBox)
|
||||
self.pb_export.setObjectName("pb_export")
|
||||
self.verticalLayout_2.addWidget(self.pb_export)
|
||||
self.pb_import = QtWidgets.QPushButton(self.groupBox)
|
||||
self.pb_import.setObjectName("pb_import")
|
||||
self.verticalLayout_2.addWidget(self.pb_import)
|
||||
self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.groupBox)
|
||||
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
|
||||
self.pb_reset = QtWidgets.QPushButton(self.groupBox)
|
||||
self.pb_reset.setObjectName("pb_reset")
|
||||
self.verticalLayout_2.addWidget(self.pb_reset)
|
||||
self.horizontalLayout_2.addWidget(self.pb_reset)
|
||||
self.pb_import = QtWidgets.QPushButton(self.groupBox)
|
||||
self.pb_import.setObjectName("pb_import")
|
||||
self.horizontalLayout_2.addWidget(self.pb_import)
|
||||
self.pb_export = QtWidgets.QPushButton(self.groupBox)
|
||||
self.pb_export.setObjectName("pb_export")
|
||||
self.horizontalLayout_2.addWidget(self.pb_export)
|
||||
self.verticalLayout.addWidget(self.groupBox)
|
||||
self.groupBox_2 = QtWidgets.QGroupBox(self.tab_advanced)
|
||||
self.groupBox_2.setObjectName("groupBox_2")
|
||||
self.gridLayout_2 = QtWidgets.QGridLayout(self.groupBox_2)
|
||||
self.gridLayout_2.setObjectName("gridLayout_2")
|
||||
self.cb_image_popup = QtWidgets.QCheckBox(self.groupBox_2)
|
||||
self.cb_image_popup.setObjectName("cb_image_popup")
|
||||
self.gridLayout_2.addWidget(self.cb_image_popup, 0, 0, 1, 1)
|
||||
self.verticalLayout.addWidget(self.groupBox_2)
|
||||
self.groupBox_logging = QtWidgets.QGroupBox(self.tab_advanced)
|
||||
self.groupBox_logging.setObjectName("groupBox_logging")
|
||||
self.gridLayout_6 = QtWidgets.QGridLayout(self.groupBox_logging)
|
||||
@@ -154,8 +162,8 @@ class Ui_Dialog(object):
|
||||
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
|
||||
self.groupBox_notifications.setTitle(_translate("Dialog", "Notifications"))
|
||||
self.label_notification_duration_ms.setText(_translate("Dialog", "ms"))
|
||||
self.label_notification_priority.setText(_translate("Dialog", "Minimum priority to show notifications:"))
|
||||
self.label_notification_duration.setText(_translate("Dialog", "Notification duration:"))
|
||||
self.label_notification_priority.setText(_translate("Dialog", "Minimum priority to show notifications:"))
|
||||
self.cb_notify.setText(_translate("Dialog", "Show a notification for missed messages after reconnecting"))
|
||||
self.groupBox_server_info.setTitle(_translate("Dialog", "Server info"))
|
||||
self.pb_change_server_info.setText(_translate("Dialog", "Change server info"))
|
||||
@@ -166,9 +174,11 @@ class Ui_Dialog(object):
|
||||
self.pb_font_message_content.setText(_translate("Dialog", "Message"))
|
||||
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_fonts), _translate("Dialog", "Fonts"))
|
||||
self.groupBox.setTitle(_translate("Dialog", "Settings"))
|
||||
self.pb_export.setText(_translate("Dialog", "Export"))
|
||||
self.pb_import.setText(_translate("Dialog", "Import"))
|
||||
self.pb_reset.setText(_translate("Dialog", "Reset"))
|
||||
self.pb_import.setText(_translate("Dialog", "Import"))
|
||||
self.pb_export.setText(_translate("Dialog", "Export"))
|
||||
self.groupBox_2.setTitle(_translate("Dialog", "Image pop-up"))
|
||||
self.cb_image_popup.setText(_translate("Dialog", "Show an image pop-up when hovering over image URLs"))
|
||||
self.groupBox_logging.setTitle(_translate("Dialog", "Logging"))
|
||||
self.label_logging.setText(_translate("Dialog", "Level"))
|
||||
self.pb_open_log.setToolTip(_translate("Dialog", "Open logfile"))
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>384</width>
|
||||
<height>274</height>
|
||||
<height>272</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -40,40 +40,6 @@
|
||||
<string>Notifications</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<item row="0" column="2">
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QLabel" name="label_notification_duration_ms">
|
||||
<property name="text">
|
||||
<string>ms</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_notification_priority">
|
||||
<property name="text">
|
||||
<string>Minimum priority to show notifications:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_notification_duration">
|
||||
<property name="text">
|
||||
<string>Notification duration:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QSpinBox" name="spin_duration">
|
||||
<property name="minimum">
|
||||
@@ -100,6 +66,40 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QLabel" name="label_notification_duration_ms">
|
||||
<property name="text">
|
||||
<string>ms</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_notification_duration">
|
||||
<property name="text">
|
||||
<string>Notification duration:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_notification_priority">
|
||||
<property name="text">
|
||||
<string>Minimum priority to show notifications:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="3">
|
||||
<widget class="QCheckBox" name="cb_notify">
|
||||
<property name="text">
|
||||
@@ -233,11 +233,11 @@
|
||||
<property name="title">
|
||||
<string>Settings</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QPushButton" name="pb_export">
|
||||
<widget class="QPushButton" name="pb_reset">
|
||||
<property name="text">
|
||||
<string>Export</string>
|
||||
<string>Reset</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -249,9 +249,25 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pb_reset">
|
||||
<widget class="QPushButton" name="pb_export">
|
||||
<property name="text">
|
||||
<string>Reset</string>
|
||||
<string>Export</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="title">
|
||||
<string>Image pop-up</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QCheckBox" name="cb_image_popup">
|
||||
<property name="text">
|
||||
<string>Show an image pop-up when hovering over image URLs</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
46
gotify_tray/gui/widgets/ImagePopup.py
Normal file
46
gotify_tray/gui/widgets/ImagePopup.py
Normal file
@@ -0,0 +1,46 @@
|
||||
from PyQt6 import QtCore, QtGui, QtWidgets
|
||||
|
||||
from gotify_tray.database import Settings
|
||||
|
||||
|
||||
settings = Settings("gotify-tray")
|
||||
|
||||
|
||||
class ImagePopup(QtWidgets.QLabel):
|
||||
def __init__(self, filename: str, pos: QtCore.QPoint, link: str = None):
|
||||
"""Create and show a pop-up image under the cursor
|
||||
|
||||
Args:
|
||||
filename (str): The path to the image to display
|
||||
pos (QtCore.QPoint): The location at which the image should be displayed
|
||||
link (str, optional): The URL of the image. Defaults to None.
|
||||
"""
|
||||
super(ImagePopup, self).__init__()
|
||||
self.link = link
|
||||
|
||||
self.setWindowFlags(QtCore.Qt.WindowType.ToolTip)
|
||||
self.installEventFilter(self)
|
||||
|
||||
self.setPixmap(
|
||||
QtGui.QPixmap(filename).scaled(
|
||||
settings.value("ImagePopup/w", type=int),
|
||||
settings.value("ImagePopup/h", type=int),
|
||||
QtCore.Qt.AspectRatioMode.KeepAspectRatio,
|
||||
)
|
||||
)
|
||||
self.move(pos - QtCore.QPoint(30, 30))
|
||||
self.show()
|
||||
|
||||
def eventFilter(self, object: QtCore.QObject, event: QtCore.QEvent) -> bool:
|
||||
if event.type() == QtCore.QEvent.Type.Leave:
|
||||
# Close the pop-up on mouse leave
|
||||
self.close()
|
||||
elif (
|
||||
event.type() == QtCore.QEvent.Type.MouseButtonPress
|
||||
and event.button() == QtCore.Qt.MouseButton.LeftButton
|
||||
and self.link
|
||||
):
|
||||
# Open the image URL on left click
|
||||
QtGui.QDesktopServices.openUrl(QtCore.QUrl(self.link))
|
||||
|
||||
return super().eventFilter(object, event)
|
||||
@@ -21,6 +21,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
delete_all = QtCore.pyqtSignal(QtGui.QStandardItem)
|
||||
delete_message = QtCore.pyqtSignal(MessagesModelItem)
|
||||
application_selection_changed = QtCore.pyqtSignal(QtGui.QStandardItem)
|
||||
image_popup = QtCore.pyqtSignal(str, QtCore.QPoint)
|
||||
|
||||
def __init__(
|
||||
self, application_model: ApplicationModel, messages_model: MessagesModel
|
||||
@@ -103,6 +104,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
self.messages_model.indexFromItem(message_item), message_widget
|
||||
)
|
||||
message_widget.deletion_requested.connect(self.delete_message.emit)
|
||||
message_widget.image_popup.connect(self.image_popup.emit)
|
||||
|
||||
def currentApplicationIndex(self) -> QtCore.QModelIndex:
|
||||
return self.listView_applications.selectionModel().currentIndex()
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import os
|
||||
|
||||
from PyQt6 import QtCore, QtGui, QtWidgets
|
||||
|
||||
from ..models.MessagesModel import MessageItemDataRole, MessagesModelItem
|
||||
from ..designs.widget_message import Ui_Form
|
||||
from gotify_tray.database import Settings
|
||||
from gotify_tray.database import Cache, Settings
|
||||
from gotify_tray.utils import convert_links, get_abs_path
|
||||
|
||||
|
||||
@@ -11,6 +13,7 @@ settings = Settings("gotify-tray")
|
||||
|
||||
class MessageWidget(QtWidgets.QWidget, Ui_Form):
|
||||
deletion_requested = QtCore.pyqtSignal(MessagesModelItem)
|
||||
image_popup = QtCore.pyqtSignal(str, QtCore.QPoint)
|
||||
|
||||
def __init__(self, message_item: MessagesModelItem, image_path: str = ""):
|
||||
super(MessageWidget, self).__init__()
|
||||
@@ -86,7 +89,16 @@ class MessageWidget(QtWidgets.QWidget, Ui_Form):
|
||||
self.label_date.setFont(font_date)
|
||||
self.label_message.setFont(font_content)
|
||||
|
||||
def link_hovered_callback(self, link: str):
|
||||
if not settings.value("ImagePopup/enabled", type=bool):
|
||||
return
|
||||
|
||||
_, ext = os.path.splitext(link)
|
||||
if ext in [".jpg", ".jpeg", ".png"]:
|
||||
self.image_popup.emit(link, QtGui.QCursor.pos())
|
||||
|
||||
def link_callbacks(self):
|
||||
self.pb_delete.clicked.connect(
|
||||
lambda: self.deletion_requested.emit(self.message_item)
|
||||
)
|
||||
self.label_message.linkHovered.connect(self.link_hovered_callback)
|
||||
|
||||
@@ -82,6 +82,10 @@ class SettingsDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
)
|
||||
self.layout_fonts_message.addWidget(self.message_widget)
|
||||
|
||||
# Advanced
|
||||
self.cb_image_popup.setChecked(settings.value("ImagePopup/enabled", type=bool))
|
||||
# TODO: w/h
|
||||
|
||||
def change_server_info_callback(self):
|
||||
self.server_changed = verify_server(force_new=True, enable_import=False)
|
||||
|
||||
@@ -174,6 +178,7 @@ class SettingsDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
self.pb_export.clicked.connect(self.export_callback)
|
||||
self.pb_import.clicked.connect(self.import_callback)
|
||||
self.pb_reset.clicked.connect(self.reset_callback)
|
||||
self.cb_image_popup.stateChanged.connect(self.settings_changed_callback)
|
||||
|
||||
def apply_settings(self):
|
||||
# Priority
|
||||
@@ -203,6 +208,9 @@ class SettingsDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
self.message_widget.label_message.font().toString(),
|
||||
)
|
||||
|
||||
# Advanced
|
||||
settings.setValue("ImagePopup/enabled", self.cb_image_popup.isChecked())
|
||||
|
||||
self.settings_changed = False
|
||||
self.buttonBox.button(
|
||||
QtWidgets.QDialogButtonBox.StandardButton.Apply
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from .ImagePopup import ImagePopup
|
||||
from .MessageWidget import MessageWidget
|
||||
from .MainWindow import MainWindow
|
||||
from .ServerInfoDialog import ServerInfoDialog
|
||||
|
||||
Reference in New Issue
Block a user