Пример #1
0
def add_tasks():
    # Pop a window to add tasks
    add_tasks_window = Toplevel()
    add_tasks_window.title("Add Tasks")
    add_tasks_window.iconbitmap('icon.ico')
    add_tasks_window.geometry("335x350")

    # reponse = messagebox.showinfo("Successfully Added", "The tasks are added successfully!")

    calendar_image_add_tasks = Image.open("calendar.jpg")
    calendar_image_add_tasks = ImageTk.PhotoImage(
        calendar_image_add_tasks.resize((20, 20)))

    # Create add_task frame
    add_task_frame = LabelFrame(add_tasks_window, borderwidth=0)

    # Find current date and subjects
    date, subjects = Task.date_subject_finder("ToDoList.txt")

    subject_label_list = []
    subject_entry_list = []

    # Create labels and entries for user to input their tasks
    for i, subject in enumerate(subjects):
        label = Label(add_task_frame, text=subject, font=("Calibri", 14))
        label.grid(row=i + 1, column=0, padx=(10, 30), sticky=W)
        subject_label_list.append(label)
        entry = Entry(add_task_frame, width=30)
        entry.grid(row=i + 1, column=1, sticky=W)
        subject_entry_list.append(entry)

    # Create date label
    current_date_label = Label(add_task_frame,
                               text=f"Today is {date}",
                               font=("Calibri", 14))
    current_date_label.grid(row=0, column=0, columnspan=2)

    # Create today/tomorrow choice Button
    add_tasks_today_button = Button(
        add_task_frame,
        text="Add To Today",
        font=("Calibri", 12),
        command=lambda: add_tasks_today(subject_entry_list, add_tasks_window))
    add_tasks_today_button.grid(row=len(subjects) + 1, column=0, pady=(10, 10))
    add_tasks_tomorrow_button = Button(
        add_task_frame,
        text="Add To Another Day",
        command=lambda: add_tasks_tomorrow(
            subjects, add_task_frame, calendar_image_add_tasks,
            subject_entry_list, add_tasks_window),
        font=("Calibri", 12))
    add_tasks_tomorrow_button.grid(row=len(subjects) + 1,
                                   column=1,
                                   pady=(10, 10))

    add_task_frame.pack()
Пример #2
0
def complete_tasks_submit(listbox, object_list, window):
    selections = list(listbox.curselection())
    # print (listbox.get(selections[0]))
    # print (object_list[selections[0]].name)
    dates, subjects = Task.date_subject_finder("ToDoList.txt")
    completed_object_list = [
        object for i, object in enumerate(object_list)
        if i in selections and object.name not in subjects
    ]
    Task.make_it_complete("ToDoList.txt", completed_object_list)
    window.destroy()
Пример #3
0
def add_tasks_tomorrow(subject_list, frame, image, subject_entry_list, window):
    global date_label, date_entry
    # Create date label and entry
    date_label = Label(frame, text="Date of The Day:", font=("Calibri", 12))
    date_label.grid(row=len(subject_list) + 2, column=0, padx=(10, 14))
    date_entry = Entry(frame, width=20)
    date_entry.grid(row=len(subject_list) + 2, column=1, sticky=W)

    # open the file to read the lines
    f = open("ToDoList.txt", "r")
    lines = f.readlines()
    f.close()

    date, subjects = Task.date_subject_finder("ToDoList.txt")

    # Find the uncompleted tasks from yesterday
    subject_index = 0
    # Create a blank list to store the tasks that haven't been completed
    subject_uncompleted_tasks = [[]] * len(subjects)
    for line in lines:
        # Find date for instanciate task objects
        if "Date:" in line:
            date = line.split(": ")[1].strip("\n")
        # Update the uncompleted list
        elif subjects[subject_index] in line:
            tasks = Task.get_tasks_from_line(date, subjects[subject_index],
                                             line)
            uncompleted = []
            for task in tasks:
                if task.completed == False:
                    uncompleted.append(task.name)
            subject_uncompleted_tasks[subject_index] = uncompleted
            subject_index += 1
            if subject_index == len(subjects):
                subject_index = 0

    f = open("Settings.txt", "r+")
    lines = f.readlines()
    if lines[0].split(": ")[1] == "On":
        # Insert the uncompleted tasks into the entry
        for i, entry in enumerate(subject_entry_list):
            for index, task in enumerate(subject_uncompleted_tasks[i]):
                if index != len(subject_uncompleted_tasks[i]) - 1:
                    entry.insert(END, task + ",")
                else:
                    entry.insert(END, task)

        # Pop up a messagebox at the first time the user use this feature
        if lines[0].split(": ")[2].strip("\n") == "Ask":
            response = messagebox.askyesno(
                "Auto Add Notification",
                f'''Auto Add is turned on by default. Turn in off?\t
(This message will not show up again)''')
            lines[0] = lines[0].replace("Ask", "Asked")
            if response == 1:
                lines[0] = lines[0].replace("On", "Off")
            # Not show up again
            f.seek(0)
            for line in lines:
                f.write(line)

    f.close()

    # Craete a date selection button
    calendar_button = Button(frame, image=image, command=select_date)
    calendar_button.grid(row=len(subject_list) + 2, column=1, padx=(96, 0))

    # Create a submit button
    add_task_tomorrow_submit_button = Button(
        frame,
        text="Submit",
        font=("Calibri", 12),
        command=lambda: add_task_tomorrow_submit(subject_entry_list, window))
    add_task_tomorrow_submit_button.grid(row=len(subject_list) + 3,
                                         column=0,
                                         columnspan=2,
                                         pady=(10, 0))
Пример #4
0
def complete_tasks():
    # pop a new window for completing tasks
    complete_tasks_window = Toplevel()
    complete_tasks_window.title("Complete Tasks")
    complete_tasks_window.iconbitmap('icon.ico')
    complete_tasks_window.geometry("335x350")

    # create a frame to display all the widgets
    complete_tasks_frame = LabelFrame(complete_tasks_window, borderwidth=0)

    # for changing background
    insert_count = 0
    subject_row = []

    with open("ToDoList.txt", "r") as f:
        lines = f.readlines()

        # find the latest date and all related tasks in that date
        latest_date, subjects = Task.date_subject_finder("ToDoList.txt")
        latest_date_list = [line for line in lines if latest_date in line]
        latest_date_index = lines.index(latest_date_list[0])
        relevant_tasks = lines[latest_date_index + 1:latest_date_index + 1 +
                               len(subjects)]
        relevant_tasks_object_list = []

        # create a label for date
        date_label = Label(
            complete_tasks_frame,
            text=f"Today is {latest_date}\n Here is what you haven't completed",
            font=("Calibri", 12))
        date_label.pack(pady=(5, 6))

        # Create a scrollbar for the complete_tasks listbox
        complete_tasks_scrollbar = Scrollbar(complete_tasks_frame,
                                             orient=VERTICAL)

        # Create a listbox to display all the tasks
        complete_tasks_listbox = Listbox(
            complete_tasks_frame,
            width=50,
            height=12,
            yscrollcommand=complete_tasks_scrollbar,
            selectmode=MULTIPLE)

        # pack and configure the scollbar and the listbox
        complete_tasks_scrollbar.config(command=complete_tasks_listbox.yview)
        complete_tasks_scrollbar.pack(side=RIGHT, fill=Y)
        complete_tasks_listbox.pack(pady=(0, 6))

        # iterate through lines in the latest date
        for index, line in enumerate(relevant_tasks):
            relevant_tasks_object_list.append(subjects[index])
            tasks = Task.get_tasks_from_line(latest_date, subjects[index],
                                             line)
            complete_tasks_listbox.insert(END, f"{subjects[index]}")
            subject_row.append(insert_count)
            insert_count += 1
            # display tasks line by line
            for task in tasks:
                if task.completed == False:
                    relevant_tasks_object_list.append(task)
                    complete_tasks_listbox.insert(END, f"{task.name}")
                    insert_count += 1

    # change the colors
    for row_index in subject_row:
        complete_tasks_listbox.itemconfig(row_index, bg='#dcf1f7')

    complete_task_submit_button = Button(
        complete_tasks_frame,
        text="Complet Select Tasks",
        font=("Calibri", 12),
        command=lambda: complete_tasks_submit(complete_tasks_listbox,
                                              relevant_tasks_object_list,
                                              complete_tasks_window))
    complete_task_submit_button.pack()

    complete_tasks_frame.pack()
Пример #5
0
def read_all_tasks():
    read_all_tasks_window = Toplevel()
    read_all_tasks_window.title("Read Tasks")
    read_all_tasks_window.iconbitmap('icon.ico')
    read_all_tasks_window.geometry("370x480")

    # Create a frame in read all tasks window

    read_all_tasks_filter_frame = LabelFrame(read_all_tasks_window,
                                             borderwidth=0)

    # Add filter options
    date_selection = StringVar()
    date_list = Task.find_date("ToDoList.txt")
    date_list.append("All")
    # Create a drop down menu to select different date
    date_filter_dropdown = OptionMenu(read_all_tasks_filter_frame,
                                      date_selection, *date_list)
    date_selection.set(date_list[-1])
    date_filter_dropdown.grid(row=1, column=1)

    # Create date Label (filter by date)
    date_label = Label(read_all_tasks_filter_frame,
                       text="By Date",
                       font=("Calibri", 12))
    date_label.grid(row=0, column=1)

    completed_selection = StringVar()
    # Create a drop down menu to select different completion status
    completed_filter_dropdown = OptionMenu(
        read_all_tasks_filter_frame, completed_selection,
        *["Completed", "Not Completed", "All"])
    completed_selection.set("All")
    completed_filter_dropdown.grid(row=1, column=2)

    # Create completed Label (filter by completed)
    completed_label = Label(read_all_tasks_filter_frame,
                            text="By Completed",
                            font=("Calibri", 12))
    completed_label.grid(row=0, column=2)

    # find the latest day(not used) and all the subjects
    latest_date, subjects = Task.date_subject_finder("ToDoList.txt")
    var_list = []
    # Create a list of variables to store the values for checkboxes
    for i in range(len(subjects)):
        var_list.append(IntVar())
    # Create checkboxes for every subject
    for i, subject in enumerate(subjects):
        var = var_list[i]
        subject_check_button = Checkbutton(read_all_tasks_filter_frame,
                                           text=subject,
                                           variable=var)
        subject_check_button.grid(row=2 + i // 4, column=i % 4)

    # Create the apply button (apply the filter options)
    apply_button = Button(
        read_all_tasks_filter_frame,
        text="Apply",
        font=("Calibri", 12),
        command=lambda: redraw_listbox(
            [var.get() for var in var_list], subjects, date_selection.get(),
            completed_selection.get(), read_all_tasks_window))
    apply_button.grid(row=3 + len(subjects) // 4, column=0, columnspan=4)

    # display the filter frame
    read_all_tasks_filter_frame.pack()

    # display all the tasks (before filter)
    with open("ToDoList.txt", "r") as f:
        read_all_tasks_listbox(read_all_tasks_window, f.readlines())