From 831097aa7542c8a51d28aceda22016c793ed7aca Mon Sep 17 00:00:00 2001 From: Jordan ERNST Date: Fri, 8 Feb 2019 12:40:33 +0100 Subject: [PATCH] Catch exception when Templates not available. --- IFPass.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/IFPass.py b/IFPass.py index aaa3ec7..c3a665f 100644 --- a/IFPass.py +++ b/IFPass.py @@ -82,7 +82,7 @@ def initialisation(): if not os.path.exists(templatesdir): move('Templates', IFPassDBdir) - return IFPassDBdir, printername, AcrobatReader, clientsfile, clientsbkpfile, imgdir, pdftemplate, pngtemplate, fonttemplate + return IFPassDBdir, printername, AcrobatReader, clientsfile, clientsbkpfile, imgdir, templatesdir, pdftemplate, pngtemplate, fonttemplate def get_fullname(): @@ -216,7 +216,15 @@ def bkpdb(): def fillcard(barcode): print("Création de la carte avec les informations...", end='') - im = Image.open(pngtemplate) + try: + im = Image.open(pngtemplate) + except FileNotFoundError: + os.system('cls') + print(colored('Vous avez besoin de 2 fichiers dans le dossier Templates pour générer des cartes :', 'red')) + print(templatesdir + '\\IFPass_PDF_Template.pdf : Modèle de la carte (recto et verso)') + print(templatesdir + '\\IFPass_PNG_Template.png : La face avant de la carte (celle à remplir)') + os.system("pause") + sys.exit() draw = ImageDraw.Draw(im) # Name embedding : @@ -324,10 +332,10 @@ def membersearch(): def main(): - global titre, firstname, surname, fullname, dateinsc, dateexp, clientID, clientsfile, IFPassDBdir, clientsfile, imgdir, clientsbkpfile, pngtemplate, fonttemplate, picture, pdftemplate, printername, AcrobatReader + global titre, firstname, surname, fullname, dateinsc, dateexp, clientID, clientsfile, IFPassDBdir, clientsfile, imgdir, clientsbkpfile, templatesdir, pngtemplate, fonttemplate, picture, pdftemplate, printername, AcrobatReader while "The program is running": init() # Initialisation of colorama - IFPassDBdir, printername, AcrobatReader, clientsfile, clientsbkpfile, imgdir, pdftemplate, pngtemplate, fonttemplate = initialisation() + IFPassDBdir, printername, AcrobatReader, clientsfile, clientsbkpfile, imgdir, templatesdir, pdftemplate, pngtemplate, fonttemplate = initialisation() os.system('cls') f = Figlet(font='big')