refactor: separate main.py
This commit is contained in:
parent
32cbac3ad6
commit
150a5dd83b
@ -7,13 +7,6 @@ gi.require_version('Adw', '1')
|
||||
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):
|
||||
def __init__(self) -> None:
|
||||
super().__init__(application_id='de.p1st.dndbuster')
|
||||
@ -61,21 +54,6 @@ class AppWindow(Gtk.ApplicationWindow):
|
||||
|
||||
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:
|
||||
if not self.timer.is_started():
|
||||
self.reset_start_timer()
|
||||
@ -87,15 +65,8 @@ class AppWindow(Gtk.ApplicationWindow):
|
||||
|
||||
self.update_label()
|
||||
|
||||
def reset_start_timer(self) -> None:
|
||||
self.timer.reset()
|
||||
self.timer.start()
|
||||
self.progress_bar.set_visible(True)
|
||||
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:
|
||||
if self.timer.is_paused():
|
||||
self.timer.resume()
|
||||
@ -110,6 +81,26 @@ class AppWindow(Gtk.ApplicationWindow):
|
||||
else:
|
||||
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__':
|
||||
main()
|
||||
def add_timeout(self) -> None:
|
||||
# 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
12
src/dndbuster/main.py
Normal 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()
|
Loading…
x
Reference in New Issue
Block a user