class ClockOut(tk.Frame): """ This displays the Clock-Out screen for a student trying to rent """ def __init__(self, parent, controller): tk.Frame.__init__(self, parent) self.controller = controller self.Descriptorinfo = tk.Label(self, text="StudentInfo") self.Descriptorinfo.grid(column=0, row=1) self.Descriptorclockout = tk.Label(self, text="Clockout") self.Descriptorclockout.grid(column=1, row=1) self.clockoutinforows = [] # list of clockoutbuttons self.mydatabaseinterface = DataBaseInterface() # updated on updatestudents self.mystudentcollection = StudentCollection() # updated on updatestudents self.createinforows(5, 2) # initiation def createinforows(self, rows, startrow): """ Dynamically make 0-5 rows to display information :param rows: rows to make :param startrow: starting column to set .grid """ for i in range(rows): myinfobar = InfoBar(self, self.clockout, i, 23, 0, int(startrow + i)) # create myinfobar self.clockoutinforows.append(myinfobar) def updatestudents(self): """ WARNING Heavy Database Usage! Needs optimization!!! CREATES self. Updates the Current Students clockedin, calls: .gathercollection() - to get all students EVER USES DATABASE .dailycollection() - returns StudentCollection for just today, USES DATETIME .whosclockedin - returns JUST whos clocked in! """ self.controller.sysprint(">DEBUG: UpdatingStudents...") todaysdate = str(datetime.now().date()) self.mystudentcollection = self.mydatabaseinterface.gathercollection() # gets all entries self.mystudentcollection = self.mydatabaseinterface.dailycollection(self.mystudentcollection, todaysdate) self.mystudentcollection = self.mydatabaseinterface.whosclockedin(self.mystudentcollection) # ONLY clocked in # now that I have a collection of students ONLY logged in, display data from them. i = 0 # for loop for student in self.mystudentcollection.listofstudents: # for student in mystudentcollection self.clockoutinforows[i].stringvar.set(student.name + "-" + str(student.studentid)) i += 1 def updatescreens(self): """ Updates the Screens on Clockout, with blanks, also updates students """ for bar in range(len(self.clockoutinforows)): self.clockoutinforows[bar].stringvar.set("-------------------------") self.updatestudents() def clockout(self, buttonnumber): """ Reads the Contents of the choosen info, IE Button1 = info1 Change the Student Clockout time from None to time right now :param buttonnumber: 1-5 number :return: """ self.clockoutinforows[buttonnumber].stringvar.set("-------------------------") # clears out clockouttime = str(datetime.now().time().hour) + ":" + str(datetime.now().time().minute) try: self.mystudentcollection.listofstudents[buttonnumber].clockouttime = clockouttime self.controller.sysprint(">DEBUG: ClockoutMethod trying.." + str(self.mystudentcollection.listofstudents[buttonnumber].name) + " at " + clockouttime) self.mydatabaseinterface.clockout(self.mystudentcollection.listofstudents[buttonnumber]) logoutstring = ("Logout of " + str(self.mystudentcollection.listofstudents[buttonnumber].name) + " At " + clockouttime) self.controller.updateflag = True # dangerous is it not? self.changeframe("PrimaryPage") mypopup = Popups("Logout Successful", logoutstring, "Ok") mypopup.mainloop() except: # meh to broad? self.controller.sysprint(">ERROR!: Bad Clockout") pass def changeframe(self, framestring): self.controller.show_frame(framestring)