forked from mik-st/TimeTrackingProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
345 lines (230 loc) · 10.6 KB
/
main.py
File metadata and controls
345 lines (230 loc) · 10.6 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
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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
from time import time
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QDialog, QApplication ,QLabel
from PyQt5.uic import loadUi
import sys
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QDialog, QApplication
from PyQt5.uic import loadUi
import functions
import time
from PyQt5.QtGui import QColorConstants
from PyQt5.QtCore import Qt
Email=''
logged=False
class First(QDialog):
def __init__(self):
super(First,self).__init__()
loadUi("./UI/first.ui",self)
self.login_button.clicked.connect(self.login_press)
self.signup_button.clicked.connect(self.signup_press)
def login_press(self) :
global logged
#take value of the email input :
#call login function from
email=self.email_input.text()
logged = functions.login(email)
self.error_msg.setText(functions.msg)
print (logged)
global Email
Email=email
self.go_to_main()
def signup_press(self) :
#get text values :
email=self.email_input2.text()
name=self.name_input.text()
#now sign up :
functions.signup(email,name)
self.error_msg.setText(functions.msg)
self.email_input.setText(email)
def go_to_main(self):
if logged :
main = Main()
widget.addWidget(main)
widget.setCurrentIndex(widget.currentIndex()+1)
class Promodoro(QDialog):
def __init__(self):
super(Promodoro,self).__init__()
loadUi("./UI/promodoro.ui",self)
self.add_task_Button.clicked.connect(self.add_task)
self.go_to_main_Button.clicked.connect(self.go_to_main)
self.start_Button.clicked.connect(self.start)
self.skip_Button.clicked.connect(self.skip)
self.unfinished_Button.clicked.connect(self.unfinished)
self.finished_Button.clicked.connect(self.finished)
self.msg_label.setText( f'{functions.current.session_name} : {functions.current.session [3] }' )
def finished (self) :
if functions.current.session[0]!= 0 and functions.current.session_name not in ['break1', 'break2', 'break3','long_break'] :
functions.user1.label_finished()
self.go_to_main()
self.msg_label.setText(functions.msg)
def timer (self,t) :
t*=60
while t:
mins, secs = divmod(t, 60)
timer2 = '{:02d}:{:02d}'.format(mins, secs)
time.sleep(0.001)
t -= 1
self.msg_label.setText(timer2 )
QApplication.processEvents()
self.msg_label.setText('Finished!' )
def add_task (self) :
task = self.task_input.text()
#changing task only if it is not a break
if task !='' and task != ' ' and functions.current.session_name not in ['break1', 'break2', 'break3','long_break']:
#now make sure that the current session is not started yet,
# because you can't add a task if the session was done before!
if functions.current.session[0] ==0 :
functions.current.session[1]=task
functions.current.update_in_user()
self.msg_label.setText('Task added!')
self.task_label.setText(task)
else:
functions.msg=''
# self.start()
def unfinished (self) :
if functions.current.session[1] !='task' and functions.current.session[0] !=0 and functions.current.session_name not in ['break1', 'break2', 'break3','long_break']:
functions.user1. label_not_finished ()
self.msg_label.setText(functions.msg)
def go_to_main (self) :
main = Main()
widget.addWidget(main)
widget.setCurrentIndex(widget.currentIndex()+1)
def start(self) :
functions.user1.start_timing_session (functions.current)
self.timer(functions.current.session[3])
def skip (self):
functions.user1.skip()
self.go_to_main()
class Main(QDialog):
def __init__(self):
super(Main,self).__init__()
loadUi("./UI/main.ui",self)
# main2.login(Email)
self.msgLabel.setText(functions.msg)
# self.comboProject.addItems(main2.user1.get_projects())
# self.comboProject2.addItems(main2.user1.get_projects())
self.update_combos()
self.comboProject.activated.connect(self.load_items )
self.comboSubject.activated.connect(self.show_progress)
self.showHistoryButton.clicked.connect(self.show_history_press )
self.backButton.clicked.connect(self.go_first )
self.addProjectButton.clicked.connect(self.add_project )
self.addSubjecttButton.clicked.connect(self.add_subject )
self.start_promodoro_Button.clicked.connect(self.start_promodoro )
self.delete_subject_Button.clicked.connect(self.delete_subject )
self.delete_project_Button.clicked.connect(self.delete_project )
self.add_r_Button.clicked.connect(self.add_recipient )
self.delete_r_Button.clicked.connect(self.delete_recipient)
self.delete_project_Button.clicked.connect(self.delete_project )
self.email_history_Button.clicked.connect(self.email_history)
def show_progress(self):
subject3=self.comboSubject.currentText()
project3=self.comboProject.currentText()
if functions.user1.get_next_session(project3,subject3 ) :
s=['start', 'study1', 'break1' , 'study2', 'break2', 'study3' , 'break3','study4' , 'long_break', 'finish' ]
for session in s[:s.index(functions.current.session_name)+1] :
functions.visualize( session)
time.sleep(0.2)
self.msgLabel.setText(functions.msg)
QApplication.processEvents()
def email_history (self):
if len(functions.user1.history ) > 2 :
functions.send_emails(functions.user1.history , functions.user1.recipients[0])
self.msgLabel.setText(functions.msg)
def add_recipient (self) :
recipient =self.recipient_input.text()
functions.user1.add_recipient(recipient)
self.msgLabel.setText(functions.msg)
self.update_combos()
def delete_recipient(self) :
recipient =self.emails_combo.currentText()
functions.user1.delete_recipient(recipient)
self.msgLabel.setText(functions.msg)
self.update_combos()
def delete_project (self) :
project =self.comboProject.currentText()
functions.user1.delete_project(project)
self.msgLabel.setText(functions.msg)
self.update_combos()
def delete_subject (self) :
subject =self.comboSubject.currentText()
project =self.comboProject.currentText()
functions.user1.delete_subject(project , subject)
self.msgLabel.setText(functions.msg)
self.update_combos()
def start_promodoro (self):
# del main2.user1
# main2.login(Email)
#1-get next session for the selected proj & subj
subject3=self.comboSubject.currentText()
project3=self.comboProject.currentText()
if functions.user1.get_next_session(project3,subject3 ) :
#2-go to another screen
self.go_promodoro ()
#3- you can access all about current session info from main2.current
# going to Promodoro screen :
def go_promodoro (self ) :
promodoro = Promodoro()
widget.addWidget(promodoro)
widget.setCurrentIndex(widget.currentIndex()+1)
def add_project (self) :
project = self.projectText.text()
functions.user1.add_project(project)
self.msgLabel.setText(functions.msg)
self.update_combos()
# self.comboProject2.clear()
# self.comboProject.clear()
# self.comboProject2.addItems(main2.user1.get_projects())
# self.comboProject.addItems(main2.user1.get_projects())
def add_subject (self) :
subject = self.subjectText.text()
project = self.comboProject2.currentText()
functions.user1.add_subject(project , subject)
self.msgLabel.setText(functions.msg)
# self.comboSubject.clear()
self.update_combos()
def update_combos (self):
self.comboProject2.clear()
self.comboProject.clear()
self.comboSubject.clear()
self.emails_combo.clear()
self.comboProject2.addItems(functions.user1.get_projects())
self.comboProject.addItems(functions.user1.get_projects())
self.emails_combo.addItems(functions.user1.recipients)
self.comboSubject.addItems(functions.user1.get_subjects(self.comboProject.currentText()) )
def go_first(self):
first = First()
widget.addWidget(first)
widget.setCurrentIndex(widget.currentIndex()+1)
def load_items (self ) :
self.comboSubject.clear()
self.comboSubject.addItems(functions.user1.get_subjects(self.comboProject.currentText()) )
def show_history_press (self) :
history_list=[]
subject=self.comboSubject.currentText()
project=self.comboProject.currentText()
before_days=self.before_days.currentText()
history_list= functions.user1.get_history (project, subject, before_days)
self.load_data(history_list)
def load_data(self, lists) :
if type (lists)==list :
self.tableWidget.setRowCount(len(lists))
for i in range (len(lists) ) :
for j in range( len(lists[i]) ):
# print (f'i is {i} and j is {j}')
self.tableWidget.setItem(i,j,QtWidgets.QTableWidgetItem(str (lists[i][j])) )
app = QApplication(sys.argv)
UI =First() # This line determines which screen you will load at first
# You can also try one of other screens to see them.
# UI = MainMenuUI()
# UI = PomodoroUI()
# UI = ShortBreakUI()
# UI = LongBreakUI()
widget = QtWidgets.QStackedWidget()
widget.addWidget(UI)
widget.setFixedWidth(2250)
widget.setFixedHeight(900)
widget.setWindowTitle("Time Tracking App")
widget.show()
sys.exit(app.exec_())