Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #:import C kivy.utils.get_color_from_hex
- #:import ListAdapter kivy.adapters.listadapter.ListAdapter
- #:import main main
- #:import FadeTransition kivy.uix.screenmanager.FadeTransition
- #:import TextInput kivy.uix.textinput.TextInput
- <UI>:
- <BaseScreen>:
- td_list_view: list_view
- FloatLayout:
- canvas.before:
- Color:
- rgba: C('#ff777b')
- Rectangle:
- size: self.size
- pos: self.pos
- BoxLayout:
- orientation: "vertical"
- size_hint_y: None
- height: 50
- pos: 0, 450
- Label:
- text: "Tasks"
- font_size: 20
- BoxLayout:
- orientation: "vertical"
- pos: 0, 130
- size_hint_y: None
- height: 310
- ListView:
- id: list_view
- adapter:
- ListAdapter(data = [""], cls=main.ToDoListButton)
- BoxLayout:
- orientation: "horizontal"
- size_hint_y: None
- height: 100
- pos: 86, 15
- spacing: 15
- Button:
- size_hint: None, None
- size: 50, 50
- background_normal: "plus.png"
- on_press:
- root.manager.transition.direction = "left"
- root.manager.transition.duration = 1
- root.manager.current = 'task'
- Button:
- size_hint: None, None
- size: 50, 50
- background_normal: "done.png"
- on_press: root.update()
- <AddTaskScreen>:
- text_input: text_input
- FloatLayout:
- canvas.before:
- Color:
- rgba: C('#ff777b')
- Rectangle:
- size: self.size
- pos: self.pos
- BoxLayout:
- orientation: "vertical"
- size_hint_y: None
- height: 50
- pos: 0, 450
- Label:
- text: "Tasks"
- font_size: 20
- BoxLayout:
- orientation: "vertical"
- pos: 0, 350
- size_hint_y: None
- height: 50
- CTextInput:
- id: text_input
- focus: True
- text: "Add your Task"
- BoxLayout:
- orientation: "horizontal"
- spacing: 15
- size_hint_y: None
- height: 100
- pos: 69, 15
- Button:
- size_hint: None, None
- size: 50, 50
- background_color: C("#f06d73")
- background_normal: "go-back.png"
- color: C("#ffffff")
- font_size: 15
- bold: True
- on_press:
- root.manager.transition.direction = "left"
- root.manager.transition.duration = 1
- root.manager.current = 'base'
- Button:
- size_hint: None, None
- size: 75, 75
- background_color: C("#f06d73")
- background_normal: ""
- text: "Add Task"
- color: C("#ffffff")
- font_size: 15
- bold: True
- on_press: root.add_task()
- <CTextInput@TextInput>:
- focus: True
- readonly: False
- import kivy
- from kivy.app import App
- from kivy.lang.builder import Builder
- from kivy.core.window import Window
- from kivy.utils import get_color_from_hex as C
- from kivy.config import Config
- from kivy.uix.boxlayout import BoxLayout
- from kivy.uix.floatlayout import FloatLayout
- from kivy.uix.listview import ListItemButton
- from kivy.properties import ObjectProperty
- from kivy.uix.screenmanager import ScreenManager, FadeTransition, Screen
- from kivy.uix.widget import Widget
- import sqlite3
- kivy.require('1.10.0')
- __version__ = '0.1'
- Config.set('graphics', 'resizable', '0')
- Window.size = (288, 512)
- file = 'tasks.json'
- class UI(FloatLayout):
- pass
- class BaseScreen(Screen):
- td_list_view = ObjectProperty()
- def update(self):
- conn = sqlite3.connect('Tasks.sqlite')
- cursor = conn.cursor()
- cursor.execute('SELECT do FROM tasks')
- while True:
- row = []
- row = cursor.fetchone()
- if row == None:
- break
- for task in row:
- task = str(task)
- self.td_list_view.adapter.data.extend([task])
- self.td_list_view._trigger_reset_populate()
- cursor.close()
- conn.close()
- def task_done(self):
- if self.td_list_view.adapter.selection:
- selection = self.td_list_view.adapter.selection[0].text
- conn = sqlite3.connect('Tasks.sqlite')
- print(selection)
- cursor = conn.cursor()
- cursor.execute('DELETE FROM tasks WHERE do == ("%s")'%selection)
- conn.commit()
- cursor.close()
- conn.close()
- self.td_list_view.adapter.data.remove(selection)
- self.td_list_view._trigger_reset_populate()
- class AddTaskScreen(Screen):
- text_input = ObjectProperty()
- bs = BaseScreen
- def add_task(self):
- # with open(file, 'w') as fileObject:
- # fileObject.write(self.text_input.text+"n")
- conn = sqlite3.connect('Tasks.sqlite')
- cursor = conn.cursor()
- cursor.execute('INSERT INTO tasks (do) VALUES ("%s")'%(self.text_input.text))
- conn.commit()
- cursor.close()
- conn.close()
- class ToDoListButton(ListItemButton):
- pass
- Builder.load_file('main.kv')
- class TodoApp(App):
- title = "To do"
- def on_start(self):
- pass
- def build(self):
- sm = ScreenManager()
- sm.add_widget(BaseScreen(name="base"))
- sm.add_widget(AddTaskScreen(name="task"))
- return sm
- if __name__ == "__main__":
- TodoApp().run()
Add Comment
Please, Sign In to add comment