From 1bcaa0180b9e2b4b8299fb64303cf124f7ee24fb Mon Sep 17 00:00:00 2001 From: "barraux.a" Date: Mon, 7 Feb 2022 22:14:29 +0100 Subject: [PATCH] =?UTF-8?q?que=20de=20nouveaut=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 182 ++++++++++++++++++++++++++++++++++--------------------- stat.bbm | 2 + 2 files changed, 116 insertions(+), 68 deletions(-) diff --git a/main.py b/main.py index 340ba3c..97f0d36 100644 --- a/main.py +++ b/main.py @@ -6,43 +6,123 @@ class Terrain: def __init__(self): self.height = 15000//25 self.width = 28000//25 - self.three_points = 6250//25 # rayon + self.three_points = 6250//25 # rayon self.middle_circle = 1800//25 # rayon class Team: - def __init__(self): - self.players = ['arthur', 'jl', 'léandre', "louis", "alex"] - self.filemenu = 'stat.txt' + def __init__(self, players): + self.players = players self.posx, self.posy = 0,0 # coo de la dernière action self.ac_player = 0 # dernier joueur +class File: + def __init__(self, name='untitled.bbm'): + self.name = name + self.temp_data = '' + self.content = [] + + def write_data(self): + with open(self.name, 'a') as f: + f.write(self.temp_data) + self.temp_data = '' + + def read_file(self): + with open(self.name, 'r') as f: + self.content = f.readlines() + + class Gui: - def __init__(self, ): + def __init__(self): self.terrain = Terrain() - self.team = Team() - self.mode = 'match' - self.file = 'untitled.bbm' - self.temp_data = '' - self.list_button_menu = [] + self.team = 0 + self.mode = 0 self.root = tkinter.Tk() - self.root.title(self.file) + self.root.title('BasketBall Analitycs®') self.canvas = tkinter.Canvas(self.root, width=self.terrain.width, height=self.terrain.height, background='#bbb') - - self.canvas.pack() + + self.start_frame = tkinter.Frame(self.root, width=self.terrain.width, height=self.terrain.height, bg='red') + self.start_button_new = tkinter.Button(self.start_frame, text='new', command=self.new) + self.start_button_open = tkinter.Button(self.start_frame, text='open', command=self.browse_open) + + self.start_frame.pack() + self.start_button_new.place(x=self.terrain.width//2-45, y=self.terrain.height//2-30, width=90, height=30) + self.start_button_open.place(x=self.terrain.width//2-45, y=self.terrain.height//2, width=90, height=30) # file menu self.menubar = tkinter.Menu(self.root) self.filemenu = tkinter.Menu(self.menubar, tearoff=0) self.filemenu.add_command(label="new", command=self.new) self.filemenu.add_command(label="open", command=self.browse_open) - self.filemenu.add_command(label="save", command=self.save) self.filemenu.add_separator() - self.filemenu.add_command(label="rename") self.filemenu.add_command(label="exit", command=self.root.quit) self.menubar.add_cascade(label="file", menu=self.filemenu) + + + # topbar + self.root.config(menu=self.menubar) + + + if self.mode != 0: + print('here') + self.root.bind('', self.context_menu) + self.root.bind("", self.browse_open) + self.root.bind("", self.new) + + self.root.mainloop() + + def get_names(self): + self.team = Team(self.players_entry.get().split(',')) + print(self.team.players) + self.w_player.destroy() + self.w_player.quit() + + def new(self, *event): + # créer un fichier vierge + self.file = File() + self.root.title(self.file.name) + + self.w_player = tkinter.Toplevel() + frame = tkinter.Frame(self.w_player, width=600, height=200) + self.players_entry = tkinter.Entry(frame) + text = tkinter.Label(frame, text="Entrez les joueurs séparés par virgules") + ok_button = tkinter.Button(frame, text='OK', command=self.get_names) + + frame.pack() + self.players_entry.place(x=200, y=80, width=200, height=20) + text.place(x=150, y=40, width=300, height=40) + ok_button.place(x=280, y=120, width=40, height=20) + + self.w_player.mainloop() + + self.setup() + + def save(self, *event): + # sauvegarde du fichier + if self.file.name == 'untitled.bbm': + path = tkinter.filedialog.asksaveasfilename(initialdir = "~", title = "Select a File", filetypes = (("BasketBall Match", "*.bbm"), ("all files", "*.*"))) + if len(path) != 0: + self.file.name = path + self.root.title(self.file.name) + + def browse_open(self, *event): + # ouvre un fichier + path = tkinter.filedialog.askopenfilename(initialdir = "~/Documents/python/basket", title = "Select a File", filetypes = (("BasketBall Match", "*.bbm"), ("all files", "*.*"))) + if len(path) != 0: + self.file = File(path) + self.file.read_file() + self.team = Team(self.file.content[0].strip().split(' ')) + self.root.title(self.file.name) + self.setup() + + def setup(self): + self.start_frame.pack_forget() + self.canvas.pack() + self.mode = 'match' + self.draw_terrain() + self.filemenu.insert_command(2, label="save", command=self.save) # mode menu self.modemenu = tkinter.Menu(self.menubar, tearoff=0) self.modemenu.add_command(label="stat", command=lambda: self.changemode('stat')) @@ -59,10 +139,6 @@ class Gui: self.statsubmenu.add_command(label=self.team.players[4], command=lambda: self.draw_player(self.team.players[4])) self.statmenu.add_cascade(label="player", menu=self.statsubmenu) self.statmenu.add_command(label='team', command=self.draw_team) - - # topbar - self.root.config(menu=self.menubar) - # menu contextuel des actions self.action = tkinter.Menu(self.root, tearoff=0) self.action.add_command(label='marque', command=lambda: self.action_menu('marque')) @@ -76,29 +152,10 @@ class Gui: self.menu.add_command(label=self.team.players[3], command=lambda: self.show_sub_menu(self.team.players[3])) self.menu.add_command(label=self.team.players[4], command=lambda: self.show_sub_menu(self.team.players[4])) - def new(self, *event): - # créer un fichier vierge - self.file = 'untitled.bbm' - self.root.title = self.file - - def save(self, *event): - # sauvegarde du fichier - if self.file == 'untitled.bbm' and self.file == '': - self.file = tkinter.filedialog.asksaveasfilename(initialdir = "~", title = "Select a File", filetypes = (("BasketBall Match", "*.bbm"), ("all files", "*.*"))) - with open(self.file, 'a') as f: - f.write(self.temp_data) - self.temp_data = '' - self.root.title(self.file) + self.root.bind('', self.contextmenu) - def browse_open(self, *event): - # ouvre un fichier - self.file = tkinter.filedialog.askopenfilename(initialdir = "~/Documents/python/basket", title = "Select a File", filetypes = (("BasketBall Match", "*.bbm"), ("all files", "*.*"))) - with open(self.file, 'r') as f: - f.read() - self.root.title(self.file) def changemode(self, newmode): - print(self.mode, newmode) if self.mode != newmode: if newmode == 'stat': self.menubar.add_cascade(label='stat', menu=self.statmenu) @@ -108,7 +165,7 @@ class Gui: items = self.canvas.find_all() while len(items) > 4: self.canvas.delete(items[-1]) - items = self.canvas.find_all() + items = self.canvas.find_all() def context_menu(self, event): self.team.posx, self.team.posy = event.x, event.y @@ -147,36 +204,34 @@ class Gui: def draw_team(self, *event): """dessine les actions de toute l'équipe""" self.clean_terrain() - with open(self.file, 'r') as f: - for line in f: - # forme type: joueur action points x y - params = line.strip().split(' ') - if params[1] == 'marque': - self.canvas.create_oval(int(params[3])-12, int(params[4])-12, int(params[3])+12, int(params[4])+12, fill='green') - else: - self.canvas.create_oval(int(params[3])-12, int(params[4])-12, int(params[3])+12, int(params[4])+12, fill='red') + for line in self.file.content[2:]: + # forme type: joueur action points x y + params = line.strip().split(' ') + if params[1] == 'marque': + self.canvas.create_oval(int(params[3])-12, int(params[4])-12, int(params[3])+12, int(params[4])+12, fill='green') + else: + self.canvas.create_oval(int(params[3])-12, int(params[4])-12, int(params[3])+12, int(params[4])+12, fill='red') def draw_player(self, player): """dessine les actions d'un joueur""" self.clean_terrain() - with open(self.file, 'r') as f: - for line in f: - # forme type: joueur action points x y - params = line.strip().split(' ') - if params[0] == player: # nom du joueur - if params[1] == 'marque': - self.canvas.create_oval(int(params[3])-12, int(params[4])-12, int(params[3])+12, int(params[4])+12, fill='green') - else: - self.canvas.create_oval(int(params[3])-12, int(params[4])-12, int(params[3])+12, int(params[4])+12, fill='red') + for line in self.file.content[2:]: + # forme type: joueur action points x y + params = line.strip().split(' ') + if params[0] == player: # nom du joueur + if params[1] == 'marque': + self.canvas.create_oval(int(params[3])-12, int(params[4])-12, int(params[3])+12, int(params[4])+12, fill='green') + else: + self.canvas.create_oval(int(params[3])-12, int(params[4])-12, int(params[3])+12, int(params[4])+12, fill='red') def draw_terrain(self): """dessinne les lignes du terrain""" # ligne des 3 points self.canvas.create_arc(-self.terrain.three_points, self.terrain.height//2 - self.terrain.three_points, self.terrain.three_points, self.terrain.height - (self.terrain.height//2 - self.terrain.three_points),width=3, start=90, extent=-180) self.canvas.create_arc(self.terrain.width-self.terrain.three_points, self.terrain.height//2 - self.terrain.three_points, self.terrain.width+self.terrain.three_points, self.terrain.height - (self.terrain.height//2 - self.terrain.three_points),width=3, start=90, extent=180) - + # ligne centrale - + self.canvas.create_line(self.terrain.width//2, 0, self.terrain.width//2, self.terrain.height, width=3) # cercle du milieu @@ -184,12 +239,3 @@ class Gui: gui = Gui() -gui.draw_terrain() - -gui.root.bind("", gui.context_menu) -gui.root.bind("", gui.save) -gui.root.bind("", gui.browse_open) -gui.root.bind("", gui.new) -gui.root.bind("", gui.draw_team) - -gui.root.mainloop() diff --git a/stat.bbm b/stat.bbm index fce5453..1581c9c 100644 --- a/stat.bbm +++ b/stat.bbm @@ -1,3 +1,5 @@ +arthur jl léandre louis alex + arthur rate 3 449 301 léandre marque 2 186 323 arthur marque 2 963 332