11"""
2- tkinter_ui.py (v0.5)
3- --------------------
4- Improved teaching Tkinter UI for SchedPlus .
2+ tkinter_ui.py (v0.5 - DB compatible MVP )
3+ ----------------------------------------
4+ Minimal compatibility update for the new DB-backed scheduler .
55
6- Still intentionally simple, but with cleaner layout,
7- better spacing, and more readable structure.
6+ Full UI overhaul will happen in a separate issue.
87"""
98
109import tkinter as tk
@@ -16,21 +15,17 @@ def run_ui(scheduler):
1615 root = tk .Tk ()
1716 root .title ("SchedPlus v0.5 (Tkinter)" )
1817
19- # Center window
2018 root .geometry ("420x420" )
2119
22- # --- Main container ---
2320 container = ttk .Frame (root , padding = 15 )
2421 container .grid (row = 0 , column = 0 , sticky = "nsew" )
2522
2623 root .columnconfigure (0 , weight = 1 )
2724 root .rowconfigure (0 , weight = 1 )
2825
29- # --- Heading ---
3026 heading = ttk .Label (container , text = "Add a Task" , font = ("Segoe UI" , 12 , "bold" ))
3127 heading .grid (row = 0 , column = 0 , columnspan = 2 , pady = (0 , 10 ))
3228
33- # --- Input fields ---
3429 ttk .Label (container , text = "Date (YYYY-MM-DD):" ).grid (row = 1 , column = 0 , sticky = "w" , pady = 3 )
3530 date_entry = ttk .Entry (container , width = 25 )
3631 date_entry .grid (row = 1 , column = 1 , sticky = "ew" , pady = 3 )
@@ -43,46 +38,57 @@ def run_ui(scheduler):
4338 task_entry = ttk .Entry (container , width = 25 )
4439 task_entry .grid (row = 3 , column = 1 , sticky = "ew" , pady = 3 )
4540
46- # --- Add Task button ---
4741 add_button = ttk .Button (container , text = "Add Task" )
4842 add_button .grid (row = 4 , column = 0 , columnspan = 2 , pady = (10 , 15 ))
4943
50- # --- Task list frame ---
5144 list_frame = ttk .LabelFrame (container , text = "Tasks" , padding = 10 )
5245 list_frame .grid (row = 5 , column = 0 , columnspan = 2 , sticky = "nsew" )
5346
5447 container .rowconfigure (5 , weight = 1 )
5548 list_frame .rowconfigure (0 , weight = 1 )
5649 list_frame .columnconfigure (0 , weight = 1 )
5750
58- # --- Task list ---
5951 task_list = tk .Listbox (list_frame , width = 50 , height = 10 , borderwidth = 1 , relief = "solid" )
6052 task_list .grid (row = 0 , column = 0 , sticky = "nsew" )
6153
62- # Populate existing tasks
63- for task in scheduler .get_tasks ():
64- task_list .insert (tk .END , f"{ task .date } { task .time } - { task .text } " )
54+ # --- Populate tasks from DB ---
55+ for entry in scheduler .list_tasks ():
56+ # entry.due_date is ISO: "YYYY-MM-DDTHH:MM"
57+ date , time = _split_due_date (entry .due_date )
58+ task_list .insert (tk .END , f"{ date } { time } - { entry .title } " )
6559
6660 # --- Add Task logic ---
6761 def add_task ():
6862 date = date_entry .get ().strip ()
6963 time = time_entry .get ().strip ()
70- text = task_entry .get ().strip ()
64+ title = task_entry .get ().strip ()
7165
72- if date and time and text :
73- scheduler .add_task (date , time , text )
74- new_task = scheduler .get_tasks ()[- 1 ]
66+ if date and time and title :
67+ due_date = f"{ date } T{ time } "
7568
76- task_list .insert (tk .END , f"{ new_task .date } { new_task .time } - { new_task .text } " )
69+ scheduler .add_task (
70+ title = title ,
71+ description = None ,
72+ due_date = due_date ,
73+ )
7774
78- try :
79- scheduler . save_tasks ( )
80- except Exception :
81- pass
75+ new_entry = scheduler . list_tasks ()[ - 1 ]
76+ new_date , new_time = _split_due_date ( new_entry . due_date )
77+
78+ task_list . insert ( tk . END , f" { new_date } { new_time } - { new_entry . title } " )
8279
8380 task_entry .delete (0 , tk .END )
8481
8582 add_button .config (command = add_task )
8683 bind_enter_key ([date_entry , time_entry , task_entry ], add_task )
8784
8885 root .mainloop ()
86+
87+
88+ def _split_due_date (due_date : str ):
89+ """
90+ Helper: Convert ISO "YYYY-MM-DDTHH:MM" → ("YYYY-MM-DD", "HH:MM")
91+ """
92+ if due_date and "T" in due_date :
93+ return due_date .split ("T" , 1 )
94+ return ("" , "" )
0 commit comments