From d1bf646118f96b61bf36f8b5d2824204d23697db Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Thu, 29 Aug 2019 12:54:43 +0200 Subject: [PATCH] Somes changes on UI and update system --- src/critical.py | 6 ++++++ src/ihm.py | 37 ++++++++++++++++++++++++------------- src/main.py | 15 ++++++++------- src/updater.py | 30 +++++++++++++++++++++++++++--- 4 files changed, 65 insertions(+), 23 deletions(-) diff --git a/src/critical.py b/src/critical.py index 74cb1d2..6b2843e 100644 --- a/src/critical.py +++ b/src/critical.py @@ -49,6 +49,12 @@ def crashCNIR(shutdown=True): 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"]) + # Force new update + try: + os.remove(globs.CNIRLastUpdate) + except: + pass + res = askquestion(lang.all[globs.CNIRlang]["CNIRevelator Fatal Eror"], lang.all[globs.CNIRlang]["Would you like to report this bug ?"]) if res == "yes": # read the log diff --git a/src/ihm.py b/src/ihm.py index ca5e68a..097c9c0 100644 --- a/src/ihm.py +++ b/src/ihm.py @@ -45,13 +45,16 @@ controlKeys = ["Escape", "Right", "Left", "Up", "Down", "Home", "End", "BackSpac class DocumentAsk(Toplevel): def __init__(self, parent, choices): - self.choice = 0 - vals = [0, 1] super().__init__(parent) self.title("{} :".format(lang.all[globs.CNIRlang]["Choose the identity document"])) - ttk.Radiobutton(self, text=choices[0], command=self.register0, value=vals[0]).pack() - ttk.Radiobutton(self, text=choices[1], command=self.register1, value=vals[1]).pack() + self.choice = 0 + vals = [i[2] for i in choices] + for i in range(len(vals)): + a = ttk.Radiobutton(self, text=vals[i], command=self.createRegister(i), value=vals[i]) + a.pack(fill=Y) + if i == 0: + a.invoke() self.button = Button(self, text='OK', command=(self.ok)).pack() self.resizable(width=False, height=False) @@ -68,10 +71,11 @@ class DocumentAsk(Toplevel): y = hs / 2 - h / 2 self.geometry('%dx%d+%d+%d' % (w, h, x, y)) - def register0(self): - self.choice = 0 - def register1(self): - self.choice = 1 + def createRegister(self, i): + def register(): + self.choice = i + return register + def ok(self): self.destroy() @@ -193,7 +197,7 @@ class ChangelogDialog(Toplevel): class langDialog(Toplevel): - def __init__(self, parent): + def __init__(self, parent, currentLang): super().__init__(parent) self.title(lang.all[globs.CNIRlang]["Language"]) @@ -202,7 +206,10 @@ class langDialog(Toplevel): vals = [i for i in lang.all] for i in range(len(lang.all)): - ttk.Radiobutton(self, text=vals[i], command=self.createRegister(i), value=vals[i]).pack(fill=Y) + a = ttk.Radiobutton(self, text=vals[i], command=self.createRegister(i), value=vals[i]) + a.pack(fill=Y) + if i == vals.index(currentLang): + a.invoke() ttk.Button(self, text="OK", command=(self.oki)).pack(fill=Y, pady=5) @@ -231,7 +238,7 @@ class langDialog(Toplevel): class updateSetDialog(Toplevel): - def __init__(self, parent): + def __init__(self, parent, currentChannel): super().__init__(parent) self.title(lang.all[globs.CNIRlang]["Update options"]) @@ -241,7 +248,11 @@ class updateSetDialog(Toplevel): self.vals = ["Stable", "Beta"] vals = self.vals for i in range(len(vals)): - ttk.Radiobutton(self, text=vals[i], command=self.createRegister(i), value=vals[i]).pack(fill=Y) + a = ttk.Radiobutton(self, text=vals[i], command=self.createRegister(i), value=vals[i]) + a.pack(fill=Y) + if i == self.vals.index(currentChannel): + a.invoke() + ttk.Button(self, text="OK", command=(self.oki)).pack(fill=Y, pady=5) @@ -265,7 +276,7 @@ class updateSetDialog(Toplevel): def createRegister(self, i): def register(): - updater.updateChannel(self.vals[i]) + updater.setUpdateChannel(self.vals[i]) return register class LauncherWindow(Tk): diff --git a/src/main.py b/src/main.py index d2ff455..6f4b4dc 100644 --- a/src/main.py +++ b/src/main.py @@ -49,6 +49,7 @@ import mrz # mrz.py import globs # globs.py import pytesseract # pytesseract.py import lang # lang.py +import updater # updater.py # Global handler logfile = logger.logCur @@ -510,9 +511,9 @@ class mainWindow(Tk): # Get the candidates candidates = mrz.allDocMatch(self.mrzChar.split("\n"), final=isFull) - if len(candidates) == 2 and len(self.mrzChar) >= 8: + if len(candidates) >= 2 and len(candidates) < 4 and len(self.mrzChar) >= 8: # Parameters for the choice invite - invite = ihm.DocumentAsk(self, [candidates[0][2], candidates[1][2]]) + invite = ihm.DocumentAsk(self, candidates) invite.transient(self) invite.grab_set() invite.focus_force() @@ -606,9 +607,9 @@ class mainWindow(Tk): # Get the candidates candidates = mrz.allDocMatch(self.mrzChar.split("\n")) - if len(candidates) == 2 and len(self.mrzChar) >= 8: + if len(candidates) >= 2 and len(candidates) < 4 and len(self.mrzChar) >= 8: # Parameters for the choice invite - invite = ihm.DocumentAsk(self, [candidates[0][2], candidates[1][2]]) + invite = ihm.DocumentAsk(self, candidates) invite.transient(self) invite.grab_set() invite.focus_force() @@ -724,7 +725,7 @@ class mainWindow(Tk): # display the infos for key in [ e for e in docInfos ]: print(key) - if key in ["CODE", "CTRL", "CTRLF", "FACULT"]: + if key in ["CODE", "CTRL", "CTRLF", "FACULT", "NOINT"]: continue if not docInfos[key][1] == False: if not docInfos[key][0] == "": @@ -1072,7 +1073,7 @@ class mainWindow(Tk): """ Update Settings """ - changeupdateWin = ihm.updateSetDialog(self) + changeupdateWin = ihm.updateSetDialog(self, updater.getUpdateChannel()) changeupdateWin.transient(self) changeupdateWin.grab_set() changeupdateWin.focus_force() @@ -1082,7 +1083,7 @@ class mainWindow(Tk): """ Lang Settings """ - changelangWin = ihm.langDialog(self) + changelangWin = ihm.langDialog(self, globs.CNIRlang) changelangWin.transient(self) changelangWin.grab_set() changelangWin.focus_force() diff --git a/src/updater.py b/src/updater.py index 8541aa4..5d62988 100644 --- a/src/updater.py +++ b/src/updater.py @@ -88,14 +88,38 @@ def exitProcess(arg): process.terminate() sys.exit(arg) -def updateChannel(choice): +def setUpdateChannel(choice): + """ + Sets the new update channel and forces new update at next launch + """ if choice == "Beta": with open(globs.CNIRUrlConfig, 'w') as (configFile): configFile.write("{}\n0\n0".format(globs.CNIRBetaURL)) - else: + # Force new update + try: + os.remove(globs.CNIRLastUpdate) + except: + pass + elif choice == "Stable": with open(globs.CNIRUrlConfig, 'w') as (configFile): configFile.write("{}\n0\n0".format(globs.CNIRDefaultURL)) - + # Force new update + try: + os.remove(globs.CNIRLastUpdate) + except: + pass + +def getUpdateChannel(): + """ + Returns the current update channel + """ + with open(globs.CNIRUrlConfig, 'r') as (configFile): + url = configFile.read() + if not "master" in url: + return "Beta" + else: + return "Stable" + def getLatestVersion(credentials): """ Returns the latest version of the software