· 4 years ago · Feb 25, 2021, 08:58 AM
1import datetime
2import json
3import sqlite3 as sql
4import time
5
6from kivy.metrics import dp
7from kivy.clock import Clock
8from kivy.lang import Builder
9from kivy.properties import StringProperty
10from kivy.uix.boxlayout import BoxLayout
11from kivy.uix.screenmanager import Screen
12from kivymd.app import MDApp
13from kivymd.uix.boxlayout import MDBoxLayout
14from kivymd.uix.button import MDFlatButton
15from kivymd.uix.dialog import MDDialog
16from kivymd.uix.expansionpanel import MDExpansionPanel, MDExpansionPanelTwoLine
17from kivymd.uix.list import IRightBodyTouch, MDList
18from kivymd.uix.datatables import MDDataTable
19from kivy.core.window import Window
20from news import News
21
22Window.size=(350,550)
23
24class NewsLayout(BoxLayout):
25 title = StringProperty()
26 picture = StringProperty(allownone=True)
27 description = StringProperty(allownone=True)
28
29
30
31class Content(MDList):
32 pass
33
34
35class RecordLine(MDBoxLayout):
36 text = StringProperty()
37
38
39class InformationDialog(MDDialog):
40 pass
41
42
43class MainMenuScreen(Screen):
44 pass
45
46
47class InputScreen(Screen):
48 pass
49
50
51class RestingHeartRateScreen(Screen):
52 pass
53
54
55class ResultObeseScreen(Screen):
56 pass
57
58
59class ResultNormalScreen(Screen):
60 pass
61
62
63class ResultOverweightScreen(Screen):
64 pass
65
66
67class ResultUnderweightScreen(Screen):
68 pass
69
70
71class LocationSearchScreen(Screen):
72 pass
73
74
75class LocationResultScreen(Screen):
76 pass
77
78
79class HistoryScreen(Screen):
80 pass
81
82
83class DemoApp(MDApp):
84 conn = sql.connect('USERINFO.db')
85 cur = conn.cursor()
86 cur.execute(""" CREATE TABLE IF NOT EXISTS results (
87 UID INTEGER PRIMARY KEY AUTOINCREMENT,
88 RESULT INT,
89 DATE_TIME TEXT DEFAULT CURRENT_TIMESTAMP)
90 """)
91 cur.execute(""" CREATE TABLE IF NOT EXISTS information (
92 id INTEGER PRIMARY KEY AUTOINCREMENT,
93 fname VARCHAR(50),
94 height INT,
95 weight INT,
96 age INT,
97 heartrate INT)
98 """)
99 conn.commit()
100 conn.close()
101
102 def __init__(self, **kwargs):
103 super().__init__(**kwargs)
104 self.data_tables = None
105 self.row_data = []
106 self.column_data = []
107 self.dctnry = []
108 self.news = News() # create the Class instance
109 self.news.get_news() # pull a list of stories from the web
110 self.i = 0 # index for moving through the
111 self.list_items = [] # Dictionary where the items is stored
112 self.counter = 0
113 self.counting = {'Item counter': self.counter}
114 self.dialog = None
115 self.selected_category = None
116 self.selected_rec = None
117 self.card_file = \
118 [{'Category': 'Barangay ALABANG',
119 'Record': [
120 {'title': 'Alabang Medical Clinic ( MAIN )',
121 'Details': [
122 ' ADDRESS: \n 297 Montillano St, Alabang, Muntinlupa \n TELEPHONE NUMBER: \n (02) 8842 0680']},
123 {'title': 'Alabang Medical Center, Alabang Zapote road',
124 'Details': [
125 ' ADDRESS: \n Ayala Life-FGU Center, Zapote Road Corner Acacia Avenue Madrigal Business Park, Ayala Alabang, Muntinlupa \n TELEPHONE NUMBER: \n 0998 855 9221']},
126 {'title': 'Asian Hospital and Medical Center',
127 'Details': [
128 ' ADDRESS: \n 2205 Civic Dr, Alabang, Muntinlupa \n TELEPHONE NUMBER: \n (02) 8771 9000']},
129 {'title': 'Aventus Medical Care, Inc. - Alabang Clinic',
130 'Details': [
131 ' ADDRESS: \n 2/F Sycamore ARCS 1 Building Buencamino Street corner Alabang - Zapote Road Madrigal Business Park, Alabang, Muntinlupa \n TELEPHONE NUMBER: \n (02) 8556 3598']},
132 {'title': 'Healthway Medical Festival Mall',
133 'Details': [
134 ' ADDRESS: \n 2nd Floor, Pixie Forest Entrance, Filinvest Ave, Filinvest City, Muntinlupa \n TELEPHONE NUMBER: \n (02) 751 4929']},
135 {'title': 'Healthfirst clinic ALABANG',
136 'Details': [
137 ' ADDRESS: \n G/F, South Supermarket, Filinvest Ave., Filinvest Corporate City \n TELEPHONE NUMBER: \n (+632) 8 821 1423 | 0917 842 8214']},
138 {'title': 'Ospital ng Muntinlupa ( OSMUN )',
139 'Details': [
140 ' ADDRESS: \n Civic Dr, Alabang, Muntinlupa \n TELEPHONE NUMBER: \n (02) 8771 0457']},
141 {'title': 'St. Michaels Medical Center',
142 'Details': [
143 ' ADDRESS: \n Starmall Alabang, South Super Hwy, Alabang, Muntinlupa\n TELEPHONE NUMBER: \n 0921 624 4418']},
144 {'title': 'San Roque Medical Clinic',
145 'Details': [' ADDRESS: \n Alabang, Muntinlupa \n TELEPHONE NUMBER: \n (02) 8842 2950']},
146 {'title': 'Megason Diagnostic Clinic',
147 'Details': [' ADDRESS: \nAlabang, Muntinlupa \n TELEPHONE NUMBER: \n (02) 8809 9044']},
148 {'title': 'Tokyo Healthlink 東京ヘルスリンク - Alabang',
149 'Details': [
150 ' ADDRESS: \n Molito Complex, Madrigal Ave, Ayala Alabang, Muntinlupa \n TELEPHONE NUMBER: \n (02) 8772 2678']},
151 {'title': 'Research Institute for Tropical Medicine',
152 'Details': [
153 ' ADDRESS: \n Filinvest Corporate City, 9002 Research Dr, Alabang, Muntinlupa \n TELEPHONE NUMBER: \n (02) 8807 2631']},
154 ]},
155 {'Category': 'Barangay BAYANAN',
156 'Record': [
157 {'title': 'Silverio Medical Clinic',
158 'Details': [
159 ' ADDRESS: \n 233g National Road, Muntinlupa \n TELEPHONE NUMBER: \n (02) 8862 0223']},
160 {'title': 'Bayanan Health Center (Annex)',
161 'Details': [
162 ' ADDRESS: \n Block 2, Purok 1, 292 M Dolleton St, Muntinlupa \n TELEPHONE NUMBER: \n (02) 8862 0124']},
163 {'title': 'Bayanan Medical Clinic, X-Ray and Laboratory Services',
164 'Details': [
165 ' ADDRESS: \n 231 National Road, Bayanan, Muntinlupa \n TELEPHONE NUMBER: \n (02) 8861 5861']},
166 {'title': 'El Natividad Medical And Maternity Clinic',
167 'Details': [
168 ' ADDRESS: \n 214 National Road, Muntinlupa \n TELEPHONE NUMBER: \n 0923 701 5164']},
169 ]},
170 {'Category': 'Barangay CUPANG',
171 'Record': [
172 {'title': 'Hillside General Hospital',
173 'Details': [
174 ' ADDRESS: \n Km. 23, West Service Road, Cupang, Muntinlupa \n TELEPHONE NUMBER: \n (02) 8842 3958']},
175 {'title': 'Alabang Medical Center',
176 'Details': [
177 ' ADDRESS: \n 8 Corregidor, Cupang, Muntinlupa \n TELEPHONE NUMBER: \n (02) 8850 8719']},
178 {'title': 'Cupang Health Center',
179 'Details': [
180 ' ADDRESS: \n Barangay Hall, Beside Cupang, Manuel L. Quezon, Cupang, Muntinlupa \n TELEPHONE NUMBER: \n --']},
181 ]},
182 {'Category': 'Barangay POBLACION',
183 'Record': [
184 {'title': 'Albia Medical & Diagnostic Clinic',
185 'Details': [
186 ' ADDRESS: \n 93 Rizal St, Poblacion, Muntinlupa \n TELEPHONE NUMBER: \n (02)8461204']},
187 {'title': 'Babaran Echavez Medical And Psychiatric Clinic',
188 'Details': [
189 ' ADDRESS: \n 1125 Amparo Corner Sto Nino Street, Poblacion, Muntinlupa \n TELEPHONE NUMBER: \n (02) 8861 3066']},
190 {'title': 'MCC De La Merced Maternity And Childrens Clinic',
191 'Details': [
192 ' ADDRESS: \n 92 Rizal St, Poblacion, Muntinlupa \n TELEPHONE NUMBER: \n (02) 8861 3944']},
193 {'title': 'Mauricestela Medical Clinic',
194 'Details': [
195 ' ADDRESS: \n 212 Pedro Diaz St, Poblacion, Muntinlupa, 1776 Metro Manila \n TELEPHONE NUMBER: \n (02) 8862 2117']},
196 {'title': 'Poblacion Health Center Main',
197 'Details': [
198 ' ADDRESS: \n Poblacion, Muntinlupa \n TELEPHONE NUMBER: \n NONE']},
199 ]},
200 {'Category': 'Barangay PUTATAN',
201 'Record': [
202 {'title': 'Alabang Medical Clinic - Muntinlupa Branch',
203 'Details': [
204 ' ADDRESS: \n 1 National Highway, Putatan, Muntinlupa \n TELEPHONE NUMBER: \n (02) 8861 1779']},
205 {'title': 'IMS Wellth Care, Inc.',
206 'Details': [
207 ' ADDRESS: \n 49 National Road, Putatan, Muntinlupa \n TELEPHONE NUMBER: \n (02) 8861 1592']},
208 {'title': 'Medical Center Muntinlupa',
209 'Details': [
210 ' ADDRESS: \n National Road, Putatan, Muntinlupa \n TELEPHONE NUMBER: \n 8620162']},
211 {'title': 'Muntinlupa Doctors Clinic',
212 'Details': [
213 ' ADDRESS: \n 1 National Road, Putatan, Muntinlupa \n TELEPHONE NUMBER: \n (02) 8842 2718']},
214 {'title': 'Medcare Multi Specialty',
215 'Details': [
216 ' ADDRESS: \n 84-I, National Road, Barangay Putatan, Muntinlupa \n TELEPHONE NUMBER: \n 0922 857 4180']},
217 ]},
218 {'Category': 'Barangay SUCAT',
219 'Record': [
220 {'title': 'Sucat Health Center',
221 'Details': [
222 ' ADDRESS: \n 624 Dir. A. Bunye, Sucat, Muntinlupa \n TELEPHONE NUMBER: \n NONE']},
223 ]},
224 {'Category': 'Barangay TUNASAN',
225 'Record': [
226 {'title': 'Beato-Cauilan Hospital',
227 'Details': [
228 ' ADDRESS: \n Manila S Rd, Tunasan, Muntinlupa \n TELEPHONE NUMBER: \n +632 861-5284']},
229 ]}]
230
231 def on_start(self):
232 conn = sql.connect('USERINFO.db')
233 cur = conn.cursor()
234 cur.execute("""
235 SELECT fname, age, height, weight, heartrate, RESULT, DATE_TIME
236 FROM information INNER JOIN results
237 ON information.id = results.UID
238 """)
239 output = cur.fetchall()
240 self.row_data = output
241 # for data in output:
242 # self.row_data = data
243 self.column_data = [("Name", dp(35)), ("Age", dp(25)), ("Height", dp(25)), ("Weight", dp(25)),
244 ("Heartrate", dp(25)), ("Result", dp(25)), ("Date/Time", dp(35))]
245 self.data_tables = MDDataTable(size_hint=(0.9, 0.6),use_pagination=True,
246 column_data=self.column_data, row_data=self.row_data)
247 self.root.ids.scr_mngr.get_screen('history').ids.dt_layout.add_widget(self.data_tables)
248 Clock.schedule_interval(self.update_news, 5) # every 5 seconds, show the next story
249 for category in self.card_file:
250 panel = MDExpansionPanel(icon="scr2.png", content=Content(),
251 panel_cls=MDExpansionPanelTwoLine(text=category['Category'],
252 secondary_text="Tap to view Hospitals"))
253 self.root.ids.scr_mngr.get_screen('locsearch').ids.rlist.add_widget(panel)
254 for rec in category['Record']:
255 rw = RecordLine(text=rec['title'])
256 var = (rec['title'])
257 self.root.ids.scr_mngr.get_screen('locsearch').ids.rlist.children[0].content.add_widget(rw)
258
259 def showinfo(self, cat, r):
260 close_button = MDFlatButton(text="Done", on_release=self.close_dialog)
261 ingredients = self.hlist(cat, r)
262 ingredients_text = ''
263 for ingredient in ingredients:
264 ingredients_text += ingredient
265 self.dialog = InformationDialog(size_hint=(0.8, 0.8), text=ingredients_text, auto_dismiss=True,
266 buttons=[close_button])
267 self.dialog.open()
268
269 def hlist(self, selected_cat, selected_r):
270 self.selected_rec = selected_r
271 self.selected_category = selected_cat
272 for category in self.card_file:
273 if category['Category'] == selected_cat:
274 for rec in category['Record']:
275 if rec['title'] == selected_r:
276 return rec['Details']
277
278 def on_stop(self): # Event handler that triggers when the application has finished running
279 # Creates a json file to saved the all the items in dictionary when closing the app
280 with open('saved_list.txt', 'w') as f:
281 json.dump(self.list_items, f)
282
283 class Container(IRightBodyTouch, MDBoxLayout): # This line position widget to the right.
284 adaptive_width = True
285
286 def update_news(self, dt):
287 # this is moving through the list of stories pulled, it does not go back to the web for more content
288 # to get refresed content call self.news.get_news()
289 # Skip stories that don't have a picture and a description
290 if not self.news.headlines[self.i][1] or not self.news.headlines[self.i][2]:
291 self.i = (self.i + 1) % len(self.news.headlines)
292 self.update_news(None) # junk parameter...
293 else:
294 p = self.root.ids.scr_mngr.get_screen('menu').ids.nl # a sort cut to avoid writing self.root.ids.dl 3x
295 p.title = self.news.headlines[self.i][0] # The title
296 p.picture = self.news.headlines[self.i][1] # url to the picture
297 p.description = self.news.headlines[self.i][2]
298 self.i = (self.i + 1) % len(self.news.headlines)
299
300 def save_data(self):
301 conn = sql.connect('USERINFO.db')
302 cur = conn.cursor()
303 cur.execute(""" INSERT INTO information (fname,height,weight,age,heartrate) VALUES (?,?,?,?,?)""",
304 (self.root.ids.scr_mngr.get_screen('input').ids.fname.text,
305 self.root.ids.scr_mngr.get_screen('input').ids.height.text,
306 self.root.ids.scr_mngr.get_screen('input').ids.weight.text,
307 self.root.ids.scr_mngr.get_screen('input').ids.age.text,
308 self.root.ids.scr_mngr.get_screen('input').ids.heartrate.text))
309 conn.commit()
310 conn.close()
311
312 def result_condition(self):
313 n = int(10000)
314 h = int(self.root.ids.scr_mngr.get_screen('input').ids.height.text)
315 w = int(self.root.ids.scr_mngr.get_screen('input').ids.weight.text)
316 unix = time.time()
317 date = str(datetime.datetime.fromtimestamp(unix).strftime('%Y-%m-%d %H:%M:%S'))
318 answer = (w / h / h) * n
319 (round(answer,2))
320
321 conn = sql.connect('USERINFO.db')
322 cur = conn.cursor()
323 cur.execute(""" INSERT INTO results (RESULT,DATE_TIME) VALUES (?,?)""",
324 (
325 (round(answer,2)),
326 date
327 ))
328 conn.commit()
329 conn.close()
330 if answer <= 18.5:
331 self.root.ids.scr_mngr.current = 'underweight'
332 elif 18.6 <= answer <= 24.9:
333 self.root.ids.scr_mngr.current = 'normal'
334 elif 25.0 <= answer <= 29.9:
335 self.root.ids.scr_mngr.current = 'overweight'
336 else:
337 self.root.ids.scr_mngr.current = 'obese'
338
339 def clear_inputs(self): # set each of the inputs to an empty string
340 self.root.ids.scr_mngr.get_screen('input').ids.fname.text = ""
341 self.root.ids.scr_mngr.get_screen('input').ids.heartrate.text = ""
342 self.root.ids.scr_mngr.get_screen('input').ids.age.text = ""
343 self.root.ids.scr_mngr.get_screen('input').ids.height.text = ""
344 self.root.ids.scr_mngr.get_screen('input').ids.weight.text = ""
345
346 def info1_dialog(self):
347 close_button = MDFlatButton(text="Okay", on_release=self.close_dialog)
348 self.dialog = MDDialog(title="Details",
349 text="Hospitals listed are still operating up-to-date",
350 size_hint=(1, 1),
351 buttons=[close_button])
352 self.dialog.open()
353
354 # def show_database(self):
355 # conn = sql.connect('USERINFO.db')
356 # cur = conn.cursor()
357 # cur.execute("""
358 # SELECT fname, height, weight, heartrate, RESULT, DATE_TIME
359 # FROM information INNER JOIN results
360 # ON information.id = results.UID
361 # """)
362 # output = cur.fetchall()
363 # for data in output:
364 # (data)
365
366 def build(self):
367 self.theme_cls.primary_palette = "Lime"
368 self.theme_cls.theme_style = "Light"
369 screen = Builder.load_file("main.kv")
370 return screen
371
372 def show_alert_dialog(self):
373 close_button = MDFlatButton(text="Okay",
374 on_release=self.okay)
375 more_button = MDFlatButton(text="Cancel", on_press=self.close_dialog)
376
377 self.dialog = MDDialog(title="Confirmation", text="Confirm Details?",
378 size_hint=(1, 1),
379 buttons=[close_button, more_button])
380 self.dialog.open()
381
382 def result_dialog(self):
383 close_button = MDFlatButton(text="Okay", on_release=self.close_dialog)
384 self.dialog = MDDialog(title="Where did we get the Results?",
385 text="Results are Determined based on the Details Given by the User",
386 size_hint=(1, 1),
387 buttons=[close_button])
388 self.dialog.open()
389
390 def hrdialog(self):
391 close_button = MDFlatButton(text="Okay", on_release=self.close_dialog)
392 self.dialog = MDDialog(title="Manual BPM Check",
393 text="Age Target BPM Average BPM \n 20 100 to 170 200 \n 30 95 to 162 "
394 " 190 \n 35 93 to 157 185 \n 40 90 to 153 180 \n 45 88 to "
395 "149 175 \n 50 85 to 145 170 \n 55 83 to 140 165 \n 60 80 "
396 "to 136 160 \n 65 78 to 132 155 \n 70 75 to 128 150 \n If "
397 "you feel that your heart is beating out of rhythm, too fast, or too slow, "
398 "speak to a doctor about your symptoms.",
399 size_hint=(1, 1),
400 buttons=[close_button])
401 self.dialog.open()
402
403 def bmidialog(self):
404 close_button = MDFlatButton(text="Okay", on_release=self.close_dialog)
405 self.dialog = MDDialog(title="Result Check",
406 text="If your BMI is less than 18.5, it falls within the underweight range. \n If your "
407 "BMI is 18.5 to 24.9, it falls within the normal or Healthy Weight range. \n If "
408 "your BMI is 25.0 to 29.9, it falls within the overweight range. \n If your BMI "
409 "is 30.0 or higher, it falls within the obese range.",
410 size_hint=(1, 1),
411 buttons=[close_button])
412 self.dialog.open()
413
414 def info2dialog(self):
415 close_button = MDFlatButton(text="Okay", on_release=self.close_dialog)
416 self.dialog = MDDialog(title="Instructions",
417 text="Manual Heartbeat check can be used to determine if you have a normal heart rate "
418 "for your age. \n "
419 "If height = feet/inches, Convert to Centimeter (FEET× 30.48 +INCHES× 2.54) ",
420 size_hint=(1, 1),
421 buttons=[close_button])
422 self.dialog.open()
423
424 def show_data(self, *args):
425 #btn.disabled=True
426 #Clock.schedule_once(partial(self.btn_enable,btn), 10)
427 if self.root.ids.scr_mngr.get_screen('input').ids.fname.text == "" \
428 or self.root.ids.scr_mngr.get_screen('input').ids.height.text == "" \
429 or self.root.ids.scr_mngr.get_screen('input').ids.weight.text == "" \
430 or self.root.ids.scr_mngr.get_screen('input').ids.heartrate.text == "" \
431 or self.root.ids.scr_mngr.get_screen('input').ids.age.text == "" \
432 or self.root.ids.scr_mngr.get_screen('input').ids.heartrate.text == "":
433 close_button = MDFlatButton(text="Okay", on_release=self.close_dialog)
434 self.dialog = MDDialog(title="Invalid", text="No item added",
435 size_hint=(1, 1), buttons=[close_button])
436 self.dialog.open()
437 else:
438 self.show_alert_dialog()
439
440 #def btn_enable(self, btn, *args):
441 # btn.disabled = False
442
443 def okay(self, *args):
444 var=(self.root.ids.scr_mngr.get_screen('input').ids.fname.text),
445 var=(self.root.ids.scr_mngr.get_screen('input').ids.height.text),
446 var=(self.root.ids.scr_mngr.get_screen('input').ids.weight.text),
447 var= (self.root.ids.scr_mngr.get_screen('input').ids.age.text),
448 var=(self.root.ids.scr_mngr.get_screen('input').ids.heartrate.text)
449 self.save_data()
450 self.result_condition()
451 self.clear_inputs()
452 self.dialog.dismiss()
453
454 def close_dialog(self, obj):
455 self.dialog.dismiss()
456
457 def history_screen(self, obj):
458 self.root.ids.scr_mngr.current = 'history'
459 self.root.ids.scr_mngr.transition.direction = "right"
460
461 def location_screen(self, obj):
462 self.root.ids.scr_mngr.current = 'locsearch'
463 self.root.ids.scr_mngr.transition.direction = "left"
464
465 def back_screen(self, obj):
466 self.root.ids.scr_mngr.current = 'menu'
467 self.root.ids.scr_mngr.transition.direction = "left"
468
469 # def back2_screen(self, obj):
470 # self.root.ids.scr_mngr.current = 'input'
471 # self.root.ids.scr_mngr.transition.direction = "right"
472
473 def back3_screen(self, obj):
474 self.root.ids.scr_mngr.current = 'menu'
475 self.root.ids.scr_mngr.transition.direction = "right"
476
477 def back4_screen(self, obj):
478 self.root.ids.scr_mngr.current = 'locsearch'
479 self.root.ids.scr_mngr.transition.direction = "right"
480
481 def back_screen6(self, obj):
482 self.root.ids.scr_mngr.current = 'menu'
483 self.root.ids.scr_mngr.transition.direction = "right"
484
485
486DemoApp().run()
487----------------------------------------
488from kivy.event import EventDispatcher
489from kivy.network.urlrequest import UrlRequest
490from kivy.properties import ListProperty
491
492
493class News(EventDispatcher):
494 headlines = ListProperty([('Uninitialized', 'Uninitialized', 'No news is good news!')])
495
496 def get_news(self, *args):
497 url = ('http://newsapi.org/v2/top-headlines?'
498 'country=ph&category=health&'
499 'apiKey=0a2a06f5a843426ca8384f89111bfe99')
500 req = UrlRequest(url, self._got_news, on_failure=self.fail, on_error=self.fail)
501
502 def _got_news(self, req, news):
503 var=(news)
504 self.headlines.clear()
505 for content in news['articles']:
506 self.headlines.append((content['title'], content['urlToImage'], content['description']))
507
508 def fail(self, instance, value):
509 print('you loose')
510 print(f'Error: {instance}, {value}')
511
512
513if __name__ == '__main__':
514 from kivy.app import App
515 from kivy.clock import Clock
516 from kivy.lang import Builder
517 from kivy.properties import StringProperty
518 from kivy.uix.screenmanager import Screen
519 from kivy.core.window import Window
520
521 import itertools
522 import pprint
523 from textwrap import dedent
524
525 kv = dedent("""
526 <NewsScreen>:
527 BoxLayout:
528 orientation: 'vertical'
529 Label:
530 size_hint_y: dp(.25)
531 text: root.headline
532 text_size: self.size
533 valign: 'center'
534 halign: 'center'
535 shorten: True
536 shorten_from: 'right'
537 font_size: dp(30)
538 padding: dp(20),dp(20)
539 theme_text_color:"ContrastParentBackground"
540 bold: True
541 GridLayout:
542 cols: 2
543 padding: dp(20)
544 AsyncImage:
545 source: root.headline_image
546 anim_delay: .03334 # 15fps, for gif videos
547 nocache: True
548 Label:
549 padding_x: dp(20)
550 text: root.description
551 text_size: self.size
552 font_size: 25
553 valign: 'center'
554
555 BoxLayout: # This is the root widget
556 orientation: 'vertical'
557 ScreenManager:
558 id: sm
559 NewsScreen:
560 name: 'news'
561 next: 'weather'
562 duration: 30
563 """)
564
565
566 class NewsScreen(Screen):
567 headline = StringProperty('')
568 headline_image = StringProperty('')
569 description = StringProperty('')
570
571 def __init__(self, **kwargs):
572 super().__init__(**kwargs)
573 self.app = App.get_running_app()
574 self.story = itertools.cycle(self.app.news.headlines)
575 Clock.schedule_once(self.initial_news, 10)
576 self.refresh = Clock.schedule_interval(self.news_next, 15)
577
578 def initial_news(self, *args):
579 self.headline = self.app.news.headlines[0][0] if self.app.news.headlines[0][0] else 'junk'
580 self.headline_image = self.app.news.headlines[0][1] if self.app.news.headlines[0][1] else 'junk'
581 self.description = self.app.news.headlines[0][2] if self.app.news.headlines[0][2] else 'No Description'
582 print(self.headline)
583
584 def news_next(self, *args):
585 n = next(self.story)
586 self.headline = n[0]
587 self.headline_image = n[1] if n[1] is not None else ''
588 self.description = n[2]
589
590 # def on_pre_enter(self, *args):
591 # self.refresh() # start the news refresh schedule
592 #
593 # def on_leave(self, *args):
594 # self.refresh.cancel() # cancel the schedule when we leave the screen
595
596
597 class TestNewsApp(App):
598 news = News()
599
600 def build(self):
601 Window.size = 1500, 303
602 Window.top = 100
603 Window.left = 10
604 return Builder.load_string(kv)
605
606 def on_start(self):
607 self.news.get_news()
608 Clock.schedule_once(self.print_news, 5) # wait for site..
609 print('waiting 5 seconds...')
610
611 def print_news(self, dt):
612 pp = pprint.PrettyPrinter(width=80, compact=True)
613 pp.pprint(self.news.headlines)
614
615
616 TestNewsApp().run()
617-------------------------------
618Screen:
619 ScreenManager:
620 id:scr_mngr
621 MainMenuScreen:
622 name:"menu"
623 InputScreen:
624 name:"input"
625 RestingHeartRateScreen:
626 name:"heartrate"
627 ResultObeseScreen:
628 name:"obese"
629 ResultUnderweightScreen:
630 name:"underweight"
631 ResultOverweightScreen:
632 name:"overweight"
633 ResultNormalScreen:
634 name:"normal"
635 LocationSearchScreen:
636 name:"locsearch"
637 LocationResultScreen:
638 name:"locresult"
639 HistoryScreen:
640 name:"history"
641
642<MainMenuScreen>
643# MDBoxLayout:
644# ScreenManager:
645# Screen:
646 MDBoxLayout:
647 orientation:'vertical'
648 # MDToolbar:
649 # title:'MD 24/7'
650 # elevation:10
651
652 NewsLayout:
653 id: nl # and in id to access the instance
654 pos_hint:{'center_y':0.3}
655 orientation:'vertical'
656
657 MDBottomAppBar:
658 MDToolbar:
659 icon: "account"
660 type: "bottom"
661 elevation_normal: 8
662 on_action_button:
663 root.manager.current='input'
664 root.manager.transition.direction = "right"
665 left_action_items:[["history",lambda x: app.history_screen("history")]]
666 right_action_items:[["google-earth",lambda x: app.location_screen("locsearch")]]
667
668<NewsLayout>:
669 orientation: 'vertical'
670 padding: dp(20)
671 Label:
672 text: root.title
673 text_size: self.size
674 halign: 'center'
675 valign: 'center'
676 color : 0,0,0,1
677 size_hint_y: None
678 height: dp(50)
679 bold: True
680 AsyncImage:
681 source: root.picture
682 size_hint_y: .5
683 Label:
684 text_size: self.size
685 halign: 'center'
686 text: root.description
687 color: 0,0,0,1
688 size_hint_y: .8
689
690<InputScreen>
691 on_pre_enter: app.clear_inputs()
692 id:information
693 BoxLayout:
694 orientation: 'vertical'
695 MDToolbar:
696 title:'Input Details'
697 elevation:10
698 left_action_items:[["backspace",lambda x:app.back_screen("menu")]]
699 right_action_items:[["head-question",lambda x:app.info2dialog()]]
700
701 Widget:
702 MDTextField:
703 id:fname
704 hint_text: "Full name"
705 icon_right:"account"
706 pos_hint: {'center_x': 0.5}
707 size_hint_x: None
708 width: '250dp'
709 helper_text:"Please enter your Registered Name"
710 helper_text_mode:"persistent"
711 Widget:
712 height: dp(35)
713
714 MDTextField:
715 id:height
716 input_filter:'int'
717 hint_text: "Height"
718 icon_right:"human-male-height"
719 pos_hint: {'center_x': 0.5}
720 size_hint_x: None
721 width: '250dp'
722 helper_text:"Must be in centimeters"
723 helper_text_mode:"persistent"
724 Widget:
725 height:dp(35)
726
727 MDTextField:
728 id:weight
729 hint_text: "Weight"
730 input_filter:'int'
731 icon_right:"weight-kilogram"
732 pos_hint: {'center_x': 0.5}
733 size_hint_x: None
734 width: '250dp'
735 helper_text:"Must be in Kilogram"
736 helper_text_mode:"persistent"
737 Widget:
738 height:dp(35)
739
740 MDTextField:
741 id:age
742 hint_text: "Age"
743 input_filter:'int'
744 icon_right:"cake"
745 pos_hint: {'center_x': 0.5}
746 size_hint_x: None
747 width: '250dp'
748 helper_text:"please enter your age"
749 helper_text_mode:"persistent"
750 Widget:
751 height: dp(35)
752
753 MDTextField:
754 id:heartrate
755 hint_text: "Heartrate"
756 input_filter:'int'
757 icon_right:"heart-pulse"
758 pos_hint: {'center_x': 0.5}
759 size_hint_x: None
760 width: '250dp'
761 helper_text:"Count the beat on your palm for 60 seconds"
762 helper_text_mode:"persistent"
763 Widget:
764 size_hint_y: None
765
766 MDScreen:
767 MDRectangleFlatButton:
768 mode: "rectangle"
769 text: '[color=#000000]Confirm'
770 pos_hint: {'center_x':0.5, 'center_y':0.8}
771 on_press :
772 app.show_data()
773
774 Widget:
775 size_hint_x: None
776
777<ResultObeseScreen>
778 BoxLayout:
779 orientation: 'vertical'
780 MDToolbar:
781 title:'Result: OBESE'
782 elevation:10
783 right_action_items:[["head-question",lambda x:app.result_dialog()]]
784 Widget:
785
786 MDLabel:
787 text: "People with obesity have increased risk of cardiovascular disease,type 2 diabetes, high blood pressure, and other health conditions. Waist-to-hip ratio, waist-to-height ratio, and body fat percentage measurements can provide a more complete picture of any health risks. A person should consult with their healthcare provider and consider making lifestyle changes through healthy eating and fitness to improve their health indicators. \n TIPS: \n *Change your diet. \n *Consider adding physical activity \n *Consume less “bad” fat and more “good” fat. \n *Eat more servings of vegetables and fruits \n *limit your vices (drinking,smoking,etc)"
788 halign: "center"
789
790 Widget:
791
792 MDScreen:
793 MDRectangleFlatIconButton:
794 icon:"account"
795 text: '[color=#000000]Main Menu'
796 pos_hint: {'center_x':0.25, 'center_y':0.9}
797 on_press : root.manager.current='menu'
798 MDRectangleFlatIconButton:
799 icon:"heart-pulse"
800 text: '[color=#000000]Heartbeat Results'
801 pos_hint: {'center_x':0.7, 'center_y':0.9}
802 on_press : app.hrdialog()
803
804
805<ResultNormalScreen>
806 BoxLayout:
807 orientation: 'vertical'
808 MDToolbar:
809 title:'Result: NORMAL WEIGHT'
810 elevation:10
811 right_action_items:[["head-question",lambda x:app.result_dialog()]]
812 Widget:
813
814 MDLabel:
815 text :"Maintaining a healthy weight may lower the risk of developing certain health conditions, including cardiovascular disease and type 2 diabetes. Waist-to-hip ratio, waist-to-height ratio, and body fat percentage measurements can provide a more complete picture of any health risks. \n TIPS: \n *Limit what you eat \n *exercise \n *sleep 7-8 hours a day \n *maintain a consistent sleeping routine \n *consider eating more healthy foods \n *limit your vices (drinking,smoking,etc)"
816 halign: "center"
817
818 Widget:
819
820 MDScreen:
821 MDRectangleFlatIconButton:
822 icon:"account"
823 text: '[color=#000000]Main Menu'
824 pos_hint: {'center_x':0.25, 'center_y':0.9}
825 on_press : root.manager.current='menu'
826 MDRectangleFlatIconButton:
827 icon:"heart-pulse"
828 text: '[color=#000000]Heartbeat Results'
829 pos_hint: {'center_x':0.7, 'center_y':0.9}
830 on_press : app.hrdialog()
831
832<ResultOverweightScreen>
833 BoxLayout:
834 orientation: 'vertical'
835 MDToolbar:
836 title:'Result: OVERWEIGHT'
837 elevation:10
838 right_action_items:[["head-question",lambda x:app.result_dialog()]]
839 Widget:
840
841 MDLabel:
842 text: "Being overweight may increase the risk of certain health conditions, including cardiovascular disease, high blood pressure, and type 2 diabetes. A person should consult with their healthcare provider and consider making lifestyle changes through healthy eating and fitness to improve their health indicators.Being overweight or fat is having more body fat than is optimally healthy \n TIPS: \n *Eat a high protein breakfast. \n *Avoid sugary drinks and fruit juice \n *Drink water before meals. \n *Choose weight-loss-friendly foods. \n *Drink coffee or tea. \n *Base your diet on whole foods. \n *Eat slowly. \n *limit your vices (drinking,smoking,etc)"
843 halign: "center"
844
845 Widget:
846
847 MDScreen:
848 MDRectangleFlatIconButton:
849 icon:"account"
850 text: '[color=#000000]Main Menu'
851 pos_hint: {'center_x':0.25, 'center_y':0.9}
852 on_press : root.manager.current='menu'
853 MDRectangleFlatIconButton:
854 icon:"heart-pulse"
855 text: '[color=#000000]Heartbeat Results'
856 pos_hint: {'center_x':0.7, 'center_y':0.9}
857 on_press : app.hrdialog()
858
859<ResultUnderweightScreen>
860 BoxLayout:
861 orientation: 'vertical'
862 MDToolbar:
863 title:'Result: UNDERWEIGHT'
864 elevation:10
865 right_action_items:[["head-question",lambda x:app.result_dialog()]]
866 Widget:
867
868 MDLabel:
869 text: "Being underweight may pose certain health risks, including nutrient deficiencies and hormonal changes. Waist-to-hip ratio, waist-to-height ratio, and body fat percentage measurements can provide a more complete picture of any health risks. A person should consult with their healthcare provider and consider making lifestyle changes through healthy eating and fitness to improve their health indicators.Being underweight can cause health problems. An underweight person is a person whose body weight is considered too low to be healthy \n TIPS: \n *eat more frequently \n *choose nutrient-rich foods \n *watch what you eat and drink \n *exercise \n *limit your vices (drinking,smoking,etc)"
870 halign: "center"
871
872 Widget:
873
874 MDScreen:
875 MDRectangleFlatIconButton:
876 icon:"account"
877 text: '[color=#000000]Main Menu'
878 pos_hint: {'center_x':0.25, 'center_y':0.9}
879 on_press : root.manager.current='menu'
880 MDRectangleFlatIconButton:
881 icon:"heart-pulse"
882 text: '[color=#000000]Heartbeat Results'
883 pos_hint: {'center_x':0.7, 'center_y':0.9}
884 on_press : app.hrdialog()
885
886<LocationSearchScreen>
887 BoxLayout:
888 orientation: 'vertical'
889 MDToolbar:
890 title:'Hospital Searcher'
891 elevation:10
892 left_action_items:[["backspace",lambda x:app.back_screen6("menu")]]
893 right_action_items:[["head-question",lambda x:app.info1_dialog()]]
894
895 ScrollView:
896 MDList:
897 id: rlist
898<RecordLine>:
899 adaptive_height: True
900 OneLineListItem:
901 text: root.text
902 on_release: app.showinfo(root.parent.parent.panel_cls.text, self.text)
903
904<InformationDialog>:
905 title: "Details:"
906
907<OneLineAvatarIconListItem>: # The list widget
908 id: icnlst
909 IconLeftWidget:
910 icon: "clipboard"
911
912<HistoryScreen>
913 FloatLayout:
914 AnchorLayout:
915 anchor_x: 'center'
916 anchor_y: 'bottom'
917
918 AnchorLayout:
919 id: dt_layout
920
921 MDToolbar:
922 id: toolbar
923 pos_hint: {"top": 1}
924 elevation: 6
925 title: "Check History"
926 left_action_items:[["backspace",lambda x:app.back_screen("menu")]]
927
928 MDScreen:
929 MDRectangleFlatIconButton:
930 icon: "weight-lifter"
931 text: '[color=#000000]Check BMI'
932 pos_hint: {'center_x':0.25, 'center_y':0.1}
933 on_press : app.bmidialog()
934 MDRectangleFlatIconButton:
935 icon: "heart-pulse"
936 text: '[color=#000000]Heartbeat Results'
937 pos_hint: {'center_x':0.7, 'center_y':0.1}
938 on_press : app.hrdialog()