use QCoreApplication.instance instead of passing the instance through several objects
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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}")
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user