Enable auto-reading and auto-writing todo file.
No updating on file completion yet
This commit is contained in:
@@ -32,7 +32,7 @@ class Codupoc(App[None]):
|
|||||||
|
|
||||||
def compose(self) -> ComposeResult:
|
def compose(self) -> ComposeResult:
|
||||||
yield Header()
|
yield Header()
|
||||||
yield VerticalScroll(id="list_items")
|
yield VerticalScroll(*self.load_todos_into_widgets(), id="list_items")
|
||||||
yield Footer()
|
yield Footer()
|
||||||
|
|
||||||
def action_new_todo(self):
|
def action_new_todo(self):
|
||||||
@@ -44,11 +44,13 @@ class Codupoc(App[None]):
|
|||||||
def save_todo(self, value: str):
|
def save_todo(self, value: str):
|
||||||
tinput = self.query_one("#newtodo")
|
tinput = self.query_one("#newtodo")
|
||||||
tinput.remove()
|
tinput.remove()
|
||||||
todo = Checkbox(value)
|
# todo = Checkbox(value)
|
||||||
scroller = self.query_one("#list_items")
|
scroller: VerticalScroll = self.query_one("#list_items")
|
||||||
scroller.mount(todo)
|
# scroller.mount(todo)
|
||||||
todo.scroll_visible()
|
# todo.scroll_visible()
|
||||||
todo.focus()
|
# todo.focus()
|
||||||
|
self.insert_todo(value, scroller)
|
||||||
|
self.tmanager.write_todos(list(self.todos.values()))
|
||||||
|
|
||||||
def insert_todo(self, title: str, scroller: VerticalScroll):
|
def insert_todo(self, title: str, scroller: VerticalScroll):
|
||||||
ntodo = Todo(title, False)
|
ntodo = Todo(title, False)
|
||||||
@@ -57,12 +59,25 @@ class Codupoc(App[None]):
|
|||||||
scroller.mount(todo)
|
scroller.mount(todo)
|
||||||
todo.focus()
|
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):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.todos = {}
|
self.tmanager = TodoManager()
|
||||||
|
self.todos = self.tmanager.get_todos()
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
app = Codupoc()
|
||||||
|
app.run()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app = Codupoc()
|
main()
|
||||||
app.run()
|
|
||||||
Reference in New Issue
Block a user