<commit_before>import datetime
import tkinter

class HabitsGui(tkinter.Tk):
    def __init__(self, parent):
        tkinter.Tk.__init__(self, parent)
        self.parent = parent
        self.initialise()

    def initialise(self):
        self.grid()
        self.username = "User"
        self.handler = HabitsHandler()
        self.labels = []

        self.titleVariable = tkinter.StringVar()
        title = tkinter.Label(self, textvariable=self.titleVariable,
                              fg="blue")
        title.grid(column=0, row=0, columnspan=2)
        
        self.titleVariable.set(self.username + "'s Habits")

        self.rowVariable = tkinter.IntVar()
        self.rowVariable.set(len(self.handler.categories) + len(self.handler.tasks) + 1)

        self.updatelists()
        
        setuserbutton = tkinter.Button(self, text="Set user", command=lambda:
                                       self.dialoguebox(["Enter username"], self.submit_name))
        setuserbutton.grid(column=3, row=0)

        catbutton = tkinter.Button(self, text="New category", command=lambda:
                                self.dialoguebox(["Category name:", "Position:",
                                    "Heading colour:"], self.submit_newcategory, 3))
        catbutton.grid(column=0, row=self.rowVariable.get())
        
        habbutton = tkinter.Button(self, text="New habit", command=lambda:
                                   self.dialoguebox(["Task name:", "Category:",
                                        "Points:", "Bonus points:", "Position:"],
                                        self.submit_newtask, 5))
        habbutton.grid(column=1, row=self.rowVariable.get())


    def updatelists(self):
        if hasattr(self, 'lists'):
            self.lists.destroy()
        self.lists = tkinter.Frame(self.parent, borderwidth=1)
        self.lists.grid(row=1)
        for key in self.handler.categories:
            self.labels.insert(self.handler.categories[key].pos, key)
            self.key = tkinter.Label(self.lists, text=key,
                                  bg=self.handler.categories[key].colour)
            self.key.grid(column=0, row=self.handler.categories[key].pos)
            print (key)
            print (self.handler.categories[key].pos)
            print (self.key.grid_info())

    def dialoguebox(self, msg, submit, entries=1):
        top = self.top = tkinter.Toplevel(self)
        self.variables = []
        self.allentries = []
        for i in range(entries):
            label = tkinter.Label(top, text=msg[i])
            label.grid(row=i, column=0, sticky='w')
            entry = tkinter.Entry(top)
            entry.grid(row=i, column=1)
            self.variables.append(label)
            self.allentries.append(entry)            
            
        self.allentries[0].focus_set()
        self.allentries[-1].bind("<Return>", submit)

        self.submitbutton = tkinter.Button(top, text="OK")
        self.submitbutton.bind("<Button-1>", submit)
        self.submitbutton.grid(row=entries+1, column=1, sticky='e')

        self.cancelbutton = tkinter.Button(top, text="Cancel",
                                      command=lambda: self.top.destroy())
        self.cancelbutton.grid(row=entries+1, column=2)

    def submit_name(self, event):
        data = self.allentries[0].get()
        if data:
            self.username = data
            self.top.destroy()
            self.titleVariable.set(self.username + "'s Habits")<commit_msg>unsuccessful attempt to display tasks<commit_after>import datetime
import tkinter

class HabitsGui(tkinter.Tk):
    def __init__(self, parent):
        tkinter.Tk.__init__(self, parent)
        self.parent = parent
        self.initialise()

    def initialise(self):
        self.grid()
        self.username = "User"
        self.handler = HabitsHandler()

        self.titleVariable = tkinter.StringVar()
        title = tkinter.Label(self, textvariable=self.titleVariable,
                              fg="blue")
        title.grid(column=0, row=0, columnspan=2)
        
        self.titleVariable.set(self.username + "'s Habits")

        self.rowVariable = tkinter.IntVar()
        self.rowVariable.set(len(self.handler.categories) + len(self.handler.tasks) + 1)

        self.updatelists()
        
        setuserbutton = tkinter.Button(self, text="Set user", command=lambda:
                                       self.dialoguebox(["Enter username"], self.submit_name))
        setuserbutton.grid(column=3, row=0)

        catbutton = tkinter.Button(self, text="New category", command=lambda:
                                self.dialoguebox(["Category name:", "Position:",
                                    "Heading colour:"], self.submit_newcategory, 3))
        catbutton.grid(column=0, row=self.rowVariable.get())
        
        habbutton = tkinter.Button(self, text="New habit", command=lambda:
                                   self.dialoguebox(["Task name:", "Category:",
                                        "Points:", "Bonus points:", "Position:"],
                                        self.submit_newtask, 5))
        habbutton.grid(column=1, row=self.rowVariable.get())


    def updatelists(self):
        if hasattr(self, 'lists'):
            self.lists.destroy()
        self.lists = tkinter.Frame(self.parent, borderwidth=1)
        self.lists.grid(row=1)
        print (self.handler.categories)
        for category in self.handler.categories:
            print (self.handler.categories[category].contents)
            self.tasks = tkinter.Frame(self.lists, borderwidth=1)
            self.tasks.grid(column=0, row=self.handler.categories[category].pos)
            self.category = tkinter.Label(self.tasks, text=category,
                                  bg=self.handler.categories[category].colour)
            
            for task in self.handler.categories[category].contents:
                self.task = tkinter.Label(self.tasks, text=task)
                self.task.grid(column=0, row=self.handler.tasks[task].pos)

    def dialoguebox(self, msg, submit, entries=1):
        top = self.top = tkinter.Toplevel(self)
        self.variables = []
        self.allentries = []
        for i in range(entries):
            label = tkinter.Label(top, text=msg[i])
            label.grid(row=i, column=0, sticky='w')
            entry = tkinter.Entry(top)
            entry.grid(row=i, column=1)
            self.variables.append(label)
            self.allentries.append(entry)            
            
        self.allentries[0].focus_set()
        self.allentries[-1].bind("<Return>", submit)

        self.submitbutton = tkinter.Button(top, text="OK")
        self.submitbutton.bind("<Button-1>", submit)
        self.submitbutton.grid(row=entries+1, column=1, sticky='e')

        self.cancelbutton = tkinter.Button(top, text="Cancel",
                                      command=lambda: self.top.destroy())
        self.cancelbutton.grid(row=entries+1, column=2)

    def submit_name(self, event):
        data = self.allentries[0].get()
        if data:
            self.username = data
            self.top.destroy()
            self.titleVariable.set(self.username + "'s Habits")
{'fraction_non_alphanumeric': 0.126417704011065, 'fraction_numerical': 0.006915629322268326, 'mean_word_length': 1.9502243982048144, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1495448', 'n_tokens_mistral': 2071, 'n_tokens_neox': 2019, 'n_words': 340}