4 Commits

Author SHA1 Message Date
celex a6e3738b7a add textual app skeleton 2026-05-18 16:28:17 +02:00
celex c7f8016c4b add textual as a dependancy 2026-05-18 16:26:59 +02:00
celex b8e2052549 rename done to is_done 2026-05-18 16:18:11 +02:00
celex 926669f28f add basic database functionality 2026-05-18 16:16:40 +02:00
4 changed files with 64 additions and 3 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
[project]
name="chore-manager"
dynamic = ["version"]
dependencies = []
dependencies = ["textual"]
requires-python = ">=3.13"
readme = "README.md"
+50
View File
@@ -0,0 +1,50 @@
import sqlite3
from pathlib import Path
import os
from dataclasses import dataclass, fields
@dataclass
class Task:
title: str
is_done: bool
def __post_init__(self):
for field in fields(self):
if field.type is bool:
value = getattr(self, field.name)
setattr(self, field.name, bool(value))
class Database:
def __init__(self, filepath: Path|str):
is_new_database = not Path(filepath).exists()
self.con = sqlite3.connect(filepath)
self.cur = self.con.cursor()
if is_new_database:
self.initialize_table()
def initialize_table(self):
self.cur.execute("CREATE TABLE tasks(title TEXT, is_done INTEGER)")
def create_task(self, title: str, done:bool=False) -> None:
converted_done = ""
if done:
converted_done = "TRUE"
else:
converted_done = "FALSE"
self.cur.execute(f"""INSERT INTO tasks VALUES ("{title}", {converted_done});""")
self.con.commit()
def get_all_tasks(self) -> list[Task]:
self.cur.execute("SELECT * FROM tasks")
raw_data = self.cur.fetchall()
return [Task(*task) for task in raw_data]
if __name__ == '__main__':
try:
os.remove("DEBUG.db")
except FileNotFoundError:
pass
database = Database("DEBUG.db")
database.create_task("test")
print(database.get_all_tasks())
+4 -2
View File
@@ -1,3 +1,5 @@
from .tui import ChoreManagerTui
def main_tui() -> None:
print("Hello World")
app = ChoreManagerTui()
app.run()
+9
View File
@@ -0,0 +1,9 @@
from textual.app import App, ComposeResult
from textual.widgets import Header
class ChoreManagerTui(App):
def compose(self) -> ComposeResult:
yield Header()