def get_value_4(Window, entry1, entry2, entry3, entry4, protocole,
                ProtoWindow):
    """
    This program gets 4 values from a label.
    
    Entry:
        Window(Frame): the protocol window
        entry1(Label variable): the first value to get
        entry2(Label variable): the second value to get
        entry3(Label variable): the third value to get
        entry4(Label variable): the fourth value to get
        protocole(list): the list of the protocole
        ProtoWindow(Frame): the protocol frame
    """
    pos = protocole.index(['position'])
    protocole[pos - 1] = [
        protocole[pos - 1][0],
        entry1.get(),
        entry2.get(),
        entry3.get(),
        entry4.get()
    ]
    Prot.EcrireProtocoleFichier(protocole, 'temp.txt')
    Prot.AfficherProtocol(ProtoWindow, protocole)
    Window.destroy()
def get_values_matrix(Window, x, y, temp_file, ProtoWindow):
    """
    This program gets 2 positions from a matrix of labels (it is called 2 times each to add one position).
    
    Entry:
        Window(Frame): the protocol window
        x: the first value to get
        y(Label variable): the second value to get
        temp_file(string): the name of the file
        ProtoWindow(Frame): the protocol frame
    """
    protocole = Prot.ReadProtocolFile(temp_file)
    pos = protocole.index(['position'])
    protocole[pos - 1] = protocole[pos - 1] + [x, y]
    Prot.EcrireProtocoleFichier(protocole, 'temp.txt')
    if len(protocole[pos - 1]) == 5:
        Prot.AfficherProtocol(ProtoWindow, protocole)
        Window.destroy()
def Delete(Window, ProtoWindow, temp_file):
    """
    This program adds the pipeting instruction.
    
    Entry:
        Window(Frame): the protocol window
        ProtoWindow(Frame): the protocol frame
        temp_file(string): the name of the file
    """
    protocole = Prot.ReadProtocolFile(temp_file)
    os.remove(temp_file)
    pos = protocole.index(['position'])
    if pos > 1:
        a = protocole[:pos - 1]
    else:
        a = []
    b = protocole[pos:]
    protocole = a + b
    Prot.EcrireProtocoleFichier(protocole, 'temp.txt')
    ProtoWindow = Prot.AfficherProtocol(ProtoWindow, protocole)
    return 1
def thaw(Window, ProtoWindow, temp_file):
    """
    This program adds the pipeting instruction.
    
    Entry:
        Window(Frame): the protocol window
        ProtoWindow(Frame): the protocol frame
        temp_file(string): the name of the file
    """
    protocole = Prot.ReadProtocolFile(temp_file)
    pos = protocole.index(['position'])
    a = protocole[:pos]
    if a == []:
        a = [['tha']]
    else:
        a = a + [['tha']]
    b = protocole[pos:]
    protocole = a + b
    Prot.EcrireProtocoleFichier(protocole, 'temp.txt')
    Prot.AfficherProtocol(ProtoWindow, protocole)
    return 1
def Save(Window, ProtoWindow, temp_file):
    """
    This program adds the pipeting instruction.
    
    Entry:
        Window(Frame): the protocol window
        ProtoWindow(Frame): the protocol frame
        temp_file(string): the name of the file
    """
    protocole = Prot.ReadProtocolFile(temp_file)
    os.remove(temp_file)
    pos = protocole.index(['position'])
    protocole = protocole[:pos] + protocole[pos + 1:]
    filename = asksaveasfile(title="Save the protocol as",
                             filetypes=[('txt files', '.txt'),
                                        ('all files', '.*')])
    filename = str(filename)
    filename = filename.split("'")
    filename = filename[1]
    Prot.EcrireProtocoleFichier(protocole, filename)
    Window.destroy()
    return 1
def PosUp(Window, ProtoWindow, temp_file):
    """
    This program adds the pipeting instruction.
    
    Entry:
        Window(Frame): the protocol window
        ProtoWindow(Frame): the protocol frame
        temp_file(string): the name of the file
    """
    protocole = Prot.ReadProtocolFile(temp_file)
    pos = protocole.index(['position'])
    sze = len(protocole)
    a = protocole[:pos - 1]
    b = [protocole[pos - 1]]
    if pos < sze:
        c = protocole[pos + 1:]
    else:
        c = []
    protocole = a + [['position']] + b + c
    Prot.EcrireProtocoleFichier(protocole, 'temp.txt')
    Prot.AfficherProtocol(ProtoWindow, protocole)
    return 1
def move(Window, ProtoWindow, temp_file):
    """
    This program adds the pipeting instruction.
    
    Entry:
        Window(Frame): the protocol window
        ProtoWindow(Frame): the protocol frame
        temp_file(string): the name of the file
    """
    protocole = Prot.ReadProtocolFile(temp_file)
    pos = protocole.index(['position'])
    a = protocole[:pos]
    if a == []:
        a = [['mov']]
    else:
        a = a + [['mov']]
    b = protocole[pos:]
    Prot.EcrireProtocoleFichier(a + b, 'temp.txt')
    #Create the new window
    Window_option = Toplevel(Window)
    Window_option.title('Neurodrop - Movement calibration')
    #Create the heading of the new window
    Heading = Create_Heading(Window_option)
    #Create the button matrix to choose the displacement

    canvas = Canvas(Window_option, width=750, height=600)
    scroll_y = Scrollbar(Window_option,
                         orient="vertical",
                         command=canvas.yview)

    Matrix = Create_Frame(canvas,
                          border_thickness=0,
                          style_border='solid',
                          back_colour=sty.Bkg_frm_blue,
                          col=1,
                          line=2,
                          nblines=6,
                          nbcolumns=8,
                          form='wens')
    fichier = open('list_pad.csv', 'r')
    lines = fichier.readlines()
    fichier.close()
    for i in range(len(lines)):
        lines[i] = lines[i].replace('\n', "")
        lines[i] = lines[i].split(';')
        #lines[i][-1]=lines[i][-1][:-1] #We get rid of the jumpline symbols
    lines[0][0] = lines[0][0][1:]
    for l in range(len(lines)):
        lin = l
        for col in range(len(lines[l])):
            if (lines[l][col] != '0'):
                Create_button(Matrix,
                              '',
                              partial(get_values_matrix, Window_option, l, col,
                                      temp_file, ProtoWindow),
                              color='#000000',
                              activefg='#318ce7',
                              Width=2,
                              Height=1,
                              Police='Arial 10',
                              col=1 + col,
                              line=3 + l,
                              form='wens',
                              nblines=1,
                              pady=0)

    Create_text(Matrix,
                'Select the departure and the arriving pads',
                color=sty.Clr_txt_frames,
                Police=sty.Font_frames_title,
                back_colour=sty.Bkg_frm_blue,
                col=1,
                line=1,
                form='wens',
                nbcolumns=col + 1,
                nblines=1)
    Create_text(Matrix,
                'END',
                color=sty.Bkg_frm_blue,
                Police=sty.Font_frames_title,
                back_colour=sty.Bkg_frm_blue,
                col=1,
                line=lin + 5,
                form='wens',
                nbcolumns=col,
                nblines=1)
    canvas.create_window(0, 0, anchor='nw', window=Matrix)
    canvas.update_idletasks()

    canvas.configure(scrollregion=canvas.bbox('all'),
                     yscrollcommand=scroll_y.set)

    canvas.grid(row=2, column=1, rowspan=6, columnspan=7, sticky='wens')
    scroll_y.grid(row=2, column=8, rowspan=6, columnspan=1, sticky='ns')

    #Configure the window
    W = [Window_option, Window_option, Heading, Matrix, Matrix]
    Lines = [[0, 2, 3, 4, 5, 6, 7, 8], [1, 9], [0], [0, 2, lin + 5],
             [1] + [i for i in range(3, lin + 4)]]
    Columns = [[1, 2, 3, 4, 5, 6, 7, 8], [0, 9], [0, 1, 2, 3, 4, 5, 6, 7],
               [1] + [i for i in range(2, col + 2)], [0, col + 2]]
    WC = [0, 1, 1, 1, 0, 1, 0]
    WL = [0, 1, 0, 1, 0, 1, 0]
    for i in range(len(W)):
        Auto_configure(W[i],
                       lines=Lines[i],
                       columns=Columns[i],
                       min_size_col=10,
                       min_size_row=10,
                       weight_col=WC[i],
                       weight_row=WL[i])
def move(Window, ProtoWindow, temp_file):
    """
    This program adds the pipeting instruction.
    
    Entry:
        Window(Frame): the protocol window
        ProtoWindow(Frame): the protocol frame
        temp_file(string): the name of the file
    """
    protocole = Prot.ReadProtocolFile(temp_file)
    pos = protocole.index(['position'])
    a = protocole[:pos]
    if a == []:
        a = [['mov']]
    else:
        a = a + [['mov']]
    b = protocole[pos:]
    Prot.EcrireProtocoleFichier(a + b, 'temp.txt')
    #Create the new window
    Window_option = Toplevel(Window)
    Window_option.title('Neurodrop - Movement calibration')
    #Create the heading of the new window
    Heading = Create_Heading(Window_option)
    #Create the button matrix to choose the displacement
    Matrix = Create_Frame(Window_option,
                          border_thickness=5,
                          style_border='groove',
                          back_colour=Bkg_frm_blue,
                          col=1,
                          line=2,
                          nblines=7,
                          nbcolumns=8,
                          form='wens')
    Pds_per_line = [10, 10, 10, 10, 10, 10, 10, 10]
    Create_text(Matrix,
                'Select the departure and the arriving pads',
                color=Clr_txt_frames,
                Police=Font_frames_title,
                back_colour=Bkg_frm_blue,
                col=1,
                line=1,
                form='wens',
                nbcolumns=max(Pds_per_line),
                nblines=1)
    for k in range(len(Pds_per_line)):
        for nb in range(Pds_per_line[k]):
            for i in range(nb):
                Create_button(Matrix,
                              '',
                              partial(get_values_matrix, Window_option, i, k,
                                      temp_file, ProtoWindow),
                              color='#000000',
                              activefg='#318ce7',
                              Width=1,
                              Height=1,
                              Police='Arial 20',
                              col=1 + i,
                              line=3 + k,
                              form='wens',
                              nblines=1)

    #Configure the window
    W = [Window_option, Window_option, Heading, Matrix, Matrix]
    Lines = [[0, 2, 3, 4, 5, 6, 7, 8], [1, 9], [0], [0, 2, 4], [1, 3],
             [0, 2, len(Pds_per_line)],
             [1] + [i for i in range(3, 2 + len(Pds_per_line))]]
    Columns = [[1, 2, 3, 4, 5, 6, 7, 8], [0, 9], [0, 1, 2, 3, 4, 5, 6, 7],
               [0, 4], [1] + [i for i in range(max(Pds_per_line))],
               [0, max(Pds_per_line)]]
    WC = [0, 1, 1, 1, 0, 1, 0]
    WL = [0, 1, 0, 1, 0, 1, 0]
    for i in range(len(W)):
        Auto_configure(W[i],
                       lines=Lines[i],
                       columns=Columns[i],
                       min_size_col=10,
                       min_size_row=10,
                       weight_col=WC[i],
                       weight_row=WL[i])