-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpoc2_textual.py
executable file
·60 lines (40 loc) · 1.36 KB
/
poc2_textual.py
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
#!/usr/bin/env python3
"""poc2_textual.py - Demonstrate use of Textual and our base widget
"""
import asyncio
from textual.app import App, ComposeResult
from textual.containers import Horizontal, Vertical
from textual.widgets import Footer
from demo_helpers import OrderNumber, new_order, pretty_order
from demo_helpers import DemoWidget
class OurWidget(DemoWidget):
async def background_task(self):
while True:
await self.make_order()
async def make_order(self):
order = await new_order()
order['count'] = count = await OrderNumber.get_next_order_number()
self.add_line(f'Order {count}: {pretty_order(order)}')
async def on_mount(self):
asyncio.create_task(self.background_task())
class MyGridApp(App):
BINDINGS = [
("q", "quit()", "Quit"),
]
def compose(self) -> ComposeResult:
with Horizontal():
with Vertical():
yield OurWidget('Widget 1')
yield OurWidget('Widget 2')
with Vertical():
yield OurWidget('Widget 3')
# And just the bare DemoWidget, to show it does *something*
yield DemoWidget('DemoWidget')
yield Footer()
def main():
"""A demonstration of our Textual widget
"""
app = MyGridApp()
app.run()
if __name__ == '__main__':
main()