def gradestudent(self):
     assignments = mydb.get_assignments()
     for assignment in assignments:
         if assignment.id == int(self.assignment_entry.get()):
             break
     grades = ast.literal_eval(assignment.grades)
     grades[int(self.student_entry.get())] = int(self.grade_entry.get())
     strgrades = str(grades)
     mydb.update_grade(self.assignment_entry.get(), strgrades)
     self.grade_summary()
 def add_assignment(self):
     mydb.add_assignment(self.name_entry.get(), self.file_id,
                         self.point_entry.get())
     assignments = mydb.get_assignments()
     self.treeview.delete(*self.treeview.get_children())
     for assignment in assignments:
         self.treeview.insert('',
                              'end',
                              text=assignment.id,
                              values=(assignment.name, assignment.files,
                                      assignment.max_point))
 def delete_assigment(self):
     select = self.tree.selection()
     if select:
         item = self.tree.item(
             select
         )  #{'text': 2, 'image': '', 'values': ['C++ homework', 15], 'open': 0, 'tags': ''}
         # Delete from database
         mydb.delete_assignment(item['text'])
         # Refresh the database
         assignments = mydb.get_assignments()
         self.treeview.delete(*self.treeview.get_children())
         for assignment in assignments:
             self.treeview.insert('',
                                  'end',
                                  text=assignment.id,
                                  values=(assignment.name, assignment.files,
                                          assignment.max_point))
    def grade_summary(self):
        students = mydb.get_people()
        assignments = mydb.get_assignments()
        i = 1
        ttk.Label(self.parent, text="Grade Summary ", font=("Helvetica", 16)) \
            .grid(row=8, column=0, columnspan=5)
        ttk.Label(self.parent, text="--------------------------------------------------- ", font=("Helvetica", 20)) \
            .grid(row=9, column=0, columnspan=5)

        for assignment in assignments:
            ttk.Label(self.parent,
                      text="AssignmentID: " + str(assignment.id) +
                      "    ").grid(column=i, row=10)
            i += 1

        i = 11
        for student in students:
            if student.isInstructor == "False":
                ttk.Label(self.parent,
                          text="StudentID: " + str(student.id)).grid(column=0,
                                                                     row=i)
                i += 1

        ttk.Label(self.parent, text="Grade Summary ", font=("Helvetica", 16)) \
            .grid(row=8, column=0, columnspan=5)
        ttk.Label(self.parent, text="--------------------------------------------------- ", font=("Helvetica", 20)) \
            .grid(row=9, column=0, columnspan=5)

        j = 1
        for assignment in assignments:
            i = 11
            for student in students:
                if student.isInstructor == "False":
                    grades = ast.literal_eval(assignment.grades)
                    if student.id in grades:
                        grade = grades[student.id]
                    else:
                        grade = None
                    # print(str(i) +" "+ str(j)+" " + str(grade))
                    ttk.Label(self.parent, text=grade).grid(row=i, column=j)
                    i += 1
            j += 1
    def initialize_user_interface(self):
        self.label1 = ttk.Label(self.parent,
                                text="Grade book for " + current_user.name,
                                font=("Helvetica", 20))
        self.label1.grid(row=0, column=0)
        self.label2 = ttk.Label(
            self.parent,
            text=
            '-----------------------------------------------------------------------------------'
        )
        self.label2.grid(row=1, column=0)
        self.label3 = ttk.Label(
            self.parent,
            text='----------------------------------------------------')
        self.label3.grid(row=2, column=0)

        self.parent.title("Grade")
        self.parent.grid_rowconfigure(0, weight=1)
        self.parent.grid_columnconfigure(0, weight=1)
        self.parent.config(background="lavender")

        self.tree = ttk.Treeview(self.parent, columns=('Grade', 'maxPoint'))
        self.tree.heading('#0', text='assignmentName')
        self.tree.heading('#1', text='Grade')
        self.tree.heading('#2', text='maxPoint')

        self.tree.column('#0', stretch=tk.YES)
        self.tree.column('#1', stretch=tk.YES)
        self.tree.column('#2', stretch=tk.YES)

        self.tree.grid(row=6, columnspan=5, sticky='nsew')
        self.treeview = self.tree
        assignments = mydb.get_assignments()
        for assignment in assignments:
            grades = ast.literal_eval(assignment.grades)
            if current_user.id in grades:
                grade = grades[current_user.id]
            else:
                grade = None
            self.treeview.insert('', 'end', text=assignment.name , \
                                 values=(grade, assignment.max_point))
    def initialize_user_interface(self):
        self.parent.title("Assignments for " + current_user.name)
        self.parent.grid_rowconfigure(0, weight=1)
        self.parent.grid_columnconfigure(0, weight=1)
        self.parent.config(background="lavender")

        label1 = ttk.Label(self.parent,
                           text="Assignment panel for " + current_user.name,
                           font=("Helvetica", 20))
        label1.grid(row=0, column=0, columnspan=2)

        label2 = ttk.Label(
            self.parent,
            text=
            '---------------------------------------------------------------------------------------------------'
        )
        label2.grid(row=1, column=0)

        download_button = ttk.Button(self.parent,
                                     text="Download",
                                     command=self.download1)
        download_button.grid(row=5, column=0, sticky=tk.W)

        self.tree.heading('#0', text='assignmenID')
        self.tree.heading('#1', text='name')
        self.tree.heading('#2', text='fileID')
        self.tree.heading('#3', text='maxPoint')

        self.tree.column('#0', stretch=tk.YES)
        self.tree.column('#1', stretch=tk.YES)
        self.tree.column('#2', stretch=tk.YES)
        self.tree.column('#3', stretch=tk.YES)

        self.tree.grid(row=12, columnspan=5, sticky='nsew')
        self.treeview = self.tree
        assignments = mydb.get_assignments()
        for assignment in assignments:
            self.treeview.insert('',
                                 'end',
                                 text=assignment.id,
                                 values=(assignment.name, assignment.files,
                                         assignment.max_point))

        if not isInstructor:
            self.submit_button = ttk.Button(self.parent,
                                            text="Submit",
                                            command=self.submit_assignment)
            self.submit_button.grid(row=9, column=0, sticky=tk.W)

        if isInstructor:
            self.name_label = ttk.Label(self.parent, text="name:")
            self.name_label.grid(row=2, column=0, sticky=tk.W)
            self.name_entry = ttk.Entry(self.parent, textvariable=self.name)
            self.name_entry.grid(row=2, column=1)

            self.point_label = ttk.Label(self.parent, text="maxPoint:")
            self.point_label.grid(row=3, column=0, sticky=tk.W)
            self.point_entry = ttk.Entry(self.parent,
                                         textvariable=self.maxPoint)
            self.point_entry.grid(row=3, column=1)

            self.file_label = ttk.Label(self.parent, text="file:")
            self.file_label.grid(row=4, column=0, sticky=tk.W)
            # self.file_entry = ttk.Entry(self.parent, textvariable = self.file, state="readonly")
            # self.file_entry.grid(row=3, column=1)

            self.add_button = ttk.Button(self.parent,
                                         text=" --- Select file ---",
                                         command=self.add_file)
            self.add_button.grid(row=4, column=1)

            self.add_button = ttk.Button(self.parent,
                                         text="Add Assignment",
                                         command=self.add_assignment)
            self.add_button.grid(row=7, column=1, rowspan=3)

            self.add_button = ttk.Button(self.parent,
                                         text="Delete Assignment",
                                         command=self.delete_assigment)
            self.add_button.grid(row=8, column=0, sticky=tk.W)