Somes changes on UI and update system

This commit is contained in:
Adrien Bourmault 2019-08-29 12:54:43 +02:00 committed by GitHub
parent 4f36d5904e
commit d1bf646118
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 65 additions and 23 deletions

View File

@ -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

View File

@ -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):

View File

@ -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()

View File

@ -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