From b441c35b1f8b490e4a42721b215d181421c5d65f Mon Sep 17 00:00:00 2001 From: Andre Wohnsland <50302161+AndreWohnsland@users.noreply.github.com> Date: Tue, 2 Jul 2024 20:46:01 +0200 Subject: [PATCH 1/3] Add plyer and win10toast on win32 --- pyproject.toml | 2 ++ requirements.txt | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index b82f6d1..37db9a7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,6 +18,8 @@ qtawesome = "^1.3.1" holidays = "^0.47" dataclasses-json = "^0.6.4" pyqt6 = "^6.4.2" +plyer = "^2.1.0" +win10toast = {version = "^0.9", platform = "win32"} [tool.poetry.group.dev.dependencies] pyinstaller = "^6.8.0" diff --git a/requirements.txt b/requirements.txt index 3d342df..a75de0f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,6 @@ xlsxwriter pyqtdarktheme qtawesome holidays -dataclasses-json \ No newline at end of file +dataclasses-json +plyer +win10toast ; sys_platform == 'win32' \ No newline at end of file From fe56d37db8c46a78609dd89451597167315e916f Mon Sep 17 00:00:00 2001 From: Andre Wohnsland <50302161+AndreWohnsland@users.noreply.github.com> Date: Tue, 2 Jul 2024 20:46:47 +0200 Subject: [PATCH 2/3] Add notification handler --- src/ui_controller.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/ui_controller.py b/src/ui_controller.py index 92b0e0e..19087e9 100644 --- a/src/ui_controller.py +++ b/src/ui_controller.py @@ -1,4 +1,16 @@ -from PyQt6.QtWidgets import QDialog, QFileDialog, QInputDialog, QLayout, QMessageBox, QTableWidget, QTableWidgetItem +import sys + +from plyer import notification +from PyQt6.QtWidgets import ( + QDialog, + QFileDialog, + QInputDialog, + QLayout, + QMessageBox, + QSystemTrayIcon, + QTableWidget, + QTableWidgetItem, +) from src import __version__ from src.config_handler import CONFIG_HANDLER @@ -20,6 +32,13 @@ def show_message(self, message: str): message_box.show() message_box.exec() + def show_notification(self, tray_icon: QSystemTrayIcon, message: str, title: str, timeout: int = 3): + # QT notification are prettier, but does not work properly on other than windows + if sys.platform.startswith("win"): + tray_icon.showMessage(title, message, QSystemTrayIcon.MessageIcon.Information, timeout * 1000) + return + notification.notify(title=title, message=message, app_name="Time Tracker", timeout=timeout) # type: ignore + def report_choice(self): message_box = QMessageBox() message_box.setText( From 81bfee649c4cbad9efc195b27f6e28d3bdd98c2d Mon Sep 17 00:00:00 2001 From: Andre Wohnsland <50302161+AndreWohnsland@users.noreply.github.com> Date: Tue, 2 Jul 2024 20:47:03 +0200 Subject: [PATCH 3/3] Use notification for pause / event entry --- src/ui_mainwindow.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ui_mainwindow.py b/src/ui_mainwindow.py index 95b9bb2..a72c073 100644 --- a/src/ui_mainwindow.py +++ b/src/ui_mainwindow.py @@ -150,7 +150,9 @@ def add_pause(self, check_past_entry: bool = True): entry_date = self.get_past_date() DB_CONTROLLER.add_pause(pause, entry_date) self.set_pause(0) - UIC.show_message(f"Added pause of {pause} minutes on date {entry_date.strftime('%d-%m-%Y')}") + UIC.show_notification( + self.tray_icon, f"Added pause of {pause} minutes on date {entry_date.strftime('%d-%m-%Y')}", "Pause Added" + ) self.update_other_windows() def get_past_date(self): @@ -175,7 +177,9 @@ def add_event(self, event: str, check_past_entry: bool = True): if self.is_past_time and check_past_entry: entry_datetime = self.get_past_datetime() DB_CONTROLLER.add_event(event, entry_datetime) - UIC.show_message(f"Added event {event} at {entry_datetime.strftime('%d-%m-%Y - %H:%M:%S')}") + UIC.show_notification( + self.tray_icon, f"Added event {event} at {entry_datetime.strftime('%d-%m-%Y - %H:%M:%S')}", "Event Added" + ) def add_start(self, check_past_entry: bool = True): """Add a start event."""