Enable auto-reading and auto-writing todo file.

No updating on file completion yet
This commit is contained in:
2025-11-30 22:55:18 -05:00
parent 89d4adc0e2
commit bc0ad8d4f8

View File

@@ -32,7 +32,7 @@ class Codupoc(App[None]):
def compose(self) -> ComposeResult:
yield Header()
yield VerticalScroll(id="list_items")
yield VerticalScroll(*self.load_todos_into_widgets(), id="list_items")
yield Footer()
def action_new_todo(self):
@@ -44,11 +44,13 @@ class Codupoc(App[None]):
def save_todo(self, value: str):
tinput = self.query_one("#newtodo")
tinput.remove()
todo = Checkbox(value)
scroller = self.query_one("#list_items")
scroller.mount(todo)
todo.scroll_visible()
todo.focus()
# todo = Checkbox(value)
scroller: VerticalScroll = self.query_one("#list_items")
# scroller.mount(todo)
# todo.scroll_visible()
# todo.focus()
self.insert_todo(value, scroller)
self.tmanager.write_todos(list(self.todos.values()))
def insert_todo(self, title: str, scroller: VerticalScroll):
ntodo = Todo(title, False)
@@ -57,12 +59,25 @@ class Codupoc(App[None]):
scroller.mount(todo)
todo.focus()
def load_todos_into_widgets(self) -> list[TodoItem]:
widgets = []
for t in self.todos.values():
nt = TodoItem(self, t, t.item, id=t.lid)
widgets.append(nt)
return widgets
def __init__(self):
super().__init__()
self.todos = {}
self.tmanager = TodoManager()
self.todos = self.tmanager.get_todos()
if __name__ == "__main__":
def main():
app = Codupoc()
app.run()
if __name__ == "__main__":
main()