from AppliDef import *
from FrmTopLevel import ModifDanger
from EtagProduits import ModifListDanger

from pathlib import Path


def ModifListDanger2(List):
    for i in range(len(List)):
        if List[i] == 0:
            List[i] = 'AttentionGHS'
        elif List[i] == 1:
            List[i] = 'CancerGHS'
        elif List[i] == 2:
            List[i] = 'CGHS'
        elif List[i] == 3:
            List[i] = 'ComburantGHS'
        elif List[i] == 4:
            List[i] = 'DangerGHS'
        elif List[i] == 5:
            List[i] = 'ExplosifGHS'
        elif List[i] == 6:
            List[i] = 'FGHS'
        elif List[i] == 7:
            List[i] = 'GazGHS'
        elif List[i] == 8:
            List[i] = 'PolluantGHS'
        elif List[i] == 9:
            List[i] = 'TGHS'
        elif List[i] == 10:
            List[i] = ''
    return List


def ChargeEntry(Entry, Val):
    Entry.EntryData.delete(0, tk.END)
    if Val is not None:
        Entry.EntryData.insert(0, Val)
    else:
        Entry.EntryData.insert(0, '')


class FrmAjoutProd(tk.Toplevel):
    def __init__(self, container, RatioX, RatioY, Appli):
        tk.Toplevel.__init__(self, container)
        self.MainAppli = Appli
        self.parent = container
        self.RatioX = RatioX
        self.RatioY = RatioY
        self.DocPDF = False
        self.FrmPDF = None
        self.PathFilePDFToOpen = ''
        self.EntryDensit = None
        self.ListNDanger = [10, 10, 10]
        self.MenuPicto = None
        self.PathFilejpgToOpen = ''
        self.CanvasContEtiqProd = None
        self.ImgEtiqProd = []
        self.ImgCanvasContEtiqProd = None
        self.CanvasGHSArmoire = []
        self.MenuClicDroit = []
        self.NPictoSelected = 0
        self.CanvasImgEtiqArmoire = None
        self.img = None
        self.MenuClicDroitFD = None
        self.ImgEtiqArmoire = None
        self.ImgCanvasImgEtiqArmoire = None
        self.PathFileFournisseurToOpen = ''
        self.TitreD = None
        self.VisuelFD = ''
        self.DocFDS = ''
        self.Fournisseur = ''
        self.QCOM = ''
        self.QCOMANNUL = ''
        self.QENCOM = ''
        self.ListMenuClicDroitCaract = []
        self.ListCaract = []
        self.NCaract = 0
        self.FrmModifFour, self.ListFours = None, None
        self.NRefFour = 0
        self.ActionModifNom = False
        self.DocFDSInit = ''
        self.VisuelFDInit = ''
        self.NomInit = ''

        screen = ctypes.windll.user32
        FrmFond = Image.open('Media/FrmAjout/Fond/Fond.jpg')
        self.SX = int((float(FrmFond.size[0]) * float(self.RatioX)))
        self.SY = int((float(FrmFond.size[1]) * float(self.RatioY)))

        self.ImgFrmFond = []
        self.ImgFrmFond = RedimImg(self.SX, self.SY, 'Media/FrmAjout/Fond/')
        self.CanvasFrmFond = CanvasApp(self, width=self.SX, height=self.SY)
        self.ImgCanvasFrmFond = self.CanvasFrmFond.create_image(0, 0, anchor=tk.NW, image=self.ImgFrmFond[0])

        self.geometry(str(self.SX) + "x" + str(self.SY) + "+" + str(int(screen.GetSystemMetrics(0) * 0.002)) + "+" +
                      str(int(screen.GetSystemMetrics(1) * 0.031)))
        self.resizable(width=False, height=False)
        self.overrideredirect(True)
        self.lift()

        self.ImgBtnClose, wsize, hsize, self.CanvasBtnClose, self.ImgCanvasBtnClose = CanInWindow(
            'Media/FrmAjout/BtnClose/', self.RatioX, self.RatioY, self.CanvasFrmFond, tk.CENTER,
            int(self.SX * 0.988), int(self.SY * 0.014), 0)
        ChangeCursor(self.CanvasBtnClose)
        self.CanvasBtnClose.bind('<Motion>',
                                 lambda action: self.CanvasBtnClose.itemconfig(self.ImgCanvasBtnClose,
                                                                               image=self.ImgBtnClose[1]))
        self.CanvasBtnClose.bind('<ButtonRelease-1>', self.CacheFrmAjout)

        if self.MainAppli.ModifEnCours:
            textlabelTag = 'Modifier un produit chimique'
        else:
            textlabelTag = 'Ajouter un produit chimique'
        coefY = float(ConfigResolution(self.MainAppli.Nconfig, 'YTitreFrm', self.MainAppli.curSave))
        self.LabelTag = LabelInCanvas(self.CanvasFrmFond, textlabelTag, '#E0E0E0',
                                      AppliFont('Helvetica', self.MainAppli.SizeFont, 'normal', 0),
                                      int(self.SX * 0.005), int(self.SY * coefY), tk.NW)

        self.CanvasFrmFond.focus_set()
        self.CanvasFrmFond.bind('<Motion>', self.MoveOnCanvas)
        self.CanvasFrmFond.bind('<Button-1>', self.ClicOnCanvas)

        self.CanvasMenu1 = CanvasMenu(self.CanvasFrmFond, 'Media/FrmAjout/Menu/', int(self.SX * 0.282),
                                      int(self.SY * 0.967), int(self.SX * 0.003), int(self.SY * 0.03), tk.NW)

        LabelInCanvas(self.CanvasMenu1.CanvasMenu, 'Informations du produit', '#E0E0E0',
                      AppliFont('Helvetica', self.MainAppli.SizeFont, 'normal', 0),
                      int(int(self.CanvasMenu1.CanvasMenu['width']) * 0.01),
                      int(int(self.CanvasMenu1.CanvasMenu['height']) * 0.005), tk.NW)

        self.CanvasCont = CanvasInWindow('Media/FrmAjout/Flacon/', self.RatioX, self.RatioY * 0.92,
                                         self.CanvasMenu1.CanvasMenu, tk.CENTER,
                                         int(int(self.CanvasMenu1.CanvasMenu['width']) * 0.5),
                                         int(int(self.CanvasMenu1.CanvasMenu['height']) * 0.5), 1)
        self.ListMenuClicDroitCaract.append(tk.Menu(self.CanvasCont.CanvasListIma, tearoff=0))
        self.ListCaract.append(self.CanvasCont.CanvasListIma)
        self.ListMenuClicDroitCaract[0].add_command(label="Recherche internet", command=self.ChercheWeb)

        self.listcont = ['Bouteille en verre', 'Flacon PEHD', 'Bouteille de gaz', 'Boîte']
        self.ListeCont = ListeDeroulante(self.CanvasMenu1.CanvasMenu,
                                         str(int(int(self.CanvasMenu1.CanvasMenu['width']) * 0.05)),
                                         values=self.listcont)
        self.CanvasMenu1.CanvasMenu.create_window(int(int(self.CanvasMenu1.CanvasMenu['width']) * 0.5),
                                                  int(int(self.CanvasMenu1.CanvasMenu['height']) * 0.95),
                                                  anchor=tk.CENTER, window=self.ListeCont)

        self.ListeCont.current(1)
        self.ListeCont.bind("<<ComboboxSelected>>", self.ChangeCont)

        self.EntryNom = EntryData(self.CanvasCont.CanvasListIma, int(self.CanvasCont.wsize * 0.095),
                                  int(self.CanvasCont.wsize * 0.5), int(self.CanvasCont.hsize * 0.34), tk.CENTER,
                                  AppliFont('Helvetica', self.MainAppli.SizeFont, 'bold', 0))
        self.EntryNom.Data.set('Nom du produit')
        self.EntryNom.EntryData.config(justify='center')
        self.EntryNom.EntryData.bind('<KeyRelease>', self.ModifNom)

        self.CanvasFD = CanvasInWindow('Media/FrmAjout/FD/', self.RatioX, self.RatioY,
                                       self.CanvasCont.CanvasListIma, tk.CENTER, int(self.CanvasCont.wsize * 0.5),
                                       int(self.CanvasCont.hsize * 0.41), 0)

        ChangeCursor(self.CanvasFD.CanvasListIma)
        self.CanvasFD.CanvasListIma.bind('<ButtonRelease-1>', self.ChargeFD)
        self.ListCaract.append(self.CanvasFD.CanvasListIma)
        self.ListMenuClicDroitCaract.append(tk.Menu(self.CanvasCont.CanvasListIma, tearoff=0))
        self.ListMenuClicDroitCaract[1].add_command(label="Recherche internet", command=self.ChercheWeb)
        self.ListMenuClicDroitCaract[1].add_separator()
        self.ListMenuClicDroitCaract[1].add_command(label="Coller une image", command=self.ColleFD)

        self.EntryFB = EntryData(self.CanvasCont.CanvasListIma, int(self.CanvasCont.wsize * 0.05),
                                 int(self.CanvasCont.wsize * 0.5), int(self.CanvasCont.hsize * 0.47), tk.CENTER,
                                 AppliFont('Helvetica', self.MainAppli.SizeFont, 'bold', 0))
        self.EntryFB.Data.set('Formule brute')
        self.EntryFB.EntryData.config(justify='center')
        self.ListCaract.append(self.EntryFB.EntryData)
        self.ListMenuClicDroitCaract.append(tk.Menu(self.CanvasCont.CanvasListIma, tearoff=0))
        self.ListMenuClicDroitCaract[2].add_command(label="Recherche internet", command=self.ChercheWeb)

        self.EntrySyno = EntryData(self.CanvasCont.CanvasListIma, int(self.CanvasCont.wsize * 0.095),
                                   int(self.CanvasCont.wsize * 0.5), int(self.CanvasCont.hsize * 0.50), tk.CENTER,
                                   AppliFont('Helvetica', self.MainAppli.SizeFont, 'bold', 0))
        self.EntrySyno.Data.set('Autre nom du produit')
        self.EntrySyno.EntryData.config(justify='center')
        self.ListCaract.append(self.EntrySyno.EntryData)
        self.ListMenuClicDroitCaract.append(tk.Menu(self.CanvasCont.CanvasListIma, tearoff=0))
        self.ListMenuClicDroitCaract[3].add_command(label="Recherche internet", command=self.ChercheWeb)

        self.EntryMM = EntryData(self.CanvasCont.CanvasListIma, int(self.CanvasCont.wsize * 0.05),
                                 int(self.CanvasCont.wsize * 0.5), int(self.CanvasCont.hsize * 0.54), tk.CENTER,
                                 AppliFont('Helvetica', self.MainAppli.SizeFont, 'bold', 0))
        self.EntryMM.Data.set('')
        self.EntryMM.EntryData.config(justify='center')
        self.ListCaract.append(self.EntryMM.EntryData)
        self.ListMenuClicDroitCaract.append(tk.Menu(self.CanvasCont.CanvasListIma, tearoff=0))
        self.ListMenuClicDroitCaract[4].add_command(label="Recherche internet", command=self.ChercheWeb)
        self.CanvasCont.CanvasListIma.create_text(int(self.CanvasCont.wsize * 0.275), int(self.CanvasCont.hsize * 0.54),
                                                  text='M:', font=AppliFont('Helvetica', self.MainAppli.SizeFont,
                                                                            'bold', 0), anchor=tk.W)
        self.CanvasCont.CanvasListIma.create_text(int(self.CanvasCont.wsize * 0.7), int(self.CanvasCont.hsize * 0.54),
                                                  text='(g/mol)',
                                                  font=AppliFont('Helvetica', self.MainAppli.SizeFont, 'bold', 0),
                                                  anchor=tk.W)

        self.EntryMP = EntryData(self.CanvasCont.CanvasListIma, int(self.CanvasCont.wsize * 0.05),
                                 int(self.CanvasCont.wsize * 0.36), int(self.CanvasCont.hsize * 0.615), tk.W,
                                 AppliFont('Helvetica', self.MainAppli.SizeFont, 'bold', 0))
        self.EntryMP.Data.set('')
        self.ListCaract.append(self.EntryMP.EntryData)
        self.ListMenuClicDroitCaract.append(tk.Menu(self.CanvasCont.CanvasListIma, tearoff=0))
        self.ListMenuClicDroitCaract[5].add_command(label="Recherche internet", command=self.ChercheWeb)
        self.CanvasCont.CanvasListIma.create_text(int(self.CanvasCont.wsize * 0.15), int(self.CanvasCont.hsize * 0.615),
                                                  text='mp (°C):', font=AppliFont('Helvetica', self.MainAppli.SizeFont,
                                                                                  'bold', 0), anchor=tk.W)

        self.EntrySolub = EntryData(self.CanvasCont.CanvasListIma, int(self.CanvasCont.wsize * 0.05),
                                    int(self.CanvasCont.wsize * 0.36), int(self.CanvasCont.hsize * 0.645), tk.W,
                                    AppliFont('Helvetica', self.MainAppli.SizeFont, 'bold', 0))
        self.EntrySolub.Data.set('')
        self.ListCaract.append(self.EntrySolub.EntryData)
        self.ListMenuClicDroitCaract.append(tk.Menu(self.CanvasCont.CanvasListIma, tearoff=0))
        self.ListMenuClicDroitCaract[6].add_command(label="Recherche internet", command=self.ChercheWeb)
        self.CanvasCont.CanvasListIma.create_text(int(self.CanvasCont.wsize * 0.15), int(self.CanvasCont.hsize * 0.638),
                                                  text='Hydrosolubilité:',
                                                  font=AppliFont('Helvetica', self.MainAppli.SizeFont - 1, 'bold', 0),
                                                  anchor=tk.W)
        self.CanvasCont.CanvasListIma.create_text(int(self.CanvasCont.wsize * 0.15), int(self.CanvasCont.hsize * 0.651),
                                                  text='(g/L à 20 °C)',
                                                  font=AppliFont('Helvetica', self.MainAppli.SizeFont - 1, 'bold', 0),
                                                  anchor=tk.W)

        self.EntryDanger = EntryData(self.CanvasCont.CanvasListIma, int(self.CanvasCont.wsize * 0.08),
                                     int(self.CanvasCont.wsize * 0.295), int(self.CanvasCont.hsize * 0.69), tk.W,
                                     AppliFont('Helvetica', self.MainAppli.SizeFont, 'bold', 0))
        self.EntryDanger.Data.set('')
        self.ListCaract.append(self.EntryDanger.EntryData)
        self.ListMenuClicDroitCaract.append(tk.Menu(self.CanvasCont.CanvasListIma, tearoff=0))
        self.ListMenuClicDroitCaract[7].add_command(label="Recherche internet", command=self.ChercheWeb)
        self.CanvasCont.CanvasListIma.create_text(int(self.CanvasCont.wsize * 0.15), int(self.CanvasCont.hsize * 0.683),
                                                  text='Mentions',
                                                  font=AppliFont('Helvetica', self.MainAppli.SizeFont - 1, 'bold', 0),
                                                  anchor=tk.W)
        self.CanvasCont.CanvasListIma.create_text(int(self.CanvasCont.wsize * 0.15), int(self.CanvasCont.hsize * 0.696),
                                                  text='de danger:',
                                                  font=AppliFont('Helvetica', self.MainAppli.SizeFont - 1, 'bold', 0),
                                                  anchor=tk.W)

        self.EntryPrud = EntryData(self.CanvasCont.CanvasListIma, int(self.CanvasCont.wsize * 0.08),
                                   int(self.CanvasCont.wsize * 0.295), int(self.CanvasCont.hsize * 0.72), tk.W,
                                   AppliFont('Helvetica', self.MainAppli.SizeFont, 'bold', 0))
        self.EntryPrud.Data.set('')
        self.ListCaract.append(self.EntryPrud.EntryData)
        self.ListMenuClicDroitCaract.append(tk.Menu(self.CanvasCont.CanvasListIma, tearoff=0))
        self.ListMenuClicDroitCaract[8].add_command(label="Recherche internet", command=self.ChercheWeb)
        self.CanvasCont.CanvasListIma.create_text(int(self.CanvasCont.wsize * 0.15), int(self.CanvasCont.hsize * 0.713),
                                                  text='Conseil de',
                                                  font=AppliFont('Helvetica', self.MainAppli.SizeFont - 1, 'bold', 0),
                                                  anchor=tk.W)
        self.CanvasCont.CanvasListIma.create_text(int(self.CanvasCont.wsize * 0.15), int(self.CanvasCont.hsize * 0.725),
                                                  text='prudence:',
                                                  font=AppliFont('Helvetica', self.MainAppli.SizeFont - 1, 'bold', 0),
                                                  anchor=tk.W)

        self.CanvasGHS = []
        for i in range(3):
            self.CanvasGHS.append(
                CanvasInWindow('Media/FrmAjout/Picto/', self.RatioX * 0.9, self.RatioX * 0.9,
                               self.CanvasCont.CanvasListIma,
                               tk.CENTER, int(self.CanvasCont.wsize * 0.3) + int(i * self.CanvasCont.wsize * 0.2),
                               int(self.CanvasCont.hsize * 0.86), self.ListNDanger[i]))
            ChangeCursor(self.CanvasGHS[i].CanvasListIma)

            self.MenuClicDroit.append(tk.Menu(self.CanvasGHS[i].CanvasListIma, tearoff=0))

            def GestEvt(_, j=i):
                return self.SelectDanger(j)

            def GestEvt2(evt, j=i):
                return self.AffichMenuClicDroit(evt, j)

            self.CanvasGHS[i].CanvasListIma.bind("<Button-3>", GestEvt2)
            self.MenuClicDroit[i].add_command(label="Effacer", command=self.EffacerPicto)

            self.CanvasGHS[i].CanvasListIma.bind('<ButtonRelease-1>', GestEvt)

        for i in range(len(self.ListCaract)):
            def GestEvt3(evt, j=i):
                return self.AffichMenuClicDroitCaract(evt, j)

            self.ListCaract[i].bind("<Button-3>", GestEvt3)

        self.CanvasMenu2 = CanvasMenu(self.CanvasFrmFond, 'Media/FrmAjout/Menu/', int(self.SX * 0.282),
                                      int(self.SY * 0.967), int(self.SX * 0.998), int(self.SY * 0.03), tk.NE)

        LabelInCanvas(self.CanvasMenu2.CanvasMenu, 'Stock / Fournisseur', '#E0E0E0',
                      AppliFont('Helvetica', self.MainAppli.SizeFont, 'normal', 0),
                      int(int(self.CanvasMenu2.CanvasMenu['width']) * 0.01),
                      int(int(self.CanvasMenu2.CanvasMenu['height']) * 0.005), tk.NW)

        self.NomProduit = LabelInCanvas(self.CanvasMenu2.CanvasMenu, self.EntryNom.EntryData.get(), '#E0E0E0',
                                        AppliFont('Helvetica', self.MainAppli.SizeFont + 3, 'bold', 0),
                                        int(int(self.CanvasMenu2.CanvasMenu['width']) * 0.5),
                                        int(int(self.CanvasMenu2.CanvasMenu['height']) * 0.05), tk.CENTER)

        self.TitreStock = self.CanvasMenu2.CanvasMenu.create_text(
            int(int(self.CanvasMenu2.CanvasMenu['width']) * 0.05),
            int(int(self.CanvasMenu2.CanvasMenu['height']) * 0.08), text='Stock',
            font=AppliFont('Helvetica', self.MainAppli.SizeFont + 2, 'bold', 1), anchor=tk.W)

        self.CanvasArmoire = CanvasInWindow('Media/FrmInfo/Armoires/', self.RatioX * 1.1, self.RatioY * 0.9,
                                            self.CanvasMenu2.CanvasMenu, tk.CENTER,
                                            int(int(self.CanvasMenu2.CanvasMenu['width']) * 0.5),
                                            int(int(self.CanvasMenu2.CanvasMenu['height']) * 0.33), 0)

        self.FonctionProd = EntryData(self.CanvasArmoire.CanvasListIma, int(self.CanvasCont.wsize * 0.05),
                                      int(self.CanvasArmoire.wsize * 0.52), int(self.CanvasArmoire.hsize * 0.1),
                                      tk.CENTER, AppliFont('Helvetica', self.MainAppli.SizeFont + 1, 'bold', 0))
        self.FonctionProd.Data.set('FONCTION')
        self.FonctionProd.EntryData.config(justify='center')
        self.FonctionProd.EntryData.bind('<Return>', self.ModifFonction)

        self.LieuStockProd = EntryData(self.CanvasArmoire.CanvasListIma, int(self.CanvasCont.wsize * 0.04),
                                       int(self.CanvasArmoire.wsize * 0.52), int(self.CanvasArmoire.hsize * 0.335),
                                       tk.CENTER, AppliFont('Helvetica', self.MainAppli.SizeFont + 1, 'bold', 0))
        self.LieuStockProd.EntryData.config(justify='center')
        self.LieuStockProd.EntryData.bind('<Return>', self.ModifLieux)

        self.QuantStockProd = EntryData(self.CanvasArmoire.CanvasListIma, int(self.CanvasCont.wsize * 0.04),
                                        int(self.CanvasArmoire.wsize * 0.52), int(self.CanvasArmoire.hsize * 0.565),
                                        tk.CENTER, AppliFont('Helvetica', self.MainAppli.SizeFont + 1, 'bold', 0))
        self.QuantStockProd.EntryData.config(justify='center')

        self.QuantUtil = EntryData(self.CanvasArmoire.CanvasListIma, int(self.CanvasCont.wsize * 0.04),
                                   int(self.CanvasArmoire.wsize * 0.52), int(self.CanvasArmoire.hsize * 0.79),
                                   tk.CENTER, AppliFont('Helvetica', self.MainAppli.SizeFont + 1, 'bold', 0))
        self.QuantUtil.EntryData.config(justify='center')

        unit = ''
        if self.ListeCont.current() == 1:
            unit = "g"
        elif self.ListeCont.current() == 0:
            unit = 'mL'
        elif self.ListeCont.current() == 2:
            unit = 'L'
        elif self.ListeCont.current() == 3:
            unit = 'Unit'
        self.unit = unit
        LabelInCanvas(self.CanvasArmoire.CanvasListIma, 'Lieu de stockage', '#C0C0C0',
                      AppliFont('Helvetica', self.MainAppli.SizeFont + 1, 'bold', 0),
                      int(self.CanvasArmoire.wsize * 0.52), int(self.CanvasArmoire.hsize * 0.245), tk.CENTER)
        self.LabelQStock = LabelInCanvas(self.CanvasArmoire.CanvasListIma, 'Quantité en stock (' + unit + '):',
                                         '#C0C0C0', AppliFont('Helvetica', self.MainAppli.SizeFont + 1, 'bold', 0),
                                         int(self.CanvasArmoire.wsize * 0.52), int(self.CanvasArmoire.hsize * 0.476),
                                         tk.CENTER)
        self.LabelQUtil = LabelInCanvas(self.CanvasArmoire.CanvasListIma, 'Quantité utilisée / an (' + unit + '):',
                                        '#C0C0C0', AppliFont('Helvetica', self.MainAppli.SizeFont + 1, 'bold', 0),
                                        int(self.CanvasArmoire.wsize * 0.52), int(self.CanvasArmoire.hsize * 0.698),
                                        tk.CENTER)

        self.TitreFournisseur = self.CanvasMenu2.CanvasMenu.create_text(
            int(int(self.CanvasMenu2.CanvasMenu['width']) * 0.05),
            int(int(self.CanvasMenu2.CanvasMenu['height']) * 0.6), text='Fournisseur',
            font=AppliFont('Helvetica', self.MainAppli.SizeFont + 2, 'bold', 1), anchor=tk.W)

        self.ListRefFour = []
        self.ListMenuClicDroitRefFour = []

        self.ImgFournisseur = ImgInCanvas(self.CanvasMenu2.CanvasMenu, 'Datas/Fournisseurs/Logos/NC', 0.4, tk.CENTER,
                                          int(int(self.CanvasMenu2.CanvasMenu['width']) * 0.5),
                                          int(int(self.CanvasMenu2.CanvasMenu['height']) * 0.7))
        ChangeCursor(self.ImgFournisseur.CanvasImg)
        self.ImgFournisseur.CanvasImg.bind('<ButtonRelease-1>', self.ChargeFournisseur)
        self.ListRefFour.append(self.ImgFournisseur.CanvasImg)
        self.ListMenuClicDroitRefFour.append(tk.Menu(self.ImgFournisseur.CanvasImg, tearoff=0))
        self.ListMenuClicDroitRefFour[0].add_command(label="Recherche internet", command=self.ChercheWebFour)

        self.CanvasEtiqPrix = CanvasInWindow('Media/FrmInfo/Etiq/', self.RatioX * 0.9, self.RatioY * 0.7,
                                             self.CanvasMenu2.CanvasMenu, tk.CENTER,
                                             int(int(self.CanvasMenu2.CanvasMenu['width']) * 0.5),
                                             int(int(self.CanvasMenu2.CanvasMenu['height']) * 0.87), 0)
        self.ImgFournisseur.CanvasImg.bind('<ButtonRelease-1>', self.ChargeFournisseur)
        self.ListRefFour.append(self.CanvasEtiqPrix.CanvasListIma)
        self.ListMenuClicDroitRefFour.append(tk.Menu(self.CanvasEtiqPrix.CanvasListIma, tearoff=0))
        self.ListMenuClicDroitRefFour[1].add_command(label="Recherche internet", command=self.ChercheWebFour)

        self.EtiqPrixNomProd = self.CanvasEtiqPrix.CanvasListIma.create_text(
            int(self.CanvasEtiqPrix.wsize * 0.5), int(self.CanvasEtiqPrix.hsize * 0.2),
            text=self.EntryNom.EntryData.get(),
            font=AppliFont('Helvetica', self.MainAppli.SizeFont - 1, 'bold', 0), anchor=tk.CENTER)

        self.CanvasEtiqPrix.CanvasListIma.create_text(
            int(self.CanvasEtiqPrix.wsize * 0.09), int(self.CanvasEtiqPrix.hsize * 0.45), text='Ref: ',
            font=AppliFont('Helvetica', self.MainAppli.SizeFont, 'bold', 0), anchor=tk.W)

        self.Ref = EntryData(self.CanvasEtiqPrix.CanvasListIma, int(self.CanvasEtiqPrix.wsize * 0.045),
                             int(self.CanvasEtiqPrix.wsize * 0.26), int(self.CanvasEtiqPrix.hsize * 0.45),
                             tk.W, AppliFont('Helvetica', self.MainAppli.SizeFont, 'bold', 0))
        self.ListRefFour.append(self.Ref.EntryData)
        self.ListMenuClicDroitRefFour.append(tk.Menu(self.Ref.EntryData, tearoff=0))
        self.ListMenuClicDroitRefFour[2].add_command(label="Recherche internet", command=self.ChercheWebFour)

        self.Cdt = EntryData(self.CanvasEtiqPrix.CanvasListIma, int(self.CanvasEtiqPrix.wsize * 0.045),
                             int(self.CanvasEtiqPrix.wsize * 0.26), int(self.CanvasEtiqPrix.hsize * 0.6),
                             tk.W, AppliFont('Helvetica', self.MainAppli.SizeFont, 'bold', 0))
        self.ListRefFour.append(self.Cdt.EntryData)
        self.ListMenuClicDroitRefFour.append(tk.Menu(self.Cdt.EntryData, tearoff=0))
        self.ListMenuClicDroitRefFour[3].add_command(label="Recherche internet", command=self.ChercheWebFour)

        self.TextCdt = self.CanvasEtiqPrix.CanvasListIma.create_text(
            int(self.CanvasEtiqPrix.wsize * 0.09), int(self.CanvasEtiqPrix.hsize * 0.6),
            text='Cdt (' + unit + '):', font=AppliFont('Helvetica', self.MainAppli.SizeFont, 'bold', 0), anchor=tk.W)

        self.PrixHT = EntryData(self.CanvasEtiqPrix.CanvasListIma, int(self.CanvasEtiqPrix.wsize * 0.025),
                                int(self.CanvasEtiqPrix.wsize * 0.73), int(self.CanvasEtiqPrix.hsize * 0.55),
                                tk.CENTER, AppliFont('Helvetica', self.MainAppli.SizeFont + 3, 'bold', 0))
        self.PrixHT.Data.set('PRIX')
        self.PrixHT.EntryData.config(justify='center')
        self.ListRefFour.append(self.PrixHT.EntryData)
        self.ListMenuClicDroitRefFour.append(tk.Menu(self.PrixHT.EntryData, tearoff=0))
        self.ListMenuClicDroitRefFour[4].add_command(label="Recherche internet", command=self.ChercheWebFour)
        self.CanvasEtiqPrix.CanvasListIma.create_text(
            int(self.CanvasEtiqPrix.wsize * 0.86), int(self.CanvasEtiqPrix.hsize * 0.55),
            text='€ HT', font=AppliFont('Helvetica', self.MainAppli.SizeFont, 'bold', 0), anchor=tk.W)

        self.CanvasEtiqPrix.CanvasListIma.create_text(
            int(self.CanvasEtiqPrix.wsize * 0.09), int(self.CanvasEtiqPrix.hsize * 0.83), fill='white',
            text='CAS:', font=AppliFont('Helvetica', self.MainAppli.SizeFont, 'bold', 0), anchor=tk.W)
        self.CAS = EntryData(self.CanvasEtiqPrix.CanvasListIma, int(self.CanvasEtiqPrix.wsize * 0.045),
                             int(self.CanvasEtiqPrix.wsize * 0.18), int(self.CanvasEtiqPrix.hsize * 0.83),
                             tk.W, AppliFont('Helvetica', self.MainAppli.SizeFont, 'bold', 0))
        self.ListRefFour.append(self.CAS.EntryData)
        self.ListMenuClicDroitRefFour.append(tk.Menu(self.CAS.EntryData, tearoff=0))
        self.ListMenuClicDroitRefFour[5].add_command(label="Recherche internet", command=self.ChercheWebFour)

        for i in range(len(self.ListRefFour)):
            def GestEvt4(evt, j=i):
                return self.AffichMenuClicDroitRefFour(evt, j)

            self.ListRefFour[i].bind("<Button-3>", GestEvt4)

        self.CanvasMenu3 = CanvasMenu(self.CanvasFrmFond, 'Media/FrmAjout/Menu/', int(self.SX * 0.43),
                                      int(self.SY * 0.967), int(self.SX * 0.5), int(self.SY * 0.03), tk.N)

        self.ImgSousMenu3 = []
        self.ImgSousMenu3 = RedimImg(int(int(self.CanvasMenu3.CanvasMenu['width']) * 0.97),
                                     int(int(self.CanvasMenu3.CanvasMenu['height']) * 0.9), 'Media/FrmAjout/SousMenu/')
        self.CanvasSousMenu3 = CanvasApp(self, width=int(self.CanvasMenu3.CanvasMenu['width']) * 0.95,
                                         height=int(self.CanvasMenu3.CanvasMenu['height']) * 0.9)
        self.CanvasMenu3.CanvasMenu.create_window(int(int(self.CanvasMenu3.CanvasMenu['width']) * 0.5),
                                                  int(int(self.CanvasMenu3.CanvasMenu['height']) * 0.53),
                                                  anchor=tk.CENTER,
                                                  window=self.CanvasSousMenu3)
        self.ImgCanvasSousMenu3 = self.CanvasSousMenu3.create_image(0, 0, anchor=tk.NW, image=self.ImgSousMenu3[0])

        LabelInCanvas(self.CanvasMenu3.CanvasMenu, 'Fiches de données de sécurité (FDS)', '#E0E0E0',
                      AppliFont('Helvetica', self.MainAppli.SizeFont, 'normal', 0),
                      int(int(self.CanvasMenu3.CanvasMenu['width']) * 0.01),
                      int(int(self.CanvasMenu3.CanvasMenu['height']) * 0.005), tk.NW)

        self.NoPDF = NoPDF(self.CanvasSousMenu3, 'Media/FrmAjout/NoPDF/NoPDF.jpg',
                           int(int(self.CanvasSousMenu3['width']) * 0.5),
                           int(int(self.CanvasSousMenu3['height']) * 0.5), self.RatioX, self.RatioY)
        ChangeCursor(self.NoPDF.CanvasImgNoPdf)
        self.NoPDF.CanvasImgNoPdf.bind('<ButtonRelease-1>', self.ChargePDF)
        self.MenuClicDroitPDF = tk.Menu(self.NoPDF.CanvasImgNoPdf, tearoff=0)
        self.MenuClicDroitPDF.add_command(label="Recherche internet", command=self.ChercheFDS)
        self.NoPDF.CanvasImgNoPdf.bind("<Button-3>", self.AffichMenuClicDroitPDF)
        self.BtnImportPDF = BtnAction(self.CanvasMenu3.CanvasMenu,
                                      int(int(self.CanvasMenu3.CanvasMenu['width']) * 0.91),
                                      int(int(self.CanvasMenu3.CanvasMenu['height']) * 0.06), self.RatioX,
                                      self.RatioY, 'Media/FrmAjout/BtnPDF/')
        self.BtnSuppPDF = BtnAction(self.CanvasMenu3.CanvasMenu, int(int(self.CanvasMenu3.CanvasMenu['width']) * 0.96),
                                    int(int(self.CanvasMenu3.CanvasMenu['height']) * 0.06), self.RatioX,
                                    self.RatioY, 'Media/FrmAjout/BtnSupp/')

        self.BtnImportPDF.CanvasBtn.bind('<ButtonRelease-1>', self.ChargePDF)
        self.BtnSuppPDF.CanvasBtn.bind('<ButtonRelease-1>', self.SupPDF)

        self.BtnOK = BtnAction(self.CanvasFrmFond, int(self.SX * 0.962), int(self.SY * 0.975), self.RatioX * 0.15,
                               self.RatioX * 0.15, 'Media/FrmAjout/BtnOK/')
        self.BtnAnnul = BtnAction(self.CanvasFrmFond, int(self.SX * 0.985), int(self.SY * 0.975), self.RatioX * 0.15,
                                  self.RatioX * 0.15, 'Media/FrmAjout/BtnAnnul/')
        ChangeCursor(self.BtnAnnul.CanvasBtn)
        ChangeCursor(self.BtnOK.CanvasBtn)
        self.BtnAnnul.CanvasBtn.bind('<ButtonRelease-1>', self.CacheFrmAjout)
        self.BtnOK.CanvasBtn.bind('<ButtonRelease-1>', self.SaveNewProd)

        if self.MainAppli.NAction != 103:
            self.AffichInfoProd()
            self.TextAction = 'Mise à jour - Produit chimique - '
        else:
            self.TextAction = 'Ajout - Produit chimique - '

        self.CanvasFrmFond.pack()

    def ModifFonction(self, _):
        self.MainAppli.cur.execute('SELECT FONCTION, LIEUX'
                                   ' FROM PRODUITS WHERE FONCTION LIKE \"%' + self.FonctionProd.EntryData.get() +
                                   '%\" AND UNITMES = "' + self.unit + '" order by FONCTION')
        Fct = self.MainAppli.cur.fetchall()
        if len(Fct) > 0:
            self.FonctionProd.Data.set(Fct[0][0])
            self.LieuStockProd.Data.set(Fct[0][1])

    def ModifLieux(self,_):
        self.MainAppli.cur.execute('SELECT LIEUX'
                                   ' FROM PRODUITS WHERE LIEUX LIKE \"%' + self.LieuStockProd.EntryData.get() +
                                   '%\" order by LIEUX')
        Lieu = self.MainAppli.cur.fetchall()
        if len(Lieu) > 0:
            self.LieuStockProd.Data.set(Lieu[0][0])

    def MoveOnCanvas(self, _):
        self.CanvasBtnClose.itemconfig(self.ImgCanvasBtnClose, image=self.ImgBtnClose[0])
        self.MainAppli.CanvasBtnQuit.itemconfig(self.MainAppli.ImgCanvasBtnQuit, image=self.MainAppli.ImgBtnQuit[0])

    def ClicOnCanvas(self, _):
        if self.FrmModifFour is not None:
            self.FrmModifFour.lift()

    def ChangeCont(self, _):
        self.ActionChangeCont()
        self.ModifFonction(_)

    def ActionChangeCont(self):
        self.CanvasCont.CanvasListIma.itemconfig(self.CanvasCont.ImgCanvasListIma,
                                                 image=self.CanvasCont.ListIma[self.ListeCont.current()])
        if self.ListeCont.current() == 1 or self.ListeCont.current() == 2 or self.ListeCont.current() == 3:
            if self.MenuPicto is None:
                if self.EntryDensit is not None:
                    self.EntryDensit.EntryData.destroy()
                    self.CanvasCont.CanvasListIma.delete(self.TitreD)
                    del (self.ListCaract[9])
                    del (self.ListMenuClicDroitCaract[9])
                    self.EntryDensit = None
                if self.ListeCont.current() == 1:
                    self.LabelQStock.Label.config(text='Quantité en stock (g):')
                    self.LabelQUtil.Label.config(text='Quantité utilisée / an (g):')
                    self.CanvasEtiqPrix.CanvasListIma.itemconfigure(self.TextCdt, text="Cdt (g):")
                    self.unit = "g"
                elif self.ListeCont.current() == 2:
                    self.LabelQStock.Label.config(text='Quantité en stock (L):')
                    self.LabelQUtil.Label.config(text='Quantité utilisée / an (L):')
                    self.CanvasEtiqPrix.CanvasListIma.itemconfigure(self.TextCdt, text="Cdt (L):")
                    self.FonctionProd.EntryData.delete(0, tk.END)
                    self.FonctionProd.EntryData.insert(0, 'GAZ')
                    self.unit = "L"
                elif self.ListeCont.current() == 3:
                    self.LabelQStock.Label.config(text='Quantité en stock (Unit):')
                    self.LabelQUtil.Label.config(text='Quantité utilisée / an (Unit):')
                    self.CanvasEtiqPrix.CanvasListIma.itemconfigure(self.TextCdt, text="Cdt (Unit):")
                    self.unit = "Unit"
        else:
            if self.MenuPicto is None:
                self.EntryDensit = EntryData(self.CanvasCont.CanvasListIma, int(self.CanvasCont.wsize * 0.05),
                                             int(self.CanvasCont.wsize * 0.5), int(self.CanvasCont.hsize * 0.57),
                                             tk.CENTER, AppliFont('Helvetica', self.MainAppli.SizeFont, 'bold', 0))
                self.EntryDensit.Data.set('')
                self.ListCaract.append(self.EntryDensit.EntryData)
                self.ListMenuClicDroitCaract.append(tk.Menu(self.CanvasCont.CanvasListIma, tearoff=0))
                self.ListMenuClicDroitCaract[9].add_command(label="Recherche internet", command=self.ChercheWeb)

                def GestEvt(evt, j=9):
                    return self.AffichMenuClicDroitCaract(evt, j)

                self.ListCaract[9].bind("<Button-3>", GestEvt)
                self.TitreD = self.CanvasCont.CanvasListIma.create_text(int(self.CanvasCont.wsize * 0.275),
                                                                        int(self.CanvasCont.hsize * 0.57), text='d:',
                                                                        font=AppliFont('Helvetica',
                                                                                       self.MainAppli.SizeFont,
                                                                                       'bold', 0), anchor=tk.W)
                self.EntryDensit.EntryData.config(justify='center')
                self.LabelQStock.Label.config(text='Quantité en stock (mL):')
                self.LabelQUtil.Label.config(text='Quantité utilisée / an (mL):')
                self.CanvasEtiqPrix.CanvasListIma.itemconfigure(self.TextCdt, text="Cdt (mL):")
                self.unit = "mL"

    def SelectDanger(self, j):
        if self.MenuPicto is None:
            self.MenuPicto = MenuPicto(self.CanvasCont.CanvasListIma, 'Media/FrmAjout/MenuPicto/',
                                       int(self.CanvasCont.wsize * 0.743), int(self.CanvasCont.hsize * 0.5),
                                       int(self.CanvasCont.wsize * 0.505), int(self.CanvasCont.hsize * 0.551),
                                       self.RatioX * 0.7, self.MainAppli.SizeFont - 1, j, self)

    def EffacerPicto(self):
        self.CanvasGHS[self.NPictoSelected].CanvasListIma.itemconfig(
            self.CanvasGHS[self.NPictoSelected].ImgCanvasListIma,
            image=self.CanvasGHS[self.NPictoSelected].ListIma[10])
        self.ListNDanger[self.NPictoSelected] = 10
        self.AjoutDangerArmoire()

    def EffacerFD(self):
        self.CanvasContEtiqProd.destroy()
        self.CanvasImgEtiqArmoire.destroy()
        for i in range(1, 5):
            self.CanvasArmoire.CanvasListIma.delete('Line' + str(i))
        self.CanvasFD.CanvasListIma.itemconfig(self.CanvasFD.ImgCanvasListIma, image=self.CanvasFD.ListIma[0])
        self.VisuelFD = ''

    def ChargeFD(self, _):
        self.PathFilejpgToOpen = ''
        self.PathFilejpgToOpen = tkfiledialog.askopenfilename(title="Ouvrir un fichier",
                                                              filetypes=[('JPG files', '*.*')], parent=self)
        if self.PathFilejpgToOpen != '':
            self.AffichFD(self.PathFilejpgToOpen)
            self.AjoutFDArmoire()

        self.lift()

    def ColleFD(self):
        img = ImageGrab.grabclipboard()
        if img is not None:
            self.PathFilejpgToOpen = 'Datas/Temp/FD.png'
            img.save(self.PathFilejpgToOpen)
            self.AffichFD(self.PathFilejpgToOpen)
            self.AjoutFDArmoire()

    def AffichFD(self, path):
        self.ImgEtiqProd = []
        img = Image.open(path)
        imgEtiqwsize = int(self.CanvasCont.wsize * 0.28)
        imgEtiqhsize = int(imgEtiqwsize * float(img.size[1]) / float(img.size[0]))
        if imgEtiqhsize > self.CanvasCont.hsize * 0.078:
            imgEtiqhsize = int(self.CanvasCont.hsize * 0.078)
            imgEtiqwsize = int(imgEtiqhsize * float(img.size[0]) / float(img.size[1]))
        img = img.resize((imgEtiqwsize, imgEtiqhsize), Image.ANTIALIAS)
        self.ImgEtiqProd.append(ImageTk.PhotoImage(img))
        self.img = img

        if self.CanvasContEtiqProd is not None:
            self.CanvasContEtiqProd.destroy()
        self.CanvasContEtiqProd = CanvasApp(self.CanvasCont.CanvasListIma, width=imgEtiqwsize, height=imgEtiqhsize)
        self.CanvasCont.CanvasListIma.create_window(int(self.CanvasCont.wsize * 0.5),
                                                    int(self.CanvasCont.hsize * 0.41), anchor=tk.CENTER,
                                                    window=self.CanvasContEtiqProd)
        self.ImgCanvasContEtiqProd = self.CanvasContEtiqProd.create_image(0, 0, anchor=tk.NW,
                                                                          image=self.ImgEtiqProd[0])
        self.CanvasFD.CanvasListIma.itemconfig(self.CanvasFD.ImgCanvasListIma, image=self.CanvasFD.ListIma[1])
        ChangeCursor(self.CanvasContEtiqProd)
        self.CanvasContEtiqProd.bind('<ButtonRelease-1>', self.ChargeFD)

        self.MenuClicDroitFD = tk.Menu(self.CanvasContEtiqProd, tearoff=0)
        self.MenuClicDroitFD.add_command(label="Effacer", command=self.EffacerFD)
        self.CanvasContEtiqProd.bind("<Button-3>", self.AffichMenuClicDroitFD)

    def ChargePDF(self, _):
        self.PathFilePDFToOpen = tkfiledialog.askopenfilename(title="Ouvrir un fichier",
                                                              filetypes=[('PDF files', '.pdf')], parent=self)
        if self.PathFilePDFToOpen != '':
            self.FrmPDF = FrmPDF(self.CanvasSousMenu3, self.PathFilePDFToOpen, 1.3,
                                 int(self.CanvasMenu3.CanvasMenu['height']),
                                 int(int(self.CanvasSousMenu3['width']) * 0.5),
                                 int(int(self.CanvasSousMenu3['height']) * 0.48),
                                 int(int(self.CanvasSousMenu3['width']) * 0.98),
                                 int(int(self.CanvasSousMenu3['height']) * 0.9))
            self.FrmPDF.CanvasDoc.bind('<Double-1>', self.OuvreFDS)
            self.MenuClicDroitPDF = tk.Menu(self.FrmPDF.CanvasDoc, tearoff=0)
            self.MenuClicDroitPDF.add_command(label="Recherche internet", command=self.ChercheFDS)
            self.MenuClicDroitPDF.add_separator()
            self.MenuClicDroitPDF.add_command(label="Supprimer la FDS", command=self.ActionSupPDF)
            self.FrmPDF.CanvasDoc.bind("<Button-3>", self.AffichMenuClicDroitPDF)
            self.DocPDF = True

        self.lift(self.parent)

    def SupPDF(self, _):
        self.ActionSupPDF()

    def ActionSupPDF(self):
        self.BtnSuppPDF.CanvasBtn.itemconfig(self.BtnSuppPDF.ImgCanvasBtn, image=self.BtnSuppPDF.ImgBtn[0])
        if self.DocPDF:
            for widget in self.FrmPDF.Container.winfo_children():
                widget.destroy()
            self.FrmPDF.CanvasScale.destroy()
            self.NoPDF = NoPDF(self.CanvasSousMenu3, 'Media/FrmAjout/NoPDF/NoPDF.jpg',
                               int(int(self.CanvasSousMenu3['width']) * 0.5),
                               int(int(self.CanvasSousMenu3['height']) * 0.5),
                               self.RatioX, self.RatioY)
            ChangeCursor(self.NoPDF.CanvasImgNoPdf)
            self.NoPDF.CanvasImgNoPdf.bind('<ButtonRelease-1>', self.ChargePDF)
            self.MenuClicDroitPDF = tk.Menu(self.NoPDF.CanvasImgNoPdf, tearoff=0)
            self.MenuClicDroitPDF.add_command(label="Recherche internet", command=self.ChercheFDS)
            self.NoPDF.CanvasImgNoPdf.bind("<Button-3>", self.AffichMenuClicDroitPDF)
            self.DocPDF = False
        self.DocFDS = ""

    def AjoutDangerArmoire(self):
        for i in range(len(self.CanvasGHSArmoire)):
            self.CanvasGHSArmoire[i].CanvasListIma.destroy()
        deb = 0
        NbrDanger = 0
        self.CanvasGHSArmoire = []
        for i in range(3):
            if self.ListNDanger[i] != 10:
                NbrDanger = NbrDanger + 1
        if NbrDanger == 3:
            deb = int(self.CanvasCont.wsize * 0.4)
        elif NbrDanger == 2:
            deb = int(self.CanvasCont.wsize * 0.45)
        elif NbrDanger == 1:
            deb = int(self.CanvasCont.wsize * 0.5)
        n = 0
        for i in range(3):
            if self.ListNDanger[i] != 10:
                self.CanvasGHSArmoire.append(
                    CanvasInWindow('Media/FrmAjout/Picto/', self.RatioX * 0.6, self.RatioX * 0.6,
                                   self.CanvasArmoire.CanvasListIma,
                                   tk.CENTER, int(self.CanvasArmoire.wsize * 0.13),
                                   deb + int(n * self.CanvasArmoire.hsize * 0.15),
                                   self.ListNDanger[i]))
                n = n + 1

    def AjoutFDArmoire(self):
        self.ImgEtiqArmoire = []
        imgEtiqwsize = int(self.CanvasArmoire.wsize * 0.2)
        imgEtiqhsize = int(imgEtiqwsize * float(self.img.size[1]) / float(self.img.size[0]))
        if imgEtiqhsize > self.CanvasArmoire.hsize * 0.2:
            imgEtiqhsize = int(self.CanvasArmoire.hsize * 0.2)
            imgEtiqwsize = int(imgEtiqhsize * float(self.img.size[0]) / float(self.img.size[1]))
        img = self.img.resize((imgEtiqwsize, imgEtiqhsize), Image.ANTIALIAS)
        self.ImgEtiqArmoire.append(ImageTk.PhotoImage(img))

        self.CanvasImgEtiqArmoire = CanvasApp(self.CanvasArmoire.CanvasListIma, width=imgEtiqwsize,
                                              height=imgEtiqhsize)
        self.CanvasArmoire.CanvasListIma.create_window(int(self.CanvasArmoire.wsize * 0.145),
                                                       int(self.CanvasArmoire.hsize * 0.065), anchor=tk.N,
                                                       window=self.CanvasImgEtiqArmoire)
        self.ImgCanvasImgEtiqArmoire = self.CanvasImgEtiqArmoire.create_image(0, 0, anchor=tk.NW,
                                                                              image=self.ImgEtiqArmoire[0])
        CreateCadre(self.CanvasArmoire.CanvasListIma, int(self.CanvasArmoire.wsize * 0.14 - imgEtiqwsize / 2),
                    int(self.CanvasArmoire.hsize * 0.06),
                    int(self.CanvasArmoire.wsize * 0.148 - imgEtiqwsize / 2) + imgEtiqwsize,
                    int(self.CanvasArmoire.hsize * 0.065) + imgEtiqhsize)

    def AffichMenuClicDroit(self, event, j):
        self.MenuClicDroit[j].post(event.x_root, event.y_root)
        self.NPictoSelected = j

    def AffichMenuClicDroitFD(self, event):
        self.MenuClicDroitFD.post(event.x_root, event.y_root)

    def AffichMenuClicDroitPDF(self, event):
        self.MenuClicDroitPDF.post(event.x_root, event.y_root)

    def ChargeFournisseur(self, _):
        self.MainAppli.cur.execute("select " + self.MainAppli.ListChampsTabFournisseurs +
                                   " from Fournisseurs order by NOM")
        self.ListFours = self.MainAppli.cur.fetchall()
        self.FrmModifFour = FrmModifFour(self.CanvasFrmFond, self.RatioX, self.RatioY, self.ListFours, 0, self)

    def ModifNom(self, _):
        self.CanvasEtiqPrix.CanvasListIma.itemconfig(self.EtiqPrixNomProd, text=self.EntryNom.EntryData.get())
        self.NomProduit.Label.config(text=self.EntryNom.EntryData.get())
        if self.EntryNom.EntryData.get() != self.NomInit:
            self.ActionModifNom = True
        else:
            self.ActionModifNom = False

    def SaveNewProd(self, _):
        if self.EntryNom.EntryData.get() != '':
            self.MainAppli.cur.execute("Select * from PRODUITS where NOMS = '" + self.EntryNom.EntryData.get() + "'")
            Rep = True
            NOcur = len(self.MainAppli.cur.fetchall())
            if NOcur > 0:
                Rep = tkMB.askyesno('Attention', 'Un produit nommé "' + self.EntryNom.EntryData.get()
                                    + '" est déja présent dans la base de données, souhaitez-vous mettre à jour '
                                      'les données?', parent=self)
            if Rep:
                if NOcur > 0:
                    SQLRequet = "DELETE FROM PRODUITS WHERE NOMS='" \
                                + self.EntryNom.EntryData.get() + "'"
                    self.MainAppli.cur.execute(SQLRequet)
                    self.MainAppli.DataBaseChimie.commit()

                Nom = self.EntryNom.EntryData.get()
                NomSave = ModifString(self.EntryNom.EntryData.get())
                self.MainAppli.cur.execute("Select NOMS from PRODUITS")
                LNoms = self.MainAppli.cur.fetchall()
                Ocur = False
                for i in range(len(LNoms)):
                    if ModifString(LNoms[i][0]) == NomSave:
                        Ocur = True
                        break
                if Ocur:
                    NomSave = ModifString(NomSave + str(datetime.now()))

                densite = None
                if self.ListeCont.current() == 1:
                    unit = "g"
                    densite = None
                elif self.ListeCont.current() == 0:
                    unit = 'mL'
                    densite = self.EntryDensit.EntryData.get()
                elif self.ListeCont.current() == 2:
                    unit = 'L'
                else:
                    unit = 'Unit'
                if self.PathFilejpgToOpen != '':
                    FD = NomSave
                    shutil.copy(self.PathFilejpgToOpen, 'Datas/FormDev/' + FD)
                elif self.ActionModifNom:
                    if self.VisuelFD != '':
                        FD = NomSave
                        if not os.path.exists('Datas/FormDev/' + FD):
                            shutil.copy('Datas/FormDev/' + self.VisuelFD, 'Datas/FormDev/' + FD)
                    else:
                        FD = self.VisuelFD
                else:
                    FD = self.VisuelFD
                FB = self.EntryFB.EntryData.get()
                ListDanger = ModifListDanger2(self.ListNDanger)
                Fonction = self.FonctionProd.EntryData.get()
                Lieu = self.LieuStockProd.EntryData.get()
                Fournisseur = self.Fournisseur
                Syno = self.EntrySyno.EntryData.get()
                MM = self.EntryMM.EntryData.get()
                MP = self.EntryMP.EntryData.get()
                Solub = self.EntrySolub.EntryData.get()
                Risque = self.EntryDanger.EntryData.get()
                Prud = self.EntryPrud.EntryData.get()
                if self.PathFilePDFToOpen != '':
                    FDS = NomSave
                    shutil.copy(self.PathFilePDFToOpen, 'Datas/FDS/' + FDS + '.pdf')
                elif self.ActionModifNom:
                    if self.DocFDS != '':
                        FDS = NomSave
                        if not os.path.exists('Datas/FDS/' + FDS + '.pdf'):
                            shutil.copy('Datas/FDS/' + self.DocFDS + '.pdf', 'Datas/FDS/' + FDS + '.pdf')
                    else:
                        FDS = self.DocFDS
                else:
                    FDS = self.DocFDS
                Qstock = self.QuantStockProd.EntryData.get()
                Qutil = self.QuantUtil.EntryData.get()
                ref = self.Ref.EntryData.get()
                Cdt = self.Cdt.EntryData.get()
                PHT = self.PrixHT.EntryData.get()
                CAS = self.CAS.EntryData.get()
                data = [(Nom, unit, FD, ListDanger[0], ListDanger[1], ListDanger[2], FB, Fonction, Lieu, Fournisseur,
                         Syno, MM, densite, MP, Solub, Risque, Prud, FDS, Qstock, Qutil, ref, Cdt, PHT, self.QCOM,
                         self.QCOMANNUL, self.QENCOM, CAS)]
                self.MainAppli.cur.execute(
                    "INSERT INTO PRODUITS(" + self.MainAppli.ListChampsTabProd + ") VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,"
                                                                                 "?,?,?,?,?,?,?,?,?,?,?,?,?, ?)",
                    data[0])

                self.MainAppli.DataBaseChimie.commit()
                self.MainAppli.SaveListModifDTB('Chimie', self.TextAction + Nom)
                self.MainAppli.cur.execute("select " + self.MainAppli.ListChampsTabProd +
                                           " from PRODUITS order by NOMS")
                self.MainAppli.ListProduits = self.MainAppli.cur.fetchall()

                if FD != self.VisuelFDInit and not self.ActionModifNom and self.VisuelFDInit != '':
                    if os.path.exists('Datas/FormDev/' + self.VisuelFDInit):
                        os.remove('Datas/FormDev/' + self.VisuelFDInit)

                if FDS != self.DocFDSInit and not self.ActionModifNom and self.DocFDSInit != '':
                    if os.path.exists('Datas/FDS/' + self.DocFDSInit + '.pdf'):
                        os.remove('Datas/FDS/' + self.DocFDSInit + '.pdf')

                if self.MainAppli.NAction == 104:
                    if self.MainAppli.OldNAction == 1:
                        self.MainAppli.ChargeListProduits(self.MainAppli.ListProduits)
                        self.MainAppli.AffichEtagProduits(self.MainAppli.ListProduits)
                    elif self.MainAppli.OldNAction == 1011:
                        self.MainAppli.NAction = 101
                        self.MainAppli.ActionRecherche()
                    elif self.MainAppli.OldNAction == 1022:
                        self.MainAppli.AffichListProdCat(self.MainAppli.NSCatselected)
                else:
                    self.MainAppli.ChargeListProduits(self.MainAppli.ListProduits)
                    self.MainAppli.AffichEtagProduits(self.MainAppli.ListProduits)

                try:
                    self.MainAppli.IndexElt = self.MainAppli.ListNomProd.index(Nom)
                    NEtag = CalculNEtag(self.MainAppli.IndexElt + 1, 15)
                    self.MainAppli.NEtag = NEtag
                    self.MainAppli.EtagProduits.DefilProduits.set(NEtag)
                    if NEtag == 0:
                        self.MainAppli.EtagProduits.SelectProd(self.MainAppli.IndexElt)
                except:
                    pass

                self.CacheFrmAjout(_)
            else:
                self.BtnOK.CanvasBtn.itemconfig(self.BtnOK.ImgCanvasBtn, image=self.BtnOK.ImgBtn[0])
                self.lift()
        else:
            tkMB.showwarning('Attention', "Veuillez indiquer le nom du produit!")
            self.lift()

    def AffichInfoProd(self):
        Prod = []
        if self.MainAppli.NAction == 1:
            Prod = self.MainAppli.ListProduits[self.MainAppli.IndexElt]
        elif self.MainAppli.NAction == 1011:
            Prod = self.MainAppli.ListRecherch[self.MainAppli.IndexElt]
        elif self.MainAppli.NAction == 1022:
            Prod = self.MainAppli.ListProdCat[self.MainAppli.IndexElt]
        ChargeEntry(self.EntryNom, Prod[0])
        self.NomInit = Prod[0]
        self.CanvasEtiqPrix.CanvasListIma.itemconfig(self.EtiqPrixNomProd, text=self.EntryNom.EntryData.get())
        self.NomProduit.Label.config(text=self.EntryNom.EntryData.get())

        if Prod[1] == "g":
            self.ListeCont.current(1)
            self.unit = "g"
        elif Prod[12] is not None and Prod[12] != '' or (Prod[1] == 'mL' and Prod[7].upper() != 'GAZ'):
            self.ListeCont.current(0)
            self.unit = "mL"
        elif Prod[7] is not None and Prod[7].upper() == 'GAZ':
            self.ListeCont.current(2)
            self.unit = "L"
        elif Prod[1].upper() == 'UNIT' or Prod[1] == '':
            self.ListeCont.current(3)
            self.unit = "Unit"

        self.ActionChangeCont()
        if self.EntryDensit is not None:
            ChargeEntry(self.EntryDensit, Prod[12])

        if Prod[2] is not None and Prod[2] != '' and os.path.exists('Datas/FormDev/' + Prod[2]):
            self.VisuelFD = Prod[2]
            self.VisuelFDInit = self.VisuelFD
            self.AffichFD('Datas/FormDev/' + Prod[2])
            self.AjoutFDArmoire()

        listGHS = []
        for i in range(3):
            if Prod[i + 3] is not None and Prod[i + 3] != '':
                listGHS.append(Prod[i + 3])
        self.ListNDanger = ModifListDanger(listGHS)
        for i in range(len(self.ListNDanger), 3):
            self.ListNDanger.append(10)
        for i in range(3):
            if self.ListNDanger[i] != 10:
                self.CanvasGHS[i].CanvasListIma.itemconfig(self.CanvasGHS[i].ImgCanvasListIma,
                                                           image=self.CanvasGHS[i].ListIma[self.ListNDanger[i]])
        self.AjoutDangerArmoire()

        ChargeEntry(self.EntryFB, Prod[6])
        ChargeEntry(self.FonctionProd, Prod[7])
        ChargeEntry(self.LieuStockProd, Prod[8])

        self.AffichLogoFour(Prod[9])

        ChargeEntry(self.EntrySyno, Prod[10])
        ChargeEntry(self.EntryMM, Prod[11])
        ChargeEntry(self.EntryMP, Prod[13])
        ChargeEntry(self.EntrySolub, Prod[14])
        ChargeEntry(self.EntryDanger, Prod[15])
        ChargeEntry(self.EntryPrud, Prod[16])

        if Prod[17] is not None and Prod[17] != '' and os.path.exists('Datas/FDS/' + Prod[17] + '.pdf'):
            self.FrmPDF = FrmPDF(self.CanvasSousMenu3, 'Datas/FDS/' + Prod[17] + '.pdf', 1.3,
                                 int(self.CanvasMenu3.CanvasMenu['height']),
                                 int(int(self.CanvasSousMenu3['width']) * 0.5),
                                 int(int(self.CanvasSousMenu3['height']) * 0.48),
                                 int(int(self.CanvasSousMenu3['width']) * 0.98),
                                 int(int(self.CanvasSousMenu3['height']) * 0.9))
            self.FrmPDF.CanvasDoc.bind('<Double-1>', self.OuvreFDS)
            self.MenuClicDroitPDF = tk.Menu(self.FrmPDF.CanvasDoc, tearoff=0)
            self.MenuClicDroitPDF.add_command(label="Recherche internet", command=self.ChercheFDS)
            self.MenuClicDroitPDF.add_separator()
            self.MenuClicDroitPDF.add_command(label="Supprimer la FDS", command=self.ActionSupPDF)
            self.FrmPDF.CanvasDoc.bind("<Button-3>", self.AffichMenuClicDroitPDF)
            self.DocPDF = True
            self.DocFDS = Prod[17]
            self.DocFDSInit = self.DocFDS

        ChargeEntry(self.QuantStockProd, Prod[18])
        ChargeEntry(self.QuantUtil, Prod[19])
        ChargeEntry(self.Ref, Prod[20])
        ChargeEntry(self.Cdt, Prod[21])
        ChargeEntry(self.PrixHT, Prod[22])

        if Prod[23] is not None and Prod[23] != '':
            self.QCOM = Prod[23]
        if Prod[24] is not None and Prod[24] != '':
            self.QCOMANNUL = Prod[24]
        if Prod[25] is not None and Prod[25] != '':
            self.QENCOM = Prod[25]
        if Prod[26] is not None and Prod[26] != '':
            ChargeEntry(self.CAS, Prod[26])

    def AffichMenuClicDroitCaract(self, event, j):
        self.ListMenuClicDroitCaract[j].post(event.x_root, event.y_root)
        self.NCaract = j

    def AffichMenuClicDroitRefFour(self, event, j):
        self.ListMenuClicDroitRefFour[j].post(event.x_root, event.y_root)
        self.NRefFour = j

    def ChercheWeb(self):
        CaractList = ['Formule topologique', 'Formule brute', 'Synonyme', 'Masse molaire', 'Point de fusion',
                      "Hydrosolubilité", 'Mentions de danger', 'Conseils de prudence', 'Densité']
        if self.NCaract == 0:
            webbrowser.open('https://fr.wikipedia.org/wiki/' + self.EntryNom.EntryData.get(), new=1)
        else:
            webbrowser.open('https://www.google.fr/search?q=' + CaractList[self.NCaract - 1] + ' - ' +
                            self.EntryNom.EntryData.get(), new=1)

    def ChercheWebFour(self):
        RefFourList = ['Fournisseur', 'Fournisseur', 'Référence', 'Conditionnement', 'Prix', 'Numéro CAS']
        if self.Fournisseur != '':
            if self.NRefFour < 2:
                webbrowser.open('https://www.google.fr/search?q=' + self.Fournisseur + ' - ' +
                                self.EntryNom.EntryData.get(), new=1)
            else:
                webbrowser.open('https://www.google.fr/search?q=' + self.Fournisseur + ' - ' +
                                RefFourList[self.NRefFour] + ' - ' + self.EntryNom.EntryData.get(), new=1)
        else:
            webbrowser.open('https://www.google.fr/search?q=' + RefFourList[self.NRefFour] + ' - ' +
                            self.EntryNom.EntryData.get(), new=1)

    def ChercheFDS(self):
        webbrowser.open('https://www.google.fr/search?q=Fiche de sécurité - ' + self.EntryNom.EntryData.get(), new=1)

    def OuvreFDS(self, _):
        self.ActionOuvreFDS()

    def ActionOuvreFDS(self):
        if self.PathFilePDFToOpen == '':
            AffichPDF(self.EntryNom.EntryData.get() + ' - FDS', 'Datas/FDS/' + self.DocFDS + '.pdf', self)
        else:
            AffichPDF(self.EntryNom.EntryData.get() + ' - FDS', self.PathFilePDFToOpen, self)

    def ClosePDF(self):
        self.MainAppli.parent.focus_force()
        self.MainAppli.FrmLift()
        self.focus_force()

    def AffichLogoFour(self, Four):
        Logo = []
        if Four is not None and Four != '':
            self.MainAppli.cur.execute('SELECT Logo'
                                       ' FROM Fournisseurs WHERE NOM LIKE \'%' + Four + '%\' order by NOM')
            Logo = self.MainAppli.cur.fetchall()
        if len(Logo) > 0 and Logo[0][0] != '' and Logo[0][0] is not None:
            PathLogo = 'Datas/Fournisseurs/Logos/' + Logo[0][0]
            self.Fournisseur = Logo[0][0]
        else:
            if Four is None or Four == '':
                PathLogo = 'Datas/Fournisseurs/Logos/NC'
                self.Fournisseur = ''
            else:
                PathLogo = 'Datas/Fournisseurs/Logos/Vide'
                self.Fournisseur = Four
        self.ImgFournisseur.CanvasImg.destroy()
        self.ImgFournisseur = ImgInCanvas(self.CanvasMenu2.CanvasMenu, PathLogo, 0.4,
                                          tk.CENTER, int(int(self.CanvasMenu2.CanvasMenu['width']) * 0.5),
                                          int(int(self.CanvasMenu2.CanvasMenu['height']) * 0.7))
        ChangeCursor(self.ImgFournisseur.CanvasImg)
        self.ImgFournisseur.CanvasImg.bind('<ButtonRelease-1>', self.ChargeFournisseur)
        self.ListRefFour[0] = self.ImgFournisseur.CanvasImg
        self.ListMenuClicDroitRefFour[0] = tk.Menu(self.ImgFournisseur.CanvasImg, tearoff=0)
        self.ListMenuClicDroitRefFour[0].add_command(label="Recherche internet", command=self.ChercheWebFour)

        def GestEvt(evt, j=0):
            return self.AffichMenuClicDroitRefFour(evt, j)

        self.ListRefFour[0].bind("<Button-3>", GestEvt)

        if (len(Logo) == 0 or Logo[0][0] == '' or Logo[0][0] is None) and self.Fournisseur != '':
            if len(self.Fournisseur) < 15:
                TextFournisseur = self.Fournisseur
            else:
                TextFournisseur = self.Fournisseur.split(' ')[0]
                for i in range(1, len(self.Fournisseur.split(' '))):
                    TextFournisseur = TextFournisseur + '\n' + self.Fournisseur.split(' ')[i]
            self.ImgFournisseur.CanvasImg.create_text(int(int(self.ImgFournisseur.CanvasImg['width']) * 0.5),
                                                      int(int(self.ImgFournisseur.CanvasImg['height']) * 0.5),
                                                      text=TextFournisseur,
                                                      font=AppliFont('Helvetica', self.MainAppli.SizeFont + 4, 'bold',
                                                                     0), anchor=tk.CENTER, justify=tk.CENTER)

    def CacheFrmAjout(self, _):
        self.CanvasBtnClose.itemconfig(self.ImgCanvasBtnClose, image=self.ImgBtnClose[0])
        self.MainAppli.ListBtnActionV[2].CanvasBtn.itemconfig(self.MainAppli.ListBtnActionV[2].ImgCanvasBtn,
                                                              image=self.MainAppli.ListBtnActionV[2].ImgBtn[0])
        self.destroy()
        if self.MainAppli.OldNAction != 0:
            self.MainAppli.NAction = self.MainAppli.OldNAction
        else:
            self.MainAppli.NAction = 1
        self.MainAppli.MAJInfo()
        self.MainAppli.parent.lift()
        self.MainAppli.FrmLift()
        self.MainAppli.ModifEnCours = False


class MenuPicto:
    def __init__(self, container, path, W, H, X, Y, ratio, sizefont, N, MainAppli):

        self.MainAppli = MainAppli
        self.N = N
        self.CanvasMenuPicto = CanvasMenu(container, path, W, H, X, Y, tk.CENTER)

        self.ListDanger = ['Attention', 'CMR', 'Corrosif', 'Comburant', 'Danger', 'Explosif', 'Inflammable',
                           'Gaz sous pression', "Nocif pour l'environnement", 'Toxique']
        self.CanvasGHS = []
        self.LabelGHS = []
        l = 0
        c = 0
        for i in range(10):
            self.CanvasGHS.append(CanvasInWindow('Media/PictoDanger/', ratio, ratio, self.CanvasMenuPicto.CanvasMenu,
                                                 tk.CENTER, int(W * 0.25 + c * W * 0.48),
                                                 int(H * 0.085 + l * H * 0.19), i))
            self.LabelGHS.append(LabelInCanvas(self.CanvasMenuPicto.CanvasMenu, self.ListDanger[i], '#E0E0E0',
                                               AppliFont('Helvetica', sizefont, 'normal', 0),
                                               int(W * 0.25 + c * W * 0.48),
                                               int(H * 0.18 + l * H * 0.19), tk.CENTER))
            c = c + 1
            if c > 1:
                c = 0
                l = l + 1

            ChangeCursor(self.CanvasGHS[i].CanvasListIma)
            ChangeCursor(self.LabelGHS[i].Label)

            def GestEvt(_, j=i):
                return self.SelectDanger(j)

            self.CanvasGHS[i].CanvasListIma.bind('<ButtonRelease-1>', GestEvt)
            self.LabelGHS[i].Label.bind('<ButtonRelease-1>', GestEvt)

    def SelectDanger(self, j):
        self.CanvasMenuPicto.CanvasMenu.destroy()
        self.MainAppli.ListNDanger[self.N] = j
        self.MainAppli.CanvasGHS[self.N].CanvasListIma.itemconfig(self.MainAppli.CanvasGHS[self.N].ImgCanvasListIma,
                                                                  image=self.MainAppli.CanvasGHS[self.N].ListIma[j])
        self.MainAppli.MenuPicto = None
        self.MainAppli.AjoutDangerArmoire()
        if self.MainAppli.ListeCont.current() == 0:
            self.MainAppli.EntryDensit = EntryData(self.MainAppli.CanvasCont.CanvasListIma,
                                                   int(self.MainAppli.CanvasCont.wsize * 0.05),
                                                   int(self.MainAppli.CanvasCont.wsize * 0.5),
                                                   int(self.MainAppli.CanvasCont.hsize * 0.57),
                                                   tk.CENTER,
                                                   AppliFont('Helvetica', self.MainAppli.MainAppli.SizeFont, 'bold', 0))
            self.MainAppli.EntryDensit.Data.set('Densité')
            self.MainAppli.EntryDensit.EntryData.config(justify='center')
        else:
            if self.MainAppli.EntryDensit is not None:
                self.MainAppli.EntryDensit.EntryData.destroy()
                self.MainAppli.EntryDensit = None


class FrmModifFour(tk.Toplevel):
    def __init__(self, container, RatioX, RatioY, ListFour, Type, Appli):
        tk.Toplevel.__init__(self, container)
        self.MainAppli = Appli
        self.parent = container
        self.ListFour = ListFour
        self.RatioX = RatioX
        self.RatioY = RatioY
        self.FrameLogos = None
        self.Fournisseur = ''
        self.ListNomNewFour = []
        self.CanvasImg = []
        self.Img = []
        self.scrollable_canvas = None
        XY = [(0.7165, 0.06), (0.005, 0.06)]

        screen = ctypes.windll.user32
        FrmFond = Image.open('Media/FrmAjout/Menu/Fond.jpg')
        self.SX = int((float(FrmFond.size[0]) * float(self.RatioX * 0.93)))
        self.SY = int((float(FrmFond.size[1]) * float(self.RatioY)))

        self.ImgFrmFond = []
        self.ImgFrmFond = RedimImg(self.SX, self.SY, 'Media/FrmAjout/Menu/')
        self.CanvasFrmFond = CanvasApp(self, width=self.SX, height=self.SY)
        self.ImgCanvasFrmFond = self.CanvasFrmFond.create_image(0, 0, anchor=tk.NW, image=self.ImgFrmFond[0])

        self.geometry(
            str(self.SX) + "x" + str(self.SY) + "+" + str(int(screen.GetSystemMetrics(0) * XY[Type][0])) + "+" +
            str(int(screen.GetSystemMetrics(1) * XY[Type][1])))
        self.resizable(width=False, height=False)
        self.overrideredirect(True)
        self.lift()

        self.LabelTag = LabelInCanvas(self.CanvasFrmFond, "Sélection d'un fournisseur", '#E0E0E0',
                                      AppliFont('Helvetica', self.MainAppli.MainAppli.SizeFont, 'normal', 0),
                                      int(self.SX * 0.005), int(self.SY * 0.004), tk.NW)

        self.ImgFournisseur = ImgInCanvas(self.CanvasFrmFond, 'Datas/Fournisseurs/Logos/NC', 0.5,
                                          tk.CENTER, int(int(self.CanvasFrmFond['width']) * 0.5),
                                          int(int(self.CanvasFrmFond['height']) * 0.15))

        self.BtnOK = BtnAction(self.CanvasFrmFond, int(self.SX * 0.85), int(self.SY * 0.96), self.RatioX * 0.75,
                               self.RatioX * 0.75, 'Media/FrmAjout/BtnOK2/')
        self.BtnAnnul = BtnAction(self.CanvasFrmFond, int(self.SX * 0.93), int(self.SY * 0.96), self.RatioX * 0.75,
                                  self.RatioX * 0.75, 'Media/FrmAjout/BtnAnnul2/')
        ChangeCursor(self.BtnAnnul.CanvasBtn)
        ChangeCursor(self.BtnOK.CanvasBtn)
        self.BtnAnnul.CanvasBtn.bind('<ButtonRelease-1>', self.CacheFrmModif)
        self.BtnOK.CanvasBtn.bind('<ButtonRelease-1>', self.SaveModif)

        self.AffichLogosFour()

        self.CanvasFrmFond.pack()

    def AffichLogosFour(self):
        self.FrameLogos = tk.Frame(self.CanvasFrmFond)
        self.CanvasFrmFond.create_window(int(int(self.CanvasFrmFond['width']) * 0.5),
                                         int(int(self.CanvasFrmFond['height']) * 0.6), anchor=tk.CENTER,
                                         window=self.FrameLogos)
        self.scrollable_canvas = ScrollableCanvas(self.FrameLogos, int(int(self.CanvasFrmFond['width']) * 0.82),
                                                  int(int(self.CanvasFrmFond['height']) * 0.615))
        self.scrollable_canvas.grid(row=1, column=1)

        self.CanvasImg = []
        self.Img = []
        l = 0
        for i in range(len(self.ListFour) + 2):
            if i < len(self.ListFour):
                if self.ListFour[i][7] is not None and self.ListFour[i][7] != '' \
                        and os.path.exists('Datas/Fournisseurs/Logos/' + self.ListFour[i][7]):
                    PathLogo = 'Datas/Fournisseurs/Logos/' + self.ListFour[i][7]
                else:
                    PathLogo = 'Datas/Fournisseurs/Logos/VIDE'
            elif i == len(self.ListFour):
                PathLogo = 'Datas/Fournisseurs/Logos/VIDE'
            else:
                PathLogo = 'Datas/Fournisseurs/Logos/NC'
            img = Image.open(PathLogo)
            imgwsize = int(int(self.CanvasFrmFond['width']) * 0.4)
            imghsize = int(imgwsize * float(img.size[1]) / float(img.size[0]))
            img = img.resize((imgwsize, imghsize), Image.ANTIALIAS)
            self.Img.append(ImageTk.PhotoImage(img))
            self.CanvasImg.append(CanvasApp(self.scrollable_canvas.interior, width=img.size[0], height=img.size[1]))
            self.CanvasImg[i].create_image(0, 0, anchor=tk.NW, image=self.Img[i])

            if i < len(self.ListFour):
                if self.ListFour[i][7] is None or self.ListFour[i][7] == '' or not os.path.exists(
                        'Datas/Fournisseurs/Logos/' + self.ListFour[i][7]):
                    if len(self.ListFour[i][0]) < 15:
                        TextFournisseur = self.ListFour[i][0]
                    else:
                        TextFournisseur = self.ListFour[i][0].split(' ')[0]
                        for j in range(1, len(self.ListFour[i][0].split(' '))):
                            TextFournisseur = TextFournisseur + '\n' + self.ListFour[i][0].split(' ')[j]
                    self.CanvasImg[i].create_text(int(int(self.CanvasImg[i]['width']) * 0.5),
                                                  int(int(self.CanvasImg[i]['height']) * 0.5),
                                                  text=TextFournisseur,
                                                  font=AppliFont('Helvetica', self.MainAppli.MainAppli.SizeFont + 4,
                                                                 'bold', 0), anchor=tk.CENTER, justify=tk.CENTER)
            elif i == len(self.ListFour):
                self.CanvasImg[i].create_text(int(int(self.CanvasImg[i]['width']) * 0.5),
                                              int(int(self.CanvasImg[i]['height']) * 0.5),
                                              text='NOUVEAU \n FOURNISSEUR',
                                              font=AppliFont('Helvetica', self.MainAppli.MainAppli.SizeFont + 4,
                                                             'bold', 0), anchor=tk.CENTER, justify=tk.CENTER)
            if i % 2 == 0:
                self.CanvasImg[i].grid(row=l, column=0)
            else:
                self.CanvasImg[i].grid(row=l, column=1)
                l = l + 1

        for i in range(len(self.ListFour) + 2):
            def GestEvt(evt, n=i):
                return self.SelectFour(evt, n)

            self.CanvasImg[i].bind('<ButtonRelease-1>', GestEvt)
            ChangeCursor(self.CanvasImg[i])

    def SelectFour(self, _, j):
        self.ImgFournisseur.CanvasImg.destroy()
        if j < len(self.ListFour):
            self.Fournisseur = self.ListFour[j][0]
            if self.ListFour[j][7] is None or self.ListFour[j][7] == '' or not os.path.exists(
                    'Datas/Fournisseurs/Logos/' + self.ListFour[j][7]):
                self.ImgFournisseur = ImgInCanvas(self.CanvasFrmFond, 'Datas/Fournisseurs/Logos/Vide', 0.5,
                                                  tk.CENTER, int(int(self.CanvasFrmFond['width']) * 0.5),
                                                  int(int(self.CanvasFrmFond['height']) * 0.15))
                if len(self.ListFour[j][0]) < 15:
                    TextFournisseur = self.ListFour[j][0]
                else:
                    TextFournisseur = self.ListFour[j][0].split(' ')[0]
                    for i in range(1, len(self.ListFour[j][0].split(' '))):
                        TextFournisseur = TextFournisseur + '\n' + self.ListFour[j][0].split(' ')[i]
                self.ImgFournisseur.CanvasImg.create_text(int(int(self.ImgFournisseur.CanvasImg['width']) * 0.5),
                                                          int(int(self.ImgFournisseur.CanvasImg['height']) * 0.5),
                                                          text=TextFournisseur,
                                                          font=AppliFont('Helvetica',
                                                                         self.MainAppli.MainAppli.SizeFont + 4,
                                                                         'bold', 0), anchor=tk.CENTER,
                                                          justify=tk.CENTER)
            else:
                self.ImgFournisseur = ImgInCanvas(self.CanvasFrmFond, 'Datas/Fournisseurs/Logos/' + self.ListFour[j][7],
                                                  0.5, tk.CENTER, int(int(self.CanvasFrmFond['width']) * 0.5),
                                                  int(int(self.CanvasFrmFond['height']) * 0.15))
        elif j == len(self.ListFour):
            self.ImgFournisseur = ImgInCanvas(self.CanvasFrmFond, 'Datas/Fournisseurs/Logos/Vide', 0.5,
                                              tk.CENTER, int(int(self.CanvasFrmFond['width']) * 0.5),
                                              int(int(self.CanvasFrmFond['height']) * 0.15))
            self.ListNomNewFour = []
            for i in range(3):
                self.ListNomNewFour.append(
                    EntryData(self.ImgFournisseur.CanvasImg, int(int(self.ImgFournisseur.CanvasImg['width']) * 0.075),
                              int(int(self.ImgFournisseur.CanvasImg['width']) * 0.08),
                              int(int(self.ImgFournisseur.CanvasImg['height']) * 0.25 +
                                  i * int(self.ImgFournisseur.CanvasImg['height']) * 0.25), tk.W,
                              AppliFont('Helvetica', self.MainAppli.MainAppli.SizeFont + 4, 'bold', 0)))
                self.ListNomNewFour[i].EntryData.config(justify='center')
            self.ListNomNewFour[0].Data.set('NOUVEAU')
            self.ListNomNewFour[1].Data.set('FOURNISSEUR')
        else:
            self.ImgFournisseur = ImgInCanvas(self.CanvasFrmFond, 'Datas/Fournisseurs/Logos/NC', 0.5,
                                              tk.CENTER, int(int(self.CanvasFrmFond['width']) * 0.5),
                                              int(int(self.CanvasFrmFond['height']) * 0.15))

    def SaveModif(self, _):
        self.destroy()
        if len(self.ListNomNewFour) > 0:
            self.Fournisseur = self.ListNomNewFour[0].Data.get()
            for i in range(1, 3):
                self.Fournisseur = self.Fournisseur + ' ' + self.ListNomNewFour[i].Data.get()
        self.MainAppli.Fournisseur = self.Fournisseur
        self.MainAppli.AffichLogoFour(self.Fournisseur)

    def CacheFrmModif(self, _):
        self.destroy()
