-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
275 lines (216 loc) · 8.48 KB
/
main.py
File metadata and controls
275 lines (216 loc) · 8.48 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
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput
from kivy.uix.scrollview import ScrollView
from kivy.core.window import Window
from instructions import txt_instruction, txt_test1, txt_test2, txt_test3, txt_sits
from ruffier import test
from seconds import Seconds
from sits import Sits
from runner import Runner
Window.clearcolor = (.87, 0.54, 0.8, 0.3)
btn_color = (0.98, 0.31, 0.8, 1)
age = 7
name = ""
p1, p2, p3 = 0, 0, 0
def check_int(str_num):
# возвращает число или False, если строка не конвертируется
try:
return int(str_num)
except:
return False
class InstrScr(Screen):
def __init__(self, **kwargs):
super().__init__(**kwargs)
instr = Label(text=txt_instruction)
lbl1 = Label(text='Введите имя:', halign='right')
self.in_name = TextInput(multiline=False)
lbl2 = Label(text='Введите возраст:', halign='right')
self.in_age = TextInput(text='7', multiline=False)
self.btn = Button(text='Начать', size_hint=(0.3, 0.2), pos_hint={'center_x': 0.5})
self.btn.background_color = btn_color
self.btn.on_press = self.next
line1 = BoxLayout(size_hint=(0.8, None), height='30sp')
line2 = BoxLayout(size_hint=(0.8, None), height='30sp')
line1.add_widget(lbl1)
line1.add_widget(self.in_name)
line2.add_widget(lbl2)
line2.add_widget(self.in_age)
outer = BoxLayout(orientation='vertical', padding=8, spacing=8)
outer.add_widget(instr)
outer.add_widget(line1)
outer.add_widget(line2)
outer.add_widget(self.btn)
self.add_widget(outer)
def next(self):
global name
name = self.in_name.text
age = check_int(self.in_age.text)
if age == False or age < 7:
age = 7
self.in_age.text = str(age)
else:
self.manager.current = 'pulse1'
class PulseScr(Screen):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.next_screen = False
instr = Label(text=txt_test1)
self.lbl_sec = Seconds(15)
self.lbl_sec.bind(done=self.sec_finished)
line = BoxLayout(size_hint=(0.8, None), height='30sp')
lbl_result = Label(text='Введите результат:', halign='right')
self.in_result = TextInput(text='0', multiline=False)
self.in_result.set_disabled(True)
line.add_widget(lbl_result)
line.add_widget(self.in_result)
self.btn = Button(text='Начать', size_hint=(0.3, 0.4), pos_hint={'center_x': 0.5})
self.btn.background_color = btn_color
self.btn.on_press = self.next
outer = BoxLayout(orientation='vertical', padding=8, spacing=8)
outer.add_widget(instr)
#outer.add_widget(lbl1)
outer.add_widget(self.lbl_sec)
outer.add_widget(line)
outer.add_widget(self.btn)
self.add_widget(outer)
def sec_finished(self, *args):
self.next_screen = True
self.in_result.set_disabled(False)
self.btn.set_disabled(False)
self.btn.text = 'Продолжить'
def next(self):
if not self.next_screen:
self.btn.set_disabled(True)
self.lbl_sec.start()
else:
global p1
p1 = check_int(self.in_result.text)
if p1 == False or p1 <= 0:
p1 = 0
self.in_result.text = str(p1)
else:
self.manager.current = 'sits'
class CheckSits(Screen):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.next_screen = False
instr = Label(text=txt_sits, size_hint=(0.5, 1))
self.lbl_sits = Sits(30)
self.run = Runner(total=30, steptime=1.5, size_hint=(0.4, 1))
self.run.bind(finished=self.run_finished)
line = BoxLayout()
vlay = BoxLayout(orientation='vertical', size_hint=(0.3, 1))
vlay.add_widget(self.lbl_sits)
line.add_widget(instr)
line.add_widget(vlay)
line.add_widget(self.run)
self.btn = Button(text='Начать', size_hint=(0.3, 0.2), pos_hint={'center_x': 0.5})
self.btn.background_color = btn_color
self.btn.on_press = self.next
outer = BoxLayout(orientation='vertical', padding=8, spacing=8)
outer.add_widget(line)
outer.add_widget(self.btn)
self.add_widget(outer)
def run_finished(self, instance, value):
self.btn.set_disabled(False)
self.btn.text = 'Продолжить'
self.next_screen = True
def next(self):
if not self.next_screen:
self.btn.set_disabled(True)
self.run.start()
self.run.bind(value=self.lbl_sits.next)
else:
self.manager.current = 'pulse2'
class PulseScr2(Screen):
def __init__(self, **kwargs):
self.next_screen = False
self.stage = 0
super().__init__(**kwargs)
instr = Label(text=txt_test3)
line1 = BoxLayout(size_hint=(0.8, None), height='30sp')
self.lbl_sec = Seconds(15)
self.lbl_sec.bind(done=self.sec_finished)
self.lbl1 = Label(text='Считайте пульс')
lbl_result1 = Label(text='Результат:', halign='right')
self.in_result1 = TextInput(text='0', multiline=False)
line1.add_widget(lbl_result1)
line1.add_widget(self.in_result1)
line2 = BoxLayout(size_hint=(0.8, None), height='30sp')
lbl_result2 = Label(text='Результат после отдыха:', halign='right')
self.in_result2 = TextInput(text='0', multiline=False)
self.in_result1.set_disabled(True)
self.in_result2.set_disabled(True)
line2.add_widget(lbl_result2)
line2.add_widget(self.in_result2)
self.btn = Button(text='Начать', size_hint=(0.3, 0.5), pos_hint={'center_x': 0.5})
self.btn.background_color = btn_color
self.btn.on_press = self.next
outer = BoxLayout(orientation='vertical', padding=8, spacing=8)
outer.add_widget(instr)
outer.add_widget(self.lbl1)
outer.add_widget(self.lbl_sec)
outer.add_widget(line1)
outer.add_widget(line2)
outer.add_widget(self.btn)
self.add_widget(outer)
def sec_finished(self, *args):
if self.stage == 0:
# закончили первый подсчет, отдыхаем
self.lbl1.text = 'Отдыхайте'
self.lbl_sec.restart1(60)
self.in_result1.set_disabled(False)
self.stage=1
elif self.stage == 1:
# закончили отдых, считаем
self.lbl1.text = 'Считайте пульс'
self.lbl_sec.restart2(45)
self.stage=2
elif self.stage == 2:
self.in_result2.set_disabled(False)
self.btn.set_disabled(False)
self.btn.text = 'Завершить'
self.next_screen = True
def next(self):
if not self.next_screen:
self.btn.set_disabled(True)
self.lbl_sec.start()
else:
global p2, p3
p2 = check_int(self.in_result1.text)
p3 = check_int(self.in_result2.text)
if p2 == False:
p2 = 0
self.in_result1.text = str(p2)
elif p3 == False:
p3 = 0
self.in_result2.text = str(p3)
else:
# переходим
self.manager.current = 'result'
class Result(Screen):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.outer = BoxLayout(orientation='vertical', padding=8, spacing=8)
self.instr = Label(text='')
self.outer.add_widget(self.instr)
self.add_widget(self.outer)
self.on_enter = self.before
def before(self):
global name
self.instr.text = name + '\n' + test(p1, p2, p3, age)
class HeartCheck(App):
def build(self):
sm = ScreenManager()
sm.add_widget(InstrScr(name='instr'))
sm.add_widget(PulseScr(name='pulse1'))
sm.add_widget(CheckSits(name='sits'))
sm.add_widget(PulseScr2(name='pulse2'))
sm.add_widget(Result(name='result'))
return sm
app = HeartCheck()
app.run()