Exemplo n.º 1
0
class Viewer():
    def __init__(self, master):
        self.master = master
        Window.clearcolor = (0, 1, 0, 5)
        self.addb = Button(text="ADD",
                           pos=(WXY(2), HXY(450)),
                           width=WXY(60),
                           height=HXY(30),
                           size_hint=(None, None),
                           font_size=HXY(16))
        self.addb.bind(on_press=self.adder)
        self.master.add_widget(self.addb)
        self.layout = GridLayout(cols=1, spacing=HXY(10), size_hint_y=None)
        self.layout.bind(minimum_height=self.layout.setter('height'))
        self.connection = Connection()
        self.values = self.connection.getvaluesasc("date,content", "diarydata")
        self.lists = []
        index = 0
        for date, content in self.values:
            label = Label(text=str(date))
            self.lists.append(
                Button(text=content + "\n" + str(date),
                       size_hint_y=None,
                       height=HXY(250),
                       font_size=HXY(18),
                       halign="left",
                       valign="middle"))
            self.lists[index].bind(size=self.lists[index].setter('text_size'))
            self.lists[index].bind(on_press=self.popuptriger)
            self.layout.add_widget(label)
            self.layout.add_widget(self.lists[index])
            index += 1
        self.connection.conn.close()
        self.root = ScrollView(size=(WXY(310), HXY(440)),
                               pos=(WXY(5), HXY(10)),
                               size_hint=(None, None))
        self.root.add_widget(self.layout)
        self.master.add_widget(self.root)

    def on_rotate(self):
        self.addb.pos = (WXY(2), HXY(450))
        self.addb.width = WXY(60)
        self.addb.height = HXY(30)
        self.addb.font_size = HXY(16)
        self.root.size = (WXY(310), HXY(440))
        self.root.pos = (WXY(5), HXY(0))
        self.layout.spacing = HXY(4)
        index = 0

    def popuptriger(self, event):
        editButton = Button(text="Edit")
        deleteButton = Button(text="Delete")
        cancelButton = Button(text="Cancel")
        layout = BoxLayout()
        self.identity = event.text
        self.userpriority = Popup(title="Do you wish to continue",
                                  content=layout,
                                  width=Window.width,
                                  height=HXY(100),
                                  size_hint=(None, None))
        layout.add_widget(deleteButton)
        layout.add_widget(editButton)
        layout.add_widget(cancelButton)

        editButton.bind(on_press=self.editviewer)
        deleteButton.bind(on_press=self.deletelists)
        cancelButton.bind(on_press=self.userpriority.dismiss)

        self.userpriority.open()

    def deletelists(self, event):
        self.connection = Connection()
        query = "delete from diarydata where date='{}'".format(
            self.identity[-10:])
        self.connection.delete(query)
        self.connection.conn.commit()
        self.userpriority.dismiss()
        self.master.remove_widget(self.root)
        self.master.remove_widget(self.addb)
        self.viewer = Viewer(self.master)

    def editviewer(self, event):
        self.connection = Connection()
        query = "delete from diarydata where date='{}'".format(
            self.identity[-10:])
        self.connection.delete(query)
        self.connection.conn.commit()
        self.userpriority.dismiss()
        self.master.remove_widget(self.root)
        self.master.remove_widget(self.addb)
        self.viewer = Notepad(self.master, self.identity[:-10],
                              self.identity[-10:])

    def adder(self, event):
        self.master.remove_widget(self.addb)
        self.master.remove_widget(self.root)
        self.master.remove_widget(self.root)
        self.master.remove_widget(self.addb)
        self.notepad = Notepad(self.master, "Empty your heart", today.today())
        global choice
        choice = 3
Exemplo n.º 2
0
class Notepad():
    def __init__(self, master, content, date):
        self.master = master
        self.datesetter = TextInput(text=str(date),
                                    pos=(WXY(5), HXY(440)),
                                    width=WXY(146),
                                    height=HXY(40),
                                    font_size=HXY(25),
                                    halign="left",
                                    size_hint=(None, None),
                                    multiline=False)
        self.submit = Button(text="submit",
                             pos=(WXY(174), HXY(440)),
                             width=WXY(141),
                             height=HXY(40),
                             size_hint=(None, None),
                             font_size=HXY(25))
        self.submit.bind(on_press=self.popuptriger)
        self.content = TextInput(text=content,
                                 pos=(WXY(5), HXY(5)),
                                 width=WXY(310),
                                 height=HXY(430),
                                 font_size=(HXY(18)),
                                 size_hint=(None, None))
        self.master.add_widget(self.datesetter)
        self.master.add_widget(self.submit)
        self.master.add_widget(self.content)
        Window.clearcolor = (0, 1, 0, 5)

    def on_rotate(self):
        global screenheight
        global screenwidth
        screenheight = Window.height
        screenwidth = Window.width

        self.datesetter.pos = (WXY(5), HXY(440))
        self.datesetter.width = WXY(146)
        self.datesetter.height = HXY(40)
        self.datesetter.font_size = HXY(25)

        self.submit.pos = (WXY(174), HXY(440))
        self.submit.width = WXY(141)
        self.submit.height = HXY(40)
        self.submit.font_size = HXY(25)

        self.content.pos = (WXY(5), HXY(5))
        self.content.width = WXY(310)
        self.content.height = HXY(430)
        self.content.font_size = HXY(18)

    def popuptriger(self, event):
        closeButton = Button(text="Close")
        cancelButton = Button(text="cancel")
        saveButton = Button(text="Save")

        layout = BoxLayout()
        self.userpriority = Popup(title="Do you wish to continue",
                                  content=layout,
                                  width=Window.width,
                                  height=HXY(100),
                                  size_hint=(None, None))
        layout.add_widget(cancelButton)
        layout.add_widget(saveButton)
        layout.add_widget(closeButton)

        saveButton.bind(on_press=self.saveswapper)
        closeButton.bind(on_press=self.nonsaveswapper)
        cancelButton.bind(on_press=self.userpriority.dismiss)

        self.userpriority.open()

    def saveswapper(self, event):
        self.connection = Connection()
        values = "('{}','{}')".format(str(self.datesetter.text),
                                      str(self.content.text))
        columnname = "('{}','{}')".format("date", "content")
        query = "delete from diarydata where date='{}'".format(
            self.datesetter.text)
        self.connection.delete(query)
        self.connection.insertintotable("diarydata", columnname, values)
        self.connection.conn.close()
        self.removelayout()

    def nonsaveswapper(self, event):
        self.removelayout()

    def removelayout(self):
        res = 0
        for i in self.datesetter.text:
            if (i >= '0' and i < '9'):
                res = (res * 10) + int(i)
        self.userpriority.dismiss()
        self.master.remove_widget(self.datesetter)
        self.master.remove_widget(self.content)
        self.master.remove_widget(self.submit)
        global choice
        choice = 2
        self.viewer = Viewer(self.master)