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 9960934 commit 76fd38f
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions auratext/Components/ToDo.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ def create_folder(folder_path):
print(f"Failed to create folder '{folder_path}': {e}")


if check_folder_exists(f"{cpath}/AuraText/"):
if check_folder_exists(f"{cpath}/Aura Text/"):
pass
else:
create_folder(f"{cpath}/AuraText")
create_folder(f"{cpath}/Aura Text")
# Path to the CSV file
CSV_FILE = "tasks.csv"
CSV_FILE = f"{cpath}/Aura Text/todo.csv"


class ToDoApp(QDialog):
Expand Down Expand Up @@ -74,14 +74,21 @@ def load_tasks(self):
"""Load tasks from the CSV file into the list widget."""
self.list_widget.clear()
try:
with open(CSV_FILE, "r", newline="") as file:
with open(f"{cpath}/Aura Text/todo.csv", "r", newline="") as file:
reader = csv.reader(file)
for row in reader:
task, status = row
display_text = f"{task} [{status}]"
self.list_widget.addItem(display_text)
except FileNotFoundError:
QMessageBox.warning(self, "Error", f"The file '{CSV_FILE}' does not exist.")
create_folder(f"{cpath}/Aura Text/")
with open(f"{cpath}/Aura Text/todo.csv", "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 mark_as_complete(self):
"""Mark the selected task as complete and update the CSV file."""
Expand Down Expand Up @@ -114,7 +121,13 @@ def mark_as_complete(self):
self.load_tasks()

except FileNotFoundError:
QMessageBox.warning(self, "Error", f"The file '{CSV_FILE}' does not exist.")
with open(f"{cpath}/Aura Text/todo.csv", "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.")


if __name__ == "__main__":
Expand Down

0 comments on commit 76fd38f

Please sign in to comment.