Browse Source

système de fichier

master
BARRAUX Arthur 3 years ago
parent
commit
8372e0e2e2
  1. 49
      main.py
  2. 9
      stat.bbm

49
main.py

@ -1,4 +1,5 @@
import tkinter import tkinter
from tkinter import filedialog
class Terrain: class Terrain:
def __init__(self): def __init__(self):
@ -11,7 +12,7 @@ class Terrain:
class Team: class Team:
def __init__(self): def __init__(self):
self.players = ['arthur', 'jl', 'léandre', "louis", "alex"] self.players = ['arthur', 'jl', 'léandre', "louis", "alex"]
self.file = 'stat.txt' 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
@ -20,17 +21,32 @@ class Gui:
def __init__(self, ): def __init__(self, ):
self.terrain = Terrain() self.terrain = Terrain()
self.team = Team() self.team = Team()
self.file = 'untitled.bbm'
self.temp_data = ''
self.list_button_menu = [] self.list_button_menu = []
self.root = tkinter.Tk() self.root = tkinter.Tk()
self.root.title(self.file)
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.canvas.pack()
# topbar
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)
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'))
self.action.add_command(label='rate', command=lambda: self.action_menu('rate')) self.action.add_command(label='rate', command=lambda: self.action_menu('rate'))
# Menu contextuel des joueurs # Menu contextuel des joueurs
self.menu = tkinter.Menu(self.root, tearoff = 0) self.menu = tkinter.Menu(self.root, tearoff = 0)
@ -39,8 +55,24 @@ class Gui:
self.menu.add_command(label=self.team.players[2], command=lambda: self.show_sub_menu(self.team.players[2])) self.menu.add_command(label=self.team.players[2], command=lambda: self.show_sub_menu(self.team.players[2]))
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.file = 'untitled.bbm'
self.root.title = self.file
def save(self, *event):
if self.file != 'untitled.bbm' and self.file != '':
with open(self.file, 'a') as f:
f.writelines(self.temp_data)
self.temp_data = ''
else:
self.file = tkinter.filedialog.askopenfilename(initialdir = "~", title = "Select a File", filetypes = (("BasketBall Match", "*.bbm"), ("all files", "*.*")))
self.root.title(self.file)
def browse_open(self, *event):
print('open')
self.file = tkinter.filedialog.askopenfilename(initialdir = "~", title = "Select a File", filetypes = (("BasketBall Match", "*.bbm"), ("all files", "*.*")))
self.root.title(self.file)
def context_menu(self, event): def context_menu(self, event):
self.team.posx, self.team.posy = event.x, event.y self.team.posx, self.team.posy = event.x, event.y
@ -56,14 +88,14 @@ class Gui:
def action_menu(self, action): def action_menu(self, action):
# test si l'action est dans la liste des 3 points # test si l'action est dans la liste des 3 points
if ((self.team.posx-0)**2) + ((self.team.posy-self.terrain.height/2)**2) <= self.terrain.three_points**2 or ((self.team.posx-self.terrain.width)**2) + ((self.team.posy-self.terrain.height/2)**2) <= self.terrain.three_points**2: if ((self.team.posx-0)**2) + ((self.team.posy-self.terrain.height/2)**2) <= self.terrain.three_points**2 or ((self.team.posx-self.terrain.width)**2) + ((self.team.posy-self.terrain.height/2)**2) <= self.terrain.three_points**2:
print('dunk') score = 2
else:
score = 3
if action == 'marque': if action == 'marque':
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')
with open('stat.txt', 'a') as f: self.temp_data += self.team.ac_player+' '+action+' '+str(score)+' '+str(self.team.posx)+' '+str(self.team.posy)+'\n'
line = self.team.ac_player+' '+action+' '+str(self.team.posx)+' '+str(self.team.posy)+'\n'
f.write(line) # écriture de l'action dans le fichier
def draw_terrain(self): def draw_terrain(self):
# ligne des 3 points # ligne des 3 points
@ -82,5 +114,8 @@ gui = Gui()
gui.draw_terrain() gui.draw_terrain()
gui.root.bind("<Button-1>", gui.context_menu) 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.mainloop() gui.root.mainloop()

9
stat.bbm

@ -0,0 +1,9 @@
arthur rate 3 449 301
léandre marque 2 186 323
arthur marque 2 963 332
arthur rate 3 849 349
arthur marque 3 392 233
jl marque 2 186 283
alex marque 3 393 274
arthur rate 3 359 210
arthur marque 3 416 212
Loading…
Cancel
Save