64 lines
1.9 KiB
Python
64 lines
1.9 KiB
Python
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."""
|
|
|
|
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()
|
|
yield CatlendarList(next_ten)
|
|
yield Footer()
|
|
|
|
def action_toggle_dark(self) -> None:
|
|
"""An action to toggle dark mode."""
|
|
self.theme = (
|
|
"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()
|
|
app.run()
|