Guest User

joresfd

a guest
Mar 21st, 2017
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1.  
  2. from kivy.app import App
  3. from kivy.properties import StringProperty
  4. from kivy.uix.screenmanager import ScreenManager, Screen, SlideTransition
  5. import os
  6.  
  7. from connected import Connected
  8.  
  9.  
  10. kv = """
  11.  
  12. #:include connected.kv
  13.  
  14. <Login>:
  15. BoxLayout
  16. id: login_layout
  17. orientation: 'vertical'
  18. padding: [10,50,10,50]
  19. spacing: 50
  20.  
  21. Label:
  22. text: 'Welcome'
  23. font_size: 32
  24.  
  25. BoxLayout:
  26. orientation: 'vertical'
  27.  
  28. Label:
  29. text: 'Login'
  30. font_size: 18
  31. halign: 'left'
  32. text_size: root.width-20, 20
  33.  
  34. TextInput:
  35. id: login
  36. multiline:False
  37. font_size: 28
  38.  
  39. BoxLayout:
  40. orientation: 'vertical'
  41. Label:
  42. text: 'Password'
  43. halign: 'left'
  44. font_size: 18
  45. text_size: root.width-20, 20
  46.  
  47. TextInput:
  48. id: password
  49. multiline:False
  50. password:True
  51. font_size: 28
  52.  
  53. Button:
  54. text: 'Connexion'
  55. font_size: 24
  56.  
  57. on_press: root.do_login(login.text, password.text)
  58.  
  59. <Connected>:
  60. BoxLayout:
  61. orientation: 'vertical'
  62.  
  63. Label:
  64. text: "You are now connected"
  65. font_size: 32
  66. Button:
  67. text: "Disconnect"
  68. font_size: 24
  69. on_press: root.disconnect()
  70.  
  71.  
  72.  
  73. """
  74. class Connected(Screen):
  75. def disconnect(self):
  76. self.manager.transition = SlideTransition(direction="right")
  77. self.manager.current = 'login'
  78. self.manager.get_screen('login').resetForm()
  79.  
  80.  
  81. class Login(Screen):
  82. def do_login(self, loginText, passwordText):
  83. app = App.get_running_app()
  84.  
  85. app.username = loginText
  86. app.password = passwordText
  87.  
  88. self.manager.transition = SlideTransition(direction="left")
  89. self.manager.current = 'connected'
  90.  
  91. app.config.read(app.get_application_config())
  92. app.config.write()
  93.  
  94. def resetForm(self):
  95. self.ids['login'].text = ""
  96. self.ids['password'].text = ""
  97.  
  98. class LoginApp(App):
  99. username = StringProperty(None)
  100. password = StringProperty(None)
  101.  
  102. def build(self):
  103. manager = ScreenManager()
  104.  
  105. manager.add_widget(Login(name='login'))
  106. manager.add_widget(Connected(name='connected'))
  107.  
  108. return manager
  109.  
  110. def get_application_config(self):
  111. if(not self.username):
  112. return super(LoginApp, self).get_application_config()
  113.  
  114. conf_directory = self.user_data_dir + '/' + self.username
  115.  
  116. if(not os.path.exists(conf_directory)):
  117. os.makedirs(conf_directory)
  118.  
  119. return super(LoginApp, self).get_application_config(
  120. '%s/config.cfg' % (conf_directory)
  121. )
  122.  
  123. if __name__ == '__main__':
  124. LoginApp().run()
Add Comment
Please, Sign In to add comment