add mypy
This commit is contained in:
parent
f92a94d331
commit
05f6204ad2
23
README.md
23
README.md
@ -9,8 +9,9 @@ A timer that notifies you - even if "do not disturb" is enabled.
|
||||
* [ToC](#toc)
|
||||
* [Application IDs](#application-ids)
|
||||
* [.desktop entry](#desktop-entry)
|
||||
* [Alternatives](#alternatives)
|
||||
* [GTK resources](#gtk-resources)
|
||||
* [mypy](#mypy)
|
||||
* [Alternatives](#alternatives)
|
||||
<!-- TOC -->
|
||||
|
||||
## Application IDs
|
||||
@ -54,6 +55,19 @@ Categories=Game;
|
||||
|
||||
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
|
||||
|
||||
https://man.archlinux.org/man/notify-send.1.en
|
||||
@ -63,10 +77,5 @@ nix-shell -p libnotify
|
||||
```
|
||||
```shell
|
||||
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
|
||||
|
@ -7,6 +7,9 @@
|
||||
# Typing Stubs for PyGObject
|
||||
pygobject-stubs
|
||||
|
||||
# Optional static typing for Python
|
||||
mypy
|
||||
|
||||
# Not sure if required
|
||||
#dbus-python
|
||||
]))
|
||||
|
@ -15,17 +15,17 @@ def main():
|
||||
|
||||
|
||||
class Application(Adw.Application):
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
super().__init__(application_id='de.p1st.dndbuster')
|
||||
self.window: AppWindow | None = None
|
||||
|
||||
def do_activate(self):
|
||||
def do_activate(self) -> None:
|
||||
# Windows are associated with the application.
|
||||
# When the last one is closed the application shuts down.
|
||||
self.window = AppWindow(application=self)
|
||||
self.window.present()
|
||||
|
||||
def notify_timer(self):
|
||||
def notify_timer(self) -> None:
|
||||
notification = Gio.Notification()
|
||||
notification.set_title('Timeout')
|
||||
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):
|
||||
def __init__(self, application: Application):
|
||||
def __init__(self, application: Application) -> None:
|
||||
super().__init__(application=application, title='DnDBuster')
|
||||
|
||||
self.app = application
|
||||
@ -76,7 +76,7 @@ class AppWindow(Gtk.ApplicationWindow):
|
||||
# Weather to continue regularly calling update_progress()
|
||||
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:
|
||||
self.add_timer()
|
||||
|
||||
@ -87,16 +87,16 @@ class AppWindow(Gtk.ApplicationWindow):
|
||||
|
||||
self.update_label()
|
||||
|
||||
def add_timer(self):
|
||||
def add_timer(self) -> None:
|
||||
self.timer = Timer()
|
||||
self.timer.start()
|
||||
self.progress_bar.set_visible(True)
|
||||
self.add_timeout()
|
||||
|
||||
def add_timeout(self):
|
||||
def add_timeout(self) -> None:
|
||||
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():
|
||||
self.timer.resume()
|
||||
self.add_timeout()
|
||||
@ -104,7 +104,7 @@ class AppWindow(Gtk.ApplicationWindow):
|
||||
self.timer.pause()
|
||||
self.update_label()
|
||||
|
||||
def update_label(self):
|
||||
def update_label(self) -> None:
|
||||
if self.timer.is_paused():
|
||||
self.button_pause_resume.set_label("Resume")
|
||||
else:
|
||||
|
@ -2,11 +2,11 @@ import time
|
||||
|
||||
|
||||
class Timer:
|
||||
def __init__(self):
|
||||
self.start_seconds = None
|
||||
self.pause_timer = None
|
||||
def __init__(self) -> None:
|
||||
self.start_seconds: float | None= None
|
||||
self.pause_timer: Timer | None = None
|
||||
|
||||
def start(self):
|
||||
def start(self) -> None:
|
||||
"""
|
||||
Start time measurement
|
||||
"""
|
||||
@ -19,20 +19,20 @@ class Timer:
|
||||
"""
|
||||
return self.start_seconds is not None
|
||||
|
||||
def pause(self):
|
||||
def pause(self) -> None:
|
||||
"""
|
||||
Pause time measurement.
|
||||
"""
|
||||
self.pause_timer = Timer()
|
||||
self.pause_timer.start()
|
||||
|
||||
def is_paused(self):
|
||||
def is_paused(self) -> bool:
|
||||
"""
|
||||
:return: Weather time measurement is paused.
|
||||
"""
|
||||
return self.pause_timer is not None
|
||||
|
||||
def resume(self):
|
||||
def resume(self) -> None:
|
||||
"""
|
||||
Resumes time measurement.
|
||||
"""
|
||||
@ -41,7 +41,7 @@ class Timer:
|
||||
self.start_seconds += pause_delta
|
||||
self.pause_timer = None
|
||||
|
||||
def read(self):
|
||||
def read(self) -> float:
|
||||
"""
|
||||
Return measured time in seconds.
|
||||
"""
|
||||
|
Loading…
x
Reference in New Issue
Block a user