Skip to content

Commit

Permalink
Merge pull request #16 from AndreWohnsland/dev
Browse files Browse the repository at this point in the history
Use notification where possible
  • Loading branch information
AndreWohnsland authored Jul 3, 2024
2 parents 8e7c25f + 81bfee6 commit e47f65e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ xlsxwriter
pyqtdarktheme
qtawesome
holidays
dataclasses-json
dataclasses-json
plyer
win10toast ; sys_platform == 'win32'
21 changes: 20 additions & 1 deletion src/ui_controller.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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(
Expand Down
8 changes: 6 additions & 2 deletions src/ui_mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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."""
Expand Down

0 comments on commit e47f65e

Please sign in to comment.