toonbach

Python Kivy Launcher File Backup

Jun 11th, 2018
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. from kivy.app import App
  2. from kivy.lang import Builder
  3. from kivy.uix.screenmanager import ScreenManager, Screen
  4. import sqlite3
  5. import datetime
  6. import shutil
  7.  
  8. KV = """
  9. <ScreenManagement>:
  10. EntryInterface:
  11. name: 'test'
  12. <EntryInterface>:
  13. BoxLayout:
  14. TextInput:
  15. id: textInput
  16. Button:
  17. text:'Save'
  18. on_press: root.save()
  19. """
  20. class ScreenManagement(ScreenManager):
  21. pass
  22.  
  23. class EntryInterface (Screen):
  24. def save(self):
  25. self.now = str(datetime.datetime.now())
  26. self.time = self.now[11:22]
  27. #formatting the text
  28. self.time = self.time.replace(':','_')
  29. self.time = self.time.replace('.','_')
  30.  
  31. if(self.ids.textInput.text ==''):
  32. self.stuff = 'Blank'
  33. else: self.stuff = self.ids.textInput.text
  34.  
  35. conn = sqlite3.connect("test.db")
  36. cur = conn.cursor()
  37. cur.execute("INSERT INTO test_table VALUES (:stuff)", {'stuff': self.stuff})
  38. conn.commit()
  39. conn.close()
  40. self.ids.textInput.text = ''
  41.  
  42. shutil.copy('test.db','BACKUP_'+self.time+'.db')
  43.  
  44. class TestApp(App):
  45. title = "Login Screen"
  46. def build(self):
  47. Builder.load_string(KV)
  48. return ScreenManagement()
  49.  
  50. if __name__ == "__main__":
  51. TestApp().run()
Advertisement
Add Comment
Please, Sign In to add comment