Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 41 additions & 21 deletions src/ui/pyqt_ui.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# pyqt_ui.py (v0.1)
# -----------------
# Teaching PyQt UI for SchedPlus.
# Mirrors the Tkinter UI but with a cleaner layout and modern widgets.
# pyqt_ui.py (v0.1 - DB compatible MVP)
# -------------------------------------
# Minimal compatibility update for the new DB-backed scheduler.
# Full UI overhaul will happen in a separate issue.

from PyQt6.QtWidgets import (
QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout,
Expand Down Expand Up @@ -51,26 +51,25 @@ def __init__(self, scheduler):

self.setWindowTitle("SchedPlus v0.5 (PyQt)")

# --- Status Bar (initialize first) ---
# --- Status Bar ---
self.statusBar().showMessage("")
self.status_timer = QTimer()
self.status_timer.setSingleShot(True)
self.status_timer.timeout.connect(self.clear_status_message)

# Create central widget and main layout
# --- Layout ---
central_widget = QWidget()
main_layout = QVBoxLayout(central_widget)

# --- Task List ---
self.task_list = QListWidget()
main_layout.addWidget(self.task_list)

for task in scheduler.get_tasks():
self.task_list.addItem(
f"{task.date} {task.time} - {task.text}"
)
# Populate tasks from DB
for entry in scheduler.list_tasks():
date, time = self._split_due_date(entry.due_date)
self.task_list.addItem(f"{date} {time} - {entry.title}")

# Display tasks loaded feedback
self.show_status_message("Tasks loaded")

# --- Add Task Button ---
Expand All @@ -81,34 +80,55 @@ def __init__(self, scheduler):
central_widget.setLayout(main_layout)
self.setCentralWidget(central_widget)

# ---------------------------------------------------------
# Status Bar Helpers
# ---------------------------------------------------------

def show_status_message(self, message, duration_ms=3000):
"""Display a status message that auto-clears after the specified duration."""
self.statusBar().showMessage(message)
self.status_timer.stop()
self.status_timer.start(duration_ms)

def clear_status_message(self):
"""Clear the status bar message."""
self.statusBar().clearMessage()

# ---------------------------------------------------------
# Add Task Dialog
# ---------------------------------------------------------

def open_add_dialog(self):
dialog = AddTaskDialog()
if dialog.exec() == QDialog.DialogCode.Accepted:
date, time, text = dialog.get_values()

if date and time and text:
self.scheduler.add_task(date, time, text)
due_date = f"{date}T{time}"

# DB-backed add
self.scheduler.add_task(
title=text,
description=None,
due_date=due_date,
)

new_entry = self.scheduler.list_tasks()[-1]
new_date, new_time = self._split_due_date(new_entry.due_date)

new_task = self.scheduler.get_tasks()[-1]
self.task_list.addItem(
f"{new_task.date} {new_task.time} - {new_task.text}"
f"{new_date} {new_time} - {new_entry.title}"
)

try:
self.scheduler.save_tasks()
self.show_status_message("Task saved")
except Exception as e:
self.show_status_message(f"Error saving task: {str(e)}")
self.show_status_message("Task added")

# ---------------------------------------------------------
# Helpers
# ---------------------------------------------------------

def _split_due_date(self, due_date: str):
"""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 ("", "")


def run_pyqt_ui(scheduler):
Expand Down
Loading