# ==============================================================================
"""CHRONO : a user-controlled digital stopwatch"""
# ==============================================================================
__author__  = "Christophe Schlick modified by Philippe Blasi"
__version__ = "0.0" # skeleton version
__date__    = "2022-11-12"
# ==============================================================================
from ezTK import *
# ------------------------------------------------------------------------------
def main():
  """create the main window and pack the widgets"""
  global win
  font1, font2 = 'Arial 16', 'Times 120 bold'
  win = Win(title='CHRONO', font=font1, op=5)
  # ----------------------------------------------------------------------------
  # TODO (use 1 Frame, 2 Buttons, 1 Label)
  # ----------------------------------------------------------------------------
  frame = Frame(win, font=font1)
  Button(frame, text=('START','STOP'), command=on_start)
  Button(frame, text='RESET', command=on_reset)
  # ----------------------------------------------------------------------------
  # ajouter les 6 couleurs au label
  colors = ('#F00','#0F0','#00F','#0FF','#F0F','#FF0')
  
  Label(win, text=0, width=5,font=font2, border=2)
  # ----------------------------------------------------------------------------
  win.chrono = win[1] # set friendly names for all widgets used in callbacks
  win.start_stop = frame[0] # c'est le premier bouton de la frame
  win.loop()
# ------------------------------------------------------------------------------
def on_reset() -> None:
  """callback function for the 'RESET' button"""
  # TODO (reset counter value to 0)
  win.chrono['text'] = 0
# ------------------------------------------------------------------------------
def on_start() -> None:
  """callback function for the 'START/STOP' button"""
  # TODO (switch label for START/STOP button and call 'tick' to start counter)

  # pour changer le texte du bouton, il suffit de changer son etat de 0 à 1 ou
  # inversement  : win.start_stop.state

  # changer la valeur de win.start_stop.state 0 <--> 1
  win.start_stop.state = 1 - win.start_stop.state  # bascule entre 0 et 1

  # appel de la fonction tick
  tick()
# ------------------------------------------------------------------------------
def tick() -> None:
  """increment counter value and schedule next 'tick'"""
  # TODO (increment counter value and use 'win.after' for recursive call)
  # on fait quelque chose seulement quand le bonton est à l'état 0
  if win.start_stop.state == 1:
    # ajouter 1 au chrono : win.chrono['text']
    win.chrono['text']+=1

    # modifier l'état du label chrono toutes les 50 valeurs
    win.chrono.state ....
    
    # appeler la fonction tick après 10 milliseconde
    win.after(10, tick)
# ==============================================================================
if __name__ == '__main__':
  main()
# ==============================================================================




