diff --git a/src/CNIRevelator.py b/src/CNIRevelator.py index 20660c5..308d41c 100644 --- a/src/CNIRevelator.py +++ b/src/CNIRevelator.py @@ -42,7 +42,7 @@ try: from tkinter.messagebox import * from tkinter import * except: - critical.LASTCHANCECRASH() + critical.crashCNIR() # Global handler logfile = logger.logCur @@ -87,7 +87,7 @@ try: # LANGUAGE lang.readLang() except: - ihm.crashCNIR() + critical.crashCNIR() updater.exitProcess(1) from main import * # main.py @@ -96,7 +96,7 @@ try: launcherThread = threading.Thread(target=updater.umain, daemon=False) launcher.lmain(launcherThread) except Exception: - ihm.crashCNIR() + critical.crashCNIR() updater.exitProcess(1) if updater.UPDATE_IS_MADE: @@ -116,10 +116,10 @@ try: try: main() except Exception as e: - ihm.crashCNIR() + critical.crashCNIR() updater.exitProcess(1) except: - critical.LASTCHANCECRASH() + critical.crashCNIR() updater.exitProcess(0) \ No newline at end of file diff --git a/src/critical.py b/src/critical.py index 8d337d0..e44639e 100644 --- a/src/critical.py +++ b/src/critical.py @@ -23,6 +23,7 @@ ******************************************************************************** """ from tkinter.messagebox import * +from importlib import reload from tkinter import * import webbrowser import traceback @@ -33,24 +34,33 @@ import lang # lang.py import logger # logger.py import globs # globs.py -def LASTCHANCECRASH(): +def crashCNIR(shutdown=True): """ very last solution """ - root = Tk() - root.withdraw() - logfile = logger.logCur - logfile.printerr("FATAL ERROR : see traceback below.\n{}".format(traceback.format_exc())) - showerror(lang.all[globs.CNIRlang]["CNIRevelator Fatal Eror"], lang.all[globs.CNIRlang]["CNIRevelator crashed because a fatal error occured. View log for more infos and please open an issue on Github"]) - res = askquestion(lang.all[globs.CNIRlang]["CNIRevelator Fatal Eror"], lang.all[globs.CNIRlang]["Would you like to open the log file ?"]) - if res == "yes": - webbrowser.open_new(globs.CNIRErrLog) - res = askquestion(lang.all[globs.CNIRlang]["CNIRevelator Fatal Eror"], lang.all[globs.CNIRlang]["Would you like to open an issue on Github to report this bug ?"]) - if res == "yes": - webbrowser.open_new("https://github.com/neox95/CNIRevelator/issues") - root.destroy() - # Quit totally without remain in memory - for process in psutil.process_iter(): - if process.pid == os.getpid(): - process.terminate() - sys.exit(arg) \ No newline at end of file + + try: + root = Tk() + root.withdraw() + logfile = logger.logCur + logfile.printerr("FATAL ERROR : see traceback below.\n{}".format(traceback.format_exc())) + showerror(lang.all[globs.CNIRlang]["CNIRevelator Fatal Eror"], lang.all[globs.CNIRlang]["CNIRevelator crashed because a fatal error occured. View log for more infos and please open an issue on Github"], parent=root) + res = askquestion(lang.all[globs.CNIRlang]["CNIRevelator Fatal Eror"], lang.all[globs.CNIRlang]["Would you like to open the log file ?"], parent=root) + if res == "yes": + webbrowser.open_new(globs.CNIRErrLog) + res = askquestion(lang.all[globs.CNIRlang]["CNIRevelator Fatal Eror"], lang.all[globs.CNIRlang]["Would you like to open an issue on Github to report this bug ?"], parent=root) + if res == "yes": + webbrowser.open_new("https://github.com/neox95/CNIRevelator/issues") + root.destroy() + + # Quit ? + if not shutdown: + return + + # Quit totally without remain in memory + for process in psutil.process_iter(): + if process.pid == os.getpid(): + process.terminate() + sys.exit(arg) + except: + traceback.print_exc() \ No newline at end of file diff --git a/src/downloader.py b/src/downloader.py index a72c8f8..3faa243 100644 --- a/src/downloader.py +++ b/src/downloader.py @@ -32,10 +32,11 @@ from Crypto.Cipher import AES from requests import Session from time import time +import critical # critical.py import logger # logger.py import globs # globs.py import ihm # ihm.py -import lang # lang.py +import lang # lang.py class AESCipher(object): diff --git a/src/globs.py b/src/globs.py index 77ba0c8..f3b0852 100644 --- a/src/globs.py +++ b/src/globs.py @@ -26,7 +26,7 @@ import os # CNIRevelator version verType = "final release" -version = [3, 1, 0] +version = [3, 1, 1] verstring_full = "{}.{}.{} {}".format(version[0], version[1], version[2], verType) verstring = "{}.{}".format(version[0], version[1]) diff --git a/src/ihm.py b/src/ihm.py index 7c1a05b..cd2784f 100644 --- a/src/ihm.py +++ b/src/ihm.py @@ -23,19 +23,21 @@ ******************************************************************************** """ -from tkinter import * -import webbrowser from tkinter.messagebox import * +from tkinter import * from tkinter import filedialog from tkinter import ttk -import cv2 import PIL.Image, PIL.ImageTk import traceback +import webbrowser +import cv2 +import critical # critical.py import logger # logger.py import globs # globs.py import lang # lang.py import updater # updater.py +import critical # critical.py controlKeys = ["Escape", "Right", "Left", "Up", "Down", "Home", "End", "BackSpace", "Delete", "Inser", "Shift_L", "Shift_R", "Control_R", "Control_L"] @@ -272,6 +274,12 @@ class LauncherWindow(Tk): Tk.__init__(self) self.resizable(width=False, height=False) + # icon + if getattr(sys, 'frozen', False): + self.iconbitmap(sys._MEIPASS + '\\id-card.ico\\id-card.ico') + else: + self.iconbitmap('id-card.ico') + # Setting up the geometry ws = self.winfo_screenwidth() hs = self.winfo_screenheight() @@ -320,11 +328,6 @@ class LauncherWindow(Tk): self.update() self.progressBar.grid(row=1, sticky='S') - - if getattr(sys, 'frozen', False): - self.iconbitmap(sys._MEIPASS + '\\id-card.ico\\id-card.ico') - else: - self.iconbitmap('id-card.ico') logfile = logger.logCur logfile.printdbg('Launcher IHM successful') self.protocol('WM_DELETE_WINDOW', lambda : 0) @@ -367,28 +370,6 @@ class StatusBar(Frame): self.label.config(text="") self.label.update_idletasks() -## Crash - -def crashCNIR(): - """ - last solution - """ - # Global handler - logfile = logger.logCur - # hide main window - root = Tk() - root.withdraw() - logfile.printerr("FATAL ERROR : see traceback below.\n{}".format(traceback.format_exc())) - showerror(lang.all[globs.CNIRlang]["CNIRevelator Fatal Eror"], lang.all[globs.CNIRlang]["CNIRevelator crashed because a fatal error occured. View log for more infos and please open an issue on Github"]) - res = askquestion(lang.all[globs.CNIRlang]["CNIRevelator Fatal Eror"], lang.all[globs.CNIRlang]["Would you like to open the log file ?"]) - if res == "yes": - webbrowser.open_new(globs.CNIRErrLog) - res = askquestion(lang.all[globs.CNIRlang]["CNIRevelator Fatal Eror"], lang.all[globs.CNIRlang]["Would you like to open an issue on Github to report this bug ?"]) - if res == "yes": - webbrowser.open_new("https://github.com/neox95/CNIRevelator/issues") - root.destroy() - - ## Global Handler launcherWindowCur = LauncherWindow() diff --git a/src/lang.py b/src/lang.py index d671572..7c2c166 100644 --- a/src/lang.py +++ b/src/lang.py @@ -25,6 +25,7 @@ import os import globs # globs.py +import critical # critical.py ## FRENCH LANGUAGE french = \ @@ -137,7 +138,8 @@ french = \ "Coller :\t\t\t\tCtrl-V \n" "Forcer une nouvelle détection du document :\tEchap\n", -"CHANGELOG" : "Version 3.1.0 \nMise-à-jour majeure avec les progressions suivantes :\n- Modifications cosmétiques de l'interface utilisateur\n- Stabilisation des changements effectués sur la version mineure 3.0 : interface utilisateur, OCR, VISA A et B, logging\n- Rationalisation du système de langues\n- Ajout des canaux de mise-à-jour\n\n" + \ +"CHANGELOG" : "Version 3.1.1 \nMise-à-jour mineure avec les progressions suivantes :\n- Correction d'un bug sévère du système de mise à jour\n\n" + \ +"Version 3.1.0 \nMise-à-jour majeure avec les progressions suivantes :\n- Modifications cosmétiques de l'interface utilisateur\n- Stabilisation des changements effectués sur la version mineure 3.0 : interface utilisateur, OCR, VISA A et B, logging\n- Rationalisation du système de langues\n- Ajout des canaux de mise-à-jour\n\n" + \ "Version 3.0.8 finale\nCorrectif : bug du système de mise-à-jour'\n\n" + \ "Version 3.0.6 \nMise-à-jour mineure avec les corrections suivantes :\n- Changement de l'apparence du launcher de l'application\n- Améliorations de l'interface, notamment de la stabilité\n- Ajout de la signature numérique de l'exécutable\n\n" + \ "Version 3.0.7 finale\nMise-à-jour majeure avec les corrections suivantes :\n- Refonte de l'interface utilisateur\n- Fonction OCR intégrée à l'application avec support des TIFF et JPEG\n- Corrections d'erreurs sur le traitement des VISA de type A et B, ainsi que les titres de séjour\n\n" + \ @@ -825,7 +827,8 @@ english = \ "Paste:\t\t\t\tCtrl-V\n" "Force a new document detection:\tEchap\n", -"CHANGELOG" : "Version 3.1.0 \nMajor update with the following progressions: \n- Cosmetic modifications of the user interface \n- Stabilization of the changes made on the minor version 3.0 : user interface, OCR, VISA A and B, logging\n- Rationalization of the language system\n- Added update channels\n\n" + \ +"CHANGELOG" : "Version 3.1.1 \nMinor update with the following progressions: \n- Fixed a severe bug in the update system" + \ +"Version 3.1.0 \nMajor update with the following progressions: \n- Cosmetic modifications of the user interface \n- Stabilization of the changes made on the minor version 3.0 : user interface, OCR, VISA A and B, logging\n- Rationalization of the language system\n- Added update channels\n\n" + \ "Version 3.0.8 final\nCorrection: bug in the update system'\n\n" + \ "Version 3.0.6 \nMinor update with the following fixes:\n- Change in the appearance of the application launcher\n- Improvements to the interface, including stability\n- Added digital signature of the executable\n" + \ "Version 3.0.7 final\nMajor update with the following corrections: \n- Redesign of the user interface\n- OCR function integrated into the application with TIFF and JPEG support\n- Corrections of errors on the processing of VISA type A and B, as well as residence permits\n\n" + \ @@ -1418,7 +1421,7 @@ def readLang(): # Reading it globs.CNIRlang = configFile.read() except Exception as e: - ihm.crashCNIR() + critical.crashCNIR() raise IOError(str(e)) else: # Recreating the url file @@ -1432,7 +1435,7 @@ def readLang(): # Writing it configFile.write(globs.CNIRlang) except Exception as e: - ihm.crashCNIR() + critical.crashCNIR() raise IOError(str(e)) def updateLang(choice): @@ -1444,7 +1447,7 @@ def updateLang(choice): globs.CNIRlang = choice configFile.write(choice) except Exception as e: - ihm.crashCNIR() + critical.crashCNIR() raise IOError(str(e)) else: # Recreating the url file @@ -1458,5 +1461,5 @@ def updateLang(choice): # Writing it configFile.write(globs.CNIRlang) except Exception as e: - ihm.crashCNIR() + critical.crashCNIR() raise IOError(str(e)) \ No newline at end of file diff --git a/src/launcher.py b/src/launcher.py index aa35b8d..116c642 100644 --- a/src/launcher.py +++ b/src/launcher.py @@ -27,6 +27,7 @@ import sys import os import threading +import critical # critical.py import updater # updater.py import ihm # ihm.py import globs # globs.py diff --git a/src/logger.py b/src/logger.py index 1e1d00f..9fea829 100644 --- a/src/logger.py +++ b/src/logger.py @@ -26,6 +26,7 @@ import logging import os +import critical # critical.py import globs # globs.py ## The logging class diff --git a/src/main.py b/src/main.py index 648f2ea..6e0f54f 100644 --- a/src/main.py +++ b/src/main.py @@ -39,6 +39,7 @@ import os, shutil import webbrowser import sys, os +import critical # critical.py import ihm # ihm.py import logger # logger.py import mrz # mrz.py @@ -68,6 +69,12 @@ class mainWindow(Tk): self.corners = [] self.validatedtext = "" + # The icon + if getattr(sys, 'frozen', False): + self.iconbitmap(sys._MEIPASS + '\\id-card.ico\\id-card.ico') + else: + self.iconbitmap('id-card.ico') + # Hide during construction self.withdraw() @@ -349,12 +356,6 @@ class mainWindow(Tk): # The title self.wm_title(globs.CNIRName) - # The icon - if getattr(sys, 'frozen', False): - self.iconbitmap(sys._MEIPASS + '\\id-card.ico\\id-card.ico') - else: - self.iconbitmap('id-card.ico') - # Make this window resizable and set her size self.resizable(0, 0) self.update() @@ -947,7 +948,7 @@ class mainWindow(Tk): self.DisplayUpdate( photo) except Exception as e: logfile.printerr("Error with opencv : {}".format(e)) - ihm.crashCNIR() + critical.crashCNIR() try: # Reload an image using OpenCV path = self.imageViewer.imagePath @@ -965,7 +966,7 @@ class mainWindow(Tk): self.DisplayUpdate(photo) except Exception as e: logfile.printerr("Critical error with opencv : ".format(e)) - ihm.crashCNIR() + critical.crashCNIR() showerror(lang.all[globs.CNIRlang]["OpenCV error (image processing)"], lang.all[globs.CNIRlang]["A critical error has occurred in the OpenCV image processing manager used by CNIRevelator, the application will reset itself"]) self.initialize() diff --git a/src/mrz.py b/src/mrz.py index 672eba7..ace7a69 100644 --- a/src/mrz.py +++ b/src/mrz.py @@ -30,6 +30,7 @@ import datetime import logger # logger.py import globs # globs.py import lang # lang.py +import critical # critical.py ## SEX CODES sexcode = {'M':'Homme', 'F':'Femme', 'X':'Non spécifié'} diff --git a/src/updater.py b/src/updater.py index e8a6a75..96445a7 100644 --- a/src/updater.py +++ b/src/updater.py @@ -24,6 +24,9 @@ """ from win32com.client import Dispatch +from tkinter.messagebox import * +from tkinter import * +import pythoncom import sys import time import os @@ -33,6 +36,7 @@ import hashlib import subprocess import psutil +import critical # critical.py import ihm # ihm.py import logger # logger.py import globs # globs.py @@ -93,6 +97,8 @@ def getLatestVersion(credentials): """ Returns the latest version of the software """ + + finalver, finalurl, finalchecksum = [None]*3 # Global Handlers logfile = logger.logCur @@ -155,7 +161,7 @@ def getLatestVersion(credentials): else: finalurl = url finalchecksum = None - + return (finalver, finalurl, finalchecksum) @@ -167,6 +173,11 @@ def tessInstall(PATH, credentials): # Verifying that Tesseract is installed if not os.path.exists(PATH + '\\Tesseract-OCR4\\'): finalver, finalurl, finalchecksum = getLatestVersion(credentials) + + if finalurl == None: + logfile.printerr('Unable to get the Tesseract url') + return False + tesseracturl = finalurl.replace("CNIRevelator.zip", "tesseract_4.zip") # WE ASSUME THAT THE MAIN FILE IS CNIRevelator.zip AND THAT THE TESSERACT PACKAGE IS tesseract_4.zip @@ -277,6 +288,7 @@ def batch(credentials): # Make a shortcut # hide main window + pythoncom.CoInitialize() root = Tk() root.withdraw() res = askquestion(lang.all[globs.CNIRlang]["Shortcut creation"], lang.all[globs.CNIRlang]["Would you like to create/update the shortcut for CNIRevelator on your desktop ?"]) @@ -351,7 +363,7 @@ def umain(): # EXECUTING THE UPDATE BATCH success = batch(credentials) except Exception as e: - ihm.crashCNIR() + critical.crashCNIR() launcherWindow.printmsg('ERROR : ' + str(e)) time.sleep(3) launcherWindow.exit() @@ -371,7 +383,7 @@ def umain(): launcherWindow.exit() return 0 except: - ihm.crashCNIR() + critical.crashCNIR() launcherWindow.exit() sys.exit(2) return 2 @@ -381,7 +393,7 @@ def umain(): # INSTALLING TESSERACT OCR success = tessInstall(globs.CNIRFolder, credentials) except Exception as e: - ihm.crashCNIR() + critical.crashCNIR() launcherWindow.printmsg('ERROR : ' + str(e)) time.sleep(3) launcherWindow.exit() @@ -398,7 +410,7 @@ def umain(): return 0 except: - ihm.crashCNIR() + critical.crashCNIR() launcherWindow.exit() sys.exit(2) return 2