From 80f3dfdd027c7a65971b4f67ba9fa4f171dc6252 Mon Sep 17 00:00:00 2001 From: "barraux.a" Date: Tue, 8 Feb 2022 13:51:28 +0100 Subject: [PATCH] =?UTF-8?q?ca=20marche=20a=20peu=20pr=C3=A8s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 48 +++++++++++++++++++++++++++++------------------- stat.bbm | 3 +++ 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/main.py b/main.py index 97f0d36..f95a747 100644 --- a/main.py +++ b/main.py @@ -27,6 +27,7 @@ class File: with open(self.name, 'a') as f: f.write(self.temp_data) self.temp_data = '' + self.read_file() def read_file(self): with open(self.name, 'r') as f: @@ -36,8 +37,8 @@ class File: class Gui: def __init__(self): self.terrain = Terrain() - self.team = 0 - self.mode = 0 + self.team = None + self.mode = None self.root = tkinter.Tk() self.root.title('BasketBall Analitycs®') self.canvas = tkinter.Canvas(self.root, width=self.terrain.width, height=self.terrain.height, background='#bbb') @@ -65,11 +66,11 @@ class Gui: 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.bind("", self.save) + self.canvas.bind("", self.context_menu) + self.root.mainloop() @@ -101,11 +102,13 @@ class Gui: 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) + if self.menu != None: + 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.file.write_data() + self.root.title(self.file.name) def browse_open(self, *event): # ouvre un fichier @@ -139,6 +142,11 @@ 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) + + # actions menubar + self.actionmenu = tkinter.Menu(self.menubar, tearoff=0) + self.actionmenu.add_checkbutton(0, label='tirs', background='red') + # menu contextuel des actions self.action = tkinter.Menu(self.root, tearoff=0) self.action.add_command(label='marque', command=lambda: self.action_menu('marque')) @@ -152,13 +160,14 @@ 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])) - self.root.bind('', self.contextmenu) - + self.bind_click = "" + self.bind_ctrl_s = "" def changemode(self, newmode): if self.mode != newmode: if newmode == 'stat': self.menubar.add_cascade(label='stat', menu=self.statmenu) + self.menubar.add_cascade(label='actions', menu=self.actionmenu) else: self.menubar.delete(3) self.mode = newmode @@ -168,10 +177,11 @@ class Gui: items = self.canvas.find_all() def context_menu(self, event): - self.team.posx, self.team.posy = event.x, event.y - self.coo = [event.x_root, event.y_root] - self.menu.tk_popup(event.x_root, event.y_root) - self.menu.grab_release() + if self.mode == "match": + self.team.posx, self.team.posy = event.x, event.y + self.coo = [event.x_root, event.y_root] + self.menu.tk_popup(event.x_root, event.y_root) + self.menu.grab_release() def show_sub_menu(self, player): self.team.ac_player = player @@ -190,9 +200,9 @@ class Gui: self.canvas.create_oval(self.team.posx-12, self.team.posy-12, self.team.posx+12, self.team.posy+12, fill='green') else: self.canvas.create_oval(self.team.posx-12, self.team.posy-12, self.team.posx+12, self.team.posy+12, fill='red') - if self.temp_data == '': - self.root.title(self.file+' *') - self.temp_data += self.team.ac_player+' '+action+' '+str(score)+' '+str(self.team.posx)+' '+str(self.team.posy)+'\n' + if self.file.temp_data == '': + self.root.title(self.file.name+' *') + self.file.temp_data += self.team.ac_player+' '+action+' '+str(score)+' '+str(self.team.posx)+' '+str(self.team.posy)+'\n' def clean_terrain(self): """Nettoie le terrain""" diff --git a/stat.bbm b/stat.bbm index 1581c9c..dd3a3ac 100644 --- a/stat.bbm +++ b/stat.bbm @@ -10,3 +10,6 @@ alex marque 3 393 274 arthur rate 3 359 210 arthur marque 3 416 212 jl rate 3 448 234 +alex rate 2 172 357 +alex marque 3 269 292 +louis marque 2 1043 277