diff --git a/gotify_tray/gui/MainApplication.py b/gotify_tray/gui/MainApplication.py index 9cf87d1..b24e656 100644 --- a/gotify_tray/gui/MainApplication.py +++ b/gotify_tray/gui/MainApplication.py @@ -72,7 +72,7 @@ class MainApplication(QtWidgets.QApplication): self.messages_model = MessagesModel() self.application_model = ApplicationModel() - self.main_window = MainWindow(self, self.application_model, self.messages_model) + self.main_window = MainWindow(self.application_model, self.messages_model) 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) @@ -309,7 +309,7 @@ class MainApplication(QtWidgets.QApplication): message_widget.set_icons() def settings_callback(self): - settings_dialog = SettingsDialog(self) + settings_dialog = SettingsDialog() settings_dialog.quit_requested.connect(self.quit) settings_dialog.theme_change_requested.connect(self.theme_change_requested_callback) accepted = settings_dialog.exec() diff --git a/gotify_tray/gui/themes/__init__.py b/gotify_tray/gui/themes/__init__.py index 0df134f..ceddc54 100644 --- a/gotify_tray/gui/themes/__init__.py +++ b/gotify_tray/gui/themes/__init__.py @@ -29,7 +29,7 @@ def is_valid_theme(theme: str) -> bool: return theme in get_themes() -def set_theme(app: QtWidgets.QApplication, theme: str = "automatic"): +def set_theme(app: QtWidgets.QApplication, theme: str = "automatic"): if not is_valid_theme(theme): logger.warning(f"set_theme: theme {theme} is unsupported.") theme = "automatic" @@ -45,7 +45,7 @@ def set_theme(app: QtWidgets.QApplication, theme: str = "automatic"): app.setStyleSheet(stylesheet) -def get_theme_file(app: QtWidgets.QApplication, file: str, theme: str | None = None) -> str: +def get_theme_file(file: str, theme: str | None = None) -> str: theme = settings.value("theme", type=str) if not theme else theme if not is_valid_theme(theme): @@ -53,6 +53,7 @@ def get_theme_file(app: QtWidgets.QApplication, file: str, theme: str | None = N theme = "automatic" if theme in ("automatic", "default"): + app = QtCore.QCoreApplication.instance() theme = "dark purple" if is_dark_mode(app) else "light purple" return get_abs_path(f"gotify_tray/gui/themes/{theme.replace(' ', '_')}/{file}") diff --git a/gotify_tray/gui/widgets/MainWindow.py b/gotify_tray/gui/widgets/MainWindow.py index b2b1037..1bc2985 100644 --- a/gotify_tray/gui/widgets/MainWindow.py +++ b/gotify_tray/gui/widgets/MainWindow.py @@ -27,10 +27,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): hidden = QtCore.pyqtSignal() activated = QtCore.pyqtSignal() - def __init__( - self, app: QtWidgets.QApplication, - application_model: ApplicationModel, messages_model: MessagesModel - ): + def __init__(self, application_model: ApplicationModel, messages_model: MessagesModel): super(MainWindow, self).__init__() self.setupUi(self) @@ -38,8 +35,6 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): self.setWindowTitle(__title__) - self.app = app - self.application_model = application_model self.messages_model = messages_model @@ -52,7 +47,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): # Do not collapse the message list self.splitter.setCollapsible(1, False) - self.status_widget = StatusWidget(app) + self.status_widget = StatusWidget() self.horizontalLayout.insertWidget(0, self.status_widget) self.set_icons() @@ -75,8 +70,8 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): def set_icons(self): # Set button icons - self.pb_refresh.setIcon(QtGui.QIcon(get_theme_file(self.app, "refresh.svg"))) - self.pb_delete_all.setIcon(QtGui.QIcon(get_theme_file(self.app, "trashcan.svg"))) + self.pb_refresh.setIcon(QtGui.QIcon(get_theme_file("refresh.svg"))) + self.pb_delete_all.setIcon(QtGui.QIcon(get_theme_file("trashcan.svg"))) # Resize the labels and icons size = settings.value("MainWindow/label/size", type=int) @@ -115,7 +110,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): application_item = self.application_model.itemFromId(message.appid) - message_widget = MessageWidget(self.app, self.listView_messages, message_item, icon=application_item.icon()) + message_widget = MessageWidget(self.listView_messages, message_item, icon=application_item.icon()) message_widget.deletion_requested.connect(self.delete_message.emit) message_widget.image_popup.connect(self.image_popup.emit) diff --git a/gotify_tray/gui/widgets/MessageWidget.py b/gotify_tray/gui/widgets/MessageWidget.py index 6079a17..57e5b7b 100644 --- a/gotify_tray/gui/widgets/MessageWidget.py +++ b/gotify_tray/gui/widgets/MessageWidget.py @@ -20,13 +20,11 @@ class MessageWidget(QtWidgets.QWidget, Ui_Form): def __init__( self, - app: QtWidgets.QApplication, parent: QtWidgets.QWidget, message_item: MessagesModelItem, icon: QtGui.QIcon | None = None, ): super(MessageWidget, self).__init__(parent) - self.app = app self._parent = parent self.setupUi(self) self.setAutoFillBackground(True) @@ -102,7 +100,7 @@ class MessageWidget(QtWidgets.QWidget, Ui_Form): self.label_message.setFont(font_content) def set_icons(self): - self.pb_delete.setIcon(QtGui.QIcon(get_theme_file(self.app, "trashcan.svg"))) + self.pb_delete.setIcon(QtGui.QIcon(get_theme_file("trashcan.svg"))) self.pb_delete.setIconSize(QtCore.QSize(24, 24)) def set_message_image(self, filename: str): diff --git a/gotify_tray/gui/widgets/SettingsDialog.py b/gotify_tray/gui/widgets/SettingsDialog.py index 0fbaa9b..c992802 100644 --- a/gotify_tray/gui/widgets/SettingsDialog.py +++ b/gotify_tray/gui/widgets/SettingsDialog.py @@ -27,13 +27,11 @@ class SettingsDialog(QtWidgets.QDialog, Ui_Dialog): quit_requested = QtCore.pyqtSignal() theme_change_requested = QtCore.pyqtSignal(str) - def __init__(self, app: QtWidgets.QApplication): + def __init__(self): super(SettingsDialog, self).__init__() self.setupUi(self) self.setWindowTitle("Settings") - self.app = app - self.settings_changed = False self.changes_applied = False self.server_changed = False @@ -91,7 +89,6 @@ class SettingsDialog(QtWidgets.QDialog, Ui_Dialog): def add_message_widget(self): self.message_widget = MessageWidget( - self.app, self, MessagesModelItem( GotifyMessageModel( diff --git a/gotify_tray/gui/widgets/StatusWidget.py b/gotify_tray/gui/widgets/StatusWidget.py index 2d57bd0..b16938a 100644 --- a/gotify_tray/gui/widgets/StatusWidget.py +++ b/gotify_tray/gui/widgets/StatusWidget.py @@ -8,9 +8,8 @@ settings = Settings("gotify-tray") class StatusWidget(QtWidgets.QLabel): - def __init__(self, app: QtWidgets.QApplication): + def __init__(self): super(StatusWidget, self).__init__() - self.app = app self.setFixedSize(QtCore.QSize(20, 20)) self.setScaledContents(True) self.set_connecting() @@ -18,7 +17,7 @@ class StatusWidget(QtWidgets.QLabel): def set_status(self, image: str): self.image = image - self.setPixmap(QtGui.QPixmap(get_theme_file(self.app, image))) + self.setPixmap(QtGui.QPixmap(get_theme_file(image))) def set_active(self): self.setToolTip("Listening for new messages")