Simple Task Manager Update (20/12/22)

First versions of Simple Task Manager
Day 1

VS

Simple Task Manager 20/12/22
Now

There is a lot to talk about in this update, as you can see a lot has changed since day 1. I will try keep this brief and not bore you with all the details.

The Updates (Summary)

  • Implemented a Treeview widget which contains three columns (Task, Due Date, Tag)
  • Implemented a calendar widget which allows the user to pick a due date from a calendar GUI when clicked.
  • Added a “Remove Task” button that when clicked will remove one task or multiple depending on how many are selected in the Treeview.
  • Implemented a function which, on closing of the application writes all the tasks to a CSV file and on opening of the application takes those tasks from the CSV file and adds them to the Treeview (saving functionality).
  • Added a tag system which allows the tasks to be categorized by the user.
  • Added a sort function, which can sort the tasks by “Due First”, “Due Last”, “Tag (ascending)”, Tag (Descending)
  • Implemented a highlighting system which highlights tasks that will be due soon (Yellow). Also highlights tasks which are due today or past their due date (red).
  • Added the ability to add tasks by pressing the enter key and also the ability to delete tasks by selecting the tasks in Treeview and pressing the delete key
  • Added an error message that will pop up if the user tries to create a task without entering anything into the task_entry widget.

Key Points

Ttk Treeview

I needed a way to display tasks, originally I was displaying tasks just using labels but that was quickly becoming problematic. So I decided I need to look more into Tkinter’s widgets to see if there was a better solution to displaying tasks. I eventually found a solution and that was Tkinter’s Treeview. Treeview works with rows and columns to display information. It is very customizable allowing you to really store anything in a nice and organized way. After researching how it worked I was able to insert data into the tree and also remove data from it. This was already much better than before however there was one issue, every time I closed the application the tasks would not save.

Saving function

I did some research online on what was a good way to save data in python and people kept on saying to write to a file. I had used python’s CSV reader and writer before so I decided I would make a function using that module.

code for writing to a file
write_data code

The function above I made takes all the data from the Treeview and writes that data to a file called “tree_data.csv.” The function activates when the main window is closed, so there is no need for the user to manually save.

Code for retrieving data
get_data code

Now that we had a “Save file” I now needed to make a function which retrieves the data from that file and adds that data to the Treeview so that the user can see it. This was simple enough to accomplish I just used DictReader to retrieve the data from the file and then used a for loop to insert the data into the Treeview. This function ran when the application first loads, however I ran into an issue. What happens if there is no save file? If you attempt to read a file that does not exist an error is thrown, so to prevent this I implemented some error handling https://docs.python.org/3/tutorial/errors.html

Sorting function and tag system

code for sorting by date
sort_by_date_code

I now had a basic application which allows the user to view tasks, create tasks, save tasks and also load tasks which are great foundations for the application. The next thing that I wanted to implement was a way for the user to sort the tasks by due date. This was bit tricky accomplish but I had a rough idea of how the code was going to go, first when the user selected an option from the sorting combo box the function would be executed. Next the tasks are copied from Treeview and each task is stored as a dictionary in a list. Then the tasks in the Treeview are cleared. After that depending on what option the user has selected from the combo box, the list of tasks are then sorted by due date in ascending or descending order. Once the list has been sorted they are then reinserted into the tree.

I wanted the user to be able to add each task into a category, for example if the user made multiple tasks for homework there should be a way to group all of them together. If the user added tasks about the bills that they had to pay, they should be able to group all of those together. In order to achieve this I made a tag system where the user can assign a tag to their tasks. I also added two options in the sort combo box so that the user can sort by tags in alphabetical order (ascending and descending).

A gif showing how sorting works.
Sorting demonstration

For now I have a very basic way of grouping the tags together. In the future I would like for the user to be able to search for a tag with a pop up entry box which removes the other tasks temporarily and only shows tasks which contain the searched tag.

Highlighting system

One feature I wanted to add was for tasks to be highlighted a certain colour as the due date got near. For example if the task is due in three days time that task should be highlighted yellow to give warning to the user. If the task is due today or the due date has passed, that task should be highlighted red. To achieve this I had to use python’s built in date time module. I had to learn how comparing dates worked as well. Down bellow is a snippet of my insert_into_tree function which takes a list of tasks, compares todays date with each task’s due date and determines if they should be marked yellow or red. This function gets used a lot in my code which is nice to be able to reuse it and try keep my code ‘DRY’

An simple task manager's insert into tree function
insert_into_tree function

I would like to be able to add more colours to the highlighting system later on and give the user the ability to adjust how much warning in advance, each colour gives about an upcoming task’s due date.

Conclusion

I have learnt a lot in the past few days and am quite proud of how the foundations of this application have turned out. I will admit that the code is more than likely very messy and I will need to do some refactoring soon to clean up the code and try make it more ‘DRY’. But this is all a learning experience for me I am not under the illusion that I will make no mistakes. But the important thing is that I keep on growing. until next time!