diff --git a/entry_point.py b/entry_point.py
index 420d067..8881836 100644
--- a/entry_point.py
+++ b/entry_point.py
@@ -1,39 +1,5 @@
-import logging
-import os
-import sys
-
-from PyQt6 import QtCore, QtGui, QtWidgets
-
-from gotify_tray.__version__ import __title__
-from gotify_tray.utils import verify_server
+from gotify_tray import start_gui
if __name__ == "__main__":
- title = __title__.replace(" ", "-")
-
- app = QtWidgets.QApplication(sys.argv)
- app.setApplicationName(title)
- app.setQuitOnLastWindowClosed(False)
- app.setWindowIcon(QtGui.QIcon("gotify_tray/gui/images/gotify-small.png"))
- app.setStyle("fusion")
-
- logdir = QtCore.QStandardPaths.standardLocations(
- QtCore.QStandardPaths.StandardLocation.AppDataLocation
- )[0]
- if not os.path.exists(logdir):
- os.mkdir(logdir)
- logging.basicConfig(
- filename=os.path.join(logdir, f"{title}.log"),
- format="%(levelname)s > %(name)s > %(asctime)s > %(message)s",
- level=logging.ERROR,
- )
-
- # import from gui has to happen after 'setApplicationName' to make sure the correct cache directory is created
- from gotify_tray.gui import MainWindow
-
- window = MainWindow(app)
-
- # prevent multiple instances
- if (window.acquire_lock() or "--no-lock" in sys.argv) and verify_server():
- window.init_ui()
- sys.exit(app.exec())
+ start_gui()
diff --git a/gotify_tray/__init__.py b/gotify_tray/__init__.py
index e69de29..183e3c0 100644
--- a/gotify_tray/__init__.py
+++ b/gotify_tray/__init__.py
@@ -0,0 +1 @@
+from .gui import start_gui
diff --git a/gotify_tray/database/default_settings.py b/gotify_tray/database/default_settings.py
index 8dfdb4d..4384dd2 100644
--- a/gotify_tray/database/default_settings.py
+++ b/gotify_tray/database/default_settings.py
@@ -1,4 +1,5 @@
DEFAULT_SETTINGS = {
+ "logging/level": "Disabled",
"MainWindow/start_minimized": True,
"MainWindow/theme": "default",
"MainWidget/status_image/size": 28,
diff --git a/gotify_tray/gui/MainWindow.py b/gotify_tray/gui/MainWindow.py
index c415438..377e76a 100644
--- a/gotify_tray/gui/MainWindow.py
+++ b/gotify_tray/gui/MainWindow.py
@@ -1,39 +1,47 @@
import getpass
import logging
import os
+import sys
import tempfile
from typing import List
from gotify_tray import gotify
+from gotify_tray.__version__ import __title__
from gotify_tray.database import Downloader, Settings
from gotify_tray.tasks import (
+ DeleteAllMessagesTask,
DeleteApplicationMessagesTask,
DeleteMessageTask,
- DeleteAllMessagesTask,
GetApplicationMessagesTask,
GetApplicationsTask,
GetMessagesTask,
)
+from gotify_tray.utils import verify_server
from PyQt6 import QtCore, QtGui, QtWidgets
from ..__version__ import __title__
from .ApplicationModel import (
- ApplicationItemDataRole,
ApplicationAllMessagesItem,
+ ApplicationItemDataRole,
ApplicationModel,
ApplicationModelItem,
)
from .designs.widget_main import Ui_Form as Ui_Main
-from .themes import set_theme
from .MessagesModel import MessageItemDataRole, MessagesModel, MessagesModelItem
from .MessageWidget import MessageWidget
from .SettingsDialog import SettingsDialog
+from .themes import set_theme
from .Tray import Tray
settings = Settings("gotify-tray")
logger = logging.getLogger("logger")
downloader = Downloader()
+if (level := settings.value("logging/level", type=str)) != "Disabled":
+ logger.setLevel(level)
+else:
+ logging.disable()
+
class MainWidget(QtWidgets.QWidget, Ui_Main):
def __init__(
@@ -460,3 +468,33 @@ class MainWindow(QtWidgets.QMainWindow):
self.gotify_client.stop()
super(MainWindow, self).closeEvent(e)
self.app.quit()
+
+
+def start_gui():
+ title = __title__.replace(" ", "-")
+
+ app = QtWidgets.QApplication(sys.argv)
+ app.setApplicationName(title)
+ app.setQuitOnLastWindowClosed(False)
+ app.setWindowIcon(QtGui.QIcon("gotify_tray/gui/images/gotify-small.png"))
+ app.setStyle("fusion")
+
+ logdir = QtCore.QStandardPaths.standardLocations(
+ QtCore.QStandardPaths.StandardLocation.AppDataLocation
+ )[0]
+ if not os.path.exists(logdir):
+ os.mkdir(logdir)
+ logging.basicConfig(
+ filename=os.path.join(logdir, f"{title}.log"),
+ format="%(levelname)s > %(name)s > %(asctime)s > %(message)s",
+ )
+
+ # import from gui has to happen after 'setApplicationName' to make sure the correct cache directory is created
+ from gotify_tray.gui import MainWindow
+
+ window = MainWindow(app)
+
+ # prevent multiple instances
+ if (window.acquire_lock() or "--no-lock" in sys.argv) and verify_server():
+ window.init_ui()
+ sys.exit(app.exec())
diff --git a/gotify_tray/gui/SettingsDialog.py b/gotify_tray/gui/SettingsDialog.py
index 3fcdb7b..ae3cd18 100644
--- a/gotify_tray/gui/SettingsDialog.py
+++ b/gotify_tray/gui/SettingsDialog.py
@@ -1,3 +1,6 @@
+import logging
+import webbrowser
+
from gotify_tray.database import Settings
from gotify_tray.utils import verify_server
from PyQt6 import QtCore, QtGui, QtWidgets
@@ -5,6 +8,8 @@ from PyQt6 import QtCore, QtGui, QtWidgets
from .designs.widget_settings import Ui_Dialog
from .themes import set_theme
+
+logger = logging.getLogger("logger")
settings = Settings("gotify-tray")
@@ -56,6 +61,18 @@ class SettingsDialog(QtWidgets.QDialog, Ui_Dialog):
settings.value("tray/notifications/duration_ms", type=int)
)
+ # Logging
+ self.combo_logging.addItems(
+ [
+ logging.getLevelName(logging.ERROR),
+ logging.getLevelName(logging.WARNING),
+ logging.getLevelName(logging.INFO),
+ logging.getLevelName(logging.DEBUG),
+ "Disabled",
+ ]
+ )
+ self.combo_logging.setCurrentText(settings.value("logging/level", type=str))
+
def set_font_labels(self):
self.label_font_message_title.setText(
settings.value("MessageWidget/font/title", type=str)
@@ -133,6 +150,12 @@ class SettingsDialog(QtWidgets.QDialog, Ui_Dialog):
# Server info
self.pb_change_server_info.clicked.connect(self.change_server_info_callback)
+ # Logging
+ self.combo_logging.currentTextChanged.connect(self.settings_changed_callback)
+ self.pb_open_log.clicked.connect(
+ lambda: webbrowser.open(logger.root.handlers[0].baseFilename)
+ )
+
def apply_settings(self):
# Fonts
settings.setValue(
@@ -162,6 +185,15 @@ 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())
+ # Logging
+ selected_level = self.combo_logging.currentText()
+ settings.setValue("logging/level", selected_level)
+ if selected_level == "Disabled":
+ logging.disable(logging.CRITICAL)
+ else:
+ logging.disable(logging.NOTSET)
+ logger.setLevel(selected_level)
+
self.settings_changed = False
self.buttonBox.button(
QtWidgets.QDialogButtonBox.StandardButton.Apply
diff --git a/gotify_tray/gui/__init__.py b/gotify_tray/gui/__init__.py
index ea9cddc..6fe1a2f 100644
--- a/gotify_tray/gui/__init__.py
+++ b/gotify_tray/gui/__init__.py
@@ -1,2 +1,2 @@
-from .MainWindow import MainWindow
+from .MainWindow import MainWindow, start_gui
from .ServerInfoDialog import ServerInfoDialog
diff --git a/gotify_tray/gui/designs/widget_settings.py b/gotify_tray/gui/designs/widget_settings.py
index 128e1c0..62e3279 100644
--- a/gotify_tray/gui/designs/widget_settings.py
+++ b/gotify_tray/gui/designs/widget_settings.py
@@ -1,6 +1,6 @@
# Form implementation generated from reading ui file 'gotify_tray/gui/designs\widget_settings.ui'
#
-# Created by: PyQt6 UI code generator 6.1.1
+# Created by: PyQt6 UI code generator 6.2.1
#
# 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.
@@ -12,7 +12,7 @@ from PyQt6 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
- Dialog.resize(375, 540)
+ Dialog.resize(375, 606)
self.verticalLayout = QtWidgets.QVBoxLayout(Dialog)
self.verticalLayout.setObjectName("verticalLayout")
self.groupBox = QtWidgets.QGroupBox(Dialog)
@@ -119,6 +119,23 @@ class Ui_Dialog(object):
spacerItem3 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum)
self.gridLayout_3.addItem(spacerItem3, 0, 1, 1, 1)
self.verticalLayout.addWidget(self.groupBox_4)
+ self.groupBox_7 = QtWidgets.QGroupBox(Dialog)
+ self.groupBox_7.setObjectName("groupBox_7")
+ self.gridLayout_6 = QtWidgets.QGridLayout(self.groupBox_7)
+ self.gridLayout_6.setObjectName("gridLayout_6")
+ self.label_7 = QtWidgets.QLabel(self.groupBox_7)
+ self.label_7.setObjectName("label_7")
+ self.gridLayout_6.addWidget(self.label_7, 0, 0, 1, 1)
+ self.combo_logging = QtWidgets.QComboBox(self.groupBox_7)
+ self.combo_logging.setObjectName("combo_logging")
+ self.gridLayout_6.addWidget(self.combo_logging, 0, 1, 1, 1)
+ self.pb_open_log = QtWidgets.QPushButton(self.groupBox_7)
+ self.pb_open_log.setMaximumSize(QtCore.QSize(30, 16777215))
+ self.pb_open_log.setObjectName("pb_open_log")
+ self.gridLayout_6.addWidget(self.pb_open_log, 0, 2, 1, 1)
+ spacerItem4 = QtWidgets.QSpacerItem(190, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum)
+ self.gridLayout_6.addItem(spacerItem4, 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)
@@ -126,8 +143,8 @@ class Ui_Dialog(object):
self.verticalLayout.addWidget(self.buttonBox)
self.retranslateUi(Dialog)
- self.buttonBox.accepted.connect(Dialog.accept)
- self.buttonBox.rejected.connect(Dialog.reject)
+ self.buttonBox.accepted.connect(Dialog.accept) # type: ignore
+ self.buttonBox.rejected.connect(Dialog.reject) # type: ignore
QtCore.QMetaObject.connectSlotsByName(Dialog)
Dialog.setTabOrder(self.pb_font_message_title, self.pb_font_message_date)
Dialog.setTabOrder(self.pb_font_message_date, self.pb_font_message_content)
@@ -163,6 +180,10 @@ class Ui_Dialog(object):
self.label_6.setText(_translate("Dialog", "ms"))
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", "..."))
if __name__ == "__main__":
diff --git a/gotify_tray/gui/designs/widget_settings.ui b/gotify_tray/gui/designs/widget_settings.ui
index 47551fe..bd31eed 100644
--- a/gotify_tray/gui/designs/widget_settings.ui
+++ b/gotify_tray/gui/designs/widget_settings.ui
@@ -7,7 +7,7 @@
0
0
375
- 540
+ 606
@@ -279,6 +279,54 @@
+ -
+
+
+ Logging
+
+
+
-
+
+
+ Level
+
+
+
+ -
+
+
+ -
+
+
+
+ 30
+ 16777215
+
+
+
+ Open logfile
+
+
+ ...
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 190
+ 20
+
+
+
+
+
+
+
-