# =============================================================================
"""CSV : display a csv file content in a tclTk window, allow modifications and
         saving"""
# ==============================================================================
__author__  = "Philippe Blasi"
__version__ = "1.0"
__date__    = "2023-05-02"
# ==============================================================================
from ezTK import *
from ezCLI import *
# ------------------------------------------------------------------------------
def main():
  """create the main window and pack the widgets"""
  global win
  win = Win(title='CSV FILE', grow=False, click=on_click)
  # ----------------------------------------------------------------------------
  # TODO 1 Frame with 2 Buttons, 1 Labels and 1 Entry
  #      2 empty Frames for later use to store the size and name of the file and
  #         to store the grid of Labels
  # ----------------------------------------------------------------------------
  win.matrix, win.grid = None, None  # store software parameters for later use
  win.row, win.col = 0,0
  win.loop()
# ------------------------------------------------------------------------------
def on_open() -> None:
  """callback for the "OPEN FILE" button"""
  # ----------------------------------------------------------------------------
  # TODO get the file name with a Dialog box and call grid_tcl
  # ----------------------------------------------------------------------------
# ------------------------------------------------------------------------------
def on_save() -> None:
  """callback for the "SAVE FILE" button"""
  # ----------------------------------------------------------------------------
  # TODO get the file name with a Dialog box
  #      transfert the grid of Label into the matrix and save it
  # ----------------------------------------------------------------------------
# ------------------------------------------------------------------------------
def on_click(widget:object, code:str, mods:str) -> None:
  """callback function for all mouse click events"""
  # ----------------------------------------------------------------------------
  # TODO check if click is on a cell
  #      memorize the coordinates and display them in the Label
  #      display the value of the cell into the Entry
  # ----------------------------------------------------------------------------
# ------------------------------------------------------------------------------
def on_entry() -> None:
  """callback function for the cell entry"""
  # ----------------------------------------------------------------------------
  # TODO change color and background of the cell if the entry value has changed
  #      change the value of the cell
  # ----------------------------------------------------------------------------
# ------------------------------------------------------------------------------
def grid_tcl(name:str) -> None:
  """create the grid within the main window and pack the widgets"""
  # ----------------------------------------------------------------------------
  # TODO read the file into a matrix (2D array)
  #      get matrix size and maximum cell width
  #      delete the olds frames
  #      create a new frame to store the size and name into labels
  #      create a new frame to store the new grid
  # ----------------------------------------------------------------------------
# ==============================================================================
if __name__ == '__main__':
  main()
# ==============================================================================
