try to improve readability
This commit is contained in:
@@ -49,9 +49,7 @@ def init_logger(logger: logging.Logger):
|
||||
else:
|
||||
logging.disable()
|
||||
|
||||
logdir = QtCore.QStandardPaths.standardLocations(
|
||||
QtCore.QStandardPaths.StandardLocation.AppDataLocation
|
||||
)[0]
|
||||
logdir = QtCore.QStandardPaths.standardLocations(QtCore.QStandardPaths.StandardLocation.AppDataLocation)[0]
|
||||
if not os.path.exists(logdir):
|
||||
os.mkdir(logdir)
|
||||
logging.basicConfig(
|
||||
@@ -106,29 +104,17 @@ class MainApplication(QtWidgets.QApplication):
|
||||
self.application_model.setItem(0, 0, ApplicationAllMessagesItem())
|
||||
|
||||
self.get_applications_task = GetApplicationsTask(self.gotify_client)
|
||||
self.get_applications_task.success.connect(
|
||||
self.get_applications_success_callback
|
||||
)
|
||||
self.get_applications_task.started.connect(
|
||||
self.main_window.disable_applications
|
||||
)
|
||||
self.get_applications_task.finished.connect(
|
||||
self.main_window.enable_applications
|
||||
)
|
||||
self.get_applications_task.success.connect(self.get_applications_success_callback)
|
||||
self.get_applications_task.started.connect(self.main_window.disable_applications)
|
||||
self.get_applications_task.finished.connect(self.main_window.enable_applications)
|
||||
self.get_applications_task.start()
|
||||
|
||||
def get_applications_success_callback(
|
||||
self, applications: list[gotify.GotifyApplicationModel],
|
||||
):
|
||||
for i, application in enumerate(applications):
|
||||
icon = QtGui.QIcon(
|
||||
self.downloader.get_filename(
|
||||
f"{self.gotify_client.url}/{application.image}"
|
||||
)
|
||||
)
|
||||
self.application_model.setItem(
|
||||
i + 1, 0, ApplicationModelItem(application, icon),
|
||||
)
|
||||
icon = QtGui.QIcon(self.downloader.get_filename(f"{self.gotify_client.url}/{application.image}"))
|
||||
self.application_model.setItem(i + 1, 0, ApplicationModelItem(application, icon))
|
||||
|
||||
def update_last_id(self, i: int):
|
||||
if i > settings.value("message/last", type=int):
|
||||
@@ -167,9 +153,7 @@ class MainApplication(QtWidgets.QApplication):
|
||||
self.main_window.set_connecting()
|
||||
self.tray.set_icon_error()
|
||||
self.gotify_client.increase_wait_time()
|
||||
QtCore.QTimer.singleShot(
|
||||
self.gotify_client.get_wait_time() * 1000, self.gotify_client.reconnect
|
||||
)
|
||||
QtCore.QTimer.singleShot(self.gotify_client.get_wait_time() * 1000, self.gotify_client.reconnect)
|
||||
|
||||
def listener_error_callback(self, exception: Exception):
|
||||
self.main_window.set_connecting()
|
||||
@@ -308,17 +292,13 @@ class MainApplication(QtWidgets.QApplication):
|
||||
|
||||
# Update the message widget icons
|
||||
for r in range(self.messages_model.rowCount()):
|
||||
message_widget: MessageWidget = self.main_window.listView_messages.indexWidget(
|
||||
self.messages_model.index(r, 0)
|
||||
)
|
||||
message_widget: MessageWidget = self.main_window.listView_messages.indexWidget(self.messages_model.index(r, 0))
|
||||
message_widget.set_icons()
|
||||
|
||||
def settings_callback(self):
|
||||
settings_dialog = SettingsDialog(self)
|
||||
settings_dialog.quit_requested.connect(self.quit)
|
||||
settings_dialog.theme_change_requested.connect(
|
||||
self.theme_change_requested_callback
|
||||
)
|
||||
settings_dialog.theme_change_requested.connect(self.theme_change_requested_callback)
|
||||
accepted = settings_dialog.exec()
|
||||
|
||||
if accepted and settings_dialog.settings_changed:
|
||||
@@ -361,9 +341,7 @@ class MainApplication(QtWidgets.QApplication):
|
||||
|
||||
self.main_window.refresh.connect(self.refresh_applications)
|
||||
self.main_window.delete_all.connect(self.delete_all_messages_callback)
|
||||
self.main_window.application_selection_changed.connect(
|
||||
self.application_selection_changed_callback
|
||||
)
|
||||
self.main_window.application_selection_changed.connect(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.main_window.hidden.connect(self.main_window_hidden_callback)
|
||||
@@ -384,9 +362,7 @@ class MainApplication(QtWidgets.QApplication):
|
||||
|
||||
def acquire_lock(self) -> bool:
|
||||
temp_dir = tempfile.gettempdir()
|
||||
lock_filename = os.path.join(
|
||||
temp_dir, __title__ + "-" + getpass.getuser() + ".lock"
|
||||
)
|
||||
lock_filename = os.path.join(temp_dir, __title__ + "-" + getpass.getuser() + ".lock")
|
||||
self.lock_file = QtCore.QLockFile(lock_filename)
|
||||
self.lock_file.setStaleLockTime(0)
|
||||
return self.lock_file.tryLock()
|
||||
|
||||
@@ -54,9 +54,7 @@ class ApplicationAllMessagesItem(QtGui.QStandardItem):
|
||||
class ApplicationModel(QtGui.QStandardItemModel):
|
||||
def __init__(self):
|
||||
super(ApplicationModel, self).__init__()
|
||||
self.setItemPrototype(
|
||||
ApplicationModelItem(gotify.GotifyApplicationModel({"name": ""}), None)
|
||||
)
|
||||
self.setItemPrototype(ApplicationModelItem(gotify.GotifyApplicationModel({"name": ""}), None))
|
||||
|
||||
def setItem(
|
||||
self,
|
||||
|
||||
@@ -43,10 +43,7 @@ class MessageWidget(QtWidgets.QWidget, Ui_Form):
|
||||
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"
|
||||
):
|
||||
if message.get("extras", {}).get("client::display", {}).get("contentType") == "text/markdown":
|
||||
self.label_message.setTextFormat(QtCore.Qt.TextFormat.MarkdownText)
|
||||
|
||||
# If the message is only an image URL, then instead of showing the message,
|
||||
@@ -107,13 +104,10 @@ class MessageWidget(QtWidgets.QWidget, Ui_Form):
|
||||
pixmap = QtGui.QPixmap(filename)
|
||||
|
||||
# Make sure the image fits within the listView
|
||||
W = settings.value("MessageWidget/content_image/W_percentage", type=float) * (
|
||||
self._parent.width() - self.label_image.width()
|
||||
)
|
||||
H = (
|
||||
settings.value("MessageWidget/content_image/H_percentage", type=float)
|
||||
* self._parent.height()
|
||||
)
|
||||
W = settings.value("MessageWidget/content_image/W_percentage", type=float)
|
||||
H = settings.value("MessageWidget/content_image/H_percentage", type=float)
|
||||
W *= self._parent.width() - self.label_image.width()
|
||||
H *= self._parent.height()
|
||||
|
||||
if pixmap.width() > W or pixmap.height() > H:
|
||||
pixmap = pixmap.scaled(
|
||||
@@ -144,7 +138,5 @@ class MessageWidget(QtWidgets.QWidget, Ui_Form):
|
||||
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.pb_delete.clicked.connect(lambda: self.deletion_requested.emit(self.message_item))
|
||||
self.label_message.linkHovered.connect(self.link_hovered_callback)
|
||||
|
||||
@@ -19,9 +19,7 @@ class ServerInfoDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
self.line_url.setPlaceholderText("https://gotify.example.com")
|
||||
self.line_url.setText(url)
|
||||
self.line_token.setText(token)
|
||||
self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setDisabled(
|
||||
True
|
||||
)
|
||||
self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setDisabled(True)
|
||||
self.pb_import.setVisible(enable_import)
|
||||
self.link_callbacks()
|
||||
|
||||
@@ -37,9 +35,7 @@ class ServerInfoDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
return
|
||||
|
||||
self.pb_test.setDisabled(True)
|
||||
self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setDisabled(
|
||||
True
|
||||
)
|
||||
self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setDisabled(True)
|
||||
|
||||
self.task = VerifyServerInfoTask(url, client_token)
|
||||
self.task.success.connect(self.server_info_success)
|
||||
@@ -59,9 +55,7 @@ class ServerInfoDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
self.update_widget_state(self.pb_test, "success")
|
||||
self.update_widget_state(self.line_token, "success")
|
||||
self.update_widget_state(self.line_url, "success")
|
||||
self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setEnabled(
|
||||
True
|
||||
)
|
||||
self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setEnabled(True)
|
||||
self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setFocus()
|
||||
|
||||
def incorrect_token_callback(self, version: GotifyVersionModel):
|
||||
@@ -95,14 +89,6 @@ class ServerInfoDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
|
||||
def link_callbacks(self):
|
||||
self.pb_test.clicked.connect(self.test_server_info)
|
||||
self.line_url.textChanged.connect(
|
||||
lambda: self.buttonBox.button(
|
||||
QtWidgets.QDialogButtonBox.StandardButton.Ok
|
||||
).setDisabled(True)
|
||||
)
|
||||
self.line_token.textChanged.connect(
|
||||
lambda: self.buttonBox.button(
|
||||
QtWidgets.QDialogButtonBox.StandardButton.Ok
|
||||
).setDisabled(True)
|
||||
)
|
||||
self.line_url.textChanged.connect(lambda: self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setDisabled(True))
|
||||
self.line_token.textChanged.connect(lambda: self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setDisabled(True))
|
||||
self.pb_import.clicked.connect(self.import_callback)
|
||||
|
||||
@@ -43,42 +43,28 @@ class SettingsDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
self.link_callbacks()
|
||||
|
||||
def initUI(self):
|
||||
self.buttonBox.button(
|
||||
QtWidgets.QDialogButtonBox.StandardButton.Apply
|
||||
).setEnabled(False)
|
||||
self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Apply).setEnabled(False)
|
||||
|
||||
# Notifications
|
||||
self.spin_priority.setValue(
|
||||
settings.value("tray/notifications/priority", type=int)
|
||||
)
|
||||
self.spin_priority.setValue(settings.value("tray/notifications/priority", type=int))
|
||||
|
||||
self.spin_duration.setValue(
|
||||
settings.value("tray/notifications/duration_ms", type=int)
|
||||
)
|
||||
self.spin_duration.setValue(settings.value("tray/notifications/duration_ms", type=int))
|
||||
if platform.system() == "Windows":
|
||||
# The notification duration setting is ignored by windows
|
||||
self.label_notification_duration.hide()
|
||||
self.spin_duration.hide()
|
||||
self.label_notification_duration_ms.hide()
|
||||
|
||||
self.cb_notify.setChecked(
|
||||
settings.value("message/check_missed/notify", type=bool)
|
||||
)
|
||||
self.cb_notify.setChecked(settings.value("message/check_missed/notify", type=bool))
|
||||
|
||||
self.cb_notification_click.setChecked(
|
||||
settings.value("tray/notifications/click", type=bool)
|
||||
)
|
||||
self.cb_notification_click.setChecked(settings.value("tray/notifications/click", type=bool))
|
||||
|
||||
self.cb_tray_icon_unread.setChecked(
|
||||
settings.value("tray/icon/unread", type=bool)
|
||||
)
|
||||
self.cb_tray_icon_unread.setChecked(settings.value("tray/icon/unread", type=bool))
|
||||
|
||||
# Interface
|
||||
self.combo_theme.addItems(get_themes())
|
||||
self.combo_theme.setCurrentText(settings.value("theme", type=str))
|
||||
self.cb_priority_colors.setChecked(
|
||||
settings.value("MessageWidget/priority_color", type=bool)
|
||||
)
|
||||
self.cb_priority_colors.setChecked(settings.value("MessageWidget/priority_color", type=bool))
|
||||
|
||||
# Logging
|
||||
self.combo_logging.addItems(
|
||||
@@ -96,9 +82,7 @@ class SettingsDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
self.add_message_widget()
|
||||
|
||||
# Advanced
|
||||
self.groupbox_image_popup.setChecked(
|
||||
settings.value("ImagePopup/enabled", type=bool)
|
||||
)
|
||||
self.groupbox_image_popup.setChecked(settings.value("ImagePopup/enabled", type=bool))
|
||||
self.spin_popup_w.setValue(settings.value("ImagePopup/w", type=int))
|
||||
self.spin_popup_h.setValue(settings.value("ImagePopup/h", type=int))
|
||||
self.label_cache.setText("0 MB")
|
||||
@@ -132,16 +116,12 @@ class SettingsDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
|
||||
def settings_changed_callback(self, *args, **kwargs):
|
||||
self.settings_changed = True
|
||||
self.buttonBox.button(
|
||||
QtWidgets.QDialogButtonBox.StandardButton.Apply
|
||||
).setEnabled(True)
|
||||
self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Apply).setEnabled(True)
|
||||
|
||||
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"
|
||||
)
|
||||
font, accepted = QtWidgets.QFontDialog.getFont(label.font(), self, f"Select a {name} font")
|
||||
|
||||
if accepted:
|
||||
self.settings_changed_callback()
|
||||
@@ -205,9 +185,7 @@ class SettingsDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
self.label_cache.setText("0 MB")
|
||||
|
||||
def link_callbacks(self):
|
||||
self.buttonBox.button(
|
||||
QtWidgets.QDialogButtonBox.StandardButton.Apply
|
||||
).clicked.connect(self.apply_settings)
|
||||
self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Apply).clicked.connect(self.apply_settings)
|
||||
|
||||
# Notifications
|
||||
self.spin_priority.valueChanged.connect(self.settings_changed_callback)
|
||||
@@ -225,22 +203,14 @@ class SettingsDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
|
||||
# Logging
|
||||
self.combo_logging.currentTextChanged.connect(self.settings_changed_callback)
|
||||
self.pb_open_log.clicked.connect(
|
||||
lambda: open_file(logger.root.handlers[0].baseFilename)
|
||||
)
|
||||
self.pb_open_log.clicked.connect(lambda: open_file(logger.root.handlers[0].baseFilename))
|
||||
|
||||
# Fonts
|
||||
self.pb_reset_fonts.clicked.connect(self.reset_fonts_callback)
|
||||
|
||||
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")
|
||||
)
|
||||
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"))
|
||||
|
||||
# Advanced
|
||||
self.pb_export.clicked.connect(self.export_callback)
|
||||
@@ -257,9 +227,7 @@ class SettingsDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
settings.setValue("tray/notifications/priority", self.spin_priority.value())
|
||||
settings.setValue("tray/notifications/duration_ms", self.spin_duration.value())
|
||||
settings.setValue("message/check_missed/notify", self.cb_notify.isChecked())
|
||||
settings.setValue(
|
||||
"tray/notifications/click", self.cb_notification_click.isChecked()
|
||||
)
|
||||
settings.setValue("tray/notifications/click", self.cb_notification_click.isChecked())
|
||||
settings.setValue("tray/icon/unread", self.cb_tray_icon_unread.isChecked())
|
||||
|
||||
# Interface
|
||||
@@ -269,9 +237,7 @@ class SettingsDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
settings.setValue("theme", selected_theme)
|
||||
self.theme_change_requested.emit(selected_theme)
|
||||
|
||||
settings.setValue(
|
||||
"MessageWidget/priority_color", self.cb_priority_colors.isChecked()
|
||||
)
|
||||
settings.setValue("MessageWidget/priority_color", self.cb_priority_colors.isChecked())
|
||||
|
||||
# Logging
|
||||
selected_level = self.combo_logging.currentText()
|
||||
@@ -283,17 +249,9 @@ class SettingsDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
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(),
|
||||
)
|
||||
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())
|
||||
|
||||
# Advanced
|
||||
settings.setValue("ImagePopup/enabled", self.groupbox_image_popup.isChecked())
|
||||
|
||||
Reference in New Issue
Block a user