This commit is contained in:
Daniel Langbein 2025-02-22 18:09:44 +01:00
parent f92a94d331
commit 05f6204ad2
Signed by: langfingaz
GPG Key ID: 6C47C753F0823002
4 changed files with 36 additions and 24 deletions

View File

@ -9,8 +9,9 @@ A timer that notifies you - even if "do not disturb" is enabled.
* [ToC](#toc) * [ToC](#toc)
* [Application IDs](#application-ids) * [Application IDs](#application-ids)
* [.desktop entry](#desktop-entry) * [.desktop entry](#desktop-entry)
* [Alternatives](#alternatives)
* [GTK resources](#gtk-resources) * [GTK resources](#gtk-resources)
* [mypy](#mypy)
* [Alternatives](#alternatives)
<!-- TOC --> <!-- TOC -->
## Application IDs ## Application IDs
@ -54,6 +55,19 @@ Categories=Game;
Copy `watch-icon.svg` to `~/.local/share/icons/hicolor/scalable/apps/dndbuster-stopwatch.svg` Copy `watch-icon.svg` to `~/.local/share/icons/hicolor/scalable/apps/dndbuster-stopwatch.svg`
## GTK resources
- https://www.technett.io/post/dev/python-gtk-2/
- https://github.com/Taiko2k/GTK4PythonTutorial?tab=readme-ov-file
## mypy
https://mypy.readthedocs.io/en/latest/getting_started.html
```shell
mypy src/dndbuster/app.py
```
## Alternatives ## Alternatives
https://man.archlinux.org/man/notify-send.1.en https://man.archlinux.org/man/notify-send.1.en
@ -63,10 +77,5 @@ nix-shell -p libnotify
``` ```
```shell ```shell
sleep 30m sleep 30m
notify-send -u critical -a PleaseDisturbTimer "Alert" "Time is over!" notify-send -u critical -a PleaseDisturbTimer "Timeout" "The time is over and your do-not-disturb mode just got busted!"
``` ```
## GTK resources
- https://www.technett.io/post/dev/python-gtk-2/
- https://github.com/Taiko2k/GTK4PythonTutorial?tab=readme-ov-file

View File

@ -7,6 +7,9 @@
# Typing Stubs for PyGObject # Typing Stubs for PyGObject
pygobject-stubs pygobject-stubs
# Optional static typing for Python
mypy
# Not sure if required # Not sure if required
#dbus-python #dbus-python
])) ]))

View File

@ -15,17 +15,17 @@ def main():
class Application(Adw.Application): class Application(Adw.Application):
def __init__(self): def __init__(self) -> None:
super().__init__(application_id='de.p1st.dndbuster') super().__init__(application_id='de.p1st.dndbuster')
self.window: AppWindow | None = None self.window: AppWindow | None = None
def do_activate(self): def do_activate(self) -> None:
# Windows are associated with the application. # Windows are associated with the application.
# When the last one is closed the application shuts down. # When the last one is closed the application shuts down.
self.window = AppWindow(application=self) self.window = AppWindow(application=self)
self.window.present() self.window.present()
def notify_timer(self): def notify_timer(self) -> None:
notification = Gio.Notification() notification = Gio.Notification()
notification.set_title('Timeout') notification.set_title('Timeout')
notification.set_body('The time is over and your do-not-disturb mode just got busted!') notification.set_body('The time is over and your do-not-disturb mode just got busted!')
@ -34,7 +34,7 @@ class Application(Adw.Application):
class AppWindow(Gtk.ApplicationWindow): class AppWindow(Gtk.ApplicationWindow):
def __init__(self, application: Application): def __init__(self, application: Application) -> None:
super().__init__(application=application, title='DnDBuster') super().__init__(application=application, title='DnDBuster')
self.app = application self.app = application
@ -76,7 +76,7 @@ class AppWindow(Gtk.ApplicationWindow):
# Weather to continue regularly calling update_progress() # Weather to continue regularly calling update_progress()
return not self.timer.is_paused() return not self.timer.is_paused()
def on_button_start_restart_clicked(self, _widget): def on_button_start_restart_clicked(self, _widget) -> None:
if self.timer is None: if self.timer is None:
self.add_timer() self.add_timer()
@ -87,16 +87,16 @@ class AppWindow(Gtk.ApplicationWindow):
self.update_label() self.update_label()
def add_timer(self): def add_timer(self) -> None:
self.timer = Timer() self.timer = Timer()
self.timer.start() self.timer.start()
self.progress_bar.set_visible(True) self.progress_bar.set_visible(True)
self.add_timeout() self.add_timeout()
def add_timeout(self): def add_timeout(self) -> None:
GLib.timeout_add_seconds(1, self.update_progress) GLib.timeout_add_seconds(1, self.update_progress)
def on_button_pause_resume_clicked(self, _widget): def on_button_pause_resume_clicked(self, _widget) -> None:
if self.timer.is_paused(): if self.timer.is_paused():
self.timer.resume() self.timer.resume()
self.add_timeout() self.add_timeout()
@ -104,7 +104,7 @@ class AppWindow(Gtk.ApplicationWindow):
self.timer.pause() self.timer.pause()
self.update_label() self.update_label()
def update_label(self): def update_label(self) -> None:
if self.timer.is_paused(): if self.timer.is_paused():
self.button_pause_resume.set_label("Resume") self.button_pause_resume.set_label("Resume")
else: else:

View File

@ -2,11 +2,11 @@ import time
class Timer: class Timer:
def __init__(self): def __init__(self) -> None:
self.start_seconds = None self.start_seconds: float | None= None
self.pause_timer = None self.pause_timer: Timer | None = None
def start(self): def start(self) -> None:
""" """
Start time measurement Start time measurement
""" """
@ -19,20 +19,20 @@ class Timer:
""" """
return self.start_seconds is not None return self.start_seconds is not None
def pause(self): def pause(self) -> None:
""" """
Pause time measurement. Pause time measurement.
""" """
self.pause_timer = Timer() self.pause_timer = Timer()
self.pause_timer.start() self.pause_timer.start()
def is_paused(self): def is_paused(self) -> bool:
""" """
:return: Weather time measurement is paused. :return: Weather time measurement is paused.
""" """
return self.pause_timer is not None return self.pause_timer is not None
def resume(self): def resume(self) -> None:
""" """
Resumes time measurement. Resumes time measurement.
""" """
@ -41,7 +41,7 @@ class Timer:
self.start_seconds += pause_delta self.start_seconds += pause_delta
self.pause_timer = None self.pause_timer = None
def read(self): def read(self) -> float:
""" """
Return measured time in seconds. Return measured time in seconds.
""" """