From 07ec96d33a6d97b1d714fbd59d8f6d5a0dd6cbfe Mon Sep 17 00:00:00 2001 From: Jordan ERNST Date: Fri, 8 Feb 2019 12:10:58 +0100 Subject: [PATCH 1/2] Bugs correction --- IFPass.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/IFPass.py b/IFPass.py index 9ddc9f4..aaa3ec7 100644 --- a/IFPass.py +++ b/IFPass.py @@ -45,7 +45,12 @@ def initialisation(): else: acrinstalled = yes_or_no("Acrobat Reader est nécessaire pour imprimer les cartes. Est il installé ?") if acrinstalled: - AcrobatReader = input(r"Quel est le chemin vers Acrobat Reader ? ( Ex : C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe) : ") + while "Wrong path": + AcrobatReader = input(r"Quel est le chemin vers Acrobat Reader ? ( Ex : C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe) : ") + if os.path.exists(AcrobatReader): + break + else: + print(colored('\nChemin invalide !', 'red')) else: print(colored('\nInstallez Acrobat Reader, puis relancez IFPass.', 'red')) os.system("pause") @@ -64,9 +69,9 @@ def initialisation(): clientsbkpfile = os.path.join(IFPassDBdir, 'Clients_IFPass_backup.csv') imgdir = os.path.join(IFPassDBdir, 'Cartes') templatesdir = os.path.join(IFPassDBdir, 'Templates') - pdftemplate = os.path.join(templatesdir, 'Templates', 'IFPass_PDF_Template.pdf') - pngtemplate = os.path.join(templatesdir, 'Templates', 'IFPass_PNG_Template.png') - fonttemplate = os.path.join(templatesdir, 'Templates', 'Roboto-Bold.ttf') + pdftemplate = os.path.join(templatesdir, 'IFPass_PDF_Template.pdf') + pngtemplate = os.path.join(templatesdir, 'IFPass_PNG_Template.png') + fonttemplate = os.path.join(templatesdir, 'Roboto-Bold.ttf') if not os.path.exists(imgdir): # Cartes dir creation if it doesn't exist os.makedirs(imgdir, 0o777) From 831097aa7542c8a51d28aceda22016c793ed7aca Mon Sep 17 00:00:00 2001 From: Jordan ERNST Date: Fri, 8 Feb 2019 12:40:33 +0100 Subject: [PATCH 2/2] 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')