screenshor plugin fix

This commit is contained in:
Will McGugan
2022-08-22 16:10:49 +01:00
parent 18f96d483c
commit 4dd4d18d2b
6 changed files with 161 additions and 51 deletions

View File

@@ -12,18 +12,19 @@ class TimeDisplay(Static):
start_time = Reactive(monotonic)
time = Reactive(0.0)
def watch_time(self, time: float) -> None:
"""Called when the time attribute changes."""
minutes, seconds = divmod(time - self.start_time, 60)
hours, minutes = divmod(minutes, 60)
self.update(f"{hours:02,.0f}:{minutes:02.0f}:{seconds:05.2f}")
def on_mount(self) -> None:
"""Event handler called when widget is added to the app."""
self.set_interval(1 / 30, self.update_time)
self.set_interval(1 / 60, self.update_time)
def update_time(self) -> None:
self.time = monotonic()
"""Method to update the time to the current time."""
self.time = monotonic() - self.start_time
def watch_time(self, time: float) -> None:
"""Called when the time attribute changes."""
minutes, seconds = divmod(time, 60)
hours, minutes = divmod(minutes, 60)
self.update(f"{hours:02,.0f}:{minutes:02.0f}:{seconds:05.2f}")
class Stopwatch(Static):
@@ -41,7 +42,7 @@ class Stopwatch(Static):
yield Button("Start", id="start", variant="success")
yield Button("Stop", id="stop", variant="error")
yield Button("Reset", id="reset")
yield TimeDisplay("00:00:00.00")
yield TimeDisplay()
class StopwatchApp(App):