-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathissue_push_screen_twice.py
More file actions
68 lines (52 loc) · 1.54 KB
/
Copy pathissue_push_screen_twice.py
File metadata and controls
68 lines (52 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import time
from textual import on, work
from textual.app import App, ComposeResult
from textual.events import ScreenResume
from textual.screen import ModalScreen
from textual.widgets import Button, LoadingIndicator, Static
from textual.worker import Worker, WorkerState
class Task(ModalScreen):
def __init__(self, title: str) -> None:
super().__init__()
self.title = title
def compose(self) -> ComposeResult:
yield Button("Close")
yield LoadingIndicator()
@on(Button.Pressed)
def close(self, event: Button.Pressed) -> None:
self.dismiss()
class TaskButton(Button):
def __init__(self, task: Task) -> None:
super().__init__()
self.task_ = task
self.label = task.title
@on(Button.Pressed)
def execute(self):
self.app.push_screen(self.task_)
class SpeedRunApp(App[None]):
CSS = """
Screen, ModalScreen {
height: 100%;
align: center middle;
}
Static {
text-align: center;
}
LoadingIndicator {
height: auto;
}
"""
def compose(self) -> ComposeResult:
for i in range(1, 4):
yield TaskButton(Task(f"Task {i}"))
yield Button("Run all", id="speedrun")
@on(Button.Pressed, "#speedrun")
def execute(self):
# task = self.query_one("#task0")
task = TaskButton("Speedrun")
self.mount(task)
task.loading = True
task.run_task()
app = SpeedRunApp()
if __name__ == "__main__":
app.run()