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