Merge branch 'application-order'
This commit is contained in:
@@ -27,6 +27,7 @@ DEFAULT_SETTINGS = {
|
|||||||
"MainWindow/label/size": 25,
|
"MainWindow/label/size": 25,
|
||||||
"MainWindow/button/size": 33,
|
"MainWindow/button/size": 33,
|
||||||
"MainWindow/application/icon/size": 40,
|
"MainWindow/application/icon/size": 40,
|
||||||
|
"ApplicationModel/sort": False,
|
||||||
"ImagePopup/enabled": False,
|
"ImagePopup/enabled": False,
|
||||||
"ImagePopup/extensions": [".jpg", ".jpeg", ".png", ".svg"],
|
"ImagePopup/extensions": [".jpg", ".jpeg", ".png", ".svg"],
|
||||||
"ImagePopup/w": 400,
|
"ImagePopup/w": 400,
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ from .models import (
|
|||||||
ApplicationItemDataRole,
|
ApplicationItemDataRole,
|
||||||
ApplicationModel,
|
ApplicationModel,
|
||||||
ApplicationModelItem,
|
ApplicationModelItem,
|
||||||
|
ApplicationProxyModel,
|
||||||
MessagesModel,
|
MessagesModel,
|
||||||
MessagesModelItem,
|
MessagesModelItem,
|
||||||
MessageItemDataRole,
|
MessageItemDataRole,
|
||||||
@@ -69,8 +70,9 @@ class MainApplication(QtWidgets.QApplication):
|
|||||||
|
|
||||||
self.messages_model = MessagesModel()
|
self.messages_model = MessagesModel()
|
||||||
self.application_model = ApplicationModel()
|
self.application_model = ApplicationModel()
|
||||||
|
self.application_proxy_model = ApplicationProxyModel(self.application_model)
|
||||||
|
|
||||||
self.main_window = MainWindow(self.application_model, self.messages_model)
|
self.main_window = MainWindow(self.application_model, self.application_proxy_model, self.messages_model)
|
||||||
self.main_window.show() # The initial .show() is necessary to get the correct sizes when adding MessageWigets
|
self.main_window.show() # The initial .show() is necessary to get the correct sizes when adding MessageWigets
|
||||||
QtCore.QTimer.singleShot(0, self.main_window.hide)
|
QtCore.QTimer.singleShot(0, self.main_window.hide)
|
||||||
|
|
||||||
@@ -195,7 +197,7 @@ class MainApplication(QtWidgets.QApplication):
|
|||||||
def add_message_to_model(self, message: gotify.GotifyMessageModel, process: bool = True):
|
def add_message_to_model(self, message: gotify.GotifyMessageModel, process: bool = True):
|
||||||
if self.application_model.itemFromId(message.appid):
|
if self.application_model.itemFromId(message.appid):
|
||||||
application_index = self.main_window.currentApplicationIndex()
|
application_index = self.main_window.currentApplicationIndex()
|
||||||
if selected_application_item := self.application_model.itemFromIndex(application_index):
|
if selected_application_item := self.application_model.itemFromIndex(self.application_proxy_model.mapToSource(application_index)):
|
||||||
|
|
||||||
def insert_message_helper():
|
def insert_message_helper():
|
||||||
if isinstance(selected_application_item, ApplicationModelItem):
|
if isinstance(selected_application_item, ApplicationModelItem):
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# Form implementation generated from reading ui file 'gotify_tray/gui/designs\widget_settings.ui'
|
# Form implementation generated from reading ui file 'gotify_tray/gui/designs\widget_settings.ui'
|
||||||
#
|
#
|
||||||
# Created by: PyQt6 UI code generator 6.5.1
|
# Created by: PyQt6 UI code generator 6.5.2
|
||||||
#
|
#
|
||||||
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
|
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
|
||||||
# run again. Do not edit this file unless you know what you are doing.
|
# run again. Do not edit this file unless you know what you are doing.
|
||||||
@@ -12,7 +12,7 @@ from PyQt6 import QtCore, QtGui, QtWidgets
|
|||||||
class Ui_Dialog(object):
|
class Ui_Dialog(object):
|
||||||
def setupUi(self, Dialog):
|
def setupUi(self, Dialog):
|
||||||
Dialog.setObjectName("Dialog")
|
Dialog.setObjectName("Dialog")
|
||||||
Dialog.resize(415, 426)
|
Dialog.resize(415, 446)
|
||||||
self.gridLayout = QtWidgets.QGridLayout(Dialog)
|
self.gridLayout = QtWidgets.QGridLayout(Dialog)
|
||||||
self.gridLayout.setObjectName("gridLayout")
|
self.gridLayout.setObjectName("gridLayout")
|
||||||
self.buttonBox = QtWidgets.QDialogButtonBox(parent=Dialog)
|
self.buttonBox = QtWidgets.QDialogButtonBox(parent=Dialog)
|
||||||
@@ -73,6 +73,9 @@ class Ui_Dialog(object):
|
|||||||
self.cb_locale = QtWidgets.QCheckBox(parent=self.groupBox_2)
|
self.cb_locale = QtWidgets.QCheckBox(parent=self.groupBox_2)
|
||||||
self.cb_locale.setObjectName("cb_locale")
|
self.cb_locale.setObjectName("cb_locale")
|
||||||
self.verticalLayout_2.addWidget(self.cb_locale)
|
self.verticalLayout_2.addWidget(self.cb_locale)
|
||||||
|
self.cb_sort_applications = QtWidgets.QCheckBox(parent=self.groupBox_2)
|
||||||
|
self.cb_sort_applications.setObjectName("cb_sort_applications")
|
||||||
|
self.verticalLayout_2.addWidget(self.cb_sort_applications)
|
||||||
self.verticalLayout_4.addWidget(self.groupBox_2)
|
self.verticalLayout_4.addWidget(self.groupBox_2)
|
||||||
self.groupBox_server_info = QtWidgets.QGroupBox(parent=self.tab_general)
|
self.groupBox_server_info = QtWidgets.QGroupBox(parent=self.tab_general)
|
||||||
self.groupBox_server_info.setObjectName("groupBox_server_info")
|
self.groupBox_server_info.setObjectName("groupBox_server_info")
|
||||||
@@ -254,6 +257,7 @@ class Ui_Dialog(object):
|
|||||||
"8..10 -> high"))
|
"8..10 -> high"))
|
||||||
self.cb_priority_colors.setText(_translate("Dialog", "Show message priority colors"))
|
self.cb_priority_colors.setText(_translate("Dialog", "Show message priority colors"))
|
||||||
self.cb_locale.setText(_translate("Dialog", "Display date in the system locale format"))
|
self.cb_locale.setText(_translate("Dialog", "Display date in the system locale format"))
|
||||||
|
self.cb_sort_applications.setText(_translate("Dialog", "Sort the application list alphabetically (requires restart)"))
|
||||||
self.groupBox_server_info.setTitle(_translate("Dialog", "Server info"))
|
self.groupBox_server_info.setTitle(_translate("Dialog", "Server info"))
|
||||||
self.pb_change_server_info.setText(_translate("Dialog", "Change server info"))
|
self.pb_change_server_info.setText(_translate("Dialog", "Change server info"))
|
||||||
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_general), _translate("Dialog", "General"))
|
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_general), _translate("Dialog", "General"))
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>415</width>
|
<width>415</width>
|
||||||
<height>426</height>
|
<height>446</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@@ -148,6 +148,13 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="cb_sort_applications">
|
||||||
|
<property name="text">
|
||||||
|
<string>Sort the application list alphabetically (requires restart)</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|||||||
@@ -77,3 +77,22 @@ class ApplicationModel(QtGui.QStandardItemModel):
|
|||||||
if item.data(ApplicationItemDataRole.ApplicationRole).id == appid:
|
if item.data(ApplicationItemDataRole.ApplicationRole).id == appid:
|
||||||
return item
|
return item
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
class ApplicationProxyModel(QtCore.QSortFilterProxyModel):
|
||||||
|
def __init__(self, application_model: ApplicationModel) -> None:
|
||||||
|
super(ApplicationProxyModel, self).__init__()
|
||||||
|
self.setSourceModel(application_model)
|
||||||
|
self.setSortCaseSensitivity(QtCore.Qt.CaseSensitivity.CaseInsensitive)
|
||||||
|
if settings.value("ApplicationModel/sort", type=bool):
|
||||||
|
self.sort(0, QtCore.Qt.SortOrder.AscendingOrder)
|
||||||
|
|
||||||
|
def lessThan(self, left: QtCore.QModelIndex, right: QtCore.QModelIndex) -> bool:
|
||||||
|
"""Make sure ApplicationAllMessagesItem remains at the top of the model -- ApplicationAllMessagesItem doesn't have any ApplicationRole data
|
||||||
|
"""
|
||||||
|
if not self.sourceModel().data(left, ApplicationItemDataRole.ApplicationRole):
|
||||||
|
return True
|
||||||
|
elif not self.sourceModel().data(right, ApplicationItemDataRole.ApplicationRole):
|
||||||
|
return False
|
||||||
|
|
||||||
|
return super().lessThan(left, right)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ from .ApplicationModel import (
|
|||||||
ApplicationAllMessagesItem,
|
ApplicationAllMessagesItem,
|
||||||
ApplicationModelItem,
|
ApplicationModelItem,
|
||||||
ApplicationModel,
|
ApplicationModel,
|
||||||
|
ApplicationProxyModel,
|
||||||
ApplicationItemDataRole,
|
ApplicationItemDataRole,
|
||||||
)
|
)
|
||||||
from .MessagesModel import MessagesModelItem, MessagesModel, MessageItemDataRole
|
from .MessagesModel import MessagesModelItem, MessagesModel, MessageItemDataRole
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||||||
hidden = QtCore.pyqtSignal()
|
hidden = QtCore.pyqtSignal()
|
||||||
activated = QtCore.pyqtSignal()
|
activated = QtCore.pyqtSignal()
|
||||||
|
|
||||||
def __init__(self, application_model: ApplicationModel, messages_model: MessagesModel):
|
def __init__(self, application_model: ApplicationModel, application_proxy_model: QtCore.QSortFilterProxyModel, messages_model: MessagesModel):
|
||||||
super(MainWindow, self).__init__()
|
super(MainWindow, self).__init__()
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
|
|
||||||
@@ -36,9 +36,10 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||||||
self.setWindowTitle(__title__)
|
self.setWindowTitle(__title__)
|
||||||
|
|
||||||
self.application_model = application_model
|
self.application_model = application_model
|
||||||
|
self.application_proxy_model = application_proxy_model
|
||||||
self.messages_model = messages_model
|
self.messages_model = messages_model
|
||||||
|
|
||||||
self.listView_applications.setModel(application_model)
|
self.listView_applications.setModel(application_proxy_model)
|
||||||
self.listView_messages.setModel(messages_model)
|
self.listView_messages.setModel(messages_model)
|
||||||
|
|
||||||
# Do not expand the applications listview when resizing
|
# Do not expand the applications listview when resizing
|
||||||
@@ -122,7 +123,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||||||
def application_selection_changed_callback(
|
def application_selection_changed_callback(
|
||||||
self, current: QtCore.QModelIndex, previous: QtCore.QModelIndex
|
self, current: QtCore.QModelIndex, previous: QtCore.QModelIndex
|
||||||
):
|
):
|
||||||
if item := self.application_model.itemFromIndex(current):
|
if item := self.application_model.itemFromIndex(self.application_proxy_model.mapToSource(current)):
|
||||||
self.label_application.setText(item.text())
|
self.label_application.setText(item.text())
|
||||||
self.application_selection_changed.emit(item)
|
self.application_selection_changed.emit(item)
|
||||||
|
|
||||||
@@ -142,7 +143,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||||||
return
|
return
|
||||||
|
|
||||||
index = self.currentApplicationIndex()
|
index = self.currentApplicationIndex()
|
||||||
if item := self.application_model.itemFromIndex(index):
|
if item := self.application_model.itemFromIndex(self.application_proxy_model.mapToSource(index)):
|
||||||
self.delete_all.emit(item)
|
self.delete_all.emit(item)
|
||||||
|
|
||||||
def disable_applications(self):
|
def disable_applications(self):
|
||||||
@@ -151,7 +152,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||||||
|
|
||||||
def enable_applications(self):
|
def enable_applications(self):
|
||||||
self.listView_applications.setEnabled(True)
|
self.listView_applications.setEnabled(True)
|
||||||
self.listView_applications.setCurrentIndex(self.application_model.index(0, 0))
|
self.listView_applications.setCurrentIndex(self.application_proxy_model.index(0, 0))
|
||||||
|
|
||||||
def disable_buttons(self):
|
def disable_buttons(self):
|
||||||
self.pb_delete_all.setDisabled(True)
|
self.pb_delete_all.setDisabled(True)
|
||||||
@@ -176,9 +177,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||||||
self.pb_refresh.clicked.connect(self.refresh.emit)
|
self.pb_refresh.clicked.connect(self.refresh.emit)
|
||||||
self.pb_delete_all.clicked.connect(self.delete_all_callback)
|
self.pb_delete_all.clicked.connect(self.delete_all_callback)
|
||||||
|
|
||||||
self.listView_applications.selectionModel().currentChanged.connect(
|
self.listView_applications.selectionModel().currentChanged.connect(self.application_selection_changed_callback)
|
||||||
self.application_selection_changed_callback
|
|
||||||
)
|
|
||||||
|
|
||||||
def store_state(self):
|
def store_state(self):
|
||||||
settings.setValue("MainWindow/geometry", self.saveGeometry())
|
settings.setValue("MainWindow/geometry", self.saveGeometry())
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ class SettingsDialog(QtWidgets.QDialog, Ui_Dialog):
|
|||||||
# Interface
|
# Interface
|
||||||
self.cb_priority_colors.setChecked(settings.value("MessageWidget/priority_color", type=bool))
|
self.cb_priority_colors.setChecked(settings.value("MessageWidget/priority_color", type=bool))
|
||||||
self.cb_locale.setChecked(settings.value("locale", type=bool))
|
self.cb_locale.setChecked(settings.value("locale", type=bool))
|
||||||
|
self.cb_sort_applications.setChecked(settings.value("ApplicationModel/sort", type=bool))
|
||||||
|
|
||||||
# Logging
|
# Logging
|
||||||
self.combo_logging.addItems(
|
self.combo_logging.addItems(
|
||||||
@@ -193,6 +194,7 @@ class SettingsDialog(QtWidgets.QDialog, Ui_Dialog):
|
|||||||
# Interface
|
# Interface
|
||||||
self.cb_priority_colors.stateChanged.connect(self.settings_changed_callback)
|
self.cb_priority_colors.stateChanged.connect(self.settings_changed_callback)
|
||||||
self.cb_locale.stateChanged.connect(self.settings_changed_callback)
|
self.cb_locale.stateChanged.connect(self.settings_changed_callback)
|
||||||
|
self.cb_sort_applications.stateChanged.connect(self.settings_changed_callback)
|
||||||
|
|
||||||
# Server info
|
# Server info
|
||||||
self.pb_change_server_info.clicked.connect(self.change_server_info_callback)
|
self.pb_change_server_info.clicked.connect(self.change_server_info_callback)
|
||||||
@@ -231,6 +233,7 @@ class SettingsDialog(QtWidgets.QDialog, Ui_Dialog):
|
|||||||
# Interface
|
# Interface
|
||||||
settings.setValue("MessageWidget/priority_color", self.cb_priority_colors.isChecked())
|
settings.setValue("MessageWidget/priority_color", self.cb_priority_colors.isChecked())
|
||||||
settings.setValue("locale", self.cb_locale.isChecked())
|
settings.setValue("locale", self.cb_locale.isChecked())
|
||||||
|
settings.setValue("ApplicationModel/sort", self.cb_sort_applications.isChecked())
|
||||||
|
|
||||||
# Logging
|
# Logging
|
||||||
selected_level = self.combo_logging.currentText()
|
selected_level = self.combo_logging.currentText()
|
||||||
|
|||||||
Reference in New Issue
Block a user