Skip to content

Commit

Permalink
#102 ToDo
Browse files Browse the repository at this point in the history
  • Loading branch information
rohankishore committed Dec 16, 2024
1 parent 76fd38f commit c71e148
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 22 deletions.
62 changes: 41 additions & 21 deletions auratext/Components/ToDo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import csv
from PyQt6.QtWidgets import (
QApplication, QMainWindow, QVBoxLayout, QWidget,
QListWidget, QPushButton, QHBoxLayout, QMessageBox, QDialog
QListWidget, QPushButton, QHBoxLayout, QMessageBox, QDialog, QLineEdit
)
from PyQt6.QtCore import Qt

Expand Down Expand Up @@ -43,7 +43,7 @@ def __init__(self):
super().__init__()

self.setWindowTitle("To-Do List")
self.resize(400, 300)
self.resize(400, 400)

# Central widget setup

Expand All @@ -67,22 +67,36 @@ def __init__(self):
self.refresh_button.clicked.connect(self.load_tasks)
self.button_layout.addWidget(self.refresh_button)

# Input field for adding tasks
self.add_task_layout = QHBoxLayout()
self.layout.addLayout(self.add_task_layout)

self.task_input = QLineEdit()
self.task_input.setPlaceholderText("Enter a new task")
self.add_task_layout.addWidget(self.task_input)

self.add_task_button = QPushButton("Add Task")
self.add_task_button.clicked.connect(self.add_task)
self.add_task_layout.addWidget(self.add_task_button)

# Load tasks from the CSV file
self.load_tasks()

def load_tasks(self):
"""Load tasks from the CSV file into the list widget."""
self.list_widget.clear()
try:
with open(f"{cpath}/Aura Text/todo.csv", "r", newline="") as file:
with open(CSV_FILE, "r", newline="") as file:
reader = csv.reader(file)
for row in reader:
if len(row) != 2:
continue
task, status = row
display_text = f"{task} [{status}]"
self.list_widget.addItem(display_text)
except FileNotFoundError:
create_folder(f"{cpath}/Aura Text/")
with open(f"{cpath}/Aura Text/todo.csv", "w", newline="") as file:
with open(CSV_FILE, "w", newline="") as file:
writer = csv.writer(file)
# Add default rows or leave empty
writer.writerow(["Task", "Status"])
Expand All @@ -105,6 +119,8 @@ def mark_as_complete(self):
with open(CSV_FILE, "r", newline="") as file:
reader = csv.reader(file)
for row in reader:
if len(row) != 2:
continue
task, status = row
if task == task_name:
updated_rows.append([task, "Complete"])
Expand All @@ -121,29 +137,33 @@ def mark_as_complete(self):
self.load_tasks()

except FileNotFoundError:
with open(f"{cpath}/Aura Text/todo.csv", "w", newline="") as file:
with open(CSV_FILE, "w", newline="") as file:
writer = csv.writer(file)
# Add default rows or leave empty
writer.writerow(["Task", "Status"])
writer.writerow(["Sample Task 1", "Incomplete"])
writer.writerow(["Sample Task 2", "Incomplete"])
print(f"File created successfully.")

def add_task(self):
"""Add a new task to the to-do list and update the CSV file."""
task_name = self.task_input.text().strip()
if not task_name:
QMessageBox.warning(self, "Warning", "Task name cannot be empty.")
return

if __name__ == "__main__":
app = QApplication(sys.argv)
try:
with open(CSV_FILE, "a", newline="") as file:
writer = csv.writer(file)
writer.writerow([task_name, "Incomplete"])

# Create the CSV file with some default tasks if it doesn't exist
try:
with open(CSV_FILE, "x", newline="") as file:
writer = csv.writer(file)
writer.writerow(["Buy groceries", "Incomplete"])
writer.writerow(["Complete Python project", "Incomplete"])
writer.writerow(["Call mom", "Incomplete"])
except FileExistsError:
pass

window = ToDoApp()
window.show()

sys.exit(app.exec())
QMessageBox.information(self, "Success", f"Task '{task_name}' added successfully.")

# Clear the input field
self.task_input.clear()

# Refresh the list
self.load_tasks()

except Exception as e:
QMessageBox.critical(self, "Error", f"Failed to add task: {e}")
3 changes: 2 additions & 1 deletion auratext/Core/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,8 @@ def notes(self):
note_dock.show()

def todo(self):
todo_widget = ToDo.ToDoApp()
todo_dialog = ToDo.ToDoApp()
todo_dialog.exec()

def redo_document(self):
self.current_editor.redo()
Expand Down

0 comments on commit c71e148

Please sign in to comment.