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.app import App, ComposeResult
|
||||||
from textual.binding import Binding
|
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 textual.widgets import Footer, Header, Label, ListItem, ListView
|
||||||
|
|
||||||
from main import get_next_ten
|
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):
|
class Catlendar(App):
|
||||||
"""A Textual app to manage stopwatches."""
|
"""A Textual app to manage stopwatches."""
|
||||||
@@ -11,17 +35,15 @@ class Catlendar(App):
|
|||||||
BINDINGS = [
|
BINDINGS = [
|
||||||
("d", "toggle_dark", "Toggle dark mode"),
|
("d", "toggle_dark", "Toggle dark mode"),
|
||||||
Binding(key="q", action="quit", description="Quit the app"),
|
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:
|
def compose(self) -> ComposeResult:
|
||||||
"""Create child widgets for the app."""
|
"""Create child widgets for the app."""
|
||||||
next_ten = get_next_ten()
|
next_ten = get_next_ten()
|
||||||
yield Header()
|
yield Header()
|
||||||
for key, item in next_ten.items():
|
yield CatlendarList(next_ten)
|
||||||
yield Label(key)
|
|
||||||
yield ListView(
|
|
||||||
*[ListItem(Label(x)) for x in item]
|
|
||||||
)
|
|
||||||
yield Footer()
|
yield Footer()
|
||||||
|
|
||||||
def action_toggle_dark(self) -> None:
|
def action_toggle_dark(self) -> None:
|
||||||
@@ -30,6 +52,11 @@ class Catlendar(App):
|
|||||||
"textual-dark" if self.theme == "textual-light" else "textual-light"
|
"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__":
|
if __name__ == "__main__":
|
||||||
app = Catlendar()
|
app = Catlendar()
|
||||||
|
|||||||
17
list_view.tcss
Normal file
17
list_view.tcss
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
Screen {
|
||||||
|
text-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
ListView {
|
||||||
|
height: auto;
|
||||||
|
text-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
ListItem {
|
||||||
|
text-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
Label {
|
||||||
|
width: auto;
|
||||||
|
text-wrap: wrap;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user