-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainTwo.py
330 lines (248 loc) · 11.4 KB
/
mainTwo.py
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
import tkinter as tk
import time
from playsound import playsound
from tkinter import messagebox
class App():
def __init__(self):
#set time
self.timeToShowTodo = '25:00'
self.timeToShowRest = '05:00'
self.basicTodoTimer = 25 * 60
self.basicRestTimer = 5 * 60
self.mainTimer = self.basicTodoTimer
self.started = False
self.todos = dict()
self.reset = False
self.restingFinished = False
self.mainFont = '#f2f2f2' # super light gray
self.back = '#F23535'
self.secondFont = '#011526' # black
self.thirdFont = '#F2505D' # red
# root staff
self.root = tk.Tk()
self.root.title('pomodoro')
self.root.geometry('600x700')
self.root.configure(bg = self.mainFont)
# scroll bar frame
self.initScrollBar()
# timer label, container for timer buttons, buttons for timer
self.initTimerThings()
# label for input, input task
self.initInputTaskThings()
# submit input btn
self.initSubmitTask()
# tasks
self.initTasksContainer()
# render
self.frame.mainloop()
def initScrollBar(self):
self.canvas = tk.Canvas(self.root, borderwidth = 0, background = self.mainFont)
self.frame = tk.Frame(self.canvas, background= self.mainFont)
self.vsb = tk.Scrollbar(self.root, orient="vertical", command = self.canvas.yview)
self.canvas.configure(yscrollcommand = self.vsb.set,
highlightbackground = self.mainFont, bd = 0,
highlightcolor = self.mainFont, highlightthickness = 0)
self.vsb.pack(side = "right", fill = "y")
self.canvas.pack(fill = 'y', expand = True)
self.canvas.create_window((192,300), window = self.frame, anchor = 'center')
self.frame.bind("<Configure>", lambda event, canvas = self.canvas: self.onFrameConfigure(canvas))
def initTimerThings(self):
# label for timer
self.label = tk.Label(self.frame,text=self.timeToShowTodo)
self.label.configure(font='helvetica 30 bold',fg = self.secondFont, bg = self.mainFont)
self.label.pack(pady = (30,20))
# container for timer buttons
self.containerBtn = tk.Frame(self.frame,width = 300 , height = 100, bg = self.mainFont)
self.containerBtn.pack()
# buttons for timer
self.startStopBtn = tk.Button(self.containerBtn, text = 'start', command = self.btnFunc)
self.startStopBtn.configure( bg = self.thirdFont, fg = self.mainFont,
font = 'helvetica 13 bold',width = 7, bd = 0)
self.startStopBtn.pack(pady = (14,30), padx = (30), side=tk.LEFT)
self.resetBtn = tk.Button(self.containerBtn,text = 'reset' , command = self.manageResets)
self.resetBtn.configure( bg = self.thirdFont, fg = self.mainFont, font='helvetica 13 bold',width = 7, bd = 0)
self.resetBtn.pack(pady = (14,30),padx = (30), side=tk.RIGHT)
def initInputTaskThings(self):
# label for input
self.inputLabel = tk.Label(self.frame,text= 'Write your task here',
bd = 0, bg = self.mainFont,
fg =self.secondFont,
font = 'helvetica 10 bold')
self.inputLabel.pack(pady = (0,5))
# input task
self.input = tk.Entry(self.frame,width = 35,
bd = 0, bg = self.mainFont,
highlightbackground = self.secondFont, highlightcolor = self.secondFont,
highlightthickness = 3)
self.input.pack(pady = (10,15), ipady = 5)
self.inputNumLabel = tk.Label(self.frame,text= 'Write number of pomodoros',
bd = 0, bg = self.mainFont, fg = self.secondFont,
font = 'helvetica 10 bold')
self.inputNumLabel.pack(pady = (10,10))
self.numberofPom = tk.Entry(self.frame,
width = 5, bd = 0,bg = self.mainFont, highlightbackground = self.secondFont,
highlightcolor = self.secondFont, highlightthickness= 3)
self.numberofPom.pack(ipady = 5)
def initSubmitTask(self):
# submit input btn
self.errorLabel = tk.Label(self.frame, text = '')
self.submBtn = tk.Button(self.frame, text = 'add', command = self.submitInput)
self.submBtn.configure(bg = self.thirdFont, fg = self.mainFont,
font='helvetica 13 bold',width = 22, bd = 0)
self.submBtn.pack(pady = (25,5))
self.errorLabel.pack(pady= (2,10))
def initTasksContainer(self):
# label for tasks container
self.labelForContainer = tk.Label(self.frame, text = 'Tasks To Do',
bd = 0, bg = self.mainFont,
fg = self.secondFont , font = 'helvetica 14 bold')
self.labelCompletedTasks = tk.Label(self.frame,text = 'Completed Tasks',
bd = 0, bg = self.mainFont,
fg = self.secondFont, font = 'helvetica 14 bold')
# frame for tasks
self.containerForAllTasks = tk.Frame(self.frame)
self.containerForCompletedTasks = tk.Frame(self.frame)
self.labelForContainer.pack()
self.containerForAllTasks.pack(pady = (6,20))
self.labelCompletedTasks.pack()
self.containerForCompletedTasks.pack(pady = (10,40))
def updateClock(self):
if self.started == True:
now = self.timerGet()
self.startStopBtn.configure(text = 'stop')
self.label.configure(text=now)
if now == '00:00':
# play system notification
self.root.bell()
if self.restingFinished == False:
self.deleteAsFull()
self.resetBtnFoo()
return
self.frame.after(1000, self.updateClock)
self.mainTimer -=1
def btnFunc(self):
if self.started == False:
self.started = True
self.updateClock()
else:
self.stopPressed()
self.started = False
def timerGet(self):
t = self.mainTimer
mins, secs = divmod(t, 60)
timer = f'{mins:02d}:{secs:02d}'
return timer
def stopPressed(self):
self.startStopBtn.configure(text = 'proceed')
def submitInput(self):
task = self.input.get()
try:
pomodoros = int(self.numberofPom.get())
except:
self.errorLabel.configure(text = 'Write a number')
tk.messagebox.showerror(title = 'pomodoro',message='Write number please')
return
if pomodoros == None or pomodoros == 0:
pomodoros = 1
if task in self.todos:
self.errorLabel.configure(text = 'This task already exists')
tk.messagebox.showerror(title = 'pomodoro',message='This task already exists')
return
self.errorLabel.configure(text = '')
taskContainer = tk.Frame(self.containerForAllTasks, height = 100, width = 100,
highlightbackground=self.secondFont, highlightthickness= 3)
todo = tk.Label(taskContainer, text = f'{task}')
todo.configure(font = 'helvetica 10 ', width = 20,
pady = 1,justify = 'left',
bg = self.mainFont, fg = self.secondFont)
progress = tk.Label(taskContainer, text = f'0/{pomodoros}',
pady = 1, padx = 5,
font = 'helvetica 10 ', bg = self.mainFont, fg = self.secondFont)
deleteBtn = tk.Button(taskContainer, font = 'helvetica 10 ', text = 'DEL',
command = lambda : self.deleteTodo(taskContainer,task),
relief="solid", bd = 0, pady=3 , fg = self.mainFont, bg = self.thirdFont)
todoObj = Todo(0,pomodoros,taskContainer,progress)
self.todos[task] = todoObj
taskContainer.pack(pady = 4)
todo.pack(side=tk.LEFT)
deleteBtn.pack(side = tk.RIGHT, padx = (1,0))
progress.pack(side=tk.RIGHT)
self.input.delete(0, 'end')
self.numberofPom.delete(0, 'end')
def deleteTodo(self,x,task):
x.destroy()
del self.todos[task]
def deleteAsFull(self):
i = 0
for key in self.todos.keys():
if i == 0:
todo = self.todos[key]
todo.currState = todo.currState + 1
maxCount = todo.pomodoros
ourCount = todo.currState
if ourCount == maxCount:
taskContainer = tk.Frame(self.containerForCompletedTasks, height = 100, width = 100,
highlightbackground=self.secondFont, highlightthickness= 3)
completedTodo = tk.Label(taskContainer, text = f'{key}',font = 'helvetica 10 ',
width = 25,pady = 3,justify = 'left',
bg = self.mainFont, fg = self.secondFont)
progress = tk.Label(taskContainer, text = f'{todo.currState}/{todo.pomodoros}', pady = 3, padx = 5,
font = 'helvetica 10 ', bg = self.mainFont, fg = self.secondFont)
taskContainer.pack(pady = (7))
completedTodo.pack(side=tk.LEFT)
progress.pack(side=tk.RIGHT)
self.deleteTodo(todo.taskContainer ,key)
else:
label = todo.progress
label.configure(text = f'{todo.currState}/{todo.pomodoros}')
label.update()
break
def resetBtnFoo(self):
if self.restingFinished == True:
self.mainTimer = self.basicTodoTimer
timeToShow = self.timeToShowTodo
nameofStart = 'start'
self.resetBtn.configure(text = 'reset')
self.restingFinished = False
else:
self.mainTimer = self.basicRestTimer
timeToShow = self.timeToShowRest
nameofStart = 'rest'
self.resetBtn.configure(text = 'skip')
self.restingFinished = True
self.resetBtn.update()
if self.started == True:
self.stopPressed()
self.started = False
self.startStopBtn.configure(text = nameofStart)
self.label.configure(text = timeToShow)
self.label.update()
self.startStopBtn.update()
def resetClassic(self):
self.mainTimer = self.basicTodoTimer
timeToShow = self.timeToShowTodo
nameofStart = 'start'
self.resetBtn.configure(text = 'reset')
self.resetBtn.update()
if self.started == True:
self.stopPressed()
self.started = False
self.startStopBtn.configure(text = nameofStart)
self.label.configure(text = timeToShow)
self.label.update()
self.startStopBtn.update()
def manageResets(self):
a = self.resetBtn.config('text')[-1]
if a == 'reset':
self.resetClassic()
else:
self.resetBtnFoo()
def onFrameConfigure(self,canvas):
canvas.configure(scrollregion=canvas.bbox("all"))
class Todo:
def __init__ (self, currState, pomodoros, taskContainer, progress):
self.currState = currState
self.pomodoros = pomodoros
self.taskContainer = taskContainer
self.progress = progress
app=App()