1- # pyqt_ui.py (v0.1)
2- # -----------------
3- # Teaching PyQt UI for SchedPlus .
4- # Mirrors the Tkinter UI but with a cleaner layout and modern widgets .
1+ # pyqt_ui.py (v0.1 - DB compatible MVP )
2+ # -------------------------------------
3+ # Minimal compatibility update for the new DB-backed scheduler .
4+ # Full UI overhaul will happen in a separate issue .
55
66from PyQt6 .QtWidgets import (
77 QApplication , QMainWindow , QWidget , QVBoxLayout , QHBoxLayout ,
@@ -51,26 +51,25 @@ def __init__(self, scheduler):
5151
5252 self .setWindowTitle ("SchedPlus v0.5 (PyQt)" )
5353
54- # --- Status Bar (initialize first) ---
54+ # --- Status Bar ---
5555 self .statusBar ().showMessage ("" )
5656 self .status_timer = QTimer ()
5757 self .status_timer .setSingleShot (True )
5858 self .status_timer .timeout .connect (self .clear_status_message )
5959
60- # Create central widget and main layout
60+ # --- Layout ---
6161 central_widget = QWidget ()
6262 main_layout = QVBoxLayout (central_widget )
6363
6464 # --- Task List ---
6565 self .task_list = QListWidget ()
6666 main_layout .addWidget (self .task_list )
6767
68- for task in scheduler . get_tasks ():
69- self . task_list . addItem (
70- f" { task . date } { task . time } - { task . text } "
71- )
68+ # Populate tasks from DB
69+ for entry in scheduler . list_tasks ():
70+ date , time = self . _split_due_date ( entry . due_date )
71+ self . task_list . addItem ( f" { date } { time } - { entry . title } " )
7272
73- # Display tasks loaded feedback
7473 self .show_status_message ("Tasks loaded" )
7574
7675 # --- Add Task Button ---
@@ -81,34 +80,55 @@ def __init__(self, scheduler):
8180 central_widget .setLayout (main_layout )
8281 self .setCentralWidget (central_widget )
8382
83+ # ---------------------------------------------------------
84+ # Status Bar Helpers
85+ # ---------------------------------------------------------
86+
8487 def show_status_message (self , message , duration_ms = 3000 ):
85- """Display a status message that auto-clears after the specified duration."""
8688 self .statusBar ().showMessage (message )
8789 self .status_timer .stop ()
8890 self .status_timer .start (duration_ms )
8991
9092 def clear_status_message (self ):
91- """Clear the status bar message."""
9293 self .statusBar ().clearMessage ()
9394
95+ # ---------------------------------------------------------
96+ # Add Task Dialog
97+ # ---------------------------------------------------------
98+
9499 def open_add_dialog (self ):
95100 dialog = AddTaskDialog ()
96101 if dialog .exec () == QDialog .DialogCode .Accepted :
97102 date , time , text = dialog .get_values ()
98103
99104 if date and time and text :
100- self .scheduler .add_task (date , time , text )
105+ due_date = f"{ date } T{ time } "
106+
107+ # DB-backed add
108+ self .scheduler .add_task (
109+ title = text ,
110+ description = None ,
111+ due_date = due_date ,
112+ )
113+
114+ new_entry = self .scheduler .list_tasks ()[- 1 ]
115+ new_date , new_time = self ._split_due_date (new_entry .due_date )
101116
102- new_task = self .scheduler .get_tasks ()[- 1 ]
103117 self .task_list .addItem (
104- f"{ new_task . date } { new_task . time } - { new_task . text } "
118+ f"{ new_date } { new_time } - { new_entry . title } "
105119 )
106120
107- try :
108- self .scheduler .save_tasks ()
109- self .show_status_message ("Task saved" )
110- except Exception as e :
111- self .show_status_message (f"Error saving task: { str (e )} " )
121+ self .show_status_message ("Task added" )
122+
123+ # ---------------------------------------------------------
124+ # Helpers
125+ # ---------------------------------------------------------
126+
127+ def _split_due_date (self , due_date : str ):
128+ """Convert ISO 'YYYY-MM-DDTHH:MM' → ('YYYY-MM-DD', 'HH:MM')"""
129+ if due_date and "T" in due_date :
130+ return due_date .split ("T" , 1 )
131+ return ("" , "" )
112132
113133
114134def run_pyqt_ui (scheduler ):
0 commit comments