def newUserCreate(self): if self.entryBoxes[1][1].get() != self.entryBoxes[2][1].get(): errorLabel = tk.Label(self, text="ERROR - Passwords do not match", font=global_variables.text(12)) errorLabel.grid(row=7, column=0, columnspan=2) elif len(self.entryBoxes[1][1].get()) < 8: errorLabel = tk.Label( self, text="ERROR - Passwords must be atleast 8 characters", font=global_variables.text(12)) errorLabel.grid(row=7, column=0, columnspan=2) elif account_management.get_user_data(self.entryBoxes[0][1].get()): errorLabel = tk.Label(self, text="ERROR - Username already exist", font=global_variables.text(12)) errorLabel.grid(row=7, column=0, columnspan=2) elif account_management.create_user(self.entryBoxes[0][1].get(), self.entryBoxes[1][1].get(), self.entryBoxes[3][1].get(), self.AdminVar.get()): self.parent.show_users() else: errorLabel = tk.Label(self, text="ERROR - Account creation failed", font=global_variables.text(12)) errorLabel.grid(row=7, column=0, columnspan=2)
def __init__(self, parent): tk.Frame.__init__(self, parent) self.parent = parent nameLabel = tk.Label(self, text="New user", font=global_variables.text(16)) nameLabel.grid(row=0, column=0, columnspan=2) self.entryBoxes = [] labels = [ "Username", "Password", "Repeated Password", "Team Number", "Admin" ] for i in range(5): array = [ tk.Label(self, text=labels[i], font=global_variables.text(12)) ] array[0].grid(row=i + 1, column=0) if i == 4: self.AdminVar = tk.IntVar() array.append(tk.Checkbutton(self, variable=self.AdminVar)) array[-1].grid(row=i + 1, column=1) elif i == 1 or i == 2: array.append( tk.Entry(self, font=global_variables.text(12), show="*")) array[-1].grid(row=i + 1, column=1) else: array.append(tk.Entry(self, font=global_variables.text(12))) array[-1].grid(row=i + 1, column=1) self.entryBoxes.append(array) self.buttons = [ tk.Button(self, text="Create User", font=global_variables.text(16), command=self.newUserCreate) ] self.buttons[0].grid(row=6, column=0, columnspan=2)
def switchToMatchViewEvent(self): selectedEventID = self.dataBox.selection_get()[0:14] if global_variables.isOnlySpaces([selectedEventID]): errorLabel = tk.Label(self, text="ERROR - Select record with an EventID", font=global_variables.text(12)) errorLabel.grid(row=self.startRow, column=0, columnspan=2) else: self.parent.switch = [selectedEventID, 0] self.parent.show_matches()
def bindSetup(self): self.cyclesCompletedCount = 0 self.currentLabel = tk.Label( self, text="Current task : Fetching complete team list", font=global_variables.text(20)) self.currentLabel.place(relx=0.5, rely=0.5, anchor=tk.CENTER) self.controller.after(timeDelay, self.dataSetup)
def show_users(self): if self.controller.isAdmin: self.currentPage.grid_forget() self.currentPage = GeneralData(self, "tblUsers") self.currentPage.grid(row=3, column=0, columnspan=5) self.bindSetup() else: errorLabel = tk.Label(self.smallMenu, text="ERROR - Insufficient permissions", font=global_variables.text(16)) errorLabel.grid(row=1, column=4)
def updateUserScreen(self): UserName = self.dataBox.selection_get()[self.columnWidth:2 * self.columnWidth].strip() if not account_management.get_user_data(UserName): errorLabel = tk.Label(self, text="ERROR - Select a user to update", font=global_variables.text(12)) errorLabel.grid(row=self.startRow, column=0, columnspan=2) self.startRow += 1 else: self.parent.show_update_users(UserName)
def showCompareScreen(self): if 2 <= len(self.selectedForCompare) <= 6: self.controller.selectedForCompare = self.selectedForCompare self.controller.show_compare() else: if len(self.selectedForCompare) > 6: msg = "ERROR - Too many teams selected" else: msg = "ERROR - Too few teams selected" errorLabel = tk.Label(self, text=msg, font=global_variables.text(12)) errorLabel.grid(row=8, column=0)
def __init__(self, parent, controller): self.controller = controller tk.Frame.__init__(self, parent) self.currentPage = None self.switch = None self.navbarGrid = tk.Frame(self, padx=10, pady=10) self.navbarGrid.grid(row=0, column=0, sticky="w") self.homeButton = tk.Button(self.navbarGrid, text="Home", font=global_variables.text(), command=self.controller.show_home) self.homeButton.grid(row=0, column=1) self.databaseButton = tk.Button(self.navbarGrid, text="Database", font=global_variables.text()) self.databaseButton.grid(row=0, column=2) self.resultsButton = tk.Button(self.navbarGrid, text="Results", font=global_variables.text(), command=self.controller.show_results) self.resultsButton.grid(row=0, column=3) self.smallMenu = tk.Frame(self, padx=10, pady=10) self.smallMenu.grid(row=1, column=0, sticky="w") self.eventButton = tk.Button(self.smallMenu, text="Events", command=self.show_events, font=global_variables.text(16)) self.eventButton.grid(row=1, column=0) self.matchButton = tk.Button(self.smallMenu, text="Matches", command=self.show_matches, font=global_variables.text(16)) self.matchButton.grid(row=1, column=1) self.teamButton = tk.Button(self.smallMenu, text="Teams", command=self.show_teams, font=global_variables.text(16)) self.teamButton.grid(row=1, column=2) self.userButton = tk.Button(self.smallMenu, text="Users", command=self.show_users, font=global_variables.text(16)) self.userButton.grid(row=1, column=3) self.show_events()
def __init__(self, parent, UserName): NewUser.__init__(self, parent) nameLabel = tk.Label(self, text="Update user", font=global_variables.text(16)) nameLabel.grid(row=0, column=0, columnspan=2) self.originalUserData = account_management.get_user_data( UserName) # Gets the select users account info self.originalUserData[2] = "" # Clears the password location self.entryBoxes[0][1].insert( 0, self.originalUserData[1]) # Inserts data into the entry boxes self.entryBoxes[3][1].insert(0, self.originalUserData[3]) for button in self.buttons: # Removes buttons from new user init button.grid_forget() self.buttons = [ tk.Button(self, text="Update User", font=global_variables.text(16), command=self.updateUserCommand) ] self.buttons[0].grid(row=6, column=0, columnspan=2) self.buttons.append( tk.Button(self, text="Delete User", font=global_variables.text(16), command=self.deleteUserCommand)) self.buttons[1].grid(row=7, column=0, columnspan=2) if self.originalUserData[4] == 1: # If the user began as an admin self.entryBoxes[4][1].select() # Put tick in entry box
def updateUserCommand(self): data = [None for i in range(3)] if self.entryBoxes[0][1].get( ) != self.originalUserData[1]: # If the username has changed if account_management.get_user_data( self.entryBoxes[0][1].get()): # If the user already exists errorLabel = tk.Label(self, text="ERROR - Username already exist", font=global_variables.text(12)) errorLabel.grid(row=8, column=0, columnspan=2) return False else: data[0] = self.entryBoxes[0][1].get() if self.entryBoxes[3][1].get( ) != self.originalUserData[3]: # If the team number has changed if not team_management.check_team_presence( self.entryBoxes[3][1].get()): if team_management.import_team( self.entryBoxes[3][1].get()) == False: errorLabel = tk.Label(self, text="ERROR - Team does not exist", font=global_variables.text(12)) errorLabel.grid(row=8, column=0, columnspan=2) return False data[1] = self.entryBoxes[3][1].get() if self.AdminVar.get( ) != self.originalUserData[4]: # If the admin state has changed data[2] = self.AdminVar.get() if data != [None for i in range(3) ]: # If one or more of the above data fields have changed account_management.update_user_data(self.originalUserData[1], data[0], data[1], data[2]) if self.entryBoxes[1][1].get( ) != "": # If a new password has been entered if self.entryBoxes[1][1].get() != self.entryBoxes[2][1].get( ): # If the password do not match errorLabel = tk.Label(self, text="ERROR - Passwords do not match", font=global_variables.text(12)) errorLabel.grid(row=8, column=0, columnspan=2) return False elif len(self.entryBoxes[1] [1].get()) < 8: # If the passwords are too short errorLabel = tk.Label( self, text="ERROR - Passwords must be atleast 8 characters", font=global_variables.text(12)) errorLabel.grid(row=8, column=0, columnspan=2) return False else: # Updates the password if data[0] is not None: # If the username has been changed already userName = data[0] else: # The username has not changed userName = self.originalUserData[1] account_management.update_user_password( userName, self.entryBoxes[1][1].get()) self.parent.show_users()
def __init__(self, parent, controller): self.controller = controller tk.Frame.__init__(self, parent) self.navbarGrid = tk.Frame(self, padx=10, pady=10) self.navbarGrid.grid(row=0, column=0, sticky="W") self.homeButton = tk.Button(self.navbarGrid, text="Home", font=global_variables.text()) self.homeButton.grid(row=0, column=1) self.databaseButton = tk.Button(self.navbarGrid, text="Database", font=global_variables.text(), command=self.controller.show_database) self.databaseButton.grid(row=0, column=2) self.resultsButton = tk.Button(self.navbarGrid, text="Results", font=global_variables.text(), command=self.controller.show_results) self.resultsButton.grid(row=0, column=3) self.mainScreenGrid = tk.Frame(self) self.mainScreenGrid.grid(row=2, column=0, columnspan=4) self.importEventGrid = tk.Frame(self.mainScreenGrid, padx=50, pady=10) self.importEventGrid.grid(row=2, column=0) importEventLabel = tk.Label(self.importEventGrid, text="Select teams via Event", font=global_variables.text()) importEventLabel.grid(row=0, column=0, columnspan=3) self.currentSeasonVar = tk.StringVar(self) self.currentSeasonVar.set("Choose season") self.currentCountryVar = tk.StringVar(self) self.currentCountryVar.set("United Kingdom") self.currentEventVar = tk.StringVar(self) self.currentEventVar.set("Choose event") countryLabel = tk.Label(self.importEventGrid, text="Country:", font=global_variables.text(12)) countryLabel.grid(row=3, column=0) self.countryMenu = tk.OptionMenu(self.importEventGrid, self.currentCountryVar, *global_variables.countries()) self.countryMenu.grid(row=3, column=1, columnspan=2, padx=10, pady=10) self.countryMenu.config(font=global_variables.text(12)) eventLabel = tk.Label(self.importEventGrid, text="Event:", font=global_variables.text(12)) eventLabel.grid(row=4, column=0) self.eventMenu = tk.OptionMenu(self.importEventGrid, self.currentEventVar, "Select country and season") self.eventMenu.grid(row=4, column=1, columnspan=2, padx=10, pady=10) self.eventMenu.config(font=global_variables.text(12)) seasonLabel = tk.Label(self.importEventGrid, text="Season:", font=global_variables.text(12)) seasonLabel.grid(row=2, column=0) self.seasonMenu = tk.OptionMenu(self.importEventGrid, self.currentSeasonVar, *tuple(global_variables.seasons()), command=self.updateEventMenu) self.seasonMenu.grid(row=2, column=1, columnspan=2, padx=10, pady=10) self.seasonMenu.config(font=global_variables.text(12)) self.importEventSubmit = tk.Button(self.importEventGrid, text="Select teams", font=global_variables.text(16), command=self.importTeamsByEvent) self.importEventSubmit.grid(row=5, column=0, columnspan=2) self.importTeamGrid = tk.Frame(self.mainScreenGrid, padx=10, pady=10) self.importTeamGrid.grid(row=3, column=0) importTeamLabel = tk.Label(self.importTeamGrid, text="Select team via team number", font=global_variables.text()) importTeamLabel.grid(row=0, column=0) self.importTeamBox = tk.Entry(self.importTeamGrid, font=global_variables.text(12)) self.importTeamBox.grid(row=1, column=0) importTeamNote = tk.Label(self.importTeamGrid, text="Use commas to separate teams", font=global_variables.text(10)) importTeamNote.grid(row=2, column=0) self.importTeamSubmit = tk.Button(self.importTeamGrid, text="Select teams", font=global_variables.text(16), command=self.importTeamsByTeamNum) self.importTeamSubmit.grid(row=3, column=0) self.dataGrid = tk.Frame(self.mainScreenGrid, padx=10, pady=10) self.dataGrid.grid(row=2, column=1, rowspan=2) selectedTeamsLabel = tk.Label(self.dataGrid, text="Currently selected teams:", font=global_variables.text()) selectedTeamsLabel.grid(row=0, column=0, columnspan=2) self.dataListbox = tk.Listbox(self.dataGrid, width=10, height=16) self.dataListbox.grid(row=2, column=0, rowspan=7, padx=10, pady=10) self.dataListbox.config(font=global_variables.text(16)) self.removeTeamButton = tk.Button(self.dataGrid, text="Remove selected team", font=global_variables.text(16), command=self.removeTeam) self.removeTeamButton.grid(row=2, column=1) self.removeAllTeamsButton = tk.Button(self.dataGrid, text="Remove all teams", font=global_variables.text(16), command=self.removeAllTeams) self.removeAllTeamsButton.grid(row=3, column=1) self.viewTeamDataButton = tk.Button(self.dataGrid, text="View selected team", font=global_variables.text(16), command=self.showTeam) self.viewTeamDataButton.grid(row=4, column=1) for record in range(0, len(self.controller.selectedTeams)): row = self.controller.selectedTeams[record] self.dataListbox.insert(tk.END, row) self.finalSeasonVar = tk.StringVar(self) self.finalSeasonVar.set("Choose season") self.finalCountryVar = tk.StringVar(self) self.finalCountryVar.set("United Kingdom") finalCountryLabel = tk.Label(self.dataGrid, text="Country:", font=global_variables.text(12)) finalCountryLabel.grid(row=5, column=1) self.finalCountryMenu = tk.OptionMenu(self.dataGrid, self.finalCountryVar, *global_variables.countries()) self.finalCountryMenu.grid(row=6, column=1) self.finalCountryMenu.config(font=global_variables.text(12)) finalseasonLabel = tk.Label(self.dataGrid, text="Season:", font=global_variables.text(12)) finalseasonLabel.grid(row=7, column=1) self.finalSeasonMenu = tk.OptionMenu(self.dataGrid, self.finalSeasonVar, *tuple(global_variables.seasons()), command=self.updateEventMenu) self.finalSeasonMenu.grid(row=8, column=1) self.finalSeasonMenu.config(font=global_variables.text(12)) self.beginButton = tk.Button(self.dataGrid, text="Begin analysis", font=global_variables.text(), command=self.runAlgorithm) self.beginButton.grid(row=9, column=0, columnspan=3) self.teamViewGrid = tk.Frame(self.mainScreenGrid) self.teamViewGrid.grid(row=4, column=0, columnspan=2) teamViewLabel = tk.Label(self.teamViewGrid, text="Enter team number to view", font=global_variables.text()) teamViewLabel.grid(row=0, column=0) self.teamViewBox = tk.Entry(self.teamViewGrid, font=global_variables.text(12)) self.teamViewBox.grid(row=1, column=0) teamViewButton = tk.Button(self.teamViewGrid, text="View team details", font=global_variables.text(14), command=self.showTeamAlt) teamViewButton.grid(row=2, column=0)
def importTeamsByTeamNum(self, test=None): data = self.importTeamBox.get().replace(" ", "").split(",") # Removes spaces and splits into list if len(data) > 0: # Ensures the box is not empty errors = [] for teamNum in data: if team_management.check_team_presence(teamNum): # Ensures the team is present in database self.controller.selectedTeams.append(teamNum) # Adds team to team list self.controller.selectedTeams = sorted(list(set(self.controller.selectedTeams))) # Removes duplicates and sorts list self.refreshTeamList() # Updates GUI else: if not team_management.import_team(teamNum): # If team cannot be imported errors.append(teamNum) # Adds to list of errors else: self.controller.selectedTeams.append(teamNum) self.controller.selectedTeams = sorted(list(set(self.controller.selectedTeams))) self.refreshTeamList() if len(errors) > 0: # Checks if there has been any errors errorLabel = tk.Label(self.importTeamGrid, text="Teams not found: " + ",".join(errors), font=global_variables.text(12)) errorLabel.grid(row=4, column=0)
def __init__(self, parent, controller): self.controller = controller tk.Frame.__init__(self, parent) self.navbarGrid = tk.Frame(self, padx=10, pady=10) self.navbarGrid.grid(row=0, column=0, rowspan=2) self.homeButton = tk.Button(self.navbarGrid, text="Home", font=global_variables.text(), command=self.controller.show_home) self.homeButton.grid(row=0, column=1) self.databaseButton = tk.Button(self.navbarGrid, text="Database", font=global_variables.text(), command=self.controller.show_database) self.databaseButton.grid(row=0, column=2) self.resultsButton = tk.Button(self.navbarGrid, text="Results", font=global_variables.text()) self.resultsButton.grid(row=0, column=3) self.descriptionLabel = tk.Label(self, text="Select teams to compare", font=global_variables.text()) self.descriptionLabel.grid(row=2, column=0, padx=10) self.showTeamButton = tk.Button(self, text="Show highlighted team details", font=global_variables.text(14), command=self.showTeamScreen) self.showTeamButton.grid(row=3, column=0) self.compareSelectedButton = tk.Button(self, text="Compare selected teams", font=global_variables.text(14), command=self.showCompareScreen ) self.compareSelectedButton.grid(row=4, column=0) self.fetchAwardDataButton = tk.Button(self, text="Collect award data", font=global_variables.text(14), command=self.fetchAwardData) self.fetchAwardDataButton.grid(row=5, column=0) self.dataBox = tk.Listbox(self, width=140, height=42) self.dataBox.grid(row=2, column=2, rowspan=20, columnspan=14) self.dataBox.config(font=("Courier", 12)) self.tickBoxGrid = tk.Frame(self) self.tickBoxGrid.grid(row=2, column=1, rowspan=20, padx=10) selectLabel = tk.Label(self.tickBoxGrid, text="Selected?", font=global_variables.text(12)) selectLabel.grid(row=0, column=0) self.tickBoxData = [] self.tickBoxes = [] for i in range(20): self.tickBoxData.append(tk.IntVar()) self.tickBoxes.append(tk.Checkbutton(self.tickBoxGrid, variable=self.tickBoxData[i], command=self.updateSelectedBox)) self.tickBoxes[-1].grid(row=i + 1, column=0, pady=7) self.upButton = tk.Button(self, text=" /\\ ", command=self.moveUp) # Smallest to biggest self.upButton.grid(row=0, column=8, pady=10, columnspan=2) self.downButton = tk.Button(self, text=" \\/ ", command=self.moveDown) # Biggest to smallest self.downButton.grid(row=30, column=8, pady=10, columnspan=2) self.sortBoxes = [] temp = [tk.Button(self, text="\\/", command=lambda: self.reSortList(0, 0)), tk.Button(self, text="/\\", command=lambda: self.reSortList(0, 1))] temp[-2].grid(row=1, column=10, pady=5) temp[-1].grid(row=1, column=11, pady=5) self.sortBoxes.append(temp) temp = [tk.Button(self, text="\\/", command=lambda: self.reSortList(1, 0)), tk.Button(self, text="/\\", command=lambda: self.reSortList(1, 1))] temp[-2].grid(row=1, column=12, pady=5) temp[-1].grid(row=1, column=13, pady=5) self.sortBoxes.append(temp) temp = [tk.Button(self, text="\\/", command=lambda: self.reSortList(2, 0)), tk.Button(self, text="/\\", command=lambda: self.reSortList(2, 1))] temp[-2].grid(row=1, column=14, pady=5) temp[-1].grid(row=1, column=15, pady=5) self.sortBoxes.append(temp) self.sortBoxes[0][0]["relief"] = "sunken" selectedLabel = tk.Label(self, text="Currently selected teams:", font=global_variables.text(12)) selectedLabel.grid(row=6, column=0) self.selectedDataBox = tk.Listbox(self, width=30, height=8) self.selectedDataBox.grid(row=7, column=0) self.selectedDataBox.config(font=("Courier", 12))
def __init__(self, parent, tblName): tk.Frame.__init__(self, parent) self.parent = parent self.tblName = tblName self.columnNames = [] db = sqlite3.connect("database.db") # c = db.cursor() columnNames = c.execute("PRAGMA table_info(" + self.tblName + ")").fetchall() for column in columnNames: self.columnNames.append(column[1]) if pc_identifier.getPC() == "BadLaptop": tempWidth = 100 else: tempWidth = 150 self.columnWidth = int( tempWidth / len(self.columnNames)) # Calculate the maximum column width tableName = tk.Label(self, text=tblName + " - Search", font=global_variables.text()) tableName.grid(row=0, column=0, columnspan=2) commaLabel = tk.Label(self, text="Use commas to separate search terms", font=global_variables.text(12)) commaLabel.grid(row=1, column=0, columnspan=2) self.startRow = 2 self.searchBoxes = [] self.labels = [] for searchItem in range(len(self.columnNames)): if self.columnNames[searchItem] not in [ "RedTeam1", "RedTeam2", "BlueTeam1", "BlueTeam2" ]: self.labels.append( tk.Label(self, text=self.columnNames[searchItem], font=global_variables.text(14))) self.labels[self.startRow - 2].grid(row=self.startRow, column=0) self.searchBoxes.append( tk.Entry(self, font=global_variables.text(14))) self.searchBoxes[self.startRow - 2].grid(row=self.startRow, column=1) self.startRow += 1 if self.tblName == "tblMatches": self.labels.append( tk.Label(self, text="TeamNumber", font=global_variables.text(14))) self.labels[self.startRow - 2].grid(row=self.startRow, column=0) self.searchBoxes.append( tk.Entry(self, font=global_variables.text(14))) self.searchBoxes[self.startRow - 2].grid(row=self.startRow, column=1) self.startRow += 1 self.refreshButton = tk.Button(self, text="Search", font=global_variables.text(14), command=self.updateData) self.refreshButton.grid(row=self.startRow, column=0, columnspan=2) self.startRow += 1 if self.parent.switch is not None: self.searchBoxes[self.parent.switch[1]].insert( 0, self.parent.switch[0]) self.parent.switch = None if self.tblName == "tblEvents": self.refreshButton = tk.Button(self, text="Update recent events", font=global_variables.text(14), command=self.refreshEventData) self.refreshButton.grid(row=self.startRow, column=0, columnspan=2) self.startRow += 1 self.showMatches = tk.Button(self, text="Show corresponding matches", font=global_variables.text(14), command=self.switchToMatchViewEvent) self.showMatches.grid(row=self.startRow, column=0, columnspan=2) self.startRow += 1 elif self.tblName == "tblMatches": self.showEvents = tk.Button(self, text="Show corresponding event", font=global_variables.text(14), command=self.switchToEventView) self.showEvents.grid(row=self.startRow, column=0, columnspan=2) self.startRow += 1 elif self.tblName == "tblTeams": self.showMatches = tk.Button(self, text="Show corresponding matches", font=global_variables.text(14), command=self.switchToMatchViewTeam) self.showMatches.grid(row=self.startRow, column=0, columnspan=2) self.startRow += 1 self.showMatches = tk.Button(self, text="Show team details", font=global_variables.text(14), command=self.showTeamScreen) self.showMatches.grid(row=self.startRow, column=0, columnspan=2) self.startRow += 1 elif self.tblName == "tblUsers": self.newUserButton = tk.Button(self, text="New user", font=global_variables.text(14), command=self.parent.show_new_users) self.newUserButton.grid(row=self.startRow, column=0, columnspan=2) self.startRow += 1 self.updateUserButton = tk.Button(self, text="Update user", font=global_variables.text(14), command=self.updateUserScreen) self.updateUserButton.grid(row=self.startRow, column=0, columnspan=2) self.startRow += 1 self.dataBox = tk.Listbox(self, width=tempWidth, height=40) self.dataBox.grid(row=1, column=2, rowspan=20) self.dataBox.config(font=("Courier", 12)) self.updateData()
def bindSetup(self): self.selectedForCompare = [x[1] for x in self.controller.selectedForCompare] # Store team list locally numTeams = len(self.selectedForCompare) rowNum = 0 # Row counter to be incremented after use returnButton = tk.Button(self, text="Return", font=global_variables.text(), command=self.goBack) returnButton.grid(row=0, column=0, sticky="W", padx=10, pady=10, columnspan=100) self.spacer = tk.Frame(self, padx=20, pady=20) self.spacer.grid(row= 1, column=0, sticky="NESW") self.boxes = [] # Generate empty array for row1 in range(int(ceil(numTeams / 2))): # Loop for top row self.boxes.append(tk.Frame(self.spacer, padx=20, pady=20, highlightbackground="black", highlightthickness=1)) # Create empty frame self.boxes[-1].grid(row=rowNum, column=2 * row1, columnspan=2, sticky="NESW") # Place empty frame on grid rowNum += 1 # Move onto next row if numTeams % 2 == 0: # If num of teams on second row is even wid = 2 else: if numTeams == 3: wid = 4 else: wid = 3 for row2 in range(int(numTeams - (numTeams / 2))): # Loop for bottom row self.boxes.append(tk.Frame(self.spacer, padx=20, pady=20, highlightbackground="black", highlightthickness=1)) # Create empty frame self.boxes[-1].grid(row=rowNum, column=wid * row2, columnspan=wid, sticky="NESW") # Place empty frame on grid rowNum += 1 self.data = [] for teamNum in self.selectedForCompare: teamData = [["Team number", teamNum], ["Team name", team_management.get_team_name(teamNum)], ["Team city", team_management.get_team_city(teamNum)], ["Skill rating", round(team_management.get_team_skill(teamNum),2)]] # Collect simple data from database if self.controller.selectedSeason != "": # Data which requires the season to have been selected teamData.append(["Alt skill rating", round(api_query.get_alt_skill(teamNum, self.controller.selectedSeason), 2)]) teamData.append(["Awards won", api_query.get_num_awards(teamNum, self.controller.selectedSeason)]) teamData.append(["Average constribution to wins", event_management.get_average_contribution_to_win(teamNum, self.controller.selectedSeason)]) matchWinRate = None # Sets none value to be overwritten if needed if self.controller.teamDict is not None: # Checks if algorithm has run winLossDraw = self.controller.teamDict[teamNum][1] # Stores win loss draw numbers locally matchWinRate = round((winLossDraw[0] + 0.5 * winLossDraw[2]) / sum(winLossDraw) * 100, 2) # Calculates match win rate as % if matchWinRate is not None: teamData.append(["Match win rate", matchWinRate]) self.data.append(teamData) for i in range(3, len(self.data[0])): # Iterate through each ranking factor minimum = 110 # Minimum value to be overwritten maximum = -110 # Maximum value to be overwritten for team in self.data: # Iterate through each team to find min/max if team[i][1] < minimum: minimum = team[i][1] if team[i][1] > maximum: maximum = team[i][1] for team in self.data: # Iterates through each team, calculate the colour values team[i].append(int(global_variables.remap(team[i][1], minimum, maximum, 0, 255 * 2)) - 255) # Appends the RGB value labels = [] for boxID in range(len(self.data)): rowNum = 0 for dataItem in self.data[boxID]: labels.append(tk.Label(self.boxes[boxID], text=dataItem[0] + ": ", font=global_variables.text(16))) labels[-1].grid(row=rowNum, column=0, sticky="NESW") if len(dataItem) > 2: hexNum = str(hex(dataItem[2]))[-2:] if hexNum[0] == "x": hexNum = "0" + hexNum[1] if dataItem[2] > 0: col = "#00{}00".format(hexNum) elif dataItem[2]: col = "#{}0000".format(hexNum) else: col = "#000000" else: col = "#000000" labels.append(tk.Label(self.boxes[boxID], text=dataItem[1], font=global_variables.text(16), foreground=col)) labels[-1].grid(row=rowNum, column=1, sticky="NESW") rowNum += 1 labels.append(tk.Button(self.boxes[boxID], text="Show team view", font=global_variables.text(16), command=lambda boxID=boxID: self.showTeamView(boxID))) labels[-1].grid(row=rowNum, column=1, sticky="NESW") rowNum += 1
def bindSetup(self): self.teamNum = self.controller.teamDisplay rowNum = 0 returnButton = tk.Button(self, text="Return", font=global_variables.text(), command=self.goBack) returnButton.grid(row=rowNum, column=0, sticky="W", padx=10, pady=10) rowNum += 1 self.labels = [] self.labels.append( tk.Label(self, text="Team number: {}".format(self.teamNum), font=global_variables.text(20))) self.labels[-1].grid(row=rowNum, column=0, columnspan=2, padx=10) rowNum += 1 self.labels.append( tk.Label(self, text="Team name: {}".format( team_management.get_team_name(self.teamNum)[0:21]), font=global_variables.text(20))) self.labels[-1].grid(row=rowNum, column=0, columnspan=2, padx=10) rowNum += 1 data = team_management.get_team_city(self.teamNum)[0:21] if data == "": data = None self.labels.append( tk.Label(self, text="Team location: {}".format(data), font=global_variables.text(20))) self.labels[-1].grid(row=rowNum, column=0, columnspan=2, padx=10) rowNum += 1 self.labels.append( tk.Label(self, text=" ", font=global_variables.text(20))) self.labels[-1].grid(row=rowNum, column=0, columnspan=2, padx=10) rowNum += 1 self.labels.append( tk.Label(self, text="Most recent skill rating: {}".format( round(team_management.get_team_skill(self.teamNum), 2)), font=global_variables.text(20))) self.labels[-1].grid(row=rowNum, column=0, columnspan=2, padx=10) rowNum += 1 matchWinRate = None # Sets none value to be overwritten if needed if self.controller.teamDict is not None: # Checks if algorithm has run if self.teamNum in self.controller.teamDict: # Checks whether selected team was included in comparision winLossDraw = self.controller.teamDict[self.teamNum][ 1] # Stores win loss draw numbers locally matchWinRate = str( round((winLossDraw[0] + 0.5 * winLossDraw[2]) / sum(winLossDraw), 3) * 100) + "%" # Calculates match win rate as % self.labels.append( tk.Label(self, text="Match win rate: {}".format(matchWinRate), font=global_variables.text(20))) # Creates label self.labels[-1].grid(row=rowNum, column=0, columnspan=2) # Places label rowNum += 1 altSkill = None if self.controller.selectedSeason != "": altSkill = round( api_query.get_alt_skill(self.teamNum, self.controller.selectedSeason), 3) else: altSkill = round( api_query.get_alt_skill(self.teamNum, global_variables.currentSeason()), 3) self.labels.append( tk.Label(self, text="Alternate skill rating: {}".format(altSkill), font=global_variables.text(20))) self.labels[-1].grid(row=rowNum, column=0, columnspan=2) rowNum += 1 rowNum += 1 self.labels.append( tk.Label(self, text="Tournament History", font=global_variables.text(20))) self.labels[-1].grid(row=rowNum, column=0, columnspan=3) rowNum += 1 self.tournamentBox = tk.Listbox(self, width=185, height=20) self.tournamentBox.grid(row=rowNum + 1, column=0, columnspan=3, padx=10, pady=10, sticky="ew") self.tournamentBox.config(font=("Courier", 12)) self.labels.append( tk.Label(self, text="Award History", font=global_variables.text(20))) self.labels[-1].grid(row=1, column=2, columnspan=1) self.awardBox = tk.Listbox(self, width=135, height=20) self.awardBox.grid(row=2, column=2, rowspan=7, padx=10, pady=10, sticky="ew") self.awardBox.config(font=("Courier", 12)) self.updateTournamentData() self.updateAwardData()