Browse Source

que de nouveautés

master
BARRAUX Arthur 3 years ago
parent
commit
1bcaa0180b
  1. 146
      main.py
  2. 2
      stat.bbm

146
main.py

@ -11,38 +11,118 @@ class Terrain:
class Team: class Team:
def __init__(self): def __init__(self, players):
self.players = ['arthur', 'jl', 'léandre', "louis", "alex"] self.players = players
self.filemenu = 'stat.txt'
self.posx, self.posy = 0,0 # coo de la dernière action self.posx, self.posy = 0,0 # coo de la dernière action
self.ac_player = 0 # dernier joueur 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: class Gui:
def __init__(self, ): def __init__(self):
self.terrain = Terrain() self.terrain = Terrain()
self.team = Team() self.team = 0
self.mode = 'match' self.mode = 0
self.file = 'untitled.bbm'
self.temp_data = ''
self.list_button_menu = []
self.root = tkinter.Tk() 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 = 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 # file menu
self.menubar = tkinter.Menu(self.root) self.menubar = tkinter.Menu(self.root)
self.filemenu = tkinter.Menu(self.menubar, tearoff=0) self.filemenu = tkinter.Menu(self.menubar, tearoff=0)
self.filemenu.add_command(label="new", command=self.new) self.filemenu.add_command(label="new", command=self.new)
self.filemenu.add_command(label="open", command=self.browse_open) 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_separator()
self.filemenu.add_command(label="rename")
self.filemenu.add_command(label="exit", command=self.root.quit) self.filemenu.add_command(label="exit", command=self.root.quit)
self.menubar.add_cascade(label="file", menu=self.filemenu) 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('<Button-2>', self.context_menu)
self.root.bind("<Control-o>", self.browse_open)
self.root.bind("<Control-n>", 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 # mode menu
self.modemenu = tkinter.Menu(self.menubar, tearoff=0) self.modemenu = tkinter.Menu(self.menubar, tearoff=0)
self.modemenu.add_command(label="stat", command=lambda: self.changemode('stat')) 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.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)
# topbar
self.root.config(menu=self.menubar)
# 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'))
@ -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[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]))
def new(self, *event): self.root.bind('<Button-2>', self.contextmenu)
# 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)
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): def changemode(self, newmode):
print(self.mode, 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)
@ -147,8 +204,7 @@ class Gui:
def draw_team(self, *event): def draw_team(self, *event):
"""dessine les actions de toute l'équipe""" """dessine les actions de toute l'équipe"""
self.clean_terrain() self.clean_terrain()
with open(self.file, 'r') as f: for line in self.file.content[2:]:
for line in f:
# forme type: joueur action points x y # forme type: joueur action points x y
params = line.strip().split(' ') params = line.strip().split(' ')
if params[1] == 'marque': if params[1] == 'marque':
@ -159,8 +215,7 @@ class Gui:
def draw_player(self, player): def draw_player(self, player):
"""dessine les actions d'un joueur""" """dessine les actions d'un joueur"""
self.clean_terrain() self.clean_terrain()
with open(self.file, 'r') as f: for line in self.file.content[2:]:
for line in f:
# forme type: joueur action points x y # forme type: joueur action points x y
params = line.strip().split(' ') params = line.strip().split(' ')
if params[0] == player: # nom du joueur if params[0] == player: # nom du joueur
@ -184,12 +239,3 @@ class Gui:
gui = Gui() gui = Gui()
gui.draw_terrain()
gui.root.bind("<Button-1>", gui.context_menu)
gui.root.bind("<Control-s>", gui.save)
gui.root.bind("<Control-o>", gui.browse_open)
gui.root.bind("<Control-n>", gui.new)
gui.root.bind("<a>", gui.draw_team)
gui.root.mainloop()

2
stat.bbm

@ -1,3 +1,5 @@
arthur jl léandre louis alex
arthur rate 3 449 301 arthur rate 3 449 301
léandre marque 2 186 323 léandre marque 2 186 323
arthur marque 2 963 332 arthur marque 2 963 332

Loading…
Cancel
Save