-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.py
More file actions
88 lines (75 loc) · 3.2 KB
/
gui.py
File metadata and controls
88 lines (75 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import functions
import FreeSimpleGUI as sg
import time
import os
if not os.path.exists('todos.txt'):
with open('todos.txt', "w") as file:
pass
sg.theme("DarkTeal2")
label_timestamp = sg.Text('', key='timestamp')
label_add = sg.Text("Type in a To-Do Item: ")
input_box = sg.InputText(tooltip="Enter todo", key='input_box')
button_add = sg.Button("Add", key='add', size=10, mouseover_colors="LightBlue2",
tooltip="Adds To-Do item to the list")
label_list_box = sg.Text("My To-Do List: ")
list_box = sg.Listbox(values=functions.get_todos(), key='selected',
enable_events=True, size=[45, 10])
button_edit = sg.Button("Edit", key='edit',
tooltip="Updates To-Do item in the list")
button_quit = sg.Button("Quit", key='quit')
button_complete = sg.Button("Done", key='complete', mouseover_colors="LightBlue2",
tooltip="Removes To-Do item from the list")
# window instance
window = sg.Window('My Todo App',
layout=[[label_timestamp],
[label_add], "",
[input_box, button_add],
[label_list_box],
[list_box, button_edit, button_complete],
[button_quit]
],
font=('Helvetica', 14)
)
while True:
event, values = window.read(timeout=200)
window["timestamp"].update(value=time.strftime("%b, %d, %Y %H:%M:%S"))
# print(1, " events ", event)
# print(2, " values ", values)
match event:
case "add":
todos_list = functions.get_todos()
new_todo = values['input_box'] + "\n"
todos_list.append(new_todo)
functions.write_todos(todos_list)
window['selected'].update(values=todos_list)
window['input_box'].update(value='')
case "edit":
try:
todo_to_edit = values['selected'][0]
new_todo = values['input_box']
todos_list = functions.get_todos()
index_of_edit = todos_list.index(todo_to_edit)
todos_list[index_of_edit] = new_todo + "\n"
functions.write_todos(todos_list)
window['selected'].update(values=todos_list)
window['input_box'].update(value='')
except IndexError:
sg.popup("Please select an item first.", font=('Helvetica', 14))
case "complete":
try:
todo_to_complete = values['selected'][0]
# print("You selected : ", todo_to_complete.rstrip('\n'))
todos_list = functions.get_todos()
todos_list.remove(todo_to_complete)
functions.write_todos(todos_list)
window['selected'].update(values=todos_list)
window['input_box'].update(value='')
except IndexError:
sg.popup("Please select an item first.", font=('Helvetica', 14))
case 'selected':
window['input_box'].update(value=values['selected'][0].rstrip('\n'))
case "quit":
break
case sg.WIN_CLOSED:
break
window.close()