Facebook
From a, 1 Month ago, written in Python.
Embed
Download Paste or View Raw
Hits: 123
  1. from kivy.app import App
  2. from kivy.uix.label import Label
  3. from kivy.uix.boxlayout import BoxLayout
  4. from kivy.uix.button import Button
  5. from kivy.uix.screenmanager import ScreenManager, Screen
  6. from kivy.uix.textinput import TextInput
  7. from instructions import txt_instruction, txt_test1, txt_sits, txt_test3, error_field_empty, error_age, error_pulse
  8. from ruffier import test
  9. from helper import check_int
  10.  
  11. name = ''
  12. age = 0
  13. P1 = 0
  14. P2 = 0
  15. P3 = 0
  16.  
  17. class ResultScreen(Screen):
  18.     def __init__(self, **kw):
  19.         super().__init__(**kw)
  20.         self.lbl1 = Label(text='ok')
  21.         outer = BoxLayout(orientation='vertical', padding=8, spacing=8)
  22.         outer.add_widget(self.lbl1)
  23.         self.add_widget(outer)
  24.         self.on_enter = self.before
  25.     def before(self):
  26.         global name, P1, P2, P3
  27.         print(name)
  28.         self.lbl1.text = name + '\n' + test(P1, P2, P3, age)
  29.        
  30.  
  31. class PulseCheck2(Screen):
  32.     def __init__(self, **kw):
  33.       super().__init__(**kw)
  34.       instr = Label(text=txt_test3)
  35.       lbl1 = Label(text="Результат:", halign='right')
  36.       self.P2 = TextInput(multiline=False)
  37.       lbl2 = Label(text='Результат після відпочинку:', halign='right')
  38.       self.P3 = TextInput(text='', multiline=False)
  39.       self.btn = Button(text='Завершити', size_hint=(0.3, 0.2), pos_hint={'center_x': 0.5})
  40.       self.btn.on_press = self.next
  41.       line1 = BoxLayout(size_hint=(0.8, None), height='30sp')
  42.       line2 = BoxLayout(size_hint=(0.8, None), height='30sp')
  43.       line1.add_widget(lbl1)
  44.       line1.add_widget(self.P2)
  45.       line2.add_widget(lbl2)
  46.       line2.add_widget(self.P3)
  47.       outer = BoxLayout(orientation='vertical', padding=8, spacing=8)
  48.       outer.add_widget(instr)
  49.       outer.add_widget(line1)
  50.       outer.add_widget(line2)
  51.       outer.add_widget(self.btn)
  52.       self.add_widget(outer)
  53.     def next(self):
  54.         global P2, P3
  55.         P2 = int(self.P2.text)
  56.         P3 = int(self.P3.text)
  57.         self.manager.current = 'ResultScreen'
  58.  
  59. class MakeFitness(Screen):
  60.     def __init__(self, **kw):
  61.         super().__init__(**kw)
  62.         instr = Label(text = txt_sits)
  63.         self.btn = Button(text='Продовжити', size_hint=(0.3, 0.2), pos_hint={'center_x': 0.5})
  64.         self.btn.on_press = self.next
  65.         outer = BoxLayout(orientation='vertical', padding=8, spacing=8)
  66.         outer.add_widget(instr)
  67.         outer.add_widget(self.btn)
  68.         self.add_widget(outer)
  69.     def next(self):
  70.         self.manager.current = 'PulseCheck2'
  71.  
  72. class PulseCheck1(Screen):
  73.     def __init__(self, **kw):
  74.         super().__init__(**kw)
  75.         instr = Label(text = txt_test1)
  76.         lbl1 = Label(text = "Введіть результат:", halign='right')
  77.         self.P1 = TextInput(multiline=False)
  78.         self.btn = Button(text='Продовжити', size_hint=(0.3, 0.2), pos_hint={'center_x': 0.5})
  79.         self.btn.on_press = self.next
  80.         line1 = BoxLayout(orientation = 'horizontal', size_hint=(0.8, None), height='30sp')
  81.         line1.add_widget(lbl1)
  82.         line1.add_widget(self.P1)
  83.         outer = BoxLayout(orientation='vertical', padding=8, spacing=8)
  84.         outer.add_widget(instr)
  85.         outer.add_widget(line1)
  86.         outer.add_widget(self.btn)
  87.         self.add_widget(outer)
  88.     def next(self):
  89.         try:
  90.             global P1
  91.             if not self.P1.text:
  92.                 raise Exception(error_field_empty)
  93.             P1 = check_int(self.P1.text)
  94.             if P1 <= 0:
  95.                 raise Exception(error_pulse)
  96.             self.manager.current = 'MakeFitness'
  97.         except Exception as error:
  98.             print(error)
  99.             self.error_lbl.text = str(error)
  100.  
  101. class UserInfoScreen(Screen):
  102.     def __init__(self, **kw):
  103.       super().__init__(**kw)
  104.       self.error_lbl = Label(text='', color='red', size_hint=(0.8, None), height='30sp', pos_hint={'center_x': 0.5})
  105.       instr = Label(text=txt_instruction)
  106.       lbl1 = Label(text="Введіть ім'я:", halign='right')
  107.       self.in_name = TextInput(multiline=False)
  108.       lbl2 = Label(text='Введіть вік:', halign='right')
  109.       self.in_age = TextInput(text='', multiline=False)
  110.       self.btn = Button(text='Почати', size_hint=(0.3, 0.2), pos_hint={'center_x': 0.5})
  111.        self.btn.
  112.       line1 = BoxLayout(size_hint=(0.8, None), height='30sp')
  113.       line2 = BoxLayout(size_hint=(0.8, None), height='30sp')
  114.       line1.add_widget(lbl1)
  115.       line1.add_widget(self.in_name)
  116.       line2.add_widget(lbl2)
  117.       line2.add_widget(self.in_age)
  118.        outer = BoxLayout(orientati padding=8, spacing=8)
  119.       outer.add_widget(self.error_lbl)
  120.       outer.add_widget(instr)
  121.       outer.add_widget(line1)
  122.       outer.add_widget(line2)
  123.       outer.add_widget(self.btn)
  124.       self.add_widget(outer)
  125.     def next(self):
  126.         try:
  127.             global name, age
  128.             if not self.in_age.text or not self.in_name.text:
  129.                 raise Exception(error_field_empty)
  130.             name = self.in_name.text
  131.             age = check_int(self.in_age.text)
  132.             if age < 7:
  133.                 raise Exception(error_age)
  134.             self.manager.current = 'PulseCheck1'
  135.         except Exception as error:
  136.             print(error)
  137.             self.error_lbl.text = str(error)
  138.  
  139. class MyApp(App):
  140.     def build(self):
  141.         sm = ScreenManager()
  142.         sm.add_widget(UserInfoScreen(name='UserInfoScreen'))
  143.         sm.add_widget(PulseCheck1(name='PulseCheck1'))
  144.         sm.add_widget(MakeFitness(name='MakeFitness'))
  145.         sm.add_widget(PulseCheck2(name='PulseCheck2'))
  146.         sm.add_widget(ResultScreen(name='ResultScreen'))
  147.         return sm
  148. app = MyApp()
  149. app.run()
  150.