make barrir in/ out working

This commit is contained in:
chrys 2018-07-07 15:35:07 +02:00
parent 8ade798ba5
commit 671a5e00f8
4 changed files with 50 additions and 27 deletions

View File

@ -15,6 +15,10 @@ StartOfLine='StartOfLine.wav'
EndOfLine='EndOfLine.wav' EndOfLine='EndOfLine.wav'
# barrier was detected # barrier was detected
BarrierFound='barrier.wav' BarrierFound='barrier.wav'
# barrier mode starts
BarrierStart='barrier_start.wav'
# barrier mode ends
BarrierEnd='barrier_end.wav'
# the Line is empty # the Line is empty
EmptyLine='EmptyLine.wav' EmptyLine='EmptyLine.wav'
# Is the first line on the screen. # Is the first line on the screen.

View File

@ -15,6 +15,10 @@ StartOfLine=''
EndOfLine='' EndOfLine=''
# barrier was detected # barrier was detected
BarrierFound='' BarrierFound=''
# barrier mode starts
BarrierStart=''
# barrier mode ends
BarrierEnd=''
# the Line is empty # the Line is empty
EmptyLine='' EmptyLine=''
# Is the first line on the screen. # Is the first line on the screen.

View File

@ -48,7 +48,9 @@ class command():
# barrier # barrier
sayLine = currLine sayLine = currLine
if self.env['runtime']['settingsManager'].getSettingAsBool('barrier','enabled'): if self.env['runtime']['settingsManager'].getSettingAsBool('barrier','enabled'):
sayLine = self.env['runtime']['barrierManager'].handleLineBarrier(sayLine, self.env['screen']['newCursor']['x']) isBarrier, barrierLine = self.env['runtime']['barrierManager'].handleLineBarrier(self.env['screen']['newContentText'].split('\n'), self.env['screen']['newCursor']['x'],self.env['screen']['newCursor']['y'])
if isBarrier:
sayLine = barrierLine
# output # output
self.env['runtime']['outputManager'].presentText(sayLine, interrupt=doInterrupt, flush=False) self.env['runtime']['outputManager'].presentText(sayLine, interrupt=doInterrupt, flush=False)
self.lastIdent = currIdent self.lastIdent = currIdent

View File

@ -24,43 +24,53 @@ class barrierManager():
self.prefIsBarrier = False self.prefIsBarrier = False
def isBarrierChange(self): def isBarrierChange(self):
return self.currIsBarrier != self.prefIsBarrier return self.currIsBarrier != self.prefIsBarrier
def handleLineBarrier(self, line, xCursor, output=True, doInterrupt=True): def handleLineBarrier(self, text, xCursor, yCursor, output=True, doInterrupt=True):
isBarrier, sayLine = self.getBarrierText(line, xCursor) isBarrier = False
try:
isBarrier, sayLine = self.getBarrierText(text, xCursor, yCursor)
except Exception as e:
return False, ''
self.updateBarrierChange(isBarrier) self.updateBarrierChange(isBarrier)
#if self.isBarrierChange(): if self.isBarrierChange():
if isBarrier: if output:
if output: if isBarrier:
self.env['runtime']['outputManager'].playSoundIcon(soundIcon='BarrierFound', interrupt=doInterrupt) self.env['runtime']['outputManager'].playSoundIcon(soundIcon='BarrierStart', interrupt=doInterrupt)
return sayLine else:
self.env['runtime']['outputManager'].playSoundIcon(soundIcon='BarrierEnd', interrupt=doInterrupt)
if not isBarrier:
sayLine = ''
return isBarrier, sayLine
def hasBorder(self, text, xCursor, yCursor, validBorder): def hasBorder(self, text, xCursor, yCursor, validBorder, barrierPos):
# check for corners here # check for corners here
lastLineNo = len(text) - 1 lastLineNo = len(text) - 1
if yCursor <= 0: if yCursor <= 0:
if not (text[0][xCursor] in validBorder): if not (text[0][barrierPos] in validBorder):
return False return False
if len(text) > 1: if len(text) > 1:
if not (text[1][xCursor] in validBorder): if not (text[1][barrierPos] in validBorder):
return False return False
if len(text) > 2: if len(text) > 2:
if not (text[2][xCursor] in validBorder): if not (text[2][barrierPos] in validBorder):
return False return False
elif yCursor >= lastLineNo: elif yCursor >= lastLineNo:
if not (text[lastLineNo][xCursor] in validBorder): if not (text[lastLineNo][barrierPos] in validBorder):
return False return False
if len(text) > 1: if len(text) > 1:
if not (text[lastLineNo - 1][xCursor] in validBorder): if not (text[lastLineNo - 1][barrierPos] in validBorder):
return False return False
if len(text) > 2: if len(text) > 2:
if not (text[lastLineNo - 2][xCursor] in validBorder): if not (text[lastLineNo - 2][barrierPos] in validBorder):
return False return False
else: else:
if not (text[yCursor][xCursor] in validBorder): if not (text[yCursor][barrierPos] in validBorder):
return False return False
if not (text[yCursor - 1][xCursor] in validBorder): if not (text[yCursor - 1][barrierPos] in validBorder):
return False return False
if not (text[yCursor + 1][xCursor] in validBorder): if not (text[yCursor + 1][barrierPos] in validBorder):
return False return False
return True return True
def getBarrierText(self, text, xCursor, yCursor): def getBarrierText(self, text, xCursor, yCursor):
line = text[yCursor] line = text[yCursor]
@ -68,27 +78,30 @@ class barrierManager():
return False, line return False, line
offset = xCursor offset = xCursor
leftBarriers = self.env['runtime']['settingsManager'].getSetting('barrier', 'barrier') leftBarriers = self.env['runtime']['settingsManager'].getSetting('barrier', 'leftBarriers')
rightBarriers = self.env['runtime']['settingsManager'].getSetting('barrier', 'grabDevices') rightBarriers = self.env['runtime']['settingsManager'].getSetting('barrier', 'rightBarriers')
# is the cursor at the begin or end of an entry: # is the cursor at the begin or end of an entry:
#print(line[:offset + 1].count('│'),line[offset:].count('│')) #print(line[:offset + 1].count('│'),line[offset:].count('│'))
# start # start
for b in leftBarriers: for b in leftBarriers:
if line[:offset + 1].count(b) > line[offset:].count(b): if line[:offset + 1].count(b) > line[offset:].count(b):
offset = xCursor - 1 offset = xCursor - 1
start = line[:offset + 1].rfind(b)
start = line[:offset + 1].rfind(b) + 1
if start != -1: if start != -1:
if not self.hasBorder(text, xCursor, yCursor): if not self.hasBorder(text, xCursor, yCursor, leftBarriers, start):
start = -1 start = -1
else:
start += 1
break break
if start == -1: if start == -1:
return False, line return False, line
# end # end
for b in rightBarriers: for b in rightBarriers:
end = line[offset + 1:].find(b) end = line[start + 1:].find(b)
if end != -1: if end != -1:
if not self.hasBorder(text, xCursor, yCursor): end = start + end
if not self.hasBorder(text, xCursor, yCursor,rightBarriers, end + 1):
end = -1 end = -1
break break
if end == -1: if end == -1: