mirror of
https://gitlab.os-k.eu/neox/CNIRevelator.git
synced 2023-08-25 14:03:10 +02:00
Working on IHM for MRZ validation
This commit is contained in:
parent
5b7e4f65e7
commit
0241b7c69a
69
src/main.py
69
src/main.py
@ -49,12 +49,8 @@ class mainWindow(Tk):
|
|||||||
self.initialize()
|
self.initialize()
|
||||||
|
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
self.PILE_ETAT = []
|
self.mrzChar = ''
|
||||||
self.MRZCHAR = ''
|
self.mrzDecided = False
|
||||||
self.varnum = 10
|
|
||||||
self.Score = []
|
|
||||||
for type in mrz.TYPES:
|
|
||||||
self.Score += [0]
|
|
||||||
|
|
||||||
# Get the screen size
|
# Get the screen size
|
||||||
ws = self.winfo_screenwidth()
|
ws = self.winfo_screenwidth()
|
||||||
@ -197,6 +193,7 @@ class mainWindow(Tk):
|
|||||||
|
|
||||||
# Some bindings
|
# Some bindings
|
||||||
self.termtext.bind('<Key>', self.entryValidation)
|
self.termtext.bind('<Key>', self.entryValidation)
|
||||||
|
self.termtext.bind('<<Paste>>', self.pasteValidation)
|
||||||
self.update()
|
self.update()
|
||||||
logfile.printdbg('Initialization successful')
|
logfile.printdbg('Initialization successful')
|
||||||
|
|
||||||
@ -208,17 +205,61 @@ class mainWindow(Tk):
|
|||||||
"""
|
"""
|
||||||
On the fly validation with regex
|
On the fly validation with regex
|
||||||
"""
|
"""
|
||||||
currentText = self.termtext.get("1.0", "end")
|
controlled = False
|
||||||
currentText = (currentText.upper()[:-1]).replace(" ", "<")
|
|
||||||
|
|
||||||
regex = re.compile("([A-Z]|[0-9]|<)*")
|
# verifying that there is no Ctrl-C/Ctrl-V and others
|
||||||
while not regex.fullmatch(currentText):
|
if event.state & 0x0004 and ( event.keysym == "c" or
|
||||||
currentText = currentText[:-1]
|
event.keysym == "v" or
|
||||||
|
event.keysym == "a" or
|
||||||
|
event.keysym == "z" or
|
||||||
|
event.keysym == "y" ):
|
||||||
|
controlled = True
|
||||||
|
|
||||||
self.termtext.delete("1.0", "end")
|
# If not a control char
|
||||||
self.termtext.insert("1.0", currentText)
|
if not controlled and not event.keysym in ["Return", "Right", "Left", "Home", "End", "Delete", "BackSpace", "Inser", "Shift", "Control"]:
|
||||||
|
# the regex
|
||||||
|
regex = re.compile("[A-Z]|<|[0-9]")
|
||||||
|
# match !
|
||||||
|
if not regex.fullmatch(event.char):
|
||||||
|
self.logOnTerm("Caractère non accepté !\n")
|
||||||
|
return "break"
|
||||||
|
|
||||||
|
# analysis
|
||||||
|
self.mrzChar = self.termtext.get("1.0", "end")[:-1] + event.char + '\n'
|
||||||
|
|
||||||
|
# If we must decide the type of the document
|
||||||
|
if not self.mrzDecided:
|
||||||
|
# Get the candidates
|
||||||
|
candidates = mrz.allDocMatch(self.mrzChar.split("\n"))
|
||||||
|
|
||||||
|
if len(candidates) == 2:
|
||||||
|
# XXX demander !
|
||||||
|
elif len(candidates) == 1:
|
||||||
|
self.logOnTerm("Document detecté : {}".format(candidates[0]))
|
||||||
|
self.mrzDecided = candidates[0]
|
||||||
|
else:
|
||||||
|
# Work with the document decided
|
||||||
|
|
||||||
|
|
||||||
|
def pasteValidation(self, event):
|
||||||
|
"""
|
||||||
|
On the fly validation of pasted text
|
||||||
|
"""
|
||||||
|
# cleanup
|
||||||
|
self.termtext.delete("1.0","end")
|
||||||
|
|
||||||
|
# get the clipboard content
|
||||||
|
lines = self.clipboard_get()
|
||||||
|
|
||||||
|
# the regex
|
||||||
|
regex = re.compile("[^A-Z0-9<]")
|
||||||
|
|
||||||
|
lines = re.sub(regex, '', lines)
|
||||||
|
|
||||||
|
# breaking the lines
|
||||||
|
self.termtext.insert("1.0", lines[:mrz.longest] + '\n' + lines[mrz.longest:mrz.longest*2] )
|
||||||
|
return "break"
|
||||||
|
|
||||||
print(currentText)
|
|
||||||
|
|
||||||
def logOnTerm(self, text):
|
def logOnTerm(self, text):
|
||||||
self.monlog['state'] = 'normal'
|
self.monlog['state'] = 'normal'
|
||||||
|
@ -734,6 +734,9 @@ DL = [
|
|||||||
#TYPES = [ID, I__, VB, VA, AC, I_, IP, P, DL]
|
#TYPES = [ID, I__, VB, VA, AC, I_, IP, P, DL]
|
||||||
TYPES = [IDFR, I__, VB, AC, I_, IP, P, DL]
|
TYPES = [IDFR, I__, VB, AC, I_, IP, P, DL]
|
||||||
|
|
||||||
|
# longest document MRZ line
|
||||||
|
longest = max([len(x[0][0]) for x in TYPES])
|
||||||
|
|
||||||
## THE ROOT OF THIS PROJECT !
|
## THE ROOT OF THIS PROJECT !
|
||||||
|
|
||||||
|
|
||||||
@ -786,10 +789,12 @@ def docMatch(doc, strs):
|
|||||||
logfile.printdbg("{} level : {}/{} (+{})".format(doc[2], level, nchar, bonus))
|
logfile.printdbg("{} level : {}/{} (+{})".format(doc[2], level, nchar, bonus))
|
||||||
return (level, nchar, bonus)
|
return (level, nchar, bonus)
|
||||||
|
|
||||||
def allDocMatches(strs, final=False):
|
def allDocMatch(strs, final=False):
|
||||||
# Global handler
|
# Global handler
|
||||||
logfile = logger.logCur
|
logfile = logger.logCur
|
||||||
|
|
||||||
|
print(strs)
|
||||||
|
|
||||||
SCORES = []
|
SCORES = []
|
||||||
for doc in TYPES:
|
for doc in TYPES:
|
||||||
# Get the score of the document on the strings
|
# Get the score of the document on the strings
|
||||||
|
Loading…
Reference in New Issue
Block a user