-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
382 lines (290 loc) · 9.9 KB
/
main.py
File metadata and controls
382 lines (290 loc) · 9.9 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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
from PyQt5 import QtGui, QtWidgets, QtCore
import sys, time, threading, home, count, analyst, cardio, demtg, playsound, winsound
import barbell_cruls as bc
import dumbbell_shoulder as ds
import yoga
import texttime as tt
ui = ''
cp = 0
img = ''
flagRight = 1
check = False
check2 = False
giay_tt = False
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
MainWindow.setFixedSize(1173, 609)
def test():
import os
os._exit(0)
app.aboutToQuit.connect(test)
tt.init()
def mainUi():
global ui, cp
playS("sound\\Button_1_down.wav", 0) # am thanh ban phim
playS("sound\\intro.wav", 1) # intro
cp = 0
bc.init(0)
ds.init(0)
yoga.init(0)
ui = home.Ui_MainWindow()
ui.setupUi(MainWindow)
ui.count.clicked.connect(countUi)
ui.analys.clicked.connect(analystUi)
ui.cadio.clicked.connect(cardioUi)
MainWindow.show()
def countUi():
global ui
playS("sound\\Button_1_down.wav", 0)
playS("sound\\task_beat.wav", 1) # 0 :0 lap lai 1: lap lai
#
ui = count.Ui_MainWindow()
ui.setupUi(MainWindow)
# phim chuc nang
ui.back.clicked.connect(mainUi)
ui.abs.clicked.connect(lambda: count_task(1))
ui.curls.clicked.connect(lambda: count_task(2))
ui.squats.clicked.connect(lambda: count_task(3))
ui.pushup.clicked.connect(lambda: count_task(4))
ui.start.clicked.connect(stop) # phim stop
# tac chuc nang chon RIGHT LEFT
ui.radioL.setVisible(False)
ui.radioR.setVisible(False)
MainWindow.show()
def analystUi():
global ui, check2
playS("sound\\Button_1_down.wav", 0)
playS("sound\\task_beat.wav", 1)
ui = analyst.Ui_MainWindow()
ui.setupUi(MainWindow)
ui.back.clicked.connect(mainUi)
ui.dumbell.clicked.connect(analyst_task)
ui.yoga.clicked.connect(yoga_task)
ui.information_2.setVisible(False)
ui.start.clicked.connect(stop) # phim stop
#check2 = True
MainWindow.show()
def cardioUi():
global ui, rep
playS("sound\\Button_1_down.wav", 0)
playS("sound\\task_beat.wav", 1)
ui = cardio.Ui_MainWindow()
ui.setupUi(MainWindow)
ui.back.clicked.connect(mainUi)
ui.beginner.clicked.connect(cardio_task)
rep = 0
MainWindow.show()
def stop():
global ui, cp
playS("sound\\Button_1_down.wav", 0)
playS("sound\\task_beat.wav", 1)
cp = 0
bc.init(0)
ds.init(0)
yoga.init(0)
ui.view.setStyleSheet("background-color: rgb(157, 157, 157);")
ui.view.setText(" ")
ui.information.setStyleSheet("background-color: rgb(157, 157, 157);")
ui.information.setText(" ")
def count_task(z):
global cp, func, giay_tt
playS("sound\\Button_1_down.wav", 0)
playS("sound\\count.wav", 1)
cp = 0
bc.init(0)
time.sleep(0.1)
bc.init(1)
cp = 1
tt.giay = 0
giay_tt = False
if (z == 1):
func = 2
ui.radioL.setVisible(False)
ui.radioR.setVisible(False)
elif (z == 2):
func = 1
ui.radioL.setVisible(True)
ui.radioR.setVisible(True)
ui.radioR.setChecked(True)
elif (z == 3):
func = 3
ui.radioL.setVisible(False)
ui.radioR.setVisible(False)
elif (z == 4):
func = 4
ui.radioL.setVisible(False)
ui.radioR.setVisible(False)
def analyst_task():
global cp
# playS("sound\\Button_1_down.wav", 0)
# playS("sound\\Abandon Ship.wav", 1)
playS("sound\\Button_1_down.wav", 0)
playS("sound\\count.wav", 1)
cp = 0
ds.init(0)
time.sleep(0.1)
ds.init(1)
cp = 2
tt.giay = 0
def yoga_task():
global cp, check2
playS("sound\\Button_1_down.wav", 0)
playS("sound\\task.wav", 1)
cp = 0
yoga.init(0)
time.sleep(0.1)
yoga.init(1)
cp = 3
check2 = True
def cardio_task():
global cp, phut_tt
playS("sound\\Button_1_down.wav", 0)
playS("sound\\cardio.wav", 1)
cp = 0
yoga.init(0)
time.sleep(0.1)
yoga.init(1)
cp = 4
tt.giay = tt.phut = 0
phut_tt = False
def hienhinh(a, b, per):
if (per <= 20):
image_path = "" + a
image_profile = QtGui.QImage(image_path)
image_profile = image_profile.scaled(261, 241, aspectRatioMode=QtCore.Qt.IgnoreAspectRatio,
transformMode=QtCore.Qt.SmoothTransformation) # To scale image for example and keep its Aspect Ration
ui.information.setPixmap(QtGui.QPixmap.fromImage(image_profile))
elif (per >= 90):
image_path = "" + b # path to your image file
image_profile = QtGui.QImage(image_path)
image_profile = image_profile.scaled(261, 241, aspectRatioMode=QtCore.Qt.IgnoreAspectRatio,
transformMode=QtCore.Qt.SmoothTransformation)
ui.information.setPixmap(QtGui.QPixmap.fromImage(image_profile))
def hienhinh_cardio(a, b, giay, thoigiantap):
global check2
if (giay < thoigiantap):
image_path = "hinh\\" + a
image_profile = QtGui.QImage(image_path)
image_profile = image_profile.scaled(261, 241, aspectRatioMode=QtCore.Qt.IgnoreAspectRatio,
transformMode=QtCore.Qt.SmoothTransformation)
ui.information.setPixmap(QtGui.QPixmap.fromImage(image_profile))
check2 = True
elif (giay > thoigiantap):
image_path = "hinh\\" + b
image_profile = QtGui.QImage(image_path)
image_profile = image_profile.scaled(261, 241, aspectRatioMode=QtCore.Qt.IgnoreAspectRatio,
transformMode=QtCore.Qt.SmoothTransformation)
ui.information.setPixmap(QtGui.QPixmap.fromImage(image_profile))
def main():
global img, ui, rep, func, flagRight, check, dem, yoga_hinh, phut_tt, check2
print("bat luong")
while True:
if cp == 1:
if func < 2:
if (ui.radioR.isChecked() and flagRight == 1):
flagRight = 0
func = 1 # barbell_curls Right_arm
bc.count = 0
playS("sound\\Button_1_down.wav", 0)
playS("sound\\count.wav", 1)
elif (ui.radioL.isChecked() and flagRight == 0):
flagRight = 1
func = 0 ## barbell_curls Left_arm
bc.count = 0
playS("sound\\Button_1_down.wav", 0)
playS("sound\\count.wav", 1)
img, per, rep = bc.run(600, 450, func)
image = QtGui.QImage(img, img.shape[1], img.shape[0], QtGui.QImage.Format_RGB888).rgbSwapped()
if cp == 1:
ui.view.setPixmap(QtGui.QPixmap.fromImage(image))
ui.lcdNumber.display(rep)
ui.timeLabel.setText("00:" + str(int(tt.giay / 10)) + str(int(tt.giay % 10)))
if func < 2:
hienhinh("balber_curl_down.jpg", "balber_curl_up.jpg", per)
elif func == 2:
hienhinh("bung_down.jpg", "bung_up.jpg", per)
elif func == 3:
hienhinh("squat_up.jpg", "squat_down.jpg", per)
elif func == 4:
hienhinh("push_up.jpg", "push_down.jpg", per)
elif cp == 2:
img, per, rep = ds.run(600, 450) # chay ham run trong dumbbell shoulder press
image = QtGui.QImage(img, img.shape[1], img.shape[0], QtGui.QImage.Format_RGB888).rgbSwapped()
if cp == 2:
ui.timeLabel.setText('00:' + str(int(tt.giay / 10)) + str(int(tt.giay % 10)))
ui.view.setPixmap(QtGui.QPixmap.fromImage(image))
ui.lcdNumber.display(rep)
hienhinh("dumbbell_down.jpg", "dumbbell_up.jpg", per)
elif cp == 3:
img, check, dem, yoga_hinh = yoga.run(600, 450, 30) # z la thoi gian uoc luong
image = QtGui.QImage(img, img.shape[1], img.shape[0], QtGui.QImage.Format_RGB888).rgbSwapped()
if cp == 3:
ui.view.setPixmap(QtGui.QPixmap.fromImage(image))
ui.information_2.setVisible(check)
ui.timeLabel.setText("00:" + str(int(dem / 10)) + str(dem % 10))
if yoga_hinh == 1:
image_path = ""
image_profile = QtGui.QImage(image_path)
image_profile = image_profile.scaled(261, 241, aspectRatioMode=QtCore.Qt.IgnoreAspectRatio,
transformMode=QtCore.Qt.SmoothTransformation)
elif yoga_hinh == 2:
image_path = ""
image_profile = QtGui.QImage(image_path)
image_profile = image_profile.scaled(261, 241, aspectRatioMode=QtCore.Qt.IgnoreAspectRatio,
transformMode=QtCore.Qt.SmoothTransformation)
ui.information.setPixmap(QtGui.QPixmap.fromImage(image_profile))
elif yoga_hinh == 3:
image_path = "yoga\\5.jpg" # path to your image file
image_profile = QtGui.QImage(image_path)
image_profile = image_profile.scaled(261, 241, aspectRatioMode=QtCore.Qt.IgnoreAspectRatio,
transformMode=QtCore.Qt.SmoothTransformation)
ui.information.setPixmap(QtGui.QPixmap.fromImage(image_profile))
elif yoga_hinh == 4:
image_path = "yoga\\finish_yoga.jpg" # path to your image file
image_profile = QtGui.QImage(image_path) # QImage object
image_profile = image_profile.scaled(261, 241, aspectRatioMode=QtCore.Qt.IgnoreAspectRatio,
transformMode=QtCore.Qt.SmoothTransformation) # To scale image for example and keep its Aspect Ration
ui.information.setPixmap(QtGui.QPixmap.fromImage(image_profile))
if check2 == True:
playS("sound\\hoanthanh.wav",0)
playS("sound\\task_beat.wav", 1)
check2 = False
elif cp == 4:
img = yoga.cardio(600, 450)
image = QtGui.QImage(img, img.shape[1], img.shape[0], QtGui.QImage.Format_RGB888).rgbSwapped()
if cp == 4:
ui.view.setPixmap(QtGui.QPixmap.fromImage(image))
if (tt.phut < 2):
hienhinh_cardio("H" + str(tt.phut + 1) + ".png", "breaktime.png", tt.giay, 40)
ui.timeLabel.setText(str(int(tt.phut / 10)) + str(tt.phut % 10) + ":" +
str(int(tt.giay / 10)) + str(tt.giay % 10))
if (tt.phut < 1 and tt.giay >= 55 and check2 == True):
playS1("sound\\readygo.mp3")
check2 = False
elif (tt.phut == 2 and phut_tt == False):
rep += 1
phut_tt = True
ui.timeLabel.setText(str(int(tt.phut / 10)) + str(tt.phut % 10) + ":" +
str(int(tt.giay / 10)) + str(tt.giay % 10))
playS("sound\\task_beat.wav", 1)
playS1("sound\\hoanthanh.mp3")
ui.view.setStyleSheet("background-color: rgb(157, 157, 157);")
ui.view.setText(" ")
ui.information.setStyleSheet("background-color: rgb(157, 157, 157);")
ui.information.setText(" ")
ui.lcdNumber.display(rep)
# AM THANH
def h_playS(a, b):
winsound.PlaySound(a, winsound.SND_LOOP + (winsound.SND_ASYNC & b))
def playS(a, b):
s = threading.Thread(target=h_playS, args=(a, b))
s.start()
def h_playS1(a):
playsound.playsound(a)
def playS1(a):
s = threading.Thread(target=h_playS1, args=(a,))
s.start()
mainUi()
t = threading.Thread(target=main)
t.start()
sys.exit(app.exec_())