#! /usr/bin/env python
#  -*- coding: latin-1 -*-
#
# GUI module generated by PAGE version 4.17
# In conjunction with Tcl version 8.6
#    Sep 20, 2018 12:17:44 PM EDT  platform: Windows NT
'''
Auteur : Hugo
'''

import sys
from AllTools import run
import numpy as np
import matplotlib.pyplot as plt
from init import *
from fct_MCRLLM import HyperspectralSegmentation_MCR_LLM
from fct_MCRALS import HyperspectralSegmentation_MCR_ALS
from fct_NMF import HyperspectralSegmentation_NMF
from SI_File_Toolbox import loadFile
import pcaselect
from h_MCR_LLM_Python import h_MCR_LLM
from PointSelector import SelectFromCollection

from tkinter.filedialog import *
import webbrowser

try:
    from Tkinter import *
except ImportError:
    from tkinter import *

try:
    import ttk
    py3 = False
except ImportError:
    import tkinter.ttk as ttk
    py3 = True
    
    
try:
    import IPython
    shell = IPython.get_ipython()
    shell.enable_matplotlib(gui='qt')
except:
    pass

class Action:
    def __init__(self, nom, typ, fonction, trigger = 0):
        self.nom = nom
        self.typ = typ
        self.do = fonction
        self.trigger = trigger

def set_Tk_var():
    
    
    global nb_level
    nb_level = IntVar()
    nb_level.set(0)
    
    
    global nb_imcr
    nb_imcr = IntVar()
    nb_imcr.set(1)
    global min_pixels
    min_pixels = IntVar()
    min_pixels.set(1)
    global max_pixels
    max_pixels = IntVar()
    max_pixels.set(40)
    global Max_level
    Max_level = IntVar()
    Max_level.set(50)
    global hier
    hier = IntVar()
    
    
    global KMeansT
    KMeansT = IntVar()
    global NFindrT
    NFindrT = IntVar()
    global MBKmeansT
    MBKmeansT = IntVar()
    global AtgpT
    AtgpT = IntVar()
    global FippiT
    FippiT = IntVar()
    global PpiT
    PpiT = IntVar()
    
    global LlmT
    LlmT = IntVar()
    global AlsT
    AlsT = IntVar()
    global NmfT
    NmfT= IntVar() 
    
    global nb_i
    nb_i = IntVar()
    nb_i.set(5)
    global nb_c
    nb_c = IntVar()
    nb_c.set(5)
    global nb_dim
    nb_dim = IntVar()
    nb_dim.set(3)
    
    global DimT
    DimT = IntVar()
    DimT.set(1)
    global dim1
    dim1 = IntVar()
    dim1.set(50)
    global dim2
    dim2= IntVar()
    dim2.set(50)
    global zDim
    zDim = IntVar()
    zDim.set(0)
    
    
    global filepath
    filepath = "Aucun fichier selectionné"

def init(top, gui, *args, **kwargs):
    global w, top_level, root
    w = gui
    top_level = top
    root = top

def destroy_window():
    # Function which closes the window.
    global top_level
    top_level.destroy()
    top_level = None

def vp_start_gui():
    '''Starting point when module is the main routine.'''
    global val, w, root
    root = Tk()
    set_Tk_var()
    top = New_Toplevel (root)
    init(root, top)
    root.mainloop()

w = None
def create_New_Toplevel(root, *args, **kwargs):
    '''Starting point when module is imported by another program.'''
    global w, w_win, rt
    rt = root
    w = Toplevel (root)
    set_Tk_var()
    top = New_Toplevel (w)
    init(w, top, *args, **kwargs)
    return (w, top)

def destroy_New_Toplevel():
    global w
    w.destroy()
    w = None




class New_Toplevel: 
    
    def returnValues():##Start the runs        
        
        
        
        LlmA = Action("MCR-LLM", "fct", HyperspectralSegmentation_MCR_LLM.mcr_llm, LlmT.get())
        AlsA = Action("MCR-ALS", "fct", HyperspectralSegmentation_MCR_ALS.mcr_als, AlsT.get())
        NmfA = Action("NMF", "fct", HyperspectralSegmentation_NMF.nmf, NmfT.get())
        fctList = list()
        fctList.append(LlmA)
        fctList.append(AlsA)
        fctList.append(NmfA)
        
        
        KMeansA = Action("Kmeans", "init", KmeansInit.initialisation, KMeansT.get())
        NFindrA = Action("Nfindr", "init", NFindrInit.initialisation, NFindrT.get())
        MBKmeansA = Action("MBKmeans", "init", MBKmeansInit.initialisation, MBKmeansT.get())
        AtgpA = Action("ATGP", "init", AtgpInit.initialisation, AtgpT.get())
        FippiA = Action("FIPPI", "init", FippiInit.initialisation, FippiT.get())
        PpiA = Action("PPI", "init", PpiInit.initialisation, PpiT.get())
        
        initList = list()
        initList.append(KMeansA)
        initList.append(NFindrA)
        initList.append(MBKmeansA)
        initList.append(AtgpA)
        initList.append(FippiA)
        initList.append(PpiA)
              
        dim = list()
        
         
        if DimT.get():
            print("Redim²")
            dim.append(dim1.get())
            dim.append(dim2.get())
            dim.append(nb_level.get())
            
            
        else:
            dim.append(0)
            dim.append(0)
            dim.append(0)
    
            
            
        
        run(initList, fctList, nb_c.get(), nb_i.get(), filepath, nb_dim.get(), hier.get())
        
    def plotRaw():
        
        x = loadFile(filepath)
        plt.figure()
        dim = nb_dim.get()
        if dim == 3:
            plt.title('Intensity Map')
            plt.imshow(np.log(np.sum(x, axis = 2)))
            plt.show()
            
            plt.figure()
            plt.title('Average Spectra')
            plt.plot(np.sum(np.sum(x,axis = 0), axis = 0))
            plt.show()
            
        elif dim ==2:
            plt.title('Intensity Line')
            plt.plot(np.sum(x, axis = 1))
            plt.show()
            
            plt.figure()
            plt.title('Average Spectra')
            plt.plot(np.sum(x,axis = 0))
            plt.show()
            
            
    def runHier():
        X3 = loadFile(filepath)
        if nb_dim.get() == 3:
            dim1 = X3.shape[0]
            dim2 = X3.shape[1]
            nb_level.set(X3.shape[2])
            nb_pix = dim1*dim2
            
            
        elif nb_dim.get() == 2:
            nb_level.set(X3.shape[1])
            nb_pix = X3.shape[0]


        Xraw = np.reshape(X3, (nb_pix, nb_level.get()))
        
        #avoid errors, if a energy level has 0 counts on all pixels, it causes log(0) and the level is meaningless, so we take it out
        deletedLevels = []
        nb_deleted = 0
        
        for lev in range(nb_level.get()):
            
            if np.sum(Xraw[:,lev-nb_deleted]) <= 0:
                
                deletedLevels.append(lev)
                Xraw = np.delete(Xraw, lev-nb_deleted, axis = 1)
                nb_deleted = nb_deleted + 1
        
        S_hier = h_MCR_LLM.h_mcr_llm( nb_imcr.get(), min_pixels.get(), max_pixels.get(), Max_level.get(), Xraw)
        
        
        for ii in range(nb_deleted):  #Insert deleted spectra back (the spectra was 0 that's why we took it out)
            S_hier = np.insert(S_hier,deletedLevels[ii], np.zeros(nb_c), axis = 1)
        np.save('S_hier.npy', S_hier)
        
        

        pcaselect.computeShow(np.array(S_hier), nb_c.get())
            
        
    def chooseSpectra():
        
        S_hier = np.load('S_hier.npy')
        
        global Sselect
        Sselect = pcaselect.computeSelect(np.array(S_hier), nb_c.get())
            
        
    def saveSpectra():
        Si = []
        
        for i in range(nb_c.get()): 
            Si.append(Sselect[i].selectedSpectra)
        
        Si = np.array(Si)
        np.save('Sselect.npy', Si)
            
    
    def selectFile():
        global filepath
        filepath = askopenfilename(title="Ouvrir un jeu de données",filetypes=[('npy files','.npy'),('dm4 files','.dm4'),('txt files','.txt'),('all files','.*')])
    
    def linkKmeans(self):
        webbrowser.open_new(r"https://www.datascience.com/blog/k-means-clustering")
        
    def linkMBKmeans(self):
        webbrowser.open_new(r"http://scikit-learn.org/stable/modules/clustering.html#mini-batch-kmeans")
                            
    def linkNFindr(self):
        webbrowser.open_new(r"https://ieeexplore.ieee.org/abstract/document/5560827") 
    
    def linkAtgp(self):
        webbrowser.open_new(r"https://ieeexplore.ieee.org/document/6947261") 
        
    def linkFippi(self):
        webbrowser.open_new(r"https://ieeexplore.ieee.org/document/1576691")
    
    def linkPpi(self):
        webbrowser.open_new(r"https://ieeexplore.ieee.org/document/1576691")
    
    def __init__(self, top=None):
        '''This class configures and populates the toplevel window.
           top is the toplevel containing window.'''
        _bgcolor = '#d9d9d9'  # X11 color: 'gray85'
        _fgcolor = '#000000'  # X11 color: 'black'
        _compcolor = '#d9d9d9' # X11 color: 'gray85'
        _ana1color = '#d9d9d9' # X11 color: 'gray85' 
        _ana2color = '#d9d9d9' # X11 color: 'gray85' 
        font10 = "-family {Book Antiqua} -size 14 -weight bold -slant "  \
            "roman -underline 0 -overstrike 0"
        font9 = "-family {Book Antiqua} -size 11 -weight normal -slant"  \
            " roman -underline 0 -overstrike 0"

        top.geometry("695x560+662+164")
        top.title("GUI - Hugo")
        top.configure(background="#d9d9d9")
        top.configure(height="2")
        top.configure(highlightbackground="#d9d9d9")
        top.configure(highlightcolor="black")



        self.menubar = Menu(top,font="TkMenuFont",bg=_bgcolor,fg=_fgcolor)
        top.configure(menu = self.menubar)

        #%% File box
        self.Frame2 = Frame(top)
        self.Frame2.place(relx=0.03, rely=0.03, relheight=0.3, relwidth=0.935)
        self.Frame2.configure(relief=GROOVE)
        self.Frame2.configure(borderwidth="2")
        self.Frame2.configure(relief=GROOVE)
        self.Frame2.configure(background="#ffffff")
        self.Frame2.configure(highlightbackground="#d9d9d9")
        self.Frame2.configure(highlightcolor="black")
        self.Frame2.configure(width=475)
        
        
        
        
        #Sélectionner fichier
        self.Label1_5 = Button(self.Frame2)
        self.Label1_5.place(relx=0.3, rely=0.00, height=31, width=260)
        self.Label1_5.configure(activebackground="#ffffff")
        self.Label1_5.configure(activeforeground="#ffffff")
        self.Label1_5.configure(background="#d9d9d9")
        self.Label1_5.configure(disabledforeground="#a3a3a3")
        self.Label1_5.configure(font=font10)
        self.Label1_5.configure(foreground="#000000")
        self.Label1_5.configure(highlightbackground="#d9d9d9")
        self.Label1_5.configure(highlightcolor="black")
        self.Label1_5.configure(text="Selectionner le fichier")
        self.Label1_5.configure(command = New_Toplevel.selectFile)
        
        
        # Composants
        self.Label1_5 = Label(self.Frame2)
        self.Label1_5.place(relx=0.0, rely=0.3, height=31, width=110)
        self.Label1_5.configure(activebackground="#ffffff")
        self.Label1_5.configure(activeforeground="#ffffff")
        self.Label1_5.configure(background="#ffffff")
        self.Label1_5.configure(disabledforeground="#a3a3a3")
        self.Label1_5.configure(font=font9)
        self.Label1_5.configure(foreground="#000000")
        self.Label1_5.configure(highlightbackground="#d9d9d9")
        self.Label1_5.configure(highlightcolor="black")
        self.Label1_5.configure(text="Composants")
        
        
        self.Spinbox1 = Spinbox(self.Frame2, from_=1.0, to=100.0)
        self.Spinbox1.place(relx=0.2, rely=0.3, relheight=0.15, relwidth=0.179)
        
        self.Spinbox1.configure(activebackground="#d9d9d9")
        self.Spinbox1.configure(background="#d9d9d9")
        self.Spinbox1.configure(buttonbackground="#d9d9d9")
        self.Spinbox1.configure(disabledforeground="#a3a3a3")
        self.Spinbox1.configure(foreground="black")
        self.Spinbox1.configure(from_="1.0")
        self.Spinbox1.configure(highlightbackground="black")
        self.Spinbox1.configure(highlightcolor="black")
        self.Spinbox1.configure(insertbackground="black")
        self.Spinbox1.configure(selectbackground="#c4c4c4")
        self.Spinbox1.configure(selectforeground="black")
        self.Spinbox1.configure(textvariable=nb_c)
        self.Spinbox1.configure(to="100.0")
        
        
        #Dimensions
        self.Label1_9 = Label(self.Frame2)
        self.Label1_9.place(relx=0.0, rely=0.57, height=31, width=110)
        self.Label1_9.configure(activebackground="#ffffff")
        self.Label1_9.configure(activeforeground="#ffffff")
        self.Label1_9.configure(background="#ffffff")
        self.Label1_9.configure(disabledforeground="#a3a3a3")
        self.Label1_9.configure(font=font9)
        self.Label1_9.configure(foreground="#000000")
        self.Label1_9.configure(highlightbackground="#d9d9d9")
        self.Label1_9.configure(highlightcolor="black")
        self.Label1_9.configure(text='''Dimensions''')
        
        
        self.Spinbox3 = Spinbox(self.Frame2, from_=2.0, to=3.0)
        self.Spinbox3.place(relx=0.2, rely=0.6, relheight=0.15, relwidth=0.179)
        
        self.Spinbox3.configure(activebackground="#d9d9d9")
        self.Spinbox3.configure(background="#d9d9d9")
        self.Spinbox3.configure(buttonbackground="#d9d9d9")
        self.Spinbox3.configure(disabledforeground="#a3a3a3")
        self.Spinbox3.configure(foreground="black")
        self.Spinbox3.configure(from_="2.0")
        self.Spinbox3.configure(highlightbackground="black")
        self.Spinbox3.configure(highlightcolor="black")
        self.Spinbox3.configure(insertbackground="black")
        self.Spinbox3.configure(selectbackground="#c4c4c4")
        self.Spinbox3.configure(selectforeground="black")
        self.Spinbox3.configure(textvariable=nb_dim)
        self.Spinbox3.configure(to="3.0")
        self.Spinbox3.configure(width=35)
        
        
        # Plot raw
        self.Button2 = Button(self.Frame2)
        self.Button2.place(relx=0.4, rely=0.4, height=34, width=117)
        self.Button2.configure(activebackground="#d9d9d9")
        self.Button2.configure(activeforeground="#000000")
        self.Button2.configure(background="#d9d9d9")
        self.Button2.configure(disabledforeground="#a3a3a3")
        self.Button2.configure(foreground="#000000")
        self.Button2.configure(highlightbackground="#d9d9d9")
        self.Button2.configure(highlightcolor="black")
        self.Button2.configure(pady="0")
        self.Button2.configure(text='''Plot Raw''')
        self.Button2.configure(width=117)
        self.Button2.configure(command = New_Toplevel.plotRaw)  
        
        
        
        
        
        
        
        #%% hier box
        self.Frame3 = Frame(top)
        self.Frame3.place(relx=0.03, rely=0.375, relheight=0.563, relwidth=0.3)
        self.Frame3.configure(relief=GROOVE)
        self.Frame3.configure(borderwidth="2")
        self.Frame3.configure(relief=GROOVE)
        self.Frame3.configure(background="#ffffff")
        self.Frame3.configure(highlightbackground="#d9d9d9")
        self.Frame3.configure(highlightcolor="black")
        self.Frame3.configure(width=195)
        
        #hier title
        self.Label3 = Label(self.Frame3)
        self.Label3.place(relx=0.0, rely=0.0, height=50, width=200)
        self.Label3.configure(activebackground="#ffffff")
        self.Label3.configure(activeforeground="#ffffff")
        self.Label3.configure(background="#ffffff")
        self.Label3.configure(disabledforeground="#a3a3a3")
        self.Label3.configure(font=font10)
        self.Label3.configure(foreground="#000000")
        self.Label3.configure(highlightbackground="#d9d9d9")
        self.Label3.configure(highlightcolor="black")
        self.Label3.configure(text="Paramètres\nhiéarchique")
        
        
        # Run hllm
        self.Button3 = Button(self.Frame3)
        self.Button3.place(relx=0.14, rely=0.6, height=34, width=130)
        self.Button3.configure(activebackground="#d9d9d9")
        self.Button3.configure(activeforeground="#000000")
        self.Button3.configure(background="#d9d9d9")
        self.Button3.configure(disabledforeground="#a3a3a3")
        self.Button3.configure(foreground="#000000")
        self.Button3.configure(highlightbackground="#d9d9d9")
        self.Button3.configure(highlightcolor="black")
        self.Button3.configure(pady="0")
        self.Button3.configure(text='''1 - Run Hier''')
        self.Button3.configure(width=117)
        self.Button3.configure(command = New_Toplevel.runHier)
        
        
        
        # Choose spectra
        self.Button4 = Button(self.Frame3)
        self.Button4.place(relx=0.14, rely=0.72, height=34, width=130)
        self.Button4.configure(activebackground="#d9d9d9")
        self.Button4.configure(activeforeground="#000000")
        self.Button4.configure(background="#d9d9d9")
        self.Button4.configure(disabledforeground="#a3a3a3")
        self.Button4.configure(foreground="#000000")
        self.Button4.configure(highlightbackground="#d9d9d9")
        self.Button4.configure(highlightcolor="black")
        self.Button4.configure(pady="0")
        self.Button4.configure(text='''2 - Choose Spectra''')
        self.Button4.configure(width=117)
        self.Button4.configure(command = New_Toplevel.chooseSpectra)
        
        
        # Save spectra
        self.Button4 = Button(self.Frame3)
        self.Button4.place(relx=0.14, rely=0.84, height=34, width=130)
        self.Button4.configure(activebackground="#d9d9d9")
        self.Button4.configure(activeforeground="#000000")
        self.Button4.configure(background="#d9d9d9")
        self.Button4.configure(disabledforeground="#a3a3a3")
        self.Button4.configure(foreground="#000000")
        self.Button4.configure(highlightbackground="#d9d9d9")
        self.Button4.configure(highlightcolor="black")
        self.Button4.configure(pady="0")
        self.Button4.configure(text='''3 - Save Spectra''')
        self.Button4.configure(width=117)
        self.Button4.configure(command = New_Toplevel.saveSpectra)
        
        
        
        
        
        # Ittérations hiéarchique
        self.Label1_1 = Label(self.Frame3)
        self.Label1_1.place(relx=0.14, rely=0.17, height=20, width=80)
        self.Label1_1.configure(activebackground="#ffffff")
        self.Label1_1.configure(activeforeground="#ffffff")
        self.Label1_1.configure(background="#ffffff")
        self.Label1_1.configure(disabledforeground="#a3a3a3")
        self.Label1_1.configure(font=font9)
        self.Label1_1.configure(foreground="#000000")
        self.Label1_1.configure(highlightbackground="#d9d9d9")
        self.Label1_1.configure(highlightcolor="black")
        self.Label1_1.configure(text='Itérations')
        

        self.Spinbox5 = Spinbox(self.Frame3, from_=1.0, to=100.0)
        self.Spinbox5.place(relx=0.6, rely=0.17, relheight=0.07, relwidth=0.17)

        self.Spinbox5.configure(activebackground="#d9d9d9")
        self.Spinbox5.configure(background="#d9d9d9")
        self.Spinbox5.configure(buttonbackground="#d9d9d9")
        self.Spinbox5.configure(disabledforeground="#a3a3a3")
        self.Spinbox5.configure(foreground="black")
        self.Spinbox5.configure(from_="1.0")
        self.Spinbox5.configure(highlightbackground="black")
        self.Spinbox5.configure(highlightcolor="black")
        self.Spinbox5.configure(insertbackground="black")
        self.Spinbox5.configure(selectbackground="#c4c4c4")
        self.Spinbox5.configure(selectforeground="black")
        self.Spinbox5.configure(textvariable=nb_imcr)
        self.Spinbox5.configure(width=35)
        
        
        
        # Min Pixels
        self.Label1_2 = Label(self.Frame3)
        self.Label1_2.place(relx=0.14, rely=0.26, height=20, width=80)
        self.Label1_2.configure(activebackground="#ffffff")
        self.Label1_2.configure(activeforeground="#ffffff")
        self.Label1_2.configure(background="#ffffff")
        self.Label1_2.configure(disabledforeground="#a3a3a3")
        self.Label1_2.configure(font=font9)
        self.Label1_2.configure(foreground="#000000")
        self.Label1_2.configure(highlightbackground="#d9d9d9")
        self.Label1_2.configure(highlightcolor="black")
        self.Label1_2.configure(text='Min Pixels')
        

        self.Spinbox6 = Spinbox(self.Frame3, from_=1.0, to=100.0)
        self.Spinbox6.place(relx=0.6, rely=0.26, relheight=0.07, relwidth=0.17)

        self.Spinbox6.configure(activebackground="#d9d9d9")
        self.Spinbox6.configure(background="#d9d9d9")
        self.Spinbox6.configure(buttonbackground="#d9d9d9")
        self.Spinbox6.configure(disabledforeground="#a3a3a3")
        self.Spinbox6.configure(foreground="black")
        self.Spinbox6.configure(from_="1.0")
        self.Spinbox6.configure(highlightbackground="black")
        self.Spinbox6.configure(highlightcolor="black")
        self.Spinbox6.configure(insertbackground="black")
        self.Spinbox6.configure(selectbackground="#c4c4c4")
        self.Spinbox6.configure(selectforeground="black")
        self.Spinbox6.configure(textvariable=min_pixels)
        self.Spinbox6.configure(width=35)
        
        
        
        # Max Pixels
        self.Label1_3 = Label(self.Frame3)
        self.Label1_3.place(relx=0.14, rely=0.35, height=20, width=85)
        self.Label1_3.configure(activebackground="#ffffff")
        self.Label1_3.configure(activeforeground="#ffffff")
        self.Label1_3.configure(background="#ffffff")
        self.Label1_3.configure(disabledforeground="#a3a3a3")
        self.Label1_3.configure(font=font9)
        self.Label1_3.configure(foreground="#000000")
        self.Label1_3.configure(highlightbackground="#d9d9d9")
        self.Label1_3.configure(highlightcolor="black")
        self.Label1_3.configure(text='Max Pixels')
        

        self.Spinbox7 = Spinbox(self.Frame3, from_=1.0, to=100.0)
        self.Spinbox7.place(relx=0.6, rely=0.35, relheight=0.07, relwidth=0.17)

        self.Spinbox7.configure(activebackground="#d9d9d9")
        self.Spinbox7.configure(background="#d9d9d9")
        self.Spinbox7.configure(buttonbackground="#d9d9d9")
        self.Spinbox7.configure(disabledforeground="#a3a3a3")
        self.Spinbox7.configure(foreground="black")
        self.Spinbox7.configure(from_="1.0")
        self.Spinbox7.configure(highlightbackground="black")
        self.Spinbox7.configure(highlightcolor="black")
        self.Spinbox7.configure(insertbackground="black")
        self.Spinbox7.configure(selectbackground="#c4c4c4")
        self.Spinbox7.configure(selectforeground="black")
        self.Spinbox7.configure(textvariable=max_pixels)
        self.Spinbox7.configure(width=35)
        
        
        # Max Levels
        self.Label2 = Label(self.Frame3)
        self.Label2.place(relx=0.14, rely=0.45, height=20, width=90)
        self.Label2.configure(activebackground="#ffffff")
        self.Label2.configure(activeforeground="#ffffff")
        self.Label2.configure(background="#ffffff")
        self.Label2.configure(disabledforeground="#a3a3a3")
        self.Label2.configure(font=font9)
        self.Label2.configure(foreground="#000000")
        self.Label2.configure(highlightbackground="#d9d9d9")
        self.Label2.configure(highlightcolor="black")
        self.Label2.configure(text='Max Levels')
        

        self.Spinbox7 = Spinbox(self.Frame3, from_=1.0, to=100.0)
        self.Spinbox7.place(relx=0.6, rely=0.45, relheight=0.07, relwidth=0.17)

        self.Spinbox7.configure(activebackground="#d9d9d9")
        self.Spinbox7.configure(background="#d9d9d9")
        self.Spinbox7.configure(buttonbackground="#d9d9d9")
        self.Spinbox7.configure(disabledforeground="#a3a3a3")
        self.Spinbox7.configure(foreground="black")
        self.Spinbox7.configure(from_="1.0")
        self.Spinbox7.configure(highlightbackground="black")
        self.Spinbox7.configure(highlightcolor="black")
        self.Spinbox7.configure(insertbackground="black")
        self.Spinbox7.configure(selectbackground="#c4c4c4")
        self.Spinbox7.configure(selectforeground="black")
        self.Spinbox7.configure(textvariable=Max_level)
        self.Spinbox7.configure(width=35)
       





        #%% init box
        self.Frame1 = Frame(top)
        self.Frame1.place(relx=0.37, rely=0.375, relheight=0.563, relwidth=0.281)
        self.Frame1.configure(relief=GROOVE)
        self.Frame1.configure(borderwidth="2")
        self.Frame1.configure(relief=GROOVE)
        self.Frame1.configure(background="#ffffff")
        self.Frame1.configure(highlightbackground="#d9d9d9")
        self.Frame1.configure(highlightcolor="black")
        self.Frame1.configure(width=195)
        
        
        #init title
        self.Label1_7 = Label(self.Frame1)
        self.Label1_7.place(relx=0.15, rely=0.0, height=20, width=140)
        self.Label1_7.configure(activebackground="#ffffff")
        self.Label1_7.configure(activeforeground="#ffffff")
        self.Label1_7.configure(background="#ffffff")
        self.Label1_7.configure(disabledforeground="#a3a3a3")
        self.Label1_7.configure(font=font10)
        self.Label1_7.configure(foreground="#000000")
        self.Label1_7.configure(highlightbackground="#d9d9d9")
        self.Label1_7.configure(highlightcolor="black")
        self.Label1_7.configure(text="Initialisation")
        
        
        
        #Hier
        self.Checkbutton1_5 = Checkbutton(self.Frame1)
        self.Checkbutton1_5.place(relx=0.205, rely=0.065, relheight=0.111, relwidth=0.569)
        self.Checkbutton1_5.configure(activebackground="#d9d9d9")
        self.Checkbutton1_5.configure(activeforeground="#000000")
        self.Checkbutton1_5.configure(background="#d9d9d9")
        self.Checkbutton1_5.configure(disabledforeground="#a3a3a3")
        self.Checkbutton1_5.configure(foreground="#000000")
        self.Checkbutton1_5.configure(highlightbackground="#d9d9d9")
        self.Checkbutton1_5.configure(highlightcolor="black")
        self.Checkbutton1_5.configure(indicatoron="0")
        self.Checkbutton1_5.configure(justify=LEFT)
        self.Checkbutton1_5.configure(text="hiéarchique")
        self.Checkbutton1_5.configure(variable=hier)
        
        
        
        
        #Kmeans
        self.Checkbutton1_6 = Checkbutton(self.Frame1)
        self.Checkbutton1_6.place(relx=0.205, rely=0.19, relheight=0.111, relwidth=0.569)
        self.Checkbutton1_6.configure(activebackground="#d9d9d9")
        self.Checkbutton1_6.configure(activeforeground="#000000")
        self.Checkbutton1_6.configure(background="#d9d9d9")
        self.Checkbutton1_6.configure(disabledforeground="#a3a3a3")
        self.Checkbutton1_6.configure(foreground="#000000")
        self.Checkbutton1_6.configure(highlightbackground="#d9d9d9")
        self.Checkbutton1_6.configure(highlightcolor="black")
        self.Checkbutton1_6.configure(indicatoron="0")
        self.Checkbutton1_6.configure(justify=LEFT)
        self.Checkbutton1_6.configure(text="Kmeans")
        self.Checkbutton1_6.configure(variable=KMeansT)
        
        self.helpKmeans = Label(self.Frame1, text="?", fg="blue", cursor="hand2")
        self.helpKmeans.pack()
        self.helpKmeans.place(relx = 0.850, rely = 0.210)
        self.helpKmeans.bind("<Button-1>", New_Toplevel.linkKmeans)
        
        
        #NFinder
        self.Checkbutton1_2 = Checkbutton(self.Frame1)
        self.Checkbutton1_2.place(relx=0.205, rely=0.317, relheight=0.111, relwidth=0.569)
        self.Checkbutton1_2.configure(activebackground="#d9d9d9")
        self.Checkbutton1_2.configure(activeforeground="#000000")
        self.Checkbutton1_2.configure(background="#d9d9d9")
        self.Checkbutton1_2.configure(disabledforeground="#a3a3a3")
        self.Checkbutton1_2.configure(foreground="#000000")
        self.Checkbutton1_2.configure(highlightbackground="#d9d9d9")
        self.Checkbutton1_2.configure(highlightcolor="black")
        self.Checkbutton1_2.configure(indicatoron="0")
        self.Checkbutton1_2.configure(justify=LEFT)
        self.Checkbutton1_2.configure(text="NFindr")
        self.Checkbutton1_2.configure(variable=NFindrT)
        
        self.helpNFindr = Label(self.Frame1, text="?", fg="blue", cursor="hand2")
        self.helpNFindr.pack()
        self.helpNFindr.place(relx = 0.850, rely = 0.337)
        self.helpNFindr.bind("<Button-1>", New_Toplevel.linkNFindr)
        
        
        
        #MBKmeans
        self.Checkbutton1_3 = Checkbutton(self.Frame1)
        self.Checkbutton1_3.place(relx=0.205, rely=0.444, relheight=0.111, relwidth=0.569)
        self.Checkbutton1_3.configure(activebackground="#d9d9d9")
        self.Checkbutton1_3.configure(activeforeground="#000000")
        self.Checkbutton1_3.configure(background="#d9d9d9")
        self.Checkbutton1_3.configure(disabledforeground="#a3a3a3")
        self.Checkbutton1_3.configure(foreground="#000000")
        self.Checkbutton1_3.configure(highlightbackground="#d9d9d9")
        self.Checkbutton1_3.configure(highlightcolor="black")
        self.Checkbutton1_3.configure(indicatoron="0")
        self.Checkbutton1_3.configure(justify=LEFT)
        self.Checkbutton1_3.configure(text="MBKmeans")
        self.Checkbutton1_3.configure(variable=MBKmeansT)
        
        self.helpMBKmeans = Label(self.Frame1, text="?", fg="blue", cursor="hand2")
        self.helpMBKmeans.pack()
        self.helpMBKmeans.place(relx = 0.850, rely = 0.464)
        self.helpMBKmeans.bind("<Button-1>", New_Toplevel.linkMBKmeans)


        #ATGP
        self.Checkbutton1_4 = Checkbutton(self.Frame1)
        self.Checkbutton1_4.place(relx=0.205, rely=0.571, relheight=0.111, relwidth=0.569)
        self.Checkbutton1_4.configure(activebackground="#d9d9d9")
        self.Checkbutton1_4.configure(activeforeground="#000000")
        self.Checkbutton1_4.configure(background="#d9d9d9")
        self.Checkbutton1_4.configure(disabledforeground="#a3a3a3")
        self.Checkbutton1_4.configure(foreground="#000000")
        self.Checkbutton1_4.configure(highlightbackground="#d9d9d9")
        self.Checkbutton1_4.configure(highlightcolor="black")
        self.Checkbutton1_4.configure(indicatoron="0")
        self.Checkbutton1_4.configure(justify=LEFT)
        self.Checkbutton1_4.configure(text="ATGP")
        self.Checkbutton1_4.configure(variable=AtgpT)
        
        self.helpAtgp = Label(self.Frame1, text="?", fg="blue", cursor="hand2")
        self.helpAtgp.pack()
        self.helpAtgp.place(relx = 0.850, rely = 0.591)
        self.helpAtgp.bind("<Button-1>", New_Toplevel.linkAtgp)
        
        
        #FIPPI
        self.Checkbutton1_1 = Checkbutton(self.Frame1)
        self.Checkbutton1_1.place(relx=0.205, rely=0.698, relheight=0.111, relwidth=0.569)
        self.Checkbutton1_1.configure(activebackground="#d9d9d9")
        self.Checkbutton1_1.configure(activeforeground="#000000")
        self.Checkbutton1_1.configure(background="#d9d9d9")
        self.Checkbutton1_1.configure(disabledforeground="#a3a3a3")
        self.Checkbutton1_1.configure(foreground="#000000")
        self.Checkbutton1_1.configure(highlightbackground="#d9d9d9")
        self.Checkbutton1_1.configure(highlightcolor="black")
        self.Checkbutton1_1.configure(indicatoron="0")
        self.Checkbutton1_1.configure(justify=LEFT)
        self.Checkbutton1_1.configure(text="FIPPI")
        self.Checkbutton1_1.configure(variable=FippiT)
        
        self.helpFippi = Label(self.Frame1, text="?", fg="blue", cursor="hand2")
        self.helpFippi.pack()
        self.helpFippi.place(relx = 0.850, rely = 0.718)
        self.helpFippi.bind("<Button-1>", New_Toplevel.linkFippi)
        
        
        #PPI
        self.Checkbutton1_2 = Checkbutton(self.Frame1)
        self.Checkbutton1_2.place(relx=0.205, rely=0.825, relheight=0.111, relwidth=0.569)
        self.Checkbutton1_2.configure(activebackground="#d9d9d9")
        self.Checkbutton1_2.configure(activeforeground="#000000")
        self.Checkbutton1_2.configure(background="#d9d9d9")
        self.Checkbutton1_2.configure(disabledforeground="#a3a3a3")
        self.Checkbutton1_2.configure(foreground="#000000")
        self.Checkbutton1_2.configure(highlightbackground="#d9d9d9")
        self.Checkbutton1_2.configure(highlightcolor="black")
        self.Checkbutton1_2.configure(indicatoron="0")
        self.Checkbutton1_2.configure(justify=LEFT)
        self.Checkbutton1_2.configure(text="PPI")
        self.Checkbutton1_2.configure(variable=PpiT)

        self.helpPpi = Label(self.Frame1, text="?", fg="blue", cursor="hand2")
        self.helpPpi.pack()
        self.helpPpi.place(relx = 0.850, rely = 0.845)
        self.helpPpi.bind("<Button-1>", New_Toplevel.linkPpi)
    





        #%% Functions box
        self.Frame1_8 = Frame(top)
        self.Frame1_8.place(relx=0.685, rely=0.375, relheight=0.563, relwidth=0.281)
        self.Frame1_8.configure(relief=GROOVE)
        self.Frame1_8.configure(borderwidth="2")
        self.Frame1_8.configure(relief=GROOVE)
        self.Frame1_8.configure(background="#ffffff")
        self.Frame1_8.configure(highlightbackground="#d9d9d9")
        self.Frame1_8.configure(highlightcolor="black")
        self.Frame1_8.configure(width=195)
        
        
        #Titre fonctions
        self.Label1_8 = Label(self.Frame1_8)
        self.Label1_8.place(relx=0.205, rely=0.063, height=31, width=110)
        self.Label1_8.configure(activebackground="#ffffff")
        self.Label1_8.configure(activeforeground="#ffffff")
        self.Label1_8.configure(background="#ffffff")
        self.Label1_8.configure(disabledforeground="#a3a3a3")
        self.Label1_8.configure(font=font10)
        self.Label1_8.configure(foreground="#000000")
        self.Label1_8.configure(highlightbackground="#d9d9d9")
        self.Label1_8.configure(highlightcolor="black")
        self.Label1_8.configure(text="Fonctions")
        
        
        #MCR_LLM
        self.Checkbutton1_7 = Checkbutton(self.Frame1_8)
        self.Checkbutton1_7.place(relx=0.205, rely=0.19, relheight=0.111, relwidth=0.569)
        self.Checkbutton1_7.configure(activebackground="#d9d9d9")
        self.Checkbutton1_7.configure(activeforeground="#000000")
        self.Checkbutton1_7.configure(background="#d9d9d9")
        self.Checkbutton1_7.configure(disabledforeground="#a3a3a3")
        self.Checkbutton1_7.configure(foreground="#000000")
        self.Checkbutton1_7.configure(highlightbackground="#d9d9d9")
        self.Checkbutton1_7.configure(highlightcolor="black")
        self.Checkbutton1_7.configure(indicatoron="0")
        self.Checkbutton1_7.configure(justify=LEFT)
        self.Checkbutton1_7.configure(text="MCR-LLM")
        self.Checkbutton1_7.configure(variable=LlmT)



        #MCR-ALS
        self.Checkbutton1_3 = Checkbutton(self.Frame1_8)
        self.Checkbutton1_3.place(relx=0.205, rely=0.317, relheight=0.111, relwidth=0.569)
        self.Checkbutton1_3.configure(activebackground="#d9d9d9")
        self.Checkbutton1_3.configure(activeforeground="#000000")
        self.Checkbutton1_3.configure(background="#d9d9d9")
        self.Checkbutton1_3.configure(disabledforeground="#a3a3a3")
        self.Checkbutton1_3.configure(foreground="#000000")
        self.Checkbutton1_3.configure(highlightbackground="#d9d9d9")
        self.Checkbutton1_3.configure(highlightcolor="black")
        self.Checkbutton1_3.configure(indicatoron="0")
        self.Checkbutton1_3.configure(justify=LEFT)
        self.Checkbutton1_3.configure(text="MCR-ALS")
        self.Checkbutton1_3.configure(variable=AlsT)
        
        
        
        #NMF
        self.Checkbutton1_3 = Checkbutton(self.Frame1_8)
        self.Checkbutton1_3.place(relx=0.205, rely=0.444, relheight=0.111
                , relwidth=0.569)
        self.Checkbutton1_3.configure(activebackground="#d9d9d9")
        self.Checkbutton1_3.configure(activeforeground="#000000")
        self.Checkbutton1_3.configure(background="#d9d9d9")
        self.Checkbutton1_3.configure(disabledforeground="#a3a3a3")
        self.Checkbutton1_3.configure(foreground="#000000")
        self.Checkbutton1_3.configure(highlightbackground="#d9d9d9")
        self.Checkbutton1_3.configure(highlightcolor="black")
        self.Checkbutton1_3.configure(indicatoron="0")
        self.Checkbutton1_3.configure(justify=LEFT)
        self.Checkbutton1_3.configure(text="NMF")
        self.Checkbutton1_3.configure(variable=NmfT)






        #Ittérations
        self.Label1_6 = Label(self.Frame1_8)
        self.Label1_6.place(relx=0.051, rely=0.7, height=31, width=110)
        self.Label1_6.configure(activebackground="#ffffff")
        self.Label1_6.configure(activeforeground="#ffffff")
        self.Label1_6.configure(background="#ffffff")
        self.Label1_6.configure(disabledforeground="#a3a3a3")
        self.Label1_6.configure(font=font9)
        self.Label1_6.configure(foreground="#000000")
        self.Label1_6.configure(highlightbackground="#d9d9d9")
        self.Label1_6.configure(highlightcolor="black")
        self.Label1_6.configure(text='''Itérations''')
        

        self.Spinbox2 = Spinbox(self.Frame1_8, from_=1.0, to=100.0)
        self.Spinbox2.place(relx=0.667, rely=0.72, relheight=0.06, relwidth=0.179)

        self.Spinbox2.configure(activebackground="#d9d9d9")
        self.Spinbox2.configure(background="#d9d9d9")
        self.Spinbox2.configure(buttonbackground="#d9d9d9")
        self.Spinbox2.configure(disabledforeground="#a3a3a3")
        self.Spinbox2.configure(foreground="black")
        self.Spinbox2.configure(from_="1.0")
        self.Spinbox2.configure(highlightbackground="black")
        self.Spinbox2.configure(highlightcolor="black")
        self.Spinbox2.configure(insertbackground="black")
        self.Spinbox2.configure(selectbackground="#c4c4c4")
        self.Spinbox2.configure(selectforeground="black")
        self.Spinbox2.configure(textvariable=nb_i)
        self.Spinbox2.configure(width=35)
        
        
        
    
        
        
        
        #GO!
        self.Button1 = Button(self.Frame1_8)
        self.Button1.place(relx=0.205, rely=0.825, height=34, width=117)
        self.Button1.configure(activebackground="#d9d9d9")
        self.Button1.configure(activeforeground="#000000")
        self.Button1.configure(background="#d9d9d9")
        self.Button1.configure(disabledforeground="#a3a3a3")
        self.Button1.configure(foreground="#000000")
        self.Button1.configure(highlightbackground="#d9d9d9")
        self.Button1.configure(highlightcolor="black")
        self.Button1.configure(pady="0")
        self.Button1.configure(text='''Go !''')
        self.Button1.configure(width=117)
        self.Button1.configure(command = New_Toplevel.returnValues)
          


        


        
        






        
if __name__ == '__main__':
    vp_start_gui()



