@ -11,38 +11,118 @@ class Terrain:
class Team :
def __init__ ( self ) :
self . players = [ ' arthur ' , ' jl ' , ' léandre ' , " louis " , " alex " ]
self . filemenu = ' stat.txt '
def __init__ ( self , players ) :
self . players = players
self . posx , self . posy = 0 , 0 # coo de la dernière action
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 :
def __init__ ( self , ) :
def __init__ ( self ) :
self . terrain = Terrain ( )
self . team = Team ( )
self . mode = ' match '
self . file = ' untitled.bbm '
self . temp_data = ' '
self . list_button_menu = [ ]
self . team = 0
self . mode = 0
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 . 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
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 )
# 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
self . modemenu = tkinter . Menu ( self . menubar , tearoff = 0 )
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 . statmenu . add_cascade ( label = " player " , menu = self . statsubmenu )
self . statmenu . add_command ( label = ' team ' , command = self . draw_team )
# topbar
self . root . config ( menu = self . menubar )
# menu contextuel des actions
self . action = tkinter . Menu ( self . root , tearoff = 0 )
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 [ 4 ] , command = lambda : self . show_sub_menu ( self . team . players [ 4 ] ) )
def new ( self , * event ) :
# 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 )
self . root . bind ( ' <Button-2> ' , self . contextmenu )
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 ) :
print ( self . mode , newmode )
if self . mode != newmode :
if newmode == ' stat ' :
self . menubar . add_cascade ( label = ' stat ' , menu = self . statmenu )
@ -147,27 +204,25 @@ class Gui:
def draw_team ( self , * event ) :
""" dessine les actions de toute l ' équipe """
self . clean_terrain ( )
with open ( self . file , ' r ' ) as f :
for line in f :
# forme type: joueur action points x y
params = line . strip ( ) . split ( ' ' )
if params [ 1 ] == ' marque ' :
self . canvas . create_oval ( int ( params [ 3 ] ) - 12 , int ( params [ 4 ] ) - 12 , int ( params [ 3 ] ) + 12 , int ( params [ 4 ] ) + 12 , fill = ' green ' )
else :
self . canvas . create_oval ( int ( params [ 3 ] ) - 12 , int ( params [ 4 ] ) - 12 , int ( params [ 3 ] ) + 12 , int ( params [ 4 ] ) + 12 , fill = ' red ' )
for line in self . file . content [ 2 : ] :
# forme type: joueur action points x y
params = line . strip ( ) . split ( ' ' )
if params [ 1 ] == ' marque ' :
self . canvas . create_oval ( int ( params [ 3 ] ) - 12 , int ( params [ 4 ] ) - 12 , int ( params [ 3 ] ) + 12 , int ( params [ 4 ] ) + 12 , fill = ' green ' )
else :
self . canvas . create_oval ( int ( params [ 3 ] ) - 12 , int ( params [ 4 ] ) - 12 , int ( params [ 3 ] ) + 12 , int ( params [ 4 ] ) + 12 , fill = ' red ' )
def draw_player ( self , player ) :
""" dessine les actions d ' un joueur """
self . clean_terrain ( )
with open ( self . file , ' r ' ) as f :
for line in f :
# forme type: joueur action points x y
params = line . strip ( ) . split ( ' ' )
if params [ 0 ] == player : # nom du joueur
if params [ 1 ] == ' marque ' :
self . canvas . create_oval ( int ( params [ 3 ] ) - 12 , int ( params [ 4 ] ) - 12 , int ( params [ 3 ] ) + 12 , int ( params [ 4 ] ) + 12 , fill = ' green ' )
else :
self . canvas . create_oval ( int ( params [ 3 ] ) - 12 , int ( params [ 4 ] ) - 12 , int ( params [ 3 ] ) + 12 , int ( params [ 4 ] ) + 12 , fill = ' red ' )
for line in self . file . content [ 2 : ] :
# forme type: joueur action points x y
params = line . strip ( ) . split ( ' ' )
if params [ 0 ] == player : # nom du joueur
if params [ 1 ] == ' marque ' :
self . canvas . create_oval ( int ( params [ 3 ] ) - 12 , int ( params [ 4 ] ) - 12 , int ( params [ 3 ] ) + 12 , int ( params [ 4 ] ) + 12 , fill = ' green ' )
else :
self . canvas . create_oval ( int ( params [ 3 ] ) - 12 , int ( params [ 4 ] ) - 12 , int ( params [ 3 ] ) + 12 , int ( params [ 4 ] ) + 12 , fill = ' red ' )
def draw_terrain ( self ) :
""" dessinne les lignes du terrain """
@ -184,12 +239,3 @@ class 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 ( )