@ -1,5 +1,6 @@
import tkinter
import tkinter
from tkinter import filedialog
from tkinter import filedialog
import os
class Terrain :
class Terrain :
def __init__ ( self ) :
def __init__ ( self ) :
@ -57,23 +58,27 @@ class Gui:
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 ) :
def new ( self , * event ) :
# créer un fichier vierge
self . file = ' untitled.bbm '
self . file = ' untitled.bbm '
self . root . title = self . file
self . root . title = self . file
def save ( self , * event ) :
def save ( self , * event ) :
if self . file != ' untitled.bbm ' and self . file != ' ' :
# 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 :
with open ( self . file , ' a ' ) as f :
f . writelines ( self . temp_data )
f . write ( self . temp_data )
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 )
self . root . title ( self . file )
def browse_open ( self , * event ) :
def browse_open ( self , * event ) :
print ( ' open ' )
# ouvre un fichier
self . file = tkinter . filedialog . askopenfilename ( initialdir = " ~ " , title = " Select a File " , filetypes = ( ( " BasketBall Match " , " *.bbm " ) , ( " all files " , " *.* " ) ) )
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 )
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
self . coo = [ event . x_root , event . y_root ]
self . coo = [ event . x_root , event . y_root ]
@ -95,8 +100,17 @@ 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 == ' ' :
self . root . title ( self . file + ' * ' )
self . temp_data + = self . team . ac_player + ' ' + action + ' ' + str ( score ) + ' ' + str ( self . team . posx ) + ' ' + str ( self . team . posy ) + ' \n '
self . temp_data + = self . team . ac_player + ' ' + action + ' ' + str ( score ) + ' ' + str ( self . team . posx ) + ' ' + str ( self . team . posy ) + ' \n '
def draw_actions ( self , * event ) :
# dessine l'entièreté des actions
items = self . canvas . find_all ( )
while len ( items ) > 4 :
self . canvas . delete ( items [ - 1 ] )
items = self . canvas . find_all ( )
def draw_terrain ( self ) :
def draw_terrain ( self ) :
# ligne des 3 points
# 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 . 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 )
@ -117,5 +131,6 @@ gui.root.bind("<Button-1>", gui.context_menu)
gui . root . bind ( " <Control-s> " , gui . save )
gui . root . bind ( " <Control-s> " , gui . save )
gui . root . bind ( " <Control-o> " , gui . browse_open )
gui . root . bind ( " <Control-o> " , gui . browse_open )
gui . root . bind ( " <Control-n> " , gui . new )
gui . root . bind ( " <Control-n> " , gui . new )
gui . root . bind ( " <a> " , gui . draw_actions )
gui . root . mainloop ( )
gui . root . mainloop ( )