Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from kivy.app import App
- from kivy.properties import StringProperty
- from kivy.uix.screenmanager import ScreenManager, Screen, SlideTransition
- import os
- from connected import Connected
- kv = """
- #:include connected.kv
- <Login>:
- BoxLayout
- id: login_layout
- orientation: 'vertical'
- padding: [10,50,10,50]
- spacing: 50
- Label:
- text: 'Welcome'
- font_size: 32
- BoxLayout:
- orientation: 'vertical'
- Label:
- text: 'Login'
- font_size: 18
- halign: 'left'
- text_size: root.width-20, 20
- TextInput:
- id: login
- multiline:False
- font_size: 28
- BoxLayout:
- orientation: 'vertical'
- Label:
- text: 'Password'
- halign: 'left'
- font_size: 18
- text_size: root.width-20, 20
- TextInput:
- id: password
- multiline:False
- password:True
- font_size: 28
- Button:
- text: 'Connexion'
- font_size: 24
- on_press: root.do_login(login.text, password.text)
- <Connected>:
- BoxLayout:
- orientation: 'vertical'
- Label:
- text: "You are now connected"
- font_size: 32
- Button:
- text: "Disconnect"
- font_size: 24
- on_press: root.disconnect()
- """
- class Connected(Screen):
- def disconnect(self):
- self.manager.transition = SlideTransition(direction="right")
- self.manager.current = 'login'
- self.manager.get_screen('login').resetForm()
- class Login(Screen):
- def do_login(self, loginText, passwordText):
- app = App.get_running_app()
- app.username = loginText
- app.password = passwordText
- self.manager.transition = SlideTransition(direction="left")
- self.manager.current = 'connected'
- app.config.read(app.get_application_config())
- app.config.write()
- def resetForm(self):
- self.ids['login'].text = ""
- self.ids['password'].text = ""
- class LoginApp(App):
- username = StringProperty(None)
- password = StringProperty(None)
- def build(self):
- manager = ScreenManager()
- manager.add_widget(Login(name='login'))
- manager.add_widget(Connected(name='connected'))
- return manager
- def get_application_config(self):
- if(not self.username):
- return super(LoginApp, self).get_application_config()
- conf_directory = self.user_data_dir + '/' + self.username
- if(not os.path.exists(conf_directory)):
- os.makedirs(conf_directory)
- return super(LoginApp, self).get_application_config(
- '%s/config.cfg' % (conf_directory)
- )
- if __name__ == '__main__':
- LoginApp().run()
Add Comment
Please, Sign In to add comment