diff --git a/src/ui/tkinter_ui.py b/src/ui/tkinter_ui.py index b642504..05d36e7 100644 --- a/src/ui/tkinter_ui.py +++ b/src/ui/tkinter_ui.py @@ -1,10 +1,9 @@ """ -tkinter_ui.py (v0.5) --------------------- -Improved teaching Tkinter UI for SchedPlus. +tkinter_ui.py (v0.5 - DB compatible MVP) +---------------------------------------- +Minimal compatibility update for the new DB-backed scheduler. -Still intentionally simple, but with cleaner layout, -better spacing, and more readable structure. +Full UI overhaul will happen in a separate issue. """ import tkinter as tk @@ -16,21 +15,17 @@ def run_ui(scheduler): root = tk.Tk() root.title("SchedPlus v0.5 (Tkinter)") - # Center window root.geometry("420x420") - # --- Main container --- container = ttk.Frame(root, padding=15) container.grid(row=0, column=0, sticky="nsew") root.columnconfigure(0, weight=1) root.rowconfigure(0, weight=1) - # --- Heading --- heading = ttk.Label(container, text="Add a Task", font=("Segoe UI", 12, "bold")) heading.grid(row=0, column=0, columnspan=2, pady=(0, 10)) - # --- Input fields --- ttk.Label(container, text="Date (YYYY-MM-DD):").grid(row=1, column=0, sticky="w", pady=3) date_entry = ttk.Entry(container, width=25) date_entry.grid(row=1, column=1, sticky="ew", pady=3) @@ -43,11 +38,9 @@ def run_ui(scheduler): task_entry = ttk.Entry(container, width=25) task_entry.grid(row=3, column=1, sticky="ew", pady=3) - # --- Add Task button --- add_button = ttk.Button(container, text="Add Task") add_button.grid(row=4, column=0, columnspan=2, pady=(10, 15)) - # --- Task list frame --- list_frame = ttk.LabelFrame(container, text="Tasks", padding=10) list_frame.grid(row=5, column=0, columnspan=2, sticky="nsew") @@ -55,30 +48,34 @@ def run_ui(scheduler): list_frame.rowconfigure(0, weight=1) list_frame.columnconfigure(0, weight=1) - # --- Task list --- task_list = tk.Listbox(list_frame, width=50, height=10, borderwidth=1, relief="solid") task_list.grid(row=0, column=0, sticky="nsew") - # Populate existing tasks - for task in scheduler.get_tasks(): - task_list.insert(tk.END, f"{task.date} {task.time} - {task.text}") + # --- Populate tasks from DB --- + for entry in scheduler.list_tasks(): + # entry.due_date is ISO: "YYYY-MM-DDTHH:MM" + date, time = _split_due_date(entry.due_date) + task_list.insert(tk.END, f"{date} {time} - {entry.title}") # --- Add Task logic --- def add_task(): date = date_entry.get().strip() time = time_entry.get().strip() - text = task_entry.get().strip() + title = task_entry.get().strip() - if date and time and text: - scheduler.add_task(date, time, text) - new_task = scheduler.get_tasks()[-1] + if date and time and title: + due_date = f"{date}T{time}" - task_list.insert(tk.END, f"{new_task.date} {new_task.time} - {new_task.text}") + scheduler.add_task( + title=title, + description=None, + due_date=due_date, + ) - try: - scheduler.save_tasks() - except Exception: - pass + new_entry = scheduler.list_tasks()[-1] + new_date, new_time = _split_due_date(new_entry.due_date) + + task_list.insert(tk.END, f"{new_date} {new_time} - {new_entry.title}") task_entry.delete(0, tk.END) @@ -86,3 +83,12 @@ def add_task(): bind_enter_key([date_entry, time_entry, task_entry], add_task) root.mainloop() + + +def _split_due_date(due_date: str): + """ + Helper: Convert ISO "YYYY-MM-DDTHH:MM" → ("YYYY-MM-DD", "HH:MM") + """ + if due_date and "T" in due_date: + return due_date.split("T", 1) + return ("", "")