· 4 years ago · Mar 02, 2021, 06:20 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
242 self.column_data = [("Name", dp(35)), ("Age", dp(25)), ("Height", dp(25)), ("Weight", dp(25)),
243 ("Heartrate", dp(25)), ("Result", dp(25)), ("Date/Time", dp(35))]
244 self.data_tables = MDDataTable(size_hint=(0.9, 0.6),use_pagination=True,
245 column_data=self.column_data, row_data=self.row_data)
246 self.root.ids.scr_mngr.get_screen('history').ids.dt_layout.add_widget(self.data_tables)
247 Clock.schedule_interval(self.update_news, 5) # every 5 seconds, show the next story
248 for category in self.card_file:
249 panel = MDExpansionPanel(icon='hospital-building', content=Content(),
250 panel_cls=MDExpansionPanelTwoLine(text=category['Category'],
251 secondary_text="Tap to view Hospitals"))
252 self.root.ids.scr_mngr.get_screen('locsearch').ids.rlist.add_widget(panel)
253 for rec in category['Record']:
254 rw = RecordLine(text=rec['title'])
255 var = (rec['title'])
256 self.root.ids.scr_mngr.get_screen('locsearch').ids.rlist.children[0].content.add_widget(rw)
257
258 def showinfo(self, cat, r):
259 close_button = MDFlatButton(text="Done", on_release=self.close_dialog)
260 ingredients = self.hlist(cat, r)
261 ingredients_text = ''
262 for ingredient in ingredients:
263 ingredients_text += ingredient
264 self.dialog = InformationDialog(size_hint=(0.8, 0.8), text=ingredients_text, auto_dismiss=True,
265 buttons=[close_button])
266 self.dialog.open()
267
268 def hlist(self, selected_cat, selected_r):
269 self.selected_rec = selected_r
270 self.selected_category = selected_cat
271 for category in self.card_file:
272 if category['Category'] == selected_cat:
273 for rec in category['Record']:
274 if rec['title'] == selected_r:
275 return rec['Details']
276
277 def on_stop(self): # Event handler that triggers when the application has finished running
278 # Creates a json file to saved the all the items in dictionary when closing the app
279 with open('saved_list.txt', 'w') as f:
280 json.dump(self.list_items, f)
281
282 class Container(IRightBodyTouch, MDBoxLayout): # This line position widget to the right.
283 adaptive_width = True
284
285 def update_news(self, dt):
286 # this is moving through the list of stories pulled, it does not go back to the web for more content
287 # to get refresed content call self.news.get_news()
288 # Skip stories that don't have a picture and a description
289 if not self.news.headlines[self.i][1] or not self.news.headlines[self.i][2]:
290 self.i = (self.i + 1) % len(self.news.headlines)
291 self.update_news(None) # junk parameter...
292 else:
293 p = self.root.ids.scr_mngr.get_screen('menu').ids.nl # a sort cut to avoid writing self.root.ids.dl 3x
294 p.title = self.news.headlines[self.i][0] # The title
295 p.picture = self.news.headlines[self.i][1] # url to the picture
296 p.description = self.news.headlines[self.i][2]
297 self.i = (self.i + 1) % len(self.news.headlines)
298
299 def save_data(self):
300 conn = sql.connect('USERINFO.db')
301 cur = conn.cursor()
302 cur.execute(""" INSERT INTO information (fname,height,weight,age,heartrate) VALUES (?,?,?,?,?)""",
303 (self.root.ids.scr_mngr.get_screen('input').ids.fname.text,
304 self.root.ids.scr_mngr.get_screen('input').ids.height.text,
305 self.root.ids.scr_mngr.get_screen('input').ids.weight.text,
306 self.root.ids.scr_mngr.get_screen('input').ids.age.text,
307 self.root.ids.scr_mngr.get_screen('input').ids.heartrate.text))
308 conn.commit()
309 conn.close()
310
311 def result_condition(self):
312 n = int(10000)
313 h = int(self.root.ids.scr_mngr.get_screen('input').ids.height.text)
314 w = int(self.root.ids.scr_mngr.get_screen('input').ids.weight.text)
315 unix = time.time()
316 date = str(datetime.datetime.fromtimestamp(unix).strftime('%Y-%m-%d %H:%M:%S'))
317 answer = (w / h / h) * n
318 (round(answer,2))
319
320 conn = sql.connect('USERINFO.db')
321 cur = conn.cursor()
322 cur.execute(""" INSERT INTO results (RESULT,DATE_TIME) VALUES (?,?)""",
323 (
324 (round(answer,2)),
325 date
326 ))
327 conn.commit()
328 conn.close()
329 if answer <= 18.5:
330 self.root.ids.scr_mngr.current = 'underweight'
331 elif 18.6 <= answer <= 24.9:
332 self.root.ids.scr_mngr.current = 'normal'
333 elif 25.0 <= answer <= 29.9:
334 self.root.ids.scr_mngr.current = 'overweight'
335 else:
336 self.root.ids.scr_mngr.current = 'obese'
337
338 def clear_inputs(self): # set each of the inputs to an empty string
339 self.root.ids.scr_mngr.get_screen('input').ids.fname.text = ""
340 self.root.ids.scr_mngr.get_screen('input').ids.heartrate.text = ""
341 self.root.ids.scr_mngr.get_screen('input').ids.age.text = ""
342 self.root.ids.scr_mngr.get_screen('input').ids.height.text = ""
343 self.root.ids.scr_mngr.get_screen('input').ids.weight.text = ""
344
345 def info1_dialog(self):
346 close_button = MDFlatButton(text="Okay", on_release=self.close_dialog)
347 self.dialog = MDDialog(title="Details",
348 text="Hospitals listed are still operating up-to-date",
349 size_hint=(1, 1),
350 buttons=[close_button])
351 self.dialog.open()
352 def build(self):
353 self.theme_cls.primary_palette = "Lime"
354 self.theme_cls.theme_style = "Light"
355 screen = Builder.load_file("main.kv")
356 return screen
357
358 def show_alert_dialog(self):
359 close_button = MDFlatButton(text="Okay",
360 on_release=self.okay)
361 more_button = MDFlatButton(text="Cancel", on_press=self.close_dialog)
362
363 self.dialog = MDDialog(title="Confirmation", text="Confirm Details?",
364 size_hint=(1, 1),
365 buttons=[close_button, more_button])
366 self.dialog.open()
367
368 def result_dialog(self):
369 close_button = MDFlatButton(text="Okay", on_release=self.close_dialog)
370 self.dialog = MDDialog(title="Where did we get the Results?",
371 text="Results are Determined based on the Details Given by the User",
372 size_hint=(1, 1),
373 buttons=[close_button])
374 self.dialog.open()
375
376 def hrdialog(self):
377 close_button = MDFlatButton(text="Okay", on_release=self.close_dialog)
378 self.dialog = MDDialog(title="Manual BPM Check",
379 text="Age Target BPM Average BPM \n 20 100 to 170 200 \n 30 95 to 162 "
380 " 190 \n 35 93 to 157 185 \n 40 90 to 153 180 \n 45 88 to "
381 "149 175 \n 50 85 to 145 170 \n 55 83 to 140 165 \n 60 80 "
382 "to 136 160 \n 65 78 to 132 155 \n 70 75 to 128 150 \n If "
383 "you feel that your heart is beating out of rhythm, too fast, or too slow, "
384 "speak to a doctor about your symptoms.",
385 size_hint=(1, 1),
386 buttons=[close_button])
387 self.dialog.open()
388
389 def bmidialog(self):
390 close_button = MDFlatButton(text="Okay", on_release=self.close_dialog)
391 self.dialog = MDDialog(title="Result Check",
392 text="If your BMI is less than 18.5, it falls within the underweight range. \n If your "
393 "BMI is 18.5 to 24.9, it falls within the normal or Healthy Weight range. \n If "
394 "your BMI is 25.0 to 29.9, it falls within the overweight range. \n If your BMI "
395 "is 30.0 or higher, it falls within the obese range.",
396 size_hint=(1, 1),
397 buttons=[close_button])
398 self.dialog.open()
399
400 def info2dialog(self):
401 close_button = MDFlatButton(text="Okay", on_release=self.close_dialog)
402 self.dialog = MDDialog(title="Instructions",
403 text="Manual Heartbeat check can be used to determine if you have a normal heart rate "
404 "for your age. \n "
405 "If height = feet/inches, Convert to Centimeter (FEET× 30.48 +INCHES× 2.54) ",
406 size_hint=(1, 1),
407 buttons=[close_button])
408 self.dialog.open()
409
410 def show_data(self, *args):
411 #btn.disabled=True
412 #Clock.schedule_once(partial(self.btn_enable,btn), 10)
413 if self.root.ids.scr_mngr.get_screen('input').ids.fname.text == "" \
414 or self.root.ids.scr_mngr.get_screen('input').ids.height.text == "" \
415 or self.root.ids.scr_mngr.get_screen('input').ids.weight.text == "" \
416 or self.root.ids.scr_mngr.get_screen('input').ids.heartrate.text == "" \
417 or self.root.ids.scr_mngr.get_screen('input').ids.age.text == "" \
418 or self.root.ids.scr_mngr.get_screen('input').ids.heartrate.text == "":
419 close_button = MDFlatButton(text="Okay", on_release=self.close_dialog)
420 self.dialog = MDDialog(title="Invalid", text="No item added",
421 size_hint=(1, 1), buttons=[close_button])
422 self.dialog.open()
423 else:
424 self.show_alert_dialog()
425
426 def okay(self, *args):
427 var=(self.root.ids.scr_mngr.get_screen('input').ids.fname.text),
428 var=(self.root.ids.scr_mngr.get_screen('input').ids.height.text),
429 var=(self.root.ids.scr_mngr.get_screen('input').ids.weight.text),
430 var= (self.root.ids.scr_mngr.get_screen('input').ids.age.text),
431 var=(self.root.ids.scr_mngr.get_screen('input').ids.heartrate.text)
432 self.save_data()
433 self.result_condition()
434 self.clear_inputs()
435 self.dialog.dismiss()
436
437 def close_dialog(self, obj):
438 self.dialog.dismiss()
439
440 def history_screen(self, obj):
441 self.root.ids.scr_mngr.current = 'history'
442 self.root.ids.scr_mngr.transition.direction = "right"
443
444 def location_screen(self, obj):
445 self.root.ids.scr_mngr.current = 'locsearch'
446 self.root.ids.scr_mngr.transition.direction = "left"
447
448 def back_screen(self, obj):
449 self.root.ids.scr_mngr.current = 'menu'
450 self.root.ids.scr_mngr.transition.direction = "left"
451
452 def back3_screen(self, obj):
453 self.root.ids.scr_mngr.current = 'menu'
454 self.root.ids.scr_mngr.transition.direction = "right"
455
456 def back4_screen(self, obj):
457 self.root.ids.scr_mngr.current = 'locsearch'
458 self.root.ids.scr_mngr.transition.direction = "right"
459
460 def back_screen6(self, obj):
461 self.root.ids.scr_mngr.current = 'menu'
462 self.root.ids.scr_mngr.transition.direction = "right"
463
464
465DemoApp().run()
466--------------------------------
467from kivy.event import EventDispatcher
468from kivy.network.urlrequest import UrlRequest
469from kivy.properties import ListProperty
470
471
472class News(EventDispatcher):
473 headlines = ListProperty([('Uninitialized', 'Uninitialized', 'No news is good news!')])
474
475 def get_news(self, *args):
476 url = ('http://newsapi.org/v2/top-headlines?'
477 'country=ph&category=health&q=covid&'
478 'apiKey=0a2a06f5a843426ca8384f89111bfe99')
479 req = UrlRequest(url, self._got_news, on_failure=self.fail, on_error=self.fail)
480
481 def _got_news(self, req, news):
482 var=(news)
483 self.headlines.clear()
484 for content in news['articles']:
485 self.headlines.append((content['title'], content['urlToImage'], content['description']))
486
487 def fail(self, instance, value):
488 print('you loose')
489 print(f'Error: {instance}, {value}')
490
491
492if __name__ == '__main__':
493 from kivy.app import App
494 from kivy.clock import Clock
495 from kivy.lang import Builder
496 from kivy.properties import StringProperty
497 from kivy.uix.screenmanager import Screen
498 from kivy.core.window import Window
499
500 import itertools
501 import pprint
502 from textwrap import dedent
503
504 kv = dedent("""
505 <NewsScreen>:
506 BoxLayout:
507 orientation: 'vertical'
508 Label:
509 size_hint_y: dp(.25)
510 text: root.headline
511 text_size: self.size
512 valign: 'center'
513 halign: 'center'
514 shorten: True
515 shorten_from: 'right'
516 font_size: dp(30)
517 padding: dp(20),dp(20)
518 theme_text_color:"ContrastParentBackground"
519 bold: True
520 GridLayout:
521 cols: 2
522 padding: dp(50)
523 AsyncImage:
524 source: root.headline_image
525 anim_delay: .03334 # 15fps, for gif videos
526 nocache: True
527 Label:
528 #padding_x: dp(20)
529 text: root.description
530 text_size: self.size
531 font_size: 25
532 valign: 'center'
533
534 BoxLayout: # This is the root widget
535 orientation: 'vertical'
536 ScreenManager:
537 id: sm
538 NewsScreen:
539 name: 'news'
540 next: 'weather'
541 duration: 30
542 """)
543
544
545 class NewsScreen(Screen):
546 headline = StringProperty('')
547 headline_image = StringProperty('')
548 description = StringProperty('')
549
550 def __init__(self, **kwargs):
551 super().__init__(**kwargs)
552 self.app = App.get_running_app()
553 self.story = itertools.cycle(self.app.news.headlines)
554 Clock.schedule_once(self.initial_news, 10)
555 self.refresh = Clock.schedule_interval(self.news_next, 15)
556
557 def initial_news(self, *args):
558 self.headline = self.app.news.headlines[0][0] if self.app.news.headlines[0][0] else 'junk'
559 self.headline_image = self.app.news.headlines[0][1] if self.app.news.headlines[0][1] else 'junk'
560 self.description = self.app.news.headlines[0][2] if self.app.news.headlines[0][2] else 'No Description'
561 print(self.headline)
562
563 def news_next(self, *args):
564 n = next(self.story)
565 self.headline = n[0]
566 self.headline_image = n[1] if n[1] is not None else ''
567 self.description = n[2]
568
569
570
571 class TestNewsApp(App):
572 news = News()
573
574 def build(self):
575 Window.size = 1500, 303
576 Window.top = 100
577 Window.left = 10
578 return Builder.load_string(kv)
579
580 def on_start(self):
581 self.news.get_news()
582 Clock.schedule_once(self.print_news, 5) # wait for site..
583 print('waiting 5 seconds...')
584
585 def print_news(self, dt):
586 pp = pprint.PrettyPrinter(width=80, compact=True)
587 pp.pprint(self.news.headlines)
588
589
590 TestNewsApp().run()
591------------------------
592Screen:
593 ScreenManager:
594 id:scr_mngr
595 MainMenuScreen:
596 name:"menu"
597 InputScreen:
598 name:"input"
599 RestingHeartRateScreen:
600 name:"heartrate"
601 ResultObeseScreen:
602 name:"obese"
603 ResultUnderweightScreen:
604 name:"underweight"
605 ResultOverweightScreen:
606 name:"overweight"
607 ResultNormalScreen:
608 name:"normal"
609 LocationSearchScreen:
610 name:"locsearch"
611 LocationResultScreen:
612 name:"locresult"
613 HistoryScreen:
614 name:"history"
615
616<MainMenuScreen>
617 MDBoxLayout:
618 orientation:'vertical'
619
620 NewsLayout:
621 id: nl # and in id to access the instance
622 #pos_hint:{'center_y':0.3}
623 # orientation:'vertical'
624
625 MDBottomAppBar:
626 MDToolbar:
627 icon: "account"
628 type: "bottom"
629 elevation_normal: 8
630 on_action_button:
631 root.manager.current='input'
632 root.manager.transition.direction = "right"
633 left_action_items:[["history",lambda x: app.history_screen("history")]]
634 right_action_items:[["google-earth",lambda x: app.location_screen("locsearch")]]
635
636<NewsLayout>:
637 orientation: 'vertical'
638 padding: dp(20)
639 spacing: dp(20)
640 MDLabel:
641 size_hint_y: None
642 height: self.texture_size[1]
643 text: root.title
644 halign: 'center'
645 valign: 'bottom'
646 font_style:'H6'
647 AsyncImage:
648 source: root.picture
649 size_hint_y: .6
650 MDLabel:
651 text_size: self.size
652 valign: 'top'
653 halign:'center'
654 text: root.description
655 size_hint_y: .4
656
657<InputScreen>
658 on_pre_enter: app.clear_inputs()
659 id:information
660 BoxLayout:
661 orientation: 'vertical'
662 MDToolbar:
663 title:'Input Details'
664 elevation:10
665 left_action_items:[["backspace",lambda x:app.back_screen("menu")]]
666 right_action_items:[["head-question",lambda x:app.info2dialog()]]
667
668 Widget:
669 MDTextField:
670 id:fname
671 hint_text: "Full name"
672 icon_right:"account"
673 pos_hint: {'center_x': 0.5}
674 size_hint: None,None
675 width: '250dp'
676 helper_text:"Please enter your Registered Name"
677 helper_text_mode:"persistent"
678 Widget:
679 height: dp(35)
680
681 MDTextField:
682 id:height
683 input_filter:'int'
684 hint_text: "Height"
685 icon_right:"human-male-height"
686 pos_hint: {'center_x': 0.5}
687 size_hint: None,None
688 width: '250dp'
689 helper_text:"Must be in centimeters"
690 helper_text_mode:"persistent"
691 Widget:
692 height:dp(35)
693
694 MDTextField:
695 id:weight
696 hint_text: "Weight"
697 input_filter:'int'
698 icon_right:"weight-kilogram"
699 pos_hint: {'center_x': 0.5}
700 size_hint: None,None
701 width: '250dp'
702 helper_text:"Must be in Kilogram"
703 helper_text_mode:"persistent"
704 Widget:
705 height:dp(35)
706
707 MDTextField:
708 id:age
709 hint_text: "Age"
710 input_filter:'int'
711 icon_right:"cake"
712 pos_hint: {'center_x': 0.5}
713 size_hint: None,None
714 width: '250dp'
715 helper_text:"please enter your age"
716 helper_text_mode:"persistent"
717 Widget:
718 height: dp(35)
719
720 MDTextField:
721 id:heartrate
722 hint_text: "Heartrate"
723 input_filter:'int'
724 icon_right:"heart-pulse"
725 pos_hint: {'center_x': 0.5}
726 size_hint: None,None
727 width: '250dp'
728 helper_text:"Count the beat on your palm for 60 seconds"
729 helper_text_mode:"persistent"
730 Widget:
731 size_hint_y: None
732
733 MDScreen:
734 MDRectangleFlatButton:
735 mode: "rectangle"
736 text: '[color=#000000]Confirm'
737 pos_hint: {'center_x':0.5, 'center_y':0.8}
738 on_press :
739 app.show_data()
740
741 Widget:
742 size_hint_x: None
743
744<ResultObeseScreen>
745 BoxLayout:
746 orientation: 'vertical'
747 MDToolbar:
748 title:'Result: OBESE'
749 elevation:10
750 right_action_items:[["head-question",lambda x:app.result_dialog()]]
751 Widget:
752
753 MDLabel:
754 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)"
755 halign: "center"
756
757 Widget:
758
759 MDScreen:
760 MDRectangleFlatIconButton:
761 icon:"account"
762 text: '[color=#000000]Main Menu'
763 pos_hint: {'center_x':0.25, 'center_y':0.9}
764 on_press : root.manager.current='menu'
765 MDRectangleFlatIconButton:
766 icon:"heart-pulse"
767 text: '[color=#000000]Heartbeat Results'
768 pos_hint: {'center_x':0.7, 'center_y':0.9}
769 on_press : app.hrdialog()
770
771
772<ResultNormalScreen>
773 BoxLayout:
774 orientation: 'vertical'
775 MDToolbar:
776 title:'Result: NORMAL WEIGHT'
777 elevation:10
778 right_action_items:[["head-question",lambda x:app.result_dialog()]]
779 Widget:
780
781 MDLabel:
782 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)"
783 halign: "center"
784
785 Widget:
786
787 MDScreen:
788 MDRectangleFlatIconButton:
789 icon:"account"
790 text: '[color=#000000]Main Menu'
791 pos_hint: {'center_x':0.25, 'center_y':0.9}
792 on_press : root.manager.current='menu'
793 MDRectangleFlatIconButton:
794 icon:"heart-pulse"
795 text: '[color=#000000]Heartbeat Results'
796 pos_hint: {'center_x':0.7, 'center_y':0.9}
797 on_press : app.hrdialog()
798
799<ResultOverweightScreen>
800 BoxLayout:
801 orientation: 'vertical'
802 MDToolbar:
803 title:'Result: OVERWEIGHT'
804 elevation:10
805 right_action_items:[["head-question",lambda x:app.result_dialog()]]
806 Widget:
807
808 MDLabel:
809 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)"
810 halign: "center"
811
812 Widget:
813
814 MDScreen:
815 MDRectangleFlatIconButton:
816 icon:"account"
817 text: '[color=#000000]Main Menu'
818 pos_hint: {'center_x':0.25, 'center_y':0.9}
819 on_press : root.manager.current='menu'
820 MDRectangleFlatIconButton:
821 icon:"heart-pulse"
822 text: '[color=#000000]Heartbeat Results'
823 pos_hint: {'center_x':0.7, 'center_y':0.9}
824 on_press : app.hrdialog()
825
826<ResultUnderweightScreen>
827 BoxLayout:
828 orientation: 'vertical'
829 MDToolbar:
830 title:'Result: UNDERWEIGHT'
831 elevation:10
832 right_action_items:[["head-question",lambda x:app.result_dialog()]]
833 Widget:
834
835 MDLabel:
836 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)"
837 halign: "center"
838
839 Widget:
840
841 MDScreen:
842 MDRectangleFlatIconButton:
843 icon:"account"
844 text: '[color=#000000]Main Menu'
845 pos_hint: {'center_x':0.25, 'center_y':0.9}
846 on_press : root.manager.current='menu'
847 MDRectangleFlatIconButton:
848 icon:"heart-pulse"
849 text: '[color=#000000]Heartbeat Results'
850 pos_hint: {'center_x':0.7, 'center_y':0.9}
851 on_press : app.hrdialog()
852
853<LocationSearchScreen>
854 BoxLayout:
855 orientation: 'vertical'
856 MDToolbar:
857 title:'Hospital Searcher'
858 elevation:10
859 left_action_items:[["backspace",lambda x:app.back_screen6("menu")]]
860 right_action_items:[["head-question",lambda x:app.info1_dialog()]]
861
862 ScrollView:
863 MDList:
864 id: rlist
865<RecordLine>:
866 adaptive_height: True
867 OneLineListItem:
868 text: root.text
869 on_release: app.showinfo(root.parent.parent.panel_cls.text, self.text)
870
871<InformationDialog>:
872 title: "Details:"
873
874<OneLineAvatarIconListItem>: # The list widget
875 id: icnlst
876 IconLeftWidget:
877 icon: "clipboard"
878
879<HistoryScreen>
880 FloatLayout:
881 AnchorLayout:
882 anchor_x: 'center'
883 anchor_y: 'bottom'
884
885 AnchorLayout:
886 id: dt_layout
887
888 MDToolbar:
889 id: toolbar
890 pos_hint: {"top": 1}
891 elevation: 6
892 title: "Check History"
893 left_action_items:[["backspace",lambda x:app.back_screen("menu")]]
894
895 MDScreen:
896 MDRectangleFlatIconButton:
897 icon: "weight-lifter"
898 text: '[color=#000000]Check BMI'
899 pos_hint: {'center_x':0.25, 'center_y':0.1}
900 on_press : app.bmidialog()
901 MDRectangleFlatIconButton:
902 icon: "heart-pulse"
903 text: '[color=#000000]Heartbeat Results'
904 pos_hint: {'center_x':0.7, 'center_y':0.1}
905 on_press : app.hrdialog()