refactor: separate main.py

This commit is contained in:
Daniel Langbein 2025-02-23 21:31:20 +01:00
parent 32cbac3ad6
commit 150a5dd83b
Signed by: langfingaz
GPG Key ID: 6C47C753F0823002
2 changed files with 34 additions and 31 deletions

View File

@ -7,13 +7,6 @@ gi.require_version('Adw', '1')
from gi.repository import GLib, Gio, Gtk, Adw from gi.repository import GLib, Gio, Gtk, Adw
def main():
# Create a new application
app = Application()
# Run the application
app.run(None)
class Application(Adw.Application): class Application(Adw.Application):
def __init__(self) -> None: def __init__(self) -> None:
super().__init__(application_id='de.p1st.dndbuster') super().__init__(application_id='de.p1st.dndbuster')
@ -61,21 +54,6 @@ class AppWindow(Gtk.ApplicationWindow):
self.timer = Timer() self.timer = Timer()
def update_progress(self) -> bool:
total_min = 25
total_sec = total_min * 60
delta_sec = self.timer.read()
progress = delta_sec / total_sec
self.progress_bar.set_fraction(progress)
if progress >= 1:
self.app.send_notification_timeout()
# Stop regularly calling update_progress()
return False
# Weather to continue regularly calling update_progress()
return not self.timer.is_paused()
def on_button_start_restart_clicked(self, _widget) -> None: def on_button_start_restart_clicked(self, _widget) -> None:
if not self.timer.is_started(): if not self.timer.is_started():
self.reset_start_timer() self.reset_start_timer()
@ -87,15 +65,8 @@ class AppWindow(Gtk.ApplicationWindow):
self.update_label() self.update_label()
def reset_start_timer(self) -> None:
self.timer.reset()
self.timer.start()
self.progress_bar.set_visible(True)
self.add_timeout() self.add_timeout()
def add_timeout(self) -> None:
GLib.timeout_add_seconds(1, self.update_progress)
def on_button_pause_resume_clicked(self, _widget) -> None: 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()
@ -110,6 +81,26 @@ class AppWindow(Gtk.ApplicationWindow):
else: else:
self.button_pause_resume.set_label("Pause") self.button_pause_resume.set_label("Pause")
def reset_start_timer(self) -> None:
self.timer.reset()
self.timer.start()
self.progress_bar.set_visible(True)
if __name__ == '__main__': def add_timeout(self) -> None:
main() # Start regularly calling update_progress()
GLib.timeout_add_seconds(1, self.update_progress)
def update_progress(self) -> bool:
total_min = 0.1
total_sec = total_min * 60
delta_sec = self.timer.read()
progress = delta_sec / total_sec
self.progress_bar.set_fraction(progress)
if progress >= 1:
self.app.send_notification_timeout()
# Stop regularly calling update_progress()
return False
# Weather to continue regularly calling update_progress()
return not self.timer.is_paused()

12
src/dndbuster/main.py Normal file
View File

@ -0,0 +1,12 @@
from dndbuster.app import Application
def main():
# Create a new application
app = Application()
# Run the application
app.run(None)
if __name__ == '__main__':
main()