-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
299 lines (247 loc) · 11 KB
/
main.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
import sys
import InformationWindow
from PyQt5 import uic
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5.QtGui import QPixmap
from PyQt5 import QtCore
from PyQt5.QtCore import *
from PyQt5.QtMultimedia import *
class MyWidget(QMainWindow):
""" главное окно"""
def __init__(self):
super().__init__()
uic.loadUi('main1.ui', self)
# отображение имени
self.continue_btn.clicked.connect(self.name_given)
# счётчик действий
self.count_healthy = 0
self.count_food = 0
self.count_mood = 0
self.count_clean = 0
self.count_sleep = 0
# проигрывание музыки на фоне
self.player = QMediaPlayer()
self.playlist = QMediaPlaylist(self.player)
self.url = QUrl.fromLocalFile('music/norm.mp3')
self.playlist.addMedia(QMediaContent(self.url))
self.url1 = QUrl.fromLocalFile('music/not norm.mp3')
self.playlist.addMedia(QMediaContent(self.url1))
self.player.setPlaylist(self.playlist)
self.player.playlist().setCurrentIndex(0)
self.player.play()
# включение и выключение музыки
self.on.clicked.connect(lambda: self.music_on_off('on'))
self.off.clicked.connect(lambda: self.music_on_off('off'))
# основное изображение
self.name_picture = 'images_for_main_label/norm.jpg'
self.picture1 = QPixmap(self.name_picture)
self.picture.setPixmap(self.picture1)
# запуск таймера при нажатии кнопки
self.begin.clicked.connect(self.do_action)
self.timer = QtCore.QBasicTimer()
# процентные показатели жизнедеятельности
self.step_food = 100
self.step_healthy = 100
self.step_sleep = 100
self.step_mood = 100
self.step_clean = 100
# переменный для счётчика дней
self.days = 300
self.number_days = 1
self.count_days = 0
# изменение показателей
self.number_food = 0.5
self.number_mood = 0.3
self.number_sleep = 0.4
self.number_clean = 0.6
self.number_healthy = 0.2
# работа кнопок "кормить", "лечить" и тд
self.healthy_btn.clicked.connect(lambda: self.life('healthy', 15))
self.food_btn.clicked.connect(lambda: self.life('food', 20))
self.mood_btn.clicked.connect(lambda: self.life('mood', 25))
self.sleep_btn.clicked.connect(lambda: self.life('sleep', 40))
self.clean_btn.clicked.connect(lambda: self.life('clean', 50))
# работа кнопки про музыку и информацию ("?")
self.misic.clicked.connect(lambda: self.open_dialog_window('музыка'))
self.qst_clean.clicked.connect(lambda: self.open_dialog_window('чистота'))
self.qst_sleep.clicked.connect(lambda: self.open_dialog_window('сон'))
self.qst_food.clicked.connect(lambda: self.open_dialog_window('еда'))
self.qst_mood.clicked.connect(lambda: self.open_dialog_window('настроение'))
self.qst_healthy.clicked.connect(lambda: self.open_dialog_window('здоровье'))
self.alina.clicked.connect(lambda: self.open_dialog_window('автор'))
def name_given(self):
""" передача введённого имени в специальное поле"""
self.label_name.setText(self.name_of_raccoon.text())
QApplication.processEvents()
self.name_of_raccoon.setText('')
def music_on_off(self, name):
""" включение/выключение музыки"""
if name == 'on':
self.player.play()
elif name == 'off':
self.player.stop()
def open_dialog_window(self, name):
""" открытие диалогового окна"""
dialog = InformationWindow.Information()
dialog.setWindowTitle(name)
dialog.set_text_on_label(name)
dialog.exec_()
def timerEvent(self, e):
"""функция для реагирования на события таймера, переопределение обработчик событий"""
# сброс показателей
self.number_food = 0.4
self.number_mood = 0.2
self.number_sleep = 0.3
self.number_clean = 0.5
self.number_healthy = 0.1
# зависимость показателей друг от друга
if self.step_food < 70:
self.number_mood += 0.4
elif self.step_mood < 60:
self.number_healthy += 0.4
elif self.step_clean < 50:
self.number_healthy += 0.5
elif self.step_healthy < 30:
self.number_healthy += 1
elif self.step_healthy < 60:
self.number_food -= 0.4
elif self.step_sleep < 50:
self.number_mood += 0.6
elif self.step_mood < 40:
self.number_sleep += 0.4
# случай, когда один из показателей равен нулю
if self.step_food < 1 or self.step_mood < 1 or self.step_clean < 1 \
or self.step_healthy < 1 or self.step_sleep < 1:
self.timer.stop()
self.begin.setText('ВСЁ СНАЧАЛА')
self.picture_put_on('images_for_main_label/hurt.jpg')
self.player.playlist().setCurrentIndex(0)
self.player.play()
return
# случай, когда все показатели в норме
elif self.step_food > 80 or self.step_mood > 80 or self.step_clean > 80 \
or self.step_healthy > 80 or self.step_sleep > 80:
self.picture_put_on('images_for_main_label/norm.jpg')
self.player.playlist().setCurrentIndex(0)
self.player.play()
# тревожная музыка на фон
if self.step_food < 50 or self.step_mood < 50 or self.step_clean < 50 \
or self.step_healthy < 50 or self.step_sleep < 50:
self.player.playlist().setCurrentIndex(1)
else:
self.player.playlist().setCurrentIndex(0)
self.player.play()
# зависимость главного изображения от показателей
if self.step_food < 80:
self.picture_put_on('images_for_main_label/wanna eat.jpg')
QApplication.processEvents()
elif self.step_mood < 80:
self.picture_put_on('images_for_main_label/boring.jpg')
QApplication.processEvents()
elif self.step_healthy < 80:
self.picture_put_on('images_for_main_label/sick.jpg')
QApplication.processEvents()
elif self.step_sleep < 80:
self.picture_put_on('images_for_main_label/wanna sleep.jpg')
QApplication.processEvents()
elif self.step_clean < 80:
self.picture_put_on('images_for_main_label/dirty.jpg')
QApplication.processEvents()
# счётчик дней
self.days = self.days - self.number_days
if self.days == 0:
self.days = 300
self.count_days += 1
# изменение показателей прогресс-баров
self.step_food = self.step_food - self.number_food
self.food.setValue(self.step_food)
self.step_sleep = self.step_sleep - self.number_sleep
self.sleep.setValue(self.step_sleep)
self.step_healthy = self.step_healthy - self.number_healthy
self.healthy.setValue(self.step_healthy)
self.step_clean = self.step_clean - self.number_clean
self.clean.setValue(self.step_clean)
self.step_mood = self.step_mood - self.number_mood
self.mood.setValue(self.step_mood)
# вывод показателей счётчиков действий
self.num_healthy.display(self.count_healthy)
QApplication.processEvents()
self.num_mood.display(self.count_mood)
QApplication.processEvents()
self.num_food.display(self.count_food)
QApplication.processEvents()
self.num_clean.display(self.count_clean)
QApplication.processEvents()
self.num_sleep.display(self.count_sleep)
QApplication.processEvents()
# вывод "прожитых" дней
self.label_count_days.setText(str(self.count_days))
QApplication.processEvents()
def picture_put_on(self, name):
""" функция для замены основной картинки"""
self.name_picture = name
self.picture1 = QPixmap(self.name_picture)
self.picture.setPixmap(self.picture1)
def life(self, name, number):
""" увеличение показателей"""
self.number = number
self.name = name
if self.name == 'healthy':
if self.step_healthy + self.number < 100:
self.step_healthy += self.number
else:
self.step_healthy = 100
self.count_healthy += 1
elif self.name == 'food':
if self.step_food + self.number < 100:
self.step_food += self.number
else:
self.step_food = 100
self.count_food += 1
elif self.name == 'mood':
if self.step_mood + self.number < 100:
self.step_mood += self.number
else:
self.step_mood = 100
self.count_mood += 1
elif self.name == 'clean':
if self.step_clean + self.number < 100:
self.step_clean += self.number
else:
self.step_clean = 100
self.count_clean += 1
elif self.name == 'sleep':
if self.step_sleep + self.number < 100:
self.step_sleep += self.number
else:
self.step_sleep = 100
self.count_sleep += 1
def do_action(self):
"""запуск таймера, его отсановка и рестарт"""
# сброс счётчика дней
self.count_days = 0
# сброс процентных показатели жизнедеятельности
self.step_food = 100
self.step_healthy = 100
self.step_sleep = 100
self.step_mood = 100
self.step_clean = 100
# сброс счётчиков действий
self.count_healthy = 0
self.count_food = 0
self.count_mood = 0
self.count_clean = 0
self.count_sleep = 0
if self.timer.isActive():
self.timer.stop()
self.begin.setText('ВСЁ СНАЧАЛА')
QApplication.processEvents()
else:
self.timer.start(100, self)
self.begin.setText('ЗАВЕРШИТЬ')
QApplication.processEvents()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = MyWidget()
ex.show()
sys.exit(app.exec_())