Sprucing it up
This commit is contained in:
37
caltui.py
37
caltui.py
@@ -1,9 +1,33 @@
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.binding import Binding
|
||||
from textual.reactive import reactive
|
||||
from textual.widget import Widget
|
||||
from textual.widgets import Footer, Header, Label, ListItem, ListView
|
||||
|
||||
from main import get_next_ten
|
||||
|
||||
class CatlendarList(Widget):
|
||||
events = reactive("events", recompose=True)
|
||||
|
||||
def __init__(self, events):
|
||||
super().__init__()
|
||||
self.events = events
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
days = list(self.events.keys())
|
||||
today = self.events[days.pop(0)]
|
||||
yield Label("Today")
|
||||
yield ListView(
|
||||
*[ListItem(Label(event)) for event in today]
|
||||
)
|
||||
yield Label("Later")
|
||||
for day in days:
|
||||
day_events = self.events.get(day, [])
|
||||
yield ListView(
|
||||
*[ListItem(Label(event)) for event in day_events]
|
||||
)
|
||||
|
||||
|
||||
|
||||
class Catlendar(App):
|
||||
"""A Textual app to manage stopwatches."""
|
||||
@@ -11,17 +35,15 @@ class Catlendar(App):
|
||||
BINDINGS = [
|
||||
("d", "toggle_dark", "Toggle dark mode"),
|
||||
Binding(key="q", action="quit", description="Quit the app"),
|
||||
Binding(key="r", action="refresh_events", description="Refresh Google Calendar"),
|
||||
]
|
||||
CSS_PATH = "list_view.tcss"
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
"""Create child widgets for the app."""
|
||||
next_ten = get_next_ten()
|
||||
yield Header()
|
||||
for key, item in next_ten.items():
|
||||
yield Label(key)
|
||||
yield ListView(
|
||||
*[ListItem(Label(x)) for x in item]
|
||||
)
|
||||
yield CatlendarList(next_ten)
|
||||
yield Footer()
|
||||
|
||||
def action_toggle_dark(self) -> None:
|
||||
@@ -30,6 +52,11 @@ class Catlendar(App):
|
||||
"textual-dark" if self.theme == "textual-light" else "textual-light"
|
||||
)
|
||||
|
||||
def action_refresh_events(self) -> None:
|
||||
catlendar = self.query_one(CatlendarList)
|
||||
catlendar.loading = True
|
||||
catlendar.next_ten = get_next_ten()
|
||||
catlendar.loading = False
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = Catlendar()
|
||||
|
||||
Reference in New Issue
Block a user