Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from kivy.app import App
- from kivy.uix.button import Button
- from kivy.uix.label import Label
- from kivy.uix.floatlayout import FloatLayout
- from kivy.clock import Clock
- from kivy.uix.screenmanager import ScreenManager, Screen, SlideTransition
- from kivy.properties import ObjectProperty
- from kivy.uix.textinput import TextInput
- import time
- import os
- class RegistrationScreen(App):
- def build(self):
- self.layout = FloatLayout(size=(100, 200))
- self.registration_text = Label(text='Registration', font_size=font_size_coeff * 60, pos_hint={'x': 0.01, 'y': 0.2})
- self.input_name = TextInput(text='Enter your name', focus=False,
- multiline=False, size_hint=(font_size_coeff * 0.5, font_size_coeff * 0.1),
- pos_hint={'x': 0.4, 'y': 0.6})
- self.input_time = TextInput(text='How many hours a day do you play Dota?', multiline=False, focus=False,
- size_hint=(font_size_coeff * 0.8, font_size_coeff * 0.1), pos_hint={'x': 0.4, 'y': 0.4})
- self.but = Button(text='Enter', font_size=font_size_coeff * 40, size_hint=(0.2, 0.1))
- self.but.bind(on_press=self.callback)
- self.layout.add_widget(self.registration_text)
- self.layout.add_widget(self.input_name)
- self.layout.add_widget(self.input_time)
- self.layout.add_widget(self.but)
- return self.layout
- def callback(self, *args):
- try:
- int(self.input_time.text)
- global script_path
- with open(os.path.join(script_path, "data.txt"), "w") as f:
- f.write(str(self.input_name.text) + '\n' + str(int(time.time())) + '\n')
- f.write(str(self.input_time.text) + '\n')
- self.stop()
- except:
- self.input_time.text = "You can play only integer hours a day"
- def registration():
- if __name__ in ('__main__', '__android__'):
- RegistrationScreen().run()
- if __name__ == '__main__':
- font_size_coeff = 0.5
- else:
- fon_size_coeff = 1
- script_path = os.path.dirname(os.path.realpath(__file__))
- try:
- with open(os.path.join(script_path,"data.txt"), "r") as f:
- f.readline()
- START = int(f.readline().strip())
- except:
- registration()
- with open(os.path.join(script_path,"data.txt"), "r") as f:
- f.readline()
- START = int(f.readline().strip())
- def current_time(seconds):
- return str(seconds // 60) + ' minutes ' + str(seconds % 60) + ' seconds'
- def main():
- app = Main()
- return app
- def callback(instance, value):
- pass
- string = "You haven't played Dota for:\n" + current_time(0)
- height = 550
- width = 350
- class TimeLabel(Label):
- def update(self, *args):
- self.font_size = 40
- self.text = "You haven't played Dota for:\n" + current_time(int(time.time()) - START)
- class Menu(Screen):
- def __init__(self, **kwargs):
- super (Menu,self).__init__(**kwargs)
- global string
- global height
- global width
- self.layout = FloatLayout(size = (width, height))
- self.but1 = Button(text='Motivation', font_size=font_size_coeff * 40, size_hint = (.45, .15),
- pos_hint = {'x' : 0.02857142857142857, 'y' : 0.02857142857142857})
- self.but2 = Button(text='Achievements', font_size=font_size_coeff * 40, size_hint = (.45, .15),
- pos_hint = {'x' : 0.5142857142857142, 'y' : 0.02857142857142857})
- self.but3 = Button(text='Stats', font_size=font_size_coeff * 40, size_hint = (.45, .15), pos_hint = {'x' : 0.02857142857142857,
- 'y' : 0.2})
- self.but4 = Button(text='Advice', font_size=font_size_coeff * 40, size_hint = (.45, .15), pos_hint = {'x' : 0.5142857142857142,
- 'y' : 0.2})
- self.text = TimeLabel()
- self.but1.bind(on_press=self.changer1)
- self.but2.bind(on_press=self.changer2)
- self.but3.bind(on_press=self.changer3)
- self.but4.bind(on_press=self.changer4)
- self.layout.add_widget(self.but1)
- self.layout.add_widget(self.but2)
- self.layout.add_widget(self.but3)
- self.layout.add_widget(self.but4)
- self.layout.add_widget(self.text)
- self.text.font_size = 60
- Clock.schedule_interval(self.text.update, 1)
- self.add_widget(self.layout)
- def my_callback(self, dt):
- self.text = "You haven't played Dota for:\n" + current_time(int(time.time() - START))
- def changer1(self,*args):
- self.manager.transition.direction = 'left'
- self.manager.current = 'motivation'
- def changer2(self,*args):
- self.manager.transition.direction = 'left'
- self.manager.current = 'achievements'
- def changer3(self,*args):
- self.manager.transition.direction = 'left'
- self.manager.current = 'stats'
- def changer4(self,*args):
- self.manager.transition.direction = 'left'
- self.manager.current = 'advice'
- class Motivation(Screen):
- def __init__(self, **kwargs):
- super (Motivation,self).__init__(**kwargs)
- global height
- global width
- self.layout = FloatLayout()
- self.but1 = Button(text = 'Back to Menu ', font_size = font_size_coeff * 40, size_hint = (.2, .1), pos_hint = {'x' : 0,
- 'y' : 0.9})
- self.but1.bind(on_press=self.changer)
- self.layout.add_widget(self.but1)
- self.add_widget(self.layout)
- def changer(self,*args):
- self.manager.transition.direction = 'right'
- self.manager.current = 'menu'
- class Achievements(Screen):
- def __init__(self, **kwargs):
- super (Achievements,self).__init__(**kwargs)
- global height
- global width
- self.layout = FloatLayout()
- self.but1 = Button(text = 'Back to Menu ', font_size = font_size_coeff * 40, size_hint = (.2, .1), pos_hint = {'x' : 0,
- 'y' : 0.9})
- self.but1.bind(on_press=self.changer)
- self.layout.add_widget(self.but1)
- self.add_widget(self.layout)
- def changer(self,*args):
- self.manager.transition.direction = 'right'
- self.manager.current = 'menu'
- class Stats(Screen):
- def __init__(self, **kwargs):
- super (Stats,self).__init__(**kwargs)
- global height
- global width
- self.layout = FloatLayout()
- self.but1 = Button(text = 'Back to Menu ', font_size = font_size_coeff * 40, size_hint = (.2, .1), pos_hint = {'x' : 0,
- 'y' : 0.9})
- self.label_time = Label(text="1) You haven't played for\n" + str(current_time(int(time.time()) - int(START))),
- pos_hint={'x': 0.05, 'y': 0.3})
- self.but1.bind(on_press=self.changer)
- self.layout.add_widget(self.but1)
- self.layout.add_widget(self.label_time)
- self.add_widget(self.layout)
- def changer(self,*args):
- self.label_time.text = "1) You haven't played for\n" + str(current_time(int(time.time()) - int(START)))
- self.manager.transition.direction = 'right'
- self.manager.current = 'menu'
- class Advice(Screen):
- def __init__(self, **kwargs):
- super (Advice,self).__init__(**kwargs)
- global height
- global width
- self.layout = FloatLayout()
- self.but1 = Button(text = 'Back to Menu ', font_size = font_size_coeff * 40, size_hint = (.2, .1), pos_hint = {'x' : 0,
- 'y' : 0.9})
- self.but1.bind(on_press=self.changer)
- self.layout.add_widget(self.but1)
- self.add_widget(self.layout)
- def changer(self,*args):
- self.manager.transition.direction = 'right'
- self.manager.current = 'menu'
- class Main(App):
- def build(self):
- global screens
- self.screenmanager = ScreenManager(transition=SlideTransition())
- self.menu = Menu(name='menu')
- self.motivation = Motivation(name='motivation')
- self.achievements = Achievements(name='achievements')
- self.stats = Stats(name='stats')
- self.advice = Advice(name='advice')
- self.screenmanager.add_widget(self.menu)
- self.screenmanager.add_widget(self.motivation)
- self.screenmanager.add_widget(self.achievements)
- self.screenmanager.add_widget(self.stats)
- self.screenmanager.add_widget(self.advice)
- del screens[:]
- screens.append(self.menu)
- screens.append(self.motivation)
- screens.append(self.achievements)
- screens.append(self.stats)
- screens.append(self.advice)
- self.screenmanager.transition.direction = 'left'
- print(screens)
- return self.screenmanager
- screens = []
- app = main()
- if __name__ in ('__main__', '__android__'):
- app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement