Skip to content

Commit

Permalink
PEP styled, logo loads on different paths (almost)
Browse files Browse the repository at this point in the history
  • Loading branch information
emadahmad2001 authored Apr 11, 2021
1 parent c396329 commit c0f74ab
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 92 deletions.
5 changes: 4 additions & 1 deletion GUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
from Pages import PageOne
from apicollect import Overwatch


class FirstGUI(tk.Tk):
"""
This is pertaining to Overwatch only, Remember that in the apicollect.py file,
Overwatch API requires you to put in platform, region and battle id of the player.
"""

def __init__(self):
tk.Tk.__init__(self)
self.title("Statistical Tracker for:")
Expand All @@ -27,6 +29,7 @@ def change_frame(self, change_frame, *player_info):
self._frame = new_frame
self._frame.pack()


if __name__ == "__main__":
app = FirstGUI()
app.mainloop()
app.mainloop()
120 changes: 53 additions & 67 deletions Pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from tkinter import messagebox
from tkinter import ttk
from apicollect import Overwatch
from PIL import Image
from PIL import ImageTk
import glob

"""
Sources:
Expand All @@ -13,12 +16,9 @@
"""






class PageOne(tk.Frame):
def __init__(self, parent):
global img
tk.Frame.__init__(self, parent)

self.game = None
Expand All @@ -33,10 +33,18 @@ def __init__(self, parent):
self.game_choices['values'] = ['Overwatch', 'Fortnite', 'Cold War', 'WoW']
self.game_choices.grid(row=1, column=1)


"""
Idea: Maybe we can use validate commands for the entries
"""
for filename in glob.glob('yourpath/logo.png'):
img = ImageTk.PhotoImage(Image.open(filename).resize((475, 221)))
self.panel = Label(self, image=img)
self.panel.grid(row=0, column=1, columnspan=4)

# img = ImageTk.PhotoImage(Image.open(r"C:\Users\maste\Desktop\CCT211\Term_Project\logo.png").resize((475, 221)))

# self.panel = Label(self, image=img)
# self.panel.grid(row=0, column=1, columnspan=4)

self.sub_btn = Button(self, text='Submit', command=lambda: parent.change_frame(PageTwo, "Hello"))
self.sub_btn.grid(row=2, column=1)
Expand All @@ -52,8 +60,6 @@ def callback(self, event_object):
self.sub_btn["state"] = NORMAL




class PageTwo(tk.Frame):
"""
For Overwatch
Expand All @@ -67,7 +73,6 @@ def __init__(self, parent):
self.duplicate_profile = False
self.parent = parent


self.ow_tree = ttk.Treeview(self)
# Create the columns
self.ow_tree['columns'] = ("Battle Tag", "Platform", "Region")
Expand All @@ -87,7 +92,6 @@ def __init__(self, parent):
self.region_chosen = StringVar()
self.battle_id = StringVar()


tk.Label(self, text="Platform:").grid(row=2, column=0, columnspan=1)
# Create a dropdown menu
self.platform_choices = ttk.Combobox(self, state="readonly", textvariable=self.platform_chosen, width=30)
Expand Down Expand Up @@ -125,8 +129,6 @@ def __init__(self, parent):
self.sub_btn.grid(row=4, column=4)
self.sub_btn["state"] = DISABLED



def validate_tag(self, id):
if "#" or " " in id.get():
self.battle_id.set(self.battle_id.get().replace("#", "-").replace(" ", ""))
Expand All @@ -140,7 +142,8 @@ def add_player(self):
self.duplicate_profile = False

for registered_player in self.parent.all_players:
if registered_player.information == [self.platform_chosen.get(), self.region_chosen.get(), self.battle_id.get()]:
if registered_player.information == [self.platform_chosen.get(), self.region_chosen.get(),
self.battle_id.get()]:
self.duplicate_profile = True
messagebox.showinfo('Error!', 'That profile has already been registered!')

Expand All @@ -153,8 +156,10 @@ def add_player(self):

self.parent.all_players.extend([o])

self.ow_tree.insert('', index='end', iid=self.num_players, text="Player {}".format(self.num_players),
values=(self.battle_id.get(), self.platform_chosen.get(), self.region_chosen.get()))
self.ow_tree.insert('', index='end', iid=self.num_players,
text="Player {}".format(self.num_players),
values=(
self.battle_id.get(), self.platform_chosen.get(), self.region_chosen.get()))

self.gamer_tag.delete(0, END)
self.platform_choices.set('Select a platform')
Expand All @@ -166,7 +171,7 @@ def add_player(self):
except:
messagebox.showinfo('Error!', 'You have entered an invalid profile!')
finally:
if len(self.parent.all_players) >=2:
if len(self.parent.all_players) >= 2:
self.sub_btn["state"] = NORMAL

def clear(self):
Expand All @@ -184,9 +189,6 @@ def remove_players(self):
selected = self.ow_tree.selection()[0]
self.ow_tree.delete(selected)




# for player in t:
# self.ow_tree.delete(player)
# print(int(player))
Expand All @@ -203,27 +205,25 @@ def __init__(self, parent):
self.parent = parent

self.Label_Stats = Label(self, text='Choose at least two stats to compare')
self.Label_Stats.grid(row=0, column=1, columnspan = 2)
self.Label_Stats.grid(row=0, column=1, columnspan=2)

self.gameplay = StringVar()
self.qp_btn = Radiobutton(self, text ="Quick Play", variable = self.gameplay, value = "quickPlayStats", command = lambda: self.gameplay_chosen(), tristatevalue=0)
self.cp_btn = Radiobutton(self, text="Competitive", variable=self.gameplay, value="competitiveStats", command=lambda: self.gameplay_chosen(), tristatevalue=0)
self.qp_btn = Radiobutton(self, text="Quick Play", variable=self.gameplay, value="quickPlayStats",
command=lambda: self.gameplay_chosen(), tristatevalue=0)
self.cp_btn = Radiobutton(self, text="Competitive", variable=self.gameplay, value="competitiveStats",
command=lambda: self.gameplay_chosen(), tristatevalue=0)

self.qp_btn.grid(row=1, column=1)
self.cp_btn.grid(row=1, column=2)


self.qp_btn.grid(row = 1, column = 1)
self.cp_btn.grid(row = 1, column = 2)

self.scrollbar = Scrollbar(self, orient = VERTICAL)
self.scrollbar = Scrollbar(self, orient=VERTICAL)
self.scrollbar.grid(row=2, column=2, sticky=tk.N + tk.S)
self.filter_list = self.parent.displayed_stats



self.filter_lb = Listbox(self, selectmode = MULTIPLE, width = 50, yscrollcommand=self.scrollbar.set)
self.filter_lb = Listbox(self, selectmode=MULTIPLE, width=50, yscrollcommand=self.scrollbar.set)
for filter in self.filter_list[1:]:
self.filter_lb.insert(END, filter)
self.filter_lb.grid(row = 2, column = 1, sticky=tk.N + tk.S + tk.E + tk.W)
self.filter_lb.grid(row=2, column=1, sticky=tk.N + tk.S + tk.E + tk.W)
self.filter_lb["state"] = DISABLED
self.filter_lb.bind("<<ListboxSelect>>", self.selected_stats)
self.scrollbar['command'] = self.filter_lb.yview
Expand All @@ -241,7 +241,7 @@ def selected_stats(self, lb):
if (selected_stats != ()):
for stat in selected_stats:

if self.filter_list[int(stat)+1] not in self.parent.compared_stats:
if self.filter_list[int(stat) + 1] not in self.parent.compared_stats:
self.parent.compared_stats.append(self.filter_list[int(stat) + 1])
if len(self.parent.compared_stats) >= 2:
self.sbt_stats["state"] = NORMAL
Expand All @@ -252,14 +252,11 @@ def transfer_second_page(self):
self.parent.all_players.clear()
self.parent.change_frame(PageTwo)



def gameplay_chosen(self):
self.filter_lb["state"] = NORMAL
self.parent.game_mode = self.gameplay.get()



class PageFour(tk.Frame):
"""
The Fourth page
Expand All @@ -274,13 +271,18 @@ def __init__(self, parent):
self.Label_table.grid(row=0, column=1, columnspan=2)
self.tree_stats = {}

self.sub_awards = {'Cards': 'cards', 'Medals': 'medals', 'Bronze Medals': 'medalsBronze', 'Silver Medals': 'medalsSilver',
'Gold Medals': 'medalsGold'}
self.sub_game_results = {'Games Won':'gamesWon', 'gamesLost':'gamesLost', 'gamesPlayed':'gamesPlayed'}
self.sub_awards = {'Cards': 'cards', 'Medals': 'medals', 'Bronze Medals': 'medalsBronze',
'Silver Medals': 'medalsSilver',
'Gold Medals': 'medalsGold'}
self.sub_game_results = {'Games Won': 'gamesWon', 'gamesLost': 'gamesLost', 'gamesPlayed': 'gamesPlayed'}
self.in_game_stats = {'barrierDamageDone': 'barrierDamageDone', 'damageDone': 'damageDone', 'deaths': 'deaths',
'eliminations': 'eliminations','soloKills': 'soloKills','objectiveKills': 'objectiveKills'}
self.best_game_results = {'allDamageDoneMostInGame': 'allDamageDoneMostInGame', 'barrierDamageDoneMostInGame':'barrierDamageDoneMostInGame', 'eliminationsMostInGame':'eliminationsMostInGame',
'healingDoneMostInGame':'healingDoneMostInGame', 'killsStreakBest':'killsStreakBest', 'multikillsBest':'multikillsBest'}
'eliminations': 'eliminations', 'soloKills': 'soloKills',
'objectiveKills': 'objectiveKills'}
self.best_game_results = {'allDamageDoneMostInGame': 'allDamageDoneMostInGame',
'barrierDamageDoneMostInGame': 'barrierDamageDoneMostInGame',
'eliminationsMostInGame': 'eliminationsMostInGame',
'healingDoneMostInGame': 'healingDoneMostInGame',
'killsStreakBest': 'killsStreakBest', 'multikillsBest': 'multikillsBest'}
self.in_game_index = 0
self.best_in_game_index = 0
self.game_outcome_index = 0
Expand All @@ -289,15 +291,8 @@ def __init__(self, parent):
self.change_btn = Button(self, text='Change Filters', command=lambda: parent.change_frame(PageThree))
self.change_btn.grid(row=5, column=1, columnspan=2)


self.back_btn = Button(self, text='New Comparision', command=self.transfer_second_page)
self.back_btn.grid(row = 4, column = 1, columnspan=2)






self.back_btn.grid(row=4, column=1, columnspan=2)

for stat in self.parent.compared_stats:
self.tree_stats[stat] = []
Expand All @@ -307,20 +302,17 @@ def __init__(self, parent):
# Create the columns
self.ow_stat_tree['columns'] = self.tree_stats['Name']


self.ow_stat_tree.column("#0", width=120, minwidth=25)
#
for x, stat in enumerate(self.tree_stats['Name']):

self.ow_stat_tree.column(x, anchor=CENTER, width=100)

# Create the headings
self.ow_stat_tree.heading("#0", text="Player #", anchor=W)
for x, stat in enumerate(self.tree_stats['Name']):
self.ow_stat_tree.heading(x, text="Player {}".format(x+1), anchor=CENTER)
self.ow_stat_tree.grid(row=0, column=2, rowspan=len(self.tree_stats['Name']) + 1, padx=5, pady=5, sticky=E + W + S + N)


self.ow_stat_tree.heading(x, text="Player {}".format(x + 1), anchor=CENTER)
self.ow_stat_tree.grid(row=0, column=2, rowspan=len(self.tree_stats['Name']) + 1, padx=5, pady=5,
sticky=E + W + S + N)

for x, stat in enumerate(self.tree_stats):
"""
Expand All @@ -339,19 +331,19 @@ def __init__(self, parent):
self.awards_index = x
self.ow_stat_tree.insert('', index='end', iid=x, text=stat)
elif stat in self.sub_awards:
self.ow_stat_tree.insert('', index='end', iid=x, text=stat, values = self.tree_stats[stat])
self.ow_stat_tree.insert('', index='end', iid=x, text=stat, values=self.tree_stats[stat])
self.ow_stat_tree.move(str(x), str(self.awards_index), str(self.awards_index))
elif stat in self.best_game_results:
self.ow_stat_tree.insert('', index='end', iid=x, text=stat, values = self.tree_stats[stat])
self.ow_stat_tree.insert('', index='end', iid=x, text=stat, values=self.tree_stats[stat])
self.ow_stat_tree.move(str(x), str(self.best_in_game_index), str(self.best_in_game_index))
elif stat in self.in_game_stats:
self.ow_stat_tree.insert('', index='end', iid=x, text=stat, values = self.tree_stats[stat])
self.ow_stat_tree.insert('', index='end', iid=x, text=stat, values=self.tree_stats[stat])
self.ow_stat_tree.move(str(x), str(self.in_game_index), str(self.in_game_index))
elif stat in self.sub_game_results:
self.ow_stat_tree.insert('', index='end', iid=x, text=stat, values = self.tree_stats[stat])
self.ow_stat_tree.insert('', index='end', iid=x, text=stat, values=self.tree_stats[stat])
self.ow_stat_tree.move(str(x), str(self.game_outcome_index), str(self.game_outcome_index))
else:
self.ow_stat_tree.insert('', index='end', iid=x, text=stat, values = self.tree_stats[stat])
self.ow_stat_tree.insert('', index='end', iid=x, text=stat, values=self.tree_stats[stat])

# self.displayed_filters = ['Name', 'Level', 'Prestige', 'Rating', 'Endorsement Level', 'In-Game Stats',
# 'Best In-Game Stats', 'Game Outcomes', 'Awards']
Expand Down Expand Up @@ -395,13 +387,7 @@ def get_player_info(self, stat):
for sub_stat in best_game_results:
if sub_stat not in self.tree_stats:
self.tree_stats[sub_stat] = []
self.tree_stats[sub_stat].append(player.get_stat(best_game_results[sub_stat], self.parent.game_mode))
self.tree_stats[sub_stat].append(
player.get_stat(best_game_results[sub_stat], self.parent.game_mode))
else:
self.tree_stats[stat].append(player.get_stat(stat, self.parent.game_mode))







Loading

0 comments on commit c0f74ab

Please sign in to comment.