Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GUI redesign and to-do list #16

Merged
merged 37 commits into from
Sep 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
87ddf83
GUI redesign and to-do list
Neoloopy Sep 5, 2021
337d2f7
Update main.py
Neoloopy Sep 5, 2021
ab174ba
Update main.py
Neoloopy Sep 5, 2021
8e7411b
Convert tabs into spaces
angelofallars Sep 5, 2021
53120a6
Fix indentation of function parameters
angelofallars Sep 5, 2021
3564cdd
Fix location of periods in function parameters
angelofallars Sep 5, 2021
a51b4e2
Turn comments describing functions into docstrings
angelofallars Sep 5, 2021
8ff095a
Improve formatting and grammar of comments
angelofallars Sep 5, 2021
e07de42
Improve comments denoting timer and todo list
angelofallars Sep 5, 2021
3322e81
Convert Timing variable in time_input into lowercase
angelofallars Sep 5, 2021
d992a77
Convert to_do_list variables into todo_list and also fix uppercase in…
angelofallars Sep 5, 2021
574ff3d
Fix the last wrong-indented function param
angelofallars Sep 5, 2021
0549612
Fix yet another over-indented function params
angelofallars Sep 5, 2021
f833481
Refactor font Arial into its own constant for easier changing
angelofallars Sep 5, 2021
c7487ab
Refactor foreground and background values into own constants
angelofallars Sep 5, 2021
476f3e7
Remove trailing whitespace
angelofallars Sep 5, 2021
08b329f
Refactor background of app into own constant
angelofallars Sep 5, 2021
d303322
Put all of the function definitions together
angelofallars Sep 5, 2021
df330e7
Improve formatting of comments
angelofallars Sep 5, 2021
4be6bb2
Refactor title into its own constant
angelofallars Sep 5, 2021
18c6d54
Put the remaining code in a def main(): function
angelofallars Sep 5, 2021
880f5bf
Add if name main
angelofallars Sep 5, 2021
2af6c71
Improve spacing and comment out unused hour_text variable
angelofallars Sep 5, 2021
4609e78
Move necessary vars out of the main func to make the other funcs work
angelofallars Sep 5, 2021
0d4dbcb
Add CLI args support with help argument
angelofallars Sep 5, 2021
c4b1c14
Change TODO_LIST to show_todo_list
angelofallars Sep 5, 2021
e0ca227
Add 'Report bugs' to --help
angelofallars Sep 5, 2021
799c02a
Improve formatting on time_input function
angelofallars Sep 5, 2021
4ab5614
Expand docstring in time_input
angelofallars Sep 5, 2021
85ee418
Add docstring to entry_clear functions
angelofallars Sep 5, 2021
6144089
Add docstring to new_task and del_task
angelofallars Sep 5, 2021
cc938a0
Refactor font size into constant
angelofallars Sep 5, 2021
7c69616
Fix inconsistency in window geometry
angelofallars Sep 5, 2021
5338183
Add requirements.txt
angelofallars Sep 5, 2021
54e6ff8
Grammar change in comments: 'to do' to 'todo'
angelofallars Sep 5, 2021
3741c98
Improve comments and add module docstring
angelofallars Sep 5, 2021
fc39f24
Merge pull request #17 from angelofallars/devwithmain
Sep 5, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
305 changes: 228 additions & 77 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,95 +1,246 @@
'''PomoDrip: Pomodoro Timer by the Algo Drip team
Keep track of your tasks with 25 minute work sessions and 5 minute breaks!
'''
import tkinter as tk
import time
from tkinter import messagebox

# creates window
from sys import argv

# Constants
TITLE = "PomoDrip"
FONT = "Arial"
BACKGROUND = "#2D142C"
ENTRY_FOREGROUND = "#C72C41"
ENTRY_BACKGROUND = "#510A32"
FONT_SIZE_ENTRIES = 24
FONT_SIZE_TODO = 12

# Create window
root = tk.Tk()
# title
root.title("PomoDrip")
# window size
root.geometry("300x200")

# Variables
# Time variables
hour = tk.StringVar()
minute = tk.StringVar()
second = tk.StringVar()

# sets the values to 0
hour.set("00")
minute.set("00")
second.set("00")

# Input for each variable
hour_entry = tk.Entry(root, font = ("Arial", 12), textvariable = hour, width = 5)
hour_entry.place(x = 80, y = 20)
# Input for each time variable
hour_entry = tk.Entry(root, font=(FONT, FONT_SIZE_ENTRIES),
textvariable=hour, width=5,
fg=ENTRY_FOREGROUND, bg=ENTRY_BACKGROUND,
justify="center", bd="0")
hour_entry.place(x=10, y=30)

minute_entry = tk.Entry(root, font=(FONT, FONT_SIZE_ENTRIES),
textvariable=minute, width=5,
fg=ENTRY_FOREGROUND, bg=ENTRY_BACKGROUND,
justify="center", bd="0")
minute_entry.place(x=100, y=30)

second_entry = tk.Entry(root, font=(FONT, FONT_SIZE_ENTRIES),
textvariable=second, width=5,
fg=ENTRY_FOREGROUND, bg=ENTRY_BACKGROUND,
justify="center", bd="0")
second_entry.place(x=190, y=30)

# Initialize necessary todo list variables
todo_list_frame = tk.Frame(root)
todo_list = tk.Listbox(todo_list_frame, width=25,
height=7, font=(FONT, FONT_SIZE_TODO),
bd=0, fg=ENTRY_FOREGROUND,
bg=ENTRY_BACKGROUND, activestyle="none")
# Create an entry box for the todo list
todo_list_entry = tk.Entry(root, font=(FONT, FONT_SIZE_TODO),
fg=ENTRY_FOREGROUND, bg=ENTRY_BACKGROUND,
bd=1, width=26)

minute_entry = tk.Entry(root, font = ("Arial", 12), textvariable = minute, width = 5)
minute_entry.place(x = 130, y = 20)

second_entry = tk.Entry(root, font = ("Arial", 12), textvariable = second, width = 5)
second_entry.place(x = 180, y = 20)
def time_input():
'''Get the values from the hour, minute and seconds entries.
If the inputted values are correct, start the timer,
notifying the user when it finishes.
'''
timing = 0

try:
timing = int(hour.get())*3600 + int(minute.get())*60 + int(second.get())

except TypeError:
messagebox.showinfo("Error", "Please check your entry.")

finally:

if timing == 0 or timing is None:
messagebox.showinfo("Error", "Enter a value.")

else:
while timing > -1:

# Convert minutes to seconds
mins, secs = divmod(timing, 60)
# Resize the window
root.geometry("300x200")
# Convert hours to minutes
hours = 0
if mins > 60:
hours, mins = divmod(mins, 60)

# Display 2 digits
hour.set("{0:2d}".format(hours))
minute.set("{0:2d}".format(mins))
second.set("{0:2d}".format(secs))

# Update the numbers displayed in the entrybox
root.update()
time.sleep(1)

# Time's up display
if timing == 0:
messagebox.showinfo("Timer", "Time's up! 🎊")
# Set the timer back to 00 instead of 0
hour.set("00")
minute.set("00")
second.set("00")
# Resets the window size
root.geometry("650x200")

# Subtract the time
timing -= 1


# Converts seconds into hour, minute, and second
def time_input():
Timing = 0
try:
Timing = int(hour.get())*3600 + int(minute.get())*60 + int(second.get())
except TypeError:
messagebox.showinfo("Error","Please check your entry.")
finally:
if Timing == 0 or Timing is None:
messagebox.showinfo("Error", "Enter a Value.")
else:
while Timing > -1:
# converts minutes to seconds
mins, secs = divmod(Timing, 60)

# converts hours to minutes
hours = 0
if mins > 60:
hours, mins = divmod(mins, 60)

# displays 2 digits
hour.set("{0:2d}".format(hours))
minute.set("{0:2d}".format(mins))
second.set("{0:2d}".format(secs))

# Updates the numbers displayed in the entrybox
root.update()
time.sleep(1)

# time's up display
if Timing == 0:
messagebox.showinfo("Timer", "Time's up! 🎊")
# sets the timer back to 00 instead of 0
hour.set("00")
minute.set("00")
second.set("00")
# subtracts the time
Timing -= 1

# Activation button
Button_Entry = tk.Button(root, text = "Start!", bd = "5", command = time_input, width = 20, compound = "c")
Button_Entry.place(x = 70, y = 120)

# Defines timer_entry_clear function
def second_entry_clear(en):
if second_entry.get() == "00" or second_entry.get() == "0":
second_entry.delete(0, tk.END)
'''Clear the second entry if it reaches zero'''
if second_entry.get() == "00" or second_entry.get() == "0":
second_entry.delete(0, tk.END)

def minute_entry_clear(en):
if minute_entry.get() == "00" or minute_entry.get() == "0":
minute_entry.delete(0, tk.END)

def hour_entry_clear(en):
if hour_entry.get() == "00" or hour_entry.get() == "0":
hour_entry.delete(0, tk.END)
def minute_entry_clear(en):
'''Clear the minute entry if it reaches zero'''
if minute_entry.get() == "00" or minute_entry.get() == "0":
minute_entry.delete(0, tk.END)

# Binds the entry boxes
hour_entry.bind("<Button-1>", hour_entry_clear)
minute_entry.bind("<Button-1>", minute_entry_clear)
second_entry.bind("<Button-1>", second_entry_clear)

# loops the window to keep it active
root.mainloop()
def hour_entry_clear(en):
'''Clear the hour entry if it reaches zero'''
if hour_entry.get() == "00" or hour_entry.get() == "0":
hour_entry.delete(0, tk.END)


def new_task():
'''Add a new task to the todo list'''
task = todo_list_entry.get()
if task != "":
todo_list.insert(tk.END, task)
else:
messagebox.showinfo("Error", "Please enter some task.")


def del_task():
'''Delete a task from the todo list'''
todo_list.delete(tk.ANCHOR)


def main():
'''
===== SETUP APPLICATION ======
'''

# Title
root.title(TITLE)
# Window size
root.geometry("650x200")
# Window background color
root.configure(background=BACKGROUND)
# Disable resizing of the window
root.resizable(width=False, height=False)

# Parse args

# Help
if "--help" in argv:
print("usage: pomodrip [--todolist]")
print("")
print("PomoDrip is a tkinter-based Pomodoro Timer written in Python.")
print("")
print("OPTIONS:")
print(" --todolist Enable a todo-list (EXPERIMENTAL)")
print("")
print("")
print("Report bugs to https://github.com/algodrip/pomodrip/issues")
return

# Activate Todo list
show_todo_list = bool("--todolist" in argv)

# --- TIMER ---

# Set the values of time to 0
hour.set("00")
minute.set("00")
second.set("00")

# Labels for the hours, minutes, and seconds
# -- Unused so we are commenting it out for now
# hour_text = tk.Label(root, font=(FONT, FONT_SIZE_TODO), fg="#EE4540")

# Button to activate the timer
button_entry = tk.Button(root, text="Start!", bd="0",
command=time_input, width=38,
compound="c",
fg=ENTRY_FOREGROUND, bg=ENTRY_BACKGROUND)
button_entry.place(x=10, y=75)

# Bind the entry boxes
hour_entry.bind("<Button-1>", hour_entry_clear)
minute_entry.bind("<Button-1>", minute_entry_clear)
second_entry.bind("<Button-1>", second_entry_clear)

# --- TO-DO LIST ---

if show_todo_list:
# Frame used to separate the todo list
todo_list_frame.place(x=300, y=30)

# Create the actual todo list
todo_list.pack(side=tk.LEFT, fill=tk.BOTH)

# task_list values
task_list = []

# Insert a new task
for item in task_list:
todo_list.insert(tk.END, item)

# Scroll bar for todo list
todo_list_scroll_bar = tk.Scrollbar(todo_list_frame)
todo_list_scroll_bar.pack(side=tk.RIGHT, fill=tk.BOTH)

# Control for the scroll bar
todo_list.config(yscrollcommand=todo_list_scroll_bar.set)
todo_list_scroll_bar.config(command=todo_list.yview)

todo_list_entry.place(x=300, y=170)

# Create a frame for the list buttons
list_button_frame = tk.Frame(root)
list_button_frame.place(x=550, y=30)

# Insert text into the listbox
addtask_button = tk.Button(list_button_frame, text="Insert",
font=(FONT, FONT_SIZE_TODO), bd=0,
fg=ENTRY_FOREGROUND, bg=ENTRY_BACKGROUND,
width=10, command=new_task)
addtask_button.pack(fill=tk.BOTH, expand=True, side=tk.TOP)

# Delete items in the list
del_task_button = tk.Button(list_button_frame, text="Remove",
font=(FONT, FONT_SIZE_TODO), bd=0,
fg=ENTRY_FOREGROUND, bg=ENTRY_BACKGROUND,
width=10, command=del_task)
del_task_button.pack(fill=tk.BOTH, expand=True, side=tk.BOTTOM)

# Loop the window
root.mainloop()


if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tk==0.1.0