Begin integrating manager into main app
This commit is contained in:
@@ -4,6 +4,8 @@ from textual.widgets import Checkbox, Input, Header, Footer
|
||||
|
||||
from base64_random import gen_random_base64
|
||||
|
||||
from todo import Todo
|
||||
|
||||
class NewTodo(Input):
|
||||
def on_input_submitted(self, event: Input.Submitted) -> None:
|
||||
self.main_app.save_todo(event.value)
|
||||
@@ -14,9 +16,10 @@ class NewTodo(Input):
|
||||
|
||||
|
||||
class TodoItem(Checkbox):
|
||||
def __init__(self, main_app: Codupoc, *args, **kwargs):
|
||||
def __init__(self, main_app: Codupoc, todo: Todo, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.main_app = main_app
|
||||
self.todo = todo
|
||||
|
||||
|
||||
class Codupoc(App[None]):
|
||||
@@ -47,9 +50,9 @@ class Codupoc(App[None]):
|
||||
todo.focus()
|
||||
|
||||
def insert_todo(self, title: str, scroller: VerticalScroll):
|
||||
todo_id = gen_random_base64(10)
|
||||
self.todos[todo_id] = { "title": title, "completed": False }
|
||||
todo = TodoItem(self, title, id=todo_id)
|
||||
ntodo = Todo(title, False)
|
||||
self.todos[ntodo.lid] = ntodo
|
||||
todo = TodoItem(self, ntodo, title, id=ntodo.lid)
|
||||
scroller.mount(todo)
|
||||
todo.focus()
|
||||
|
||||
|
||||
@@ -24,4 +24,7 @@ class TodoManager:
|
||||
for line in f:
|
||||
todos.append(parse_todo(line))
|
||||
|
||||
return todos
|
||||
return todos
|
||||
|
||||
def close_todo_file(self):
|
||||
self.file.close()
|
||||
Reference in New Issue
Block a user