Guest User

Untitled

a guest
Jun 20th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.76 KB | None | 0 0
  1. #:import C kivy.utils.get_color_from_hex
  2. #:import ListAdapter kivy.adapters.listadapter.ListAdapter
  3. #:import main main
  4. #:import FadeTransition kivy.uix.screenmanager.FadeTransition
  5. #:import TextInput kivy.uix.textinput.TextInput
  6.  
  7.  
  8. <UI>:
  9. <BaseScreen>:
  10. td_list_view: list_view
  11. FloatLayout:
  12. canvas.before:
  13. Color:
  14. rgba: C('#ff777b')
  15. Rectangle:
  16. size: self.size
  17. pos: self.pos
  18.  
  19. BoxLayout:
  20. orientation: "vertical"
  21. size_hint_y: None
  22. height: 50
  23. pos: 0, 450
  24. Label:
  25. text: "Tasks"
  26. font_size: 20
  27.  
  28. BoxLayout:
  29. orientation: "vertical"
  30. pos: 0, 130
  31. size_hint_y: None
  32. height: 310
  33. ListView:
  34. id: list_view
  35. adapter:
  36. ListAdapter(data = [""], cls=main.ToDoListButton)
  37.  
  38. BoxLayout:
  39. orientation: "horizontal"
  40. size_hint_y: None
  41. height: 100
  42. pos: 86, 15
  43. spacing: 15
  44.  
  45. Button:
  46. size_hint: None, None
  47. size: 50, 50
  48. background_normal: "plus.png"
  49. on_press:
  50. root.manager.transition.direction = "left"
  51. root.manager.transition.duration = 1
  52. root.manager.current = 'task'
  53.  
  54. Button:
  55. size_hint: None, None
  56. size: 50, 50
  57. background_normal: "done.png"
  58. on_press: root.update()
  59.  
  60.  
  61. <AddTaskScreen>:
  62. text_input: text_input
  63. FloatLayout:
  64. canvas.before:
  65. Color:
  66. rgba: C('#ff777b')
  67. Rectangle:
  68. size: self.size
  69. pos: self.pos
  70.  
  71. BoxLayout:
  72. orientation: "vertical"
  73. size_hint_y: None
  74. height: 50
  75. pos: 0, 450
  76. Label:
  77. text: "Tasks"
  78. font_size: 20
  79.  
  80. BoxLayout:
  81. orientation: "vertical"
  82. pos: 0, 350
  83. size_hint_y: None
  84. height: 50
  85. CTextInput:
  86. id: text_input
  87. focus: True
  88. text: "Add your Task"
  89.  
  90. BoxLayout:
  91. orientation: "horizontal"
  92. spacing: 15
  93. size_hint_y: None
  94. height: 100
  95. pos: 69, 15
  96.  
  97. Button:
  98. size_hint: None, None
  99. size: 50, 50
  100. background_color: C("#f06d73")
  101. background_normal: "go-back.png"
  102. color: C("#ffffff")
  103. font_size: 15
  104. bold: True
  105. on_press:
  106. root.manager.transition.direction = "left"
  107. root.manager.transition.duration = 1
  108. root.manager.current = 'base'
  109.  
  110. Button:
  111. size_hint: None, None
  112. size: 75, 75
  113. background_color: C("#f06d73")
  114. background_normal: ""
  115. text: "Add Task"
  116. color: C("#ffffff")
  117. font_size: 15
  118. bold: True
  119. on_press: root.add_task()
  120.  
  121. <CTextInput@TextInput>:
  122. focus: True
  123. readonly: False
  124.  
  125.  
  126. import kivy
  127. from kivy.app import App
  128. from kivy.lang.builder import Builder
  129. from kivy.core.window import Window
  130. from kivy.utils import get_color_from_hex as C
  131. from kivy.config import Config
  132. from kivy.uix.boxlayout import BoxLayout
  133. from kivy.uix.floatlayout import FloatLayout
  134. from kivy.uix.listview import ListItemButton
  135. from kivy.properties import ObjectProperty
  136. from kivy.uix.screenmanager import ScreenManager, FadeTransition, Screen
  137. from kivy.uix.widget import Widget
  138. import sqlite3
  139. kivy.require('1.10.0')
  140. __version__ = '0.1'
  141. Config.set('graphics', 'resizable', '0')
  142. Window.size = (288, 512)
  143. file = 'tasks.json'
  144. class UI(FloatLayout):
  145. pass
  146. class BaseScreen(Screen):
  147.  
  148. td_list_view = ObjectProperty()
  149. def update(self):
  150. conn = sqlite3.connect('Tasks.sqlite')
  151. cursor = conn.cursor()
  152. cursor.execute('SELECT do FROM tasks')
  153. while True:
  154. row = []
  155. row = cursor.fetchone()
  156. if row == None:
  157. break
  158. for task in row:
  159. task = str(task)
  160. self.td_list_view.adapter.data.extend([task])
  161. self.td_list_view._trigger_reset_populate()
  162. cursor.close()
  163. conn.close()
  164.  
  165. def task_done(self):
  166. if self.td_list_view.adapter.selection:
  167. selection = self.td_list_view.adapter.selection[0].text
  168. conn = sqlite3.connect('Tasks.sqlite')
  169. print(selection)
  170. cursor = conn.cursor()
  171. cursor.execute('DELETE FROM tasks WHERE do == ("%s")'%selection)
  172. conn.commit()
  173. cursor.close()
  174. conn.close()
  175. self.td_list_view.adapter.data.remove(selection)
  176. self.td_list_view._trigger_reset_populate()
  177.  
  178.  
  179.  
  180. class AddTaskScreen(Screen):
  181. text_input = ObjectProperty()
  182. bs = BaseScreen
  183. def add_task(self):
  184. # with open(file, 'w') as fileObject:
  185. # fileObject.write(self.text_input.text+"n")
  186. conn = sqlite3.connect('Tasks.sqlite')
  187. cursor = conn.cursor()
  188. cursor.execute('INSERT INTO tasks (do) VALUES ("%s")'%(self.text_input.text))
  189. conn.commit()
  190. cursor.close()
  191. conn.close()
  192.  
  193. class ToDoListButton(ListItemButton):
  194. pass
  195.  
  196. Builder.load_file('main.kv')
  197.  
  198. class TodoApp(App):
  199. title = "To do"
  200.  
  201. def on_start(self):
  202. pass
  203.  
  204. def build(self):
  205. sm = ScreenManager()
  206. sm.add_widget(BaseScreen(name="base"))
  207. sm.add_widget(AddTaskScreen(name="task"))
  208. return sm
  209.  
  210. if __name__ == "__main__":
  211. TodoApp().run()
Add Comment
Please, Sign In to add comment