From 0f0627287fa917c0ecfa3cd88619c825e15cf1f1 Mon Sep 17 00:00:00 2001 From: Yash Date: Wed, 7 Apr 2021 17:54:54 -0400 Subject: [PATCH] Almost finished the second stage --- GUI.py | 102 +++++--------------------------- Pages.py | 159 ++++++++++++++++++++++++++++++++++++++++++++++++++ apicollect.py | 3 +- 3 files changed, 176 insertions(+), 88 deletions(-) create mode 100644 Pages.py diff --git a/GUI.py b/GUI.py index fde3f7f..6596340 100644 --- a/GUI.py +++ b/GUI.py @@ -1,98 +1,28 @@ from tkinter import * from tkinter import ttk +import tkinter as tk +from Pages import PageOne from apicollect import Overwatch - -class FirstGUI: +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, parent): - self.parent = parent - self.game = None - - self.frame = Frame(self.parent) - self.labelSelect = Label(self.frame, text='Choose a game to find stats to compare between multiple players') - self.labelSelect.grid(row=0, column=1) - self.game_chosen = StringVar() - # Create a dropdown menu - self.game_choices = ttk.Combobox(self.frame, state="readonly", textvariable=self.game_chosen, width=30) - # Default text shown - self.game_choices.set("Select a game") - # Possible games to choose from: Cold war and WoW are examples for now - 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 - """ - # Entry for user to put in platform - - # platform_label_text = StringVar() - # platform_label_text.set("Enter game platform (pc, etc)") - # self.label1 = Label(app, textvariable=platform_label_text, height=4) - # self.label1.grid(row=2, column=0) - - platform_id = StringVar() - self.first_gamer_plat = Entry(self.frame, textvariable=platform_id) - self.first_gamer_plat.grid(row=2, column=1) - - # Entry for user to put in region - - # region_label_text = StringVar() - # region_label_text.set("Enter game region (us, eu, asia)") - # self.label2 = Label(app, textvariable=region_label_text, height=4) - # self.label2.grid(row=3, column=0) - - region_id = StringVar() - self.first_gamer_reg = Entry(self.frame, textvariable=region_id) - self.first_gamer_reg.grid(row=3, column=1) - - # Entry for user to put in battle_id - - # battleID_label_text = StringVar() - # battleID_label_text.set("Your battlenet tag, replacing the # with a -") - # self.label3 = Label(app, textvariable=battleID_label_text, height=4) - # self.label3.grid(row=3, column=0) - - battle_id = StringVar() - self.first_gamer_batt = Entry(self.frame, textvariable=battle_id) - self.first_gamer_batt.grid(row=4, column=1) - - # Submit Button - self.sub_btn = Button(self.frame, text='Submit', command=self.submit) - self.sub_btn.grid(row=5, column=3) - - self.frame.pack() - # If a game option is selected call the callbackf function - self.game_choices.bind("<>", self.callback) - - def callback(self, event_object): - self.game = event_object.widget.get() + def __init__(self): + tk.Tk.__init__(self) + self._frame = None + self.change_frame(PageOne) - def submit(self): - """ - Retrieve the values from each entry and check if they are valid. - """ - platform = self.first_gamer_plat.get() - region = self.first_gamer_reg.get() - battle_tag = self.first_gamer_batt.get() + def change_frame(self, change_frame): + new_frame = change_frame(self) + if self._frame is not None: + self._frame.destroy() + self._frame = new_frame + self._frame.pack() - try: - o = Overwatch(platform, region, battle_tag) - if o.result: - # Simple check to see if values are valid - print(o.test_get_player_info()) - else: - print("Invalid Profile") - except: - # Need to likely change this try/except. Debugging required - print("Invalid Profile") -app = Tk() -gui = FirstGUI(app) -app.title("Game App") -app.geometry('500x600') -app.mainloop() +if __name__ == "__main__": + app = FirstGUI() + app.mainloop() \ No newline at end of file diff --git a/Pages.py b/Pages.py new file mode 100644 index 0000000..c47e13b --- /dev/null +++ b/Pages.py @@ -0,0 +1,159 @@ +from tkinter import * +import tkinter as tk +from tkinter import ttk +from apicollect import Overwatch +""" +Sources: +https://www.youtube.com/watch?v=YTqDYmfccQU +https://www.delftstack.com/howto/python-tkinter/how-to-switch-frames-in-tkinter/ +https://www.youtube.com/watch?v=7JoMTQgdxg0 +""" + + + + + +class PageOne(tk.Frame): + def __init__(self, parent): + tk.Frame.__init__(self, parent) + + self.game = None + self.labelSelect = Label(self, text='Choose a game to find stats to compare between multiple players') + self.labelSelect.grid(row=0, column=1) + self.game_chosen = StringVar() + # Create a dropdown menu + self.game_choices = ttk.Combobox(self, state="readonly", textvariable=self.game_chosen, width=30) + # Default text shown + self.game_choices.set("Select a game") + # Possible games to choose from: Cold war and WoW are examples for now + 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 + """ + + # Submit Button: we will need to change this for different games entered + self.sub_btn = Button(self, text='Submit', command=lambda: parent.change_frame(PageTwo)).grid(row=2, column=1) + # self.sub_btn.grid(row=5, column=3) + + self.pack() + # If a game option is selected call the callback function + self.game_choices.bind("<>", self.callback) + + + def callback(self, event_object): + self.game = event_object.widget.get() + +class PageTwo(tk.Frame): + """ + For Overwatch + """ + + def __init__(self, parent): + tk.Frame.__init__(self, parent) + tk.Label(self, text="Input the player").grid(row=1, column = 0, columnspan = 2) + self.num_players = 0 + # self.all_players = [] + + self.ow_tree = ttk.Treeview(self) + #Create the columns + self.ow_tree['columns'] = ("Battle Tag", "Platform", "Region") + self.ow_tree.column("#0", width=120, minwidth = 25) + self.ow_tree.column("Battle Tag", anchor=W, width=120) + self.ow_tree.column("Platform", anchor=CENTER, width=80) + self.ow_tree.column("Region", anchor = W, width = 60) + #Create the headings + self.ow_tree.heading("#0", text="Label", anchor=W) + self.ow_tree.heading("Battle Tag", text="Battle Tag", anchor=CENTER) + self.ow_tree.heading("Platform", text="Platform", anchor=W) + self.ow_tree.heading("Region", text="Region", anchor=CENTER) + + #Add Data + # ow_tree.insert('', index='end', iid=0, text="Player", values=("Yash", "pc", "us")) + + self.ow_tree.grid(row=0, column=0) + + + self.platform_chosen = StringVar() + self.region_chosen = StringVar() + self.battletag_chosen = StringVar() + + tk.Label(self, text="Player 1").grid(row=2, column=0, columnspan = 2) + + tk.Label(self, text="Platform:").grid(row=3, column=0, columnspan = 2) + # Create a dropdown menu + self.platform_choices = ttk.Combobox(self, state="readonly", textvariable=self.platform_chosen, width=30) + # Default text shown + self.platform_choices.set("Select a platform") + # Possible platforms to choose + self.platform_choices['values'] = ['pc', 'xbl', 'psn'] + self.platform_choices.grid(row=3, column=1) + + tk.Label(self, text="Region:").grid(row=4, column=0, columnspan = 2) + # Create a dropdown menu + self.region_choices = ttk.Combobox(self, state="readonly", textvariable=self.region_chosen, width=30) + # Default text shown + self.region_choices.set("Select a region") + # Possible regions to choose + self.region_choices['values'] = ['us', 'eu', 'kr', 'cn', 'global'] + self.region_choices.grid(row=4, column=1) + + tk.Label(self, text="Battle Tag:").grid(row=5, column=0, columnspan = 2) + + self.battle_id = StringVar() + self.gamer_tag = Entry(self, textvariable=self.battle_id) + self.gamer_tag.grid(row=5, column=1) + + + self.add_btn = Button(self, text='Add Player', command= self.add_player) + self.add_btn.grid(row=6, column=4) + self.add_btn = Button(self, text='Clear', command=self.clear) + self.add_btn.grid(row=7, column=4) + self.add_btn = Button(self, text='Remove Player(s)', command=self.remove_players) + self.add_btn.grid(row=8, column=4) + self.back_btn = Button(self, text='Go back', command=lambda: parent.change_frame(PageOne)).grid(row=9, column=4) + self.sub_btn = Button(self, text='Submit', command=lambda: parent.change_frame(PageThree)).grid(row=10, column=4) + + def add_player(self): + + try: + o = Overwatch(self.platform_chosen.get(), self.region_chosen.get(), self.battle_id.get()) + if o.result: + self.num_players += 1 + 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') + self.region_choices.set('Select a region') + else: + print("Invalid Profile") + + except: + print("Invalid Profile") + + + def clear(self): + for player in self.ow_tree.get_children(): + self.ow_tree.delete(player) + + def remove_players(self): + t = self.ow_tree.selection() + for player in t: + self.ow_tree.delete(player) + + +class PageThree(tk.Frame): + """ + The Third page + """ + + def __init__(self, parent): + tk.Frame.__init__(self, parent) + tk.Label(self, text="Input the player").grid(row=1, column=0, columnspan=2) + + + + + diff --git a/apicollect.py b/apicollect.py index 33049c5..c8f2f94 100644 --- a/apicollect.py +++ b/apicollect.py @@ -87,5 +87,4 @@ def compare_2players(self, player1, player2): ov = Overwatch('pc', 'us', 'cats-11481') ov.get_filers() -print("hey") -print("testing push") +