mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
screenshor plugin fix
This commit is contained in:
@@ -9,15 +9,9 @@ from textual.widgets import Button, Header, Footer, Static
|
||||
class TimeDisplay(Static):
|
||||
"""A widget to display elapsed time."""
|
||||
|
||||
total = Reactive(0.0)
|
||||
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, 60)
|
||||
hours, minutes = divmod(minutes, 60)
|
||||
self.update(f"{hours:02,.0f}:{minutes:02.0f}:{seconds:05.2f}")
|
||||
total = Reactive(0.0)
|
||||
|
||||
def on_mount(self) -> None:
|
||||
"""Event handler called when widget is added to the app."""
|
||||
@@ -27,6 +21,12 @@ class TimeDisplay(Static):
|
||||
"""Method to update time to current."""
|
||||
self.time = self.total + (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}")
|
||||
|
||||
def start(self) -> None:
|
||||
"""Method to start (or resume) time updating."""
|
||||
self.start_time = monotonic()
|
||||
@@ -41,21 +41,21 @@ class TimeDisplay(Static):
|
||||
def reset(self):
|
||||
"""Method to reset the time display to zero."""
|
||||
self.total = 0
|
||||
self.time = self.start_time
|
||||
self.time = 0
|
||||
|
||||
|
||||
class Stopwatch(Static):
|
||||
"""A Textual app to manage stopwatches."""
|
||||
|
||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
||||
"""Event handler called when a button is pressed."""
|
||||
time_display = self.query_one(TimeDisplay)
|
||||
if event.button.id == "start":
|
||||
time_display.start()
|
||||
self.add_class("started")
|
||||
self.query_one("#stop").focus()
|
||||
elif event.button.id == "stop":
|
||||
time_display.stop()
|
||||
self.remove_class("started")
|
||||
self.query_one("#start").focus()
|
||||
elif event.button.id == "reset":
|
||||
time_display.reset()
|
||||
|
||||
@@ -64,7 +64,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):
|
||||
|
||||
Reference in New Issue
Block a user