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