From ff8f7328fa4b0be035af13b937d791e3d68b7d01 Mon Sep 17 00:00:00 2001 From: "dries.k" Date: Thu, 10 Feb 2022 17:56:39 +0100 Subject: [PATCH] message fonts setting --- gotify_tray/database/default_settings.py | 2 +- gotify_tray/gui/designs/widget_message.py | 20 +- gotify_tray/gui/designs/widget_message.ui | 2 +- gotify_tray/gui/designs/widget_settings.py | 106 ++++-- gotify_tray/gui/designs/widget_settings.ui | 416 +++++++++++++-------- gotify_tray/gui/widgets/MessageWidget.py | 8 +- gotify_tray/gui/widgets/SettingsDialog.py | 71 ++-- 7 files changed, 393 insertions(+), 232 deletions(-) diff --git a/gotify_tray/database/default_settings.py b/gotify_tray/database/default_settings.py index e527ad3..87d3c94 100644 --- a/gotify_tray/database/default_settings.py +++ b/gotify_tray/database/default_settings.py @@ -7,7 +7,7 @@ DEFAULT_SETTINGS = { "MessageWidget/image/size": 33, "MessageWidget/font/title": "Noto Sans,17,-1,5,75,0,0,0,0,0,Bold", "MessageWidget/font/date": "Noto Sans,11,-1,5,50,1,0,0,0,0,Italic", - "MessageWidget/font/content": "Noto Sans,11,-1,5,50,0,0,0,0,0,Regular", + "MessageWidget/font/message": "Noto Sans,11,-1,5,50,0,0,0,0,0,Regular", "ApplicationItem/font": "Noto Sans,10,-1,5,50,0,0,0,0,0,Regular", "MainWindow/font/application": "Noto Sans,13,-1,5,75,0,0,0,0,0,Bold", "MainWindow/label/size": 25, diff --git a/gotify_tray/gui/designs/widget_message.py b/gotify_tray/gui/designs/widget_message.py index 2d8cf7e..2001a89 100644 --- a/gotify_tray/gui/designs/widget_message.py +++ b/gotify_tray/gui/designs/widget_message.py @@ -39,20 +39,20 @@ class Ui_Form(object): self.label_title.setTextInteractionFlags(QtCore.Qt.TextInteractionFlag.LinksAccessibleByMouse|QtCore.Qt.TextInteractionFlag.TextSelectableByMouse) self.label_title.setObjectName("label_title") self.gridLayout_frame.addWidget(self.label_title, 0, 1, 1, 1) - self.text_message = QtWidgets.QLabel(self.frame) + self.label_message = QtWidgets.QLabel(self.frame) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Preferred, QtWidgets.QSizePolicy.Policy.MinimumExpanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) - sizePolicy.setHeightForWidth(self.text_message.sizePolicy().hasHeightForWidth()) - self.text_message.setSizePolicy(sizePolicy) + sizePolicy.setHeightForWidth(self.label_message.sizePolicy().hasHeightForWidth()) + self.label_message.setSizePolicy(sizePolicy) font = QtGui.QFont() font.setPointSize(11) - self.text_message.setFont(font) - self.text_message.setWordWrap(True) - self.text_message.setOpenExternalLinks(True) - self.text_message.setTextInteractionFlags(QtCore.Qt.TextInteractionFlag.LinksAccessibleByMouse|QtCore.Qt.TextInteractionFlag.TextSelectableByMouse) - self.text_message.setObjectName("text_message") - self.gridLayout_frame.addWidget(self.text_message, 3, 1, 1, 3) + self.label_message.setFont(font) + self.label_message.setWordWrap(True) + self.label_message.setOpenExternalLinks(True) + self.label_message.setTextInteractionFlags(QtCore.Qt.TextInteractionFlag.LinksAccessibleByMouse|QtCore.Qt.TextInteractionFlag.TextSelectableByMouse) + self.label_message.setObjectName("label_message") + self.gridLayout_frame.addWidget(self.label_message, 3, 1, 1, 3) self.label_date = QtWidgets.QLabel(self.frame) font = QtGui.QFont() font.setPointSize(11) @@ -80,7 +80,7 @@ class Ui_Form(object): _translate = QtCore.QCoreApplication.translate Form.setWindowTitle(_translate("Form", "Form")) self.label_title.setText(_translate("Form", "Title")) - self.text_message.setText(_translate("Form", "TextLabel")) + self.label_message.setText(_translate("Form", "TextLabel")) self.label_date.setText(_translate("Form", "Date")) diff --git a/gotify_tray/gui/designs/widget_message.ui b/gotify_tray/gui/designs/widget_message.ui index 718406f..a2ba26d 100644 --- a/gotify_tray/gui/designs/widget_message.ui +++ b/gotify_tray/gui/designs/widget_message.ui @@ -71,7 +71,7 @@ - + 0 diff --git a/gotify_tray/gui/designs/widget_settings.py b/gotify_tray/gui/designs/widget_settings.py index caad204..218f9bd 100644 --- a/gotify_tray/gui/designs/widget_settings.py +++ b/gotify_tray/gui/designs/widget_settings.py @@ -12,41 +12,49 @@ from PyQt6 import QtCore, QtGui, QtWidgets class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") - Dialog.resize(375, 292) - self.verticalLayout = QtWidgets.QVBoxLayout(Dialog) - self.verticalLayout.setObjectName("verticalLayout") - self.groupBox_5 = QtWidgets.QGroupBox(Dialog) + Dialog.resize(384, 391) + self.gridLayout = QtWidgets.QGridLayout(Dialog) + self.gridLayout.setObjectName("gridLayout") + self.buttonBox = QtWidgets.QDialogButtonBox(Dialog) + self.buttonBox.setOrientation(QtCore.Qt.Orientation.Horizontal) + self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.StandardButton.Apply|QtWidgets.QDialogButtonBox.StandardButton.Cancel|QtWidgets.QDialogButtonBox.StandardButton.Ok) + self.buttonBox.setObjectName("buttonBox") + self.gridLayout.addWidget(self.buttonBox, 1, 0, 1, 1) + self.tabWidget = QtWidgets.QTabWidget(Dialog) + self.tabWidget.setObjectName("tabWidget") + self.tab_general = QtWidgets.QWidget() + self.tab_general.setObjectName("tab_general") + self.verticalLayout_4 = QtWidgets.QVBoxLayout(self.tab_general) + self.verticalLayout_4.setObjectName("verticalLayout_4") + self.groupBox_5 = QtWidgets.QGroupBox(self.tab_general) self.groupBox_5.setObjectName("groupBox_5") self.gridLayout_4 = QtWidgets.QGridLayout(self.groupBox_5) self.gridLayout_4.setObjectName("gridLayout_4") - spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum) - self.gridLayout_4.addItem(spacerItem, 1, 2, 1, 1) - self.label_6 = QtWidgets.QLabel(self.groupBox_5) - self.label_6.setObjectName("label_6") - self.gridLayout_4.addWidget(self.label_6, 2, 2, 1, 1) - self.label_5 = QtWidgets.QLabel(self.groupBox_5) - self.label_5.setObjectName("label_5") - self.gridLayout_4.addWidget(self.label_5, 2, 0, 1, 1) self.spin_duration = QtWidgets.QSpinBox(self.groupBox_5) self.spin_duration.setMinimum(500) self.spin_duration.setMaximum(30000) self.spin_duration.setSingleStep(100) self.spin_duration.setObjectName("spin_duration") - self.gridLayout_4.addWidget(self.spin_duration, 2, 1, 1, 1) + self.gridLayout_4.addWidget(self.spin_duration, 1, 1, 1, 1) + self.label_6 = QtWidgets.QLabel(self.groupBox_5) + self.label_6.setObjectName("label_6") + self.gridLayout_4.addWidget(self.label_6, 1, 2, 1, 1) + self.label_5 = QtWidgets.QLabel(self.groupBox_5) + self.label_5.setObjectName("label_5") + self.gridLayout_4.addWidget(self.label_5, 1, 0, 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_4 = QtWidgets.QLabel(self.groupBox_5) + self.label_4.setObjectName("label_4") + self.gridLayout_4.addWidget(self.label_4, 0, 0, 1, 1) self.spin_priority = QtWidgets.QSpinBox(self.groupBox_5) self.spin_priority.setMinimum(1) self.spin_priority.setMaximum(10) self.spin_priority.setProperty("value", 5) self.spin_priority.setObjectName("spin_priority") - self.gridLayout_4.addWidget(self.spin_priority, 1, 1, 1, 1) - self.label_4 = QtWidgets.QLabel(self.groupBox_5) - self.label_4.setObjectName("label_4") - self.gridLayout_4.addWidget(self.label_4, 1, 0, 1, 1) - self.cb_icons_notification = QtWidgets.QCheckBox(self.groupBox_5) - self.cb_icons_notification.setObjectName("cb_icons_notification") - self.gridLayout_4.addWidget(self.cb_icons_notification, 0, 0, 1, 3) - self.verticalLayout.addWidget(self.groupBox_5) - self.groupBox_4 = QtWidgets.QGroupBox(Dialog) + self.gridLayout_4.addWidget(self.spin_priority, 0, 1, 1, 1) + self.verticalLayout_4.addWidget(self.groupBox_5) + self.groupBox_4 = QtWidgets.QGroupBox(self.tab_general) self.groupBox_4.setObjectName("groupBox_4") self.gridLayout_3 = QtWidgets.QGridLayout(self.groupBox_4) self.gridLayout_3.setObjectName("gridLayout_3") @@ -55,8 +63,8 @@ class Ui_Dialog(object): self.gridLayout_3.addWidget(self.pb_change_server_info, 0, 0, 1, 1) spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum) self.gridLayout_3.addItem(spacerItem1, 0, 1, 1, 1) - self.verticalLayout.addWidget(self.groupBox_4) - self.groupBox_7 = QtWidgets.QGroupBox(Dialog) + self.verticalLayout_4.addWidget(self.groupBox_4) + self.groupBox_7 = QtWidgets.QGroupBox(self.tab_general) self.groupBox_7.setObjectName("groupBox_7") self.gridLayout_6 = QtWidgets.QGridLayout(self.groupBox_7) self.gridLayout_6.setObjectName("gridLayout_6") @@ -72,22 +80,51 @@ class Ui_Dialog(object): self.gridLayout_6.addWidget(self.pb_open_log, 0, 2, 1, 1) spacerItem2 = QtWidgets.QSpacerItem(190, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum) self.gridLayout_6.addItem(spacerItem2, 0, 3, 1, 1) - self.verticalLayout.addWidget(self.groupBox_7) - self.buttonBox = QtWidgets.QDialogButtonBox(Dialog) - self.buttonBox.setOrientation(QtCore.Qt.Orientation.Horizontal) - self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.StandardButton.Apply|QtWidgets.QDialogButtonBox.StandardButton.Cancel|QtWidgets.QDialogButtonBox.StandardButton.Ok) - self.buttonBox.setObjectName("buttonBox") - self.verticalLayout.addWidget(self.buttonBox) + self.verticalLayout_4.addWidget(self.groupBox_7) + spacerItem3 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Expanding) + self.verticalLayout_4.addItem(spacerItem3) + self.tabWidget.addTab(self.tab_general, "") + self.tab_fonts = QtWidgets.QWidget() + self.tab_fonts.setObjectName("tab_fonts") + self.verticalLayout_5 = QtWidgets.QVBoxLayout(self.tab_fonts) + self.verticalLayout_5.setObjectName("verticalLayout_5") + self.groupBox_2 = QtWidgets.QGroupBox(self.tab_fonts) + self.groupBox_2.setObjectName("groupBox_2") + self.layout_fonts_message = QtWidgets.QVBoxLayout(self.groupBox_2) + self.layout_fonts_message.setContentsMargins(4, 4, 4, 4) + self.layout_fonts_message.setSpacing(6) + self.layout_fonts_message.setObjectName("layout_fonts_message") + self.horizontalLayout = QtWidgets.QHBoxLayout() + self.horizontalLayout.setObjectName("horizontalLayout") + self.pb_font_message_title = QtWidgets.QPushButton(self.groupBox_2) + self.pb_font_message_title.setObjectName("pb_font_message_title") + self.horizontalLayout.addWidget(self.pb_font_message_title) + self.pb_font_message_date = QtWidgets.QPushButton(self.groupBox_2) + self.pb_font_message_date.setObjectName("pb_font_message_date") + self.horizontalLayout.addWidget(self.pb_font_message_date) + self.pb_font_message_content = QtWidgets.QPushButton(self.groupBox_2) + self.pb_font_message_content.setObjectName("pb_font_message_content") + self.horizontalLayout.addWidget(self.pb_font_message_content) + self.layout_fonts_message.addLayout(self.horizontalLayout) + self.verticalLayout_5.addWidget(self.groupBox_2) + spacerItem4 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Expanding) + self.verticalLayout_5.addItem(spacerItem4) + self.tabWidget.addTab(self.tab_fonts, "") + self.gridLayout.addWidget(self.tabWidget, 0, 0, 1, 1) self.retranslateUi(Dialog) + self.tabWidget.setCurrentIndex(0) self.buttonBox.accepted.connect(Dialog.accept) self.buttonBox.rejected.connect(Dialog.reject) QtCore.QMetaObject.connectSlotsByName(Dialog) - Dialog.setTabOrder(self.cb_icons_notification, self.spin_priority) + Dialog.setTabOrder(self.tabWidget, self.spin_priority) Dialog.setTabOrder(self.spin_priority, self.spin_duration) Dialog.setTabOrder(self.spin_duration, self.pb_change_server_info) Dialog.setTabOrder(self.pb_change_server_info, self.combo_logging) Dialog.setTabOrder(self.combo_logging, self.pb_open_log) + Dialog.setTabOrder(self.pb_open_log, self.pb_font_message_title) + Dialog.setTabOrder(self.pb_font_message_title, self.pb_font_message_date) + Dialog.setTabOrder(self.pb_font_message_date, self.pb_font_message_content) def retranslateUi(self, Dialog): _translate = QtCore.QCoreApplication.translate @@ -96,13 +133,18 @@ class Ui_Dialog(object): self.label_6.setText(_translate("Dialog", "ms")) self.label_5.setText(_translate("Dialog", "Notification duration")) self.label_4.setText(_translate("Dialog", "Minimum priority to show notifications:")) - self.cb_icons_notification.setText(_translate("Dialog", "Show notification icons")) self.groupBox_4.setTitle(_translate("Dialog", "Server info")) self.pb_change_server_info.setText(_translate("Dialog", "Change server info")) self.groupBox_7.setTitle(_translate("Dialog", "Logging")) self.label_7.setText(_translate("Dialog", "Level")) self.pb_open_log.setToolTip(_translate("Dialog", "Open logfile")) self.pb_open_log.setText(_translate("Dialog", "...")) + self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_general), _translate("Dialog", "General")) + self.groupBox_2.setTitle(_translate("Dialog", "Message")) + self.pb_font_message_title.setText(_translate("Dialog", "Title")) + self.pb_font_message_date.setText(_translate("Dialog", "Date")) + self.pb_font_message_content.setText(_translate("Dialog", "Message")) + self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_fonts), _translate("Dialog", "Fonts")) if __name__ == "__main__": diff --git a/gotify_tray/gui/designs/widget_settings.ui b/gotify_tray/gui/designs/widget_settings.ui index 6f80242..cc34928 100644 --- a/gotify_tray/gui/designs/widget_settings.ui +++ b/gotify_tray/gui/designs/widget_settings.ui @@ -6,168 +6,15 @@ 0 0 - 375 - 292 + 384 + 391 Dialog - - - - - Notifications - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - ms - - - - - - - Notification duration - - - - - - - 500 - - - 30000 - - - 100 - - - - - - - 1 - - - 10 - - - 5 - - - - - - - Minimum priority to show notifications: - - - - - - - Show notification icons - - - - - - - - - - Server info - - - - - - Change server info - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - Logging - - - - - - Level - - - - - - - - - - - 30 - 16777215 - - - - Open logfile - - - ... - - - - - - - Qt::Horizontal - - - - 190 - 20 - - - - - - - - + + Qt::Horizontal @@ -177,15 +24,260 @@ + + + + 0 + + + + General + + + + + + Notifications + + + + + + 500 + + + 30000 + + + 100 + + + + + + + ms + + + + + + + Notification duration + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Minimum priority to show notifications: + + + + + + + 1 + + + 10 + + + 5 + + + + + + + + + + Server info + + + + + + Change server info + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + Logging + + + + + + Level + + + + + + + + + + + 30 + 16777215 + + + + Open logfile + + + ... + + + + + + + Qt::Horizontal + + + + 190 + 20 + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + Fonts + + + + + + Message + + + + 6 + + + 4 + + + 4 + + + 4 + + + 4 + + + + + + + Title + + + + + + + Date + + + + + + + Message + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + - cb_icons_notification + tabWidget spin_priority spin_duration pb_change_server_info combo_logging pb_open_log + pb_font_message_title + pb_font_message_date + pb_font_message_content @@ -196,8 +288,8 @@ accept() - 248 - 254 + 257 + 330 157 @@ -212,8 +304,8 @@ reject() - 316 - 260 + 325 + 330 286 diff --git a/gotify_tray/gui/widgets/MessageWidget.py b/gotify_tray/gui/widgets/MessageWidget.py index d8400eb..1089bf4 100644 --- a/gotify_tray/gui/widgets/MessageWidget.py +++ b/gotify_tray/gui/widgets/MessageWidget.py @@ -27,19 +27,19 @@ class MessageWidget(QtWidgets.QWidget, Ui_Form): font_title.fromString(settings.value("MessageWidget/font/title", type=str)) font_date.fromString(settings.value("MessageWidget/font/date", type=str)) - font_content.fromString(settings.value("MessageWidget/font/content", type=str)) + font_content.fromString(settings.value("MessageWidget/font/message", type=str)) self.label_title.setFont(font_title) self.label_date.setFont(font_date) - self.text_message.setFont(font_content) + self.label_message.setFont(font_content) # Display message contents self.label_title.setText(message.title) self.label_date.setText(message.date.strftime("%Y-%m-%d, %H:%M")) if markdown := message.get("extras", {}).get("client::display", {}).get("contentType") == "text/markdown": - self.text_message.setTextFormat(QtCore.Qt.TextFormat.MarkdownText) - self.text_message.setText(convert_links(message.message)) + self.label_message.setTextFormat(QtCore.Qt.TextFormat.MarkdownText) + self.label_message.setText(convert_links(message.message)) # Show the application icon if image_path: diff --git a/gotify_tray/gui/widgets/SettingsDialog.py b/gotify_tray/gui/widgets/SettingsDialog.py index 72b5150..57a422a 100644 --- a/gotify_tray/gui/widgets/SettingsDialog.py +++ b/gotify_tray/gui/widgets/SettingsDialog.py @@ -2,6 +2,9 @@ import logging import webbrowser from gotify_tray.database import Settings +from gotify_tray.gotify import GotifyMessageModel +from gotify_tray.gui.models import MessagesModelItem +from . import MessageWidget from gotify_tray.utils import verify_server from PyQt6 import QtCore, QtGui, QtWidgets @@ -31,11 +34,6 @@ class SettingsDialog(QtWidgets.QDialog, Ui_Dialog): QtWidgets.QDialogButtonBox.StandardButton.Apply ).setEnabled(False) - # Icons - self.cb_icons_notification.setChecked( - settings.value("tray/notifications/icon/show", type=bool) - ) - # Notifications self.spin_priority.setValue( settings.value("tray/notifications/priority", type=int) @@ -57,6 +55,20 @@ class SettingsDialog(QtWidgets.QDialog, Ui_Dialog): ) self.combo_logging.setCurrentText(settings.value("logging/level", type=str)) + # Fonts + self.message_widget = MessageWidget( + MessagesModelItem( + GotifyMessageModel( + { + "date": "2021-01-01T11:11:00.928224+01:00", + "message": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin luctus.", + "title": "Title", + } + ) + ) + ) + self.layout_fonts_message.addWidget(self.message_widget) + def change_server_info_callback(self): self.server_changed = verify_server(force_new=True) @@ -66,26 +78,22 @@ class SettingsDialog(QtWidgets.QDialog, Ui_Dialog): QtWidgets.QDialogButtonBox.StandardButton.Apply ).setEnabled(True) - def reset_settings_callback(self): - response = QtWidgets.QMessageBox.warning( - self, - "Are you sure?", - "Reset all settings?", - QtWidgets.QMessageBox.StandardButton.Ok - | QtWidgets.QMessageBox.StandardButton.Cancel, - defaultButton=QtWidgets.QMessageBox.StandardButton.Cancel, + def change_font_callback(self, name: str): + label: QtWidgets.QLabel = getattr(self.message_widget, "label_" + name) + + font, accepted = QtWidgets.QFontDialog.getFont( + label.font(), self, f"Select a {name} font" ) - if response == QtWidgets.QMessageBox.StandardButton.Ok: - settings.clear() + + if accepted: + self.settings_changed_callback() + label.setFont(font) def link_callbacks(self): self.buttonBox.button( QtWidgets.QDialogButtonBox.StandardButton.Apply ).clicked.connect(self.apply_settings) - # Icons - self.cb_icons_notification.stateChanged.connect(self.settings_changed_callback) - # Notifications self.spin_priority.valueChanged.connect(self.settings_changed_callback) self.spin_duration.valueChanged.connect(self.settings_changed_callback) @@ -99,12 +107,18 @@ class SettingsDialog(QtWidgets.QDialog, Ui_Dialog): lambda: webbrowser.open(logger.root.handlers[0].baseFilename) ) - def apply_settings(self): - # Icons - settings.setValue( - "tray/notifications/icon/show", self.cb_icons_notification.isChecked() + # Fonts + self.pb_font_message_title.clicked.connect( + lambda: self.change_font_callback("title") + ) + self.pb_font_message_date.clicked.connect( + lambda: self.change_font_callback("date") + ) + self.pb_font_message_content.clicked.connect( + lambda: self.change_font_callback("message") ) + def apply_settings(self): # Priority settings.setValue("tray/notifications/priority", self.spin_priority.value()) settings.setValue("tray/notifications/duration_ms", self.spin_duration.value()) @@ -118,6 +132,19 @@ class SettingsDialog(QtWidgets.QDialog, Ui_Dialog): logging.disable(logging.NOTSET) logger.setLevel(selected_level) + # Fonts + settings.setValue( + "MessageWidget/font/title", + self.message_widget.label_title.font().toString(), + ) + settings.setValue( + "MessageWidget/font/date", self.message_widget.label_date.font().toString() + ) + settings.setValue( + "MessageWidget/font/message", + self.message_widget.label_message.font().toString(), + ) + self.settings_changed = False self.buttonBox.button( QtWidgets.QDialogButtonBox.StandardButton.Apply