-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from harrymkt/main
Changed to GUI tool
- Loading branch information
Showing
4 changed files
with
91 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
tasks.json | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,95 @@ | ||
# To-Do List Manager | ||
import wx | ||
import json | ||
|
||
# Function to add a task to the to-do list | ||
def add_task(task): | ||
todo_list.append(task) | ||
print("Task added successfully!") | ||
def add_task(event): | ||
task = task_entry.GetValue() | ||
if task.strip(): | ||
todo_list.append(task) | ||
task_entry.Clear() | ||
update_list() | ||
save_tasks() | ||
wx.MessageBox("Task added successfully!", "Success", wx.OK | wx.ICON_INFORMATION) | ||
else: | ||
wx.MessageBox("Please enter a task.", "Error", wx.OK | wx.ICON_ERROR) | ||
|
||
# Function to mark a task as completed | ||
def complete_task(task_index): | ||
if 0 <= task_index < len(todo_list): | ||
todo_list[task_index] += " - Completed" | ||
print("Task marked as completed!") | ||
else: | ||
print("Invalid task index") | ||
def complete_task(event): | ||
task_index = task_list.GetSelection() | ||
if task_index != -1: | ||
todo_list[task_index] += " - Completed" | ||
update_list() | ||
save_tasks() | ||
wx.MessageBox("Task marked as completed!", "Success", wx.OK | wx.ICON_INFORMATION) | ||
else: | ||
wx.MessageBox("No task selected.", "Error", wx.OK | wx.ICON_ERROR) | ||
|
||
# Function to view the to-do list | ||
def view_list(): | ||
if todo_list: | ||
print("To-Do List:") | ||
for index, task in enumerate(todo_list): | ||
print(f"{index + 1}. {task}") | ||
else: | ||
print("Your to-do list is empty.") | ||
def update_list(): | ||
task_list.Clear() | ||
for task in todo_list: | ||
task_list.Append(task) | ||
|
||
# Function to remove a task from the to-do list | ||
def remove_task(task_index): | ||
if 0 <= task_index < len(todo_list): | ||
removed_task = todo_list.pop(task_index) | ||
print(f"Task '{removed_task}' removed successfully!") | ||
else: | ||
print("Invalid task index") | ||
def remove_task(event): | ||
task_index = task_list.GetSelection() | ||
if task_index != -1: | ||
removed_task = todo_list.pop(task_index) | ||
update_list() | ||
save_tasks() | ||
wx.MessageBox(f"Task '{removed_task}' removed successfully!", "Success", wx.OK | wx.ICON_INFORMATION) | ||
else: | ||
wx.MessageBox("No task selected.", "Error", wx.OK | wx.ICON_ERROR) | ||
|
||
# Function to save tasks to JSON file | ||
def save_tasks(): | ||
with open("tasks.json", "w") as file: | ||
json.dump(todo_list, file) | ||
|
||
# Function to load tasks from JSON file | ||
def load_tasks(): | ||
try: | ||
with open("tasks.json", "r") as file: | ||
return json.load(file) | ||
except FileNotFoundError: | ||
return [] | ||
|
||
# Main program | ||
todo_list = [] | ||
|
||
while True: | ||
print("\nMenu:") | ||
print("1. Add Task") | ||
print("2. Mark Task as Completed") | ||
print("3. View To-Do List") | ||
print("4. Remove Task") | ||
print("5. Exit") | ||
|
||
choice = input("Enter your choice (1-5): ") | ||
|
||
if choice == '1': | ||
task = input("Enter the task: ") | ||
add_task(task) | ||
elif choice == '2': | ||
task_index = int(input("Enter the index of the task to mark as completed: ")) - 1 | ||
complete_task(task_index) | ||
elif choice == '3': | ||
view_list() | ||
elif choice == '4': | ||
task_index = int(input("Enter the index of the task to remove: ")) - 1 | ||
remove_task(task_index) | ||
elif choice == '5': | ||
print("Exiting program. Goodbye!") | ||
break | ||
else: | ||
print("Invalid choice. Please enter a number from 1 to 5.") | ||
todo_list = load_tasks() | ||
|
||
app = wx.App() | ||
frame = wx.Frame(None, title="To-Do List Manager", size=(400, 400)) | ||
|
||
panel = wx.Panel(frame) | ||
|
||
task_label = wx.StaticText(panel, label="Enter Task:") | ||
task_entry = wx.TextCtrl(panel, style=wx.TE_MULTILINE) | ||
|
||
add_button = wx.Button(panel, label="Add Task") | ||
add_button.Bind(wx.EVT_BUTTON, add_task) | ||
|
||
complete_button = wx.Button(panel, label="Mark Task as Completed") | ||
complete_button.Bind(wx.EVT_BUTTON, complete_task) | ||
|
||
remove_button = wx.Button(panel, label="Remove Task") | ||
remove_button.Bind(wx.EVT_BUTTON, remove_task) | ||
|
||
list_title = wx.StaticText(panel, label="Tasks") | ||
task_list = wx.ListBox(panel, style=wx.LB_SINGLE | wx.LB_ALWAYS_SB) | ||
|
||
# Load tasks initially | ||
update_list() | ||
|
||
sizer = wx.BoxSizer(wx.VERTICAL) | ||
sizer.Add(task_label, 0, wx.ALL, 5) | ||
sizer.Add(task_entry, 0, wx.EXPAND | wx.ALL, 5) | ||
sizer.Add(add_button, 0, wx.ALL, 5) | ||
sizer.Add(complete_button, 0, wx.ALL, 5) | ||
sizer.Add(remove_button, 0, wx.ALL, 5) | ||
sizer.Add(list_title, 0, wx.LEFT | wx.TOP, 5) | ||
sizer.Add(task_list, 1, wx.EXPAND | wx.ALL, 5) | ||
|
||
panel.SetSizer(sizer) | ||
|
||
frame.Show() | ||
app.MainLoop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
## To-Do List | ||
|
||
A simple command-line tool that allows you to save your to-do list. For example, you can save tasks for today. | ||
A simple tool that allows you to save your to-do list. For example, you can save tasks for today. | ||
|
||
### Features | ||
|
||
- Currently, the tool has no features. | ||
- It does not save your to-do list yet. After opening the tool, you need to retype your to-do list. | ||
* simple with GUI dialogs. | ||
* Automatically saves your to-do list. | ||
|
||
### Feedback | ||
|
||
Any feedback is appreciated. If you have suggestions, you can open an issue on the repository page or send an email to hongjuntew@gmail.com. | ||
|
||
#### Pull Requests | ||
### Pull Requests | ||
|
||
Any pull requests are appreciated. I'll review and accept them when I have time. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
wxpython |