Browse Source

ca marche a peu près

master
BARRAUX Arthur 3 years ago
parent
commit
80f3dfdd02
  1. 48
      main.py
  2. 3
      stat.bbm

48
main.py

@ -27,6 +27,7 @@ class File:
with open(self.name, 'a') as f: with open(self.name, 'a') as f:
f.write(self.temp_data) f.write(self.temp_data)
self.temp_data = '' self.temp_data = ''
self.read_file()
def read_file(self): def read_file(self):
with open(self.name, 'r') as f: with open(self.name, 'r') as f:
@ -36,8 +37,8 @@ class File:
class Gui: class Gui:
def __init__(self): def __init__(self):
self.terrain = Terrain() self.terrain = Terrain()
self.team = 0 self.team = None
self.mode = 0 self.mode = None
self.root = tkinter.Tk() self.root = tkinter.Tk()
self.root.title('BasketBall Analitycs®') self.root.title('BasketBall Analitycs®')
self.canvas = tkinter.Canvas(self.root, width=self.terrain.width, height=self.terrain.height, background='#bbb') 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) self.root.config(menu=self.menubar)
if self.mode != 0:
print('here')
self.root.bind('<Button-2>', self.context_menu)
self.root.bind("<Control-o>", self.browse_open) self.root.bind("<Control-o>", self.browse_open)
self.root.bind("<Control-n>", self.new) self.root.bind("<Control-n>", self.new)
self.root.bind("<Control-s>", self.save)
self.canvas.bind("<Button-1>", self.context_menu)
self.root.mainloop() self.root.mainloop()
@ -101,11 +102,13 @@ class Gui:
def save(self, *event): def save(self, *event):
# sauvegarde du fichier # sauvegarde du fichier
if self.file.name == 'untitled.bbm': if self.menu != None:
path = tkinter.filedialog.asksaveasfilename(initialdir = "~", title = "Select a File", filetypes = (("BasketBall Match", "*.bbm"), ("all files", "*.*"))) if self.file.name == 'untitled.bbm':
if len(path) != 0: path = tkinter.filedialog.asksaveasfilename(initialdir = "~", title = "Select a File", filetypes = (("BasketBall Match", "*.bbm"), ("all files", "*.*")))
self.file.name = path if len(path) != 0:
self.root.title(self.file.name) self.file.name = path
self.file.write_data()
self.root.title(self.file.name)
def browse_open(self, *event): def browse_open(self, *event):
# ouvre un fichier # 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.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_cascade(label="player", menu=self.statsubmenu)
self.statmenu.add_command(label='team', command=self.draw_team) 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 # menu contextuel des actions
self.action = tkinter.Menu(self.root, tearoff=0) self.action = tkinter.Menu(self.root, tearoff=0)
self.action.add_command(label='marque', command=lambda: self.action_menu('marque')) 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[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.menu.add_command(label=self.team.players[4], command=lambda: self.show_sub_menu(self.team.players[4]))
self.root.bind('<Button-2>', self.contextmenu) self.bind_click = "<Button-1>"
self.bind_ctrl_s = "<Control-s>"
def changemode(self, newmode): def changemode(self, newmode):
if self.mode != newmode: if self.mode != newmode:
if newmode == 'stat': if newmode == 'stat':
self.menubar.add_cascade(label='stat', menu=self.statmenu) self.menubar.add_cascade(label='stat', menu=self.statmenu)
self.menubar.add_cascade(label='actions', menu=self.actionmenu)
else: else:
self.menubar.delete(3) self.menubar.delete(3)
self.mode = newmode self.mode = newmode
@ -168,10 +177,11 @@ class Gui:
items = self.canvas.find_all() items = self.canvas.find_all()
def context_menu(self, event): def context_menu(self, event):
self.team.posx, self.team.posy = event.x, event.y if self.mode == "match":
self.coo = [event.x_root, event.y_root] self.team.posx, self.team.posy = event.x, event.y
self.menu.tk_popup(event.x_root, event.y_root) self.coo = [event.x_root, event.y_root]
self.menu.grab_release() self.menu.tk_popup(event.x_root, event.y_root)
self.menu.grab_release()
def show_sub_menu(self, player): def show_sub_menu(self, player):
self.team.ac_player = 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') self.canvas.create_oval(self.team.posx-12, self.team.posy-12, self.team.posx+12, self.team.posy+12, fill='green')
else: else:
self.canvas.create_oval(self.team.posx-12, self.team.posy-12, self.team.posx+12, self.team.posy+12, fill='red') 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 == '': if self.file.temp_data == '':
self.root.title(self.file+' *') self.root.title(self.file.name+' *')
self.temp_data += self.team.ac_player+' '+action+' '+str(score)+' '+str(self.team.posx)+' '+str(self.team.posy)+'\n' self.file.temp_data += self.team.ac_player+' '+action+' '+str(score)+' '+str(self.team.posx)+' '+str(self.team.posy)+'\n'
def clean_terrain(self): def clean_terrain(self):
"""Nettoie le terrain""" """Nettoie le terrain"""

3
stat.bbm

@ -10,3 +10,6 @@ alex marque 3 393 274
arthur rate 3 359 210 arthur rate 3 359 210
arthur marque 3 416 212 arthur marque 3 416 212
jl rate 3 448 234 jl rate 3 448 234
alex rate 2 172 357
alex marque 3 269 292
louis marque 2 1043 277

Loading…
Cancel
Save