port onInput to new return values

This commit is contained in:
chrys 2016-10-21 17:21:39 +02:00
parent 4a46858bd0
commit 591511fc75
13 changed files with 178 additions and 129 deletions

View File

@ -96,7 +96,7 @@ interruptOnKeyPress=False
doubleTapTimeout=0.2 doubleTapTimeout=0.2
[general] [general]
debugLevel=0 debugLevel=1
punctuationProfile=default punctuationProfile=default
punctuationLevel=some punctuationLevel=some
respectPunctuationPause=True respectPunctuationPause=True

View File

@ -17,13 +17,13 @@ class command():
return '' return ''
def run(self): def run(self):
if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'interruptOnKeyPress'):
return
if self.env['runtime']['inputManager'].noKeyPressed(): if self.env['runtime']['inputManager'].noKeyPressed():
return return
if len(self.env['input']['prevDeepestInput']) > len(self.env['input']['currInput']): if len(self.env['input']['prevDeepestInput']) > len(self.env['input']['currInput']):
return return
if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'interruptOnKeyPress'): if self.environment['runtime']['screenManager'].isScreenChange():
return
if self.env['screenData']['newTTY'] != self.env['screenData']['oldTTY']:
return return
self.env['runtime']['outputManager'].interruptOutput() self.env['runtime']['outputManager'].interruptOutput()

View File

@ -18,22 +18,22 @@ class command():
return '' return ''
def run(self): def run(self):
if self.environment['runtime']['screenManager'].isScreenChange(): if self.env['runtime']['screenManager'].isScreenChange():
return return
if self.env['runtime']['inputManager'].noKeyPressed(): if self.env['runtime']['inputManager'].noKeyPressed():
return return
# detect an change on the screen, we just want to cursor arround, so no change should appear # detect an change on the screen, we just want to cursor arround, so no change should appear
if self.environment['runtime']['screenManager'].isDelta(): if self.env['runtime']['screenManager'].isDelta():
return return
if self.environment['runtime']['screenManager'].isNegativeDelta(): if self.env['runtime']['screenManager'].isNegativeDelta():
return return
# is a vertical change? # is a vertical change?
if self.environment['runtime']['cursorManager'].isCursorVerticalMove(): if self.env['runtime']['cursorManager'].isCursorVerticalMove():
return return
# is it a horizontal change? # is it a horizontal change?
if not self.environment['runtime']['cursorManager'].isCursorHorizontalMove(): if not self.env['runtime']['cursorManager'].isCursorHorizontalMove():
return return
x, y, currChar, endOfScreen = char_utils.getCurrentChar(self.env['screenData']['newCursor']['x'], self.env['screenData']['newCursor']['y'], self.env['screenData']['newContentText']) x, y, currChar = char_utils.getCurrentChar(self.env['screenData']['newCursor']['x'], self.env['screenData']['newCursor']['y'], self.env['screenData']['newContentText'])
if not currChar.isspace(): if not currChar.isspace():
self.env['runtime']['outputManager'].presentText(currChar, interrupt=True, ignorePunctuation=True, announceCapital=True) self.env['runtime']['outputManager'].presentText(currChar, interrupt=True, ignorePunctuation=True, announceCapital=True)
def setCallback(self, callback): def setCallback(self, callback):

View File

@ -20,15 +20,15 @@ class command():
def run(self): def run(self):
if self.env['runtime']['inputManager'].noKeyPressed(): if self.env['runtime']['inputManager'].noKeyPressed():
return return
if self.environment['runtime']['screenManager'].isScreenChange(): if self.env['runtime']['screenManager'].isScreenChange():
return return
if self.environment['runtime']['screenManager'].isDelta(): if self.env['runtime']['screenManager'].isDelta():
return return
# is a vertical change? # is a vertical change?
if not self.environment['runtime']['cursorManager'].isCursorVerticalMove(): if not self.env['runtime']['cursorManager'].isCursorVerticalMove():
return return
x, y, currLine, endOfScreen = line_utils.getCurrentLine(self.env['screenData']['newCursor']['x'], self.env['screenData']['newCursor']['y'], self.env['screenData']['newContentText']) x, y, currLine = line_utils.getCurrentLine(self.env['screenData']['newCursor']['x'], self.env['screenData']['newCursor']['y'], self.env['screenData']['newContentText'])
if currLine.isspace(): if currLine.isspace():
self.env['runtime']['outputManager'].presentText("blank", soundIcon='EmptyLine', interrupt=True) self.env['runtime']['outputManager'].presentText("blank", soundIcon='EmptyLine', interrupt=True)

View File

@ -6,6 +6,7 @@
from core import debug from core import debug
from utils import word_utils from utils import word_utils
import string
class command(): class command():
def __init__(self): def __init__(self):
@ -26,28 +27,26 @@ class command():
return return
# just when cursor move worddetection is needed # just when cursor move worddetection is needed
if not self.environment['runtime']['cursorManager'].isCursorHorizontalMove(): if not self.env['runtime']['cursorManager'].isCursorHorizontalMove():
return return
if self.env['runtime']['inputManager'].noKeyPressed(): if self.env['runtime']['inputManager'].noKeyPressed():
return return
# for now no new line # for now no new line
if self.environment['runtime']['cursorManager'].isCursorVerticalMove(): if self.env['runtime']['cursorManager'].isCursorVerticalMove():
return return
# get the word
newContent = self.env['screenData']['newContentText'].split('\n')[self.env['screenData']['newCursor']['y']]
x, y, currWord = word_utils.getCurrentWord(self.env['screenData']['newCursor']['x'], 0, newContent)
# was this a typed word?
if self.env['runtime']['screenManager'].isDelta():
# is there a delta bigger than keyecho? # is there a delta bigger than keyecho?
if len(self.env['screenData']['newDelta']) > 1: if len(self.env['screenData']['newDelta']) > 1:
return return
if not(newContent[self.env['screenData']['oldCursor']['x']].isspace() and x != self.env['screenData']['oldCursor']['x']):
# get the word
newContent = self.env['screenData']['newContentText'].split('\n')[self.env['screenData']['newCursor']['y']]
x, y, currWord, endOfScreen = word_utils.getCurrentWord(self.env['screenData']['newCursor']['x'], 0, newContent)
# was this a typed word?
if self.env['screenData']['newDelta'] != '':
if not(newContent[self.env['screenData']['oldCursor']['x']].strip(" \t\n") == '' and x != self.env['screenData']['oldCursor']['x']):
return return
else: else:
# or just arrow arround? # or just arrow arround?
if not(newContent[self.env['screenData']['newCursor']['x']].strip(" \t\n") == '' and x != self.env['screenData']['newCursor']['x']): if not(newContent[self.env['screenData']['newCursor']['x']].isspace() and x != self.env['screenData']['newCursor']['x']):
return return
if currWord != '': if currWord != '':

View File

@ -45,17 +45,17 @@ class command():
return return
# just when cursor move worddetection is needed # just when cursor move worddetection is needed
if not self.environment['runtime']['cursorManager'].isCursorHorizontalMove(): if not self.env['runtime']['cursorManager'].isCursorHorizontalMove():
return return
# for now no new line # for now no new line
if self.environment['runtime']['cursorManager'].isCursorVerticalMove(): if self.env['runtime']['cursorManager'].isCursorVerticalMove():
return return
# more than a keyecho? # more than a keyecho?
if len(self.env['screenData']['newDelta']) > 1: if len(self.env['screenData']['newDelta']) > 1:
return return
# deletion # deletion
if self.environment['runtime']['screenManager'].isNegativeDelta(): if self.env['runtime']['screenManager'].isNegativeDelta():
return return
# first place could not be the end of a word # first place could not be the end of a word
if self.env['screenData']['newCursor']['x'] == 0: if self.env['screenData']['newCursor']['x'] == 0:
@ -63,7 +63,7 @@ class command():
# get the word (just for speedup only look at current line # get the word (just for speedup only look at current line
newContent = self.env['screenData']['newContentText'].split('\n')[self.env['screenData']['newCursor']['y']] newContent = self.env['screenData']['newContentText'].split('\n')[self.env['screenData']['newCursor']['y']]
x, y, currWord, endOfScreen = word_utils.getCurrentWord(self.env['screenData']['newCursor']['x'], 0, newContent) x, y, currWord, endOfScreen, lineBreak = word_utils.getCurrentWord(self.env['screenData']['newCursor']['x'], 0, newContent)
# was this a typed word? # was this a typed word?
if self.env['screenData']['newDelta'] != '': if self.env['screenData']['newDelta'] != '':
if not(newContent[self.env['screenData']['oldCursor']['x']] in string.whitespace + '!"#$%&()*+,-./:;<=>?@[\\]^_{|}~' and x != self.env['screenData']['oldCursor']['x']): if not(newContent[self.env['screenData']['oldCursor']['x']] in string.whitespace + '!"#$%&()*+,-./:;<=>?@[\\]^_{|}~' and x != self.env['screenData']['oldCursor']['x']):

View File

@ -19,9 +19,9 @@ class command():
def run(self): def run(self):
if self.env['runtime']['inputManager'].noKeyPressed(): if self.env['runtime']['inputManager'].noKeyPressed():
return return
if self.env['screenData']['newTTY'] != self.env['screenData']['oldTTY']: if self.env['runtime']['screenManager'].isScreenChange():
return return
if self.env['screenData']['newCursor']['y'] != self.env['screenData']['oldCursor']['y']: if self.env['runtime']['cursorManager'].isCursorVerticalMove():
return return
if len(self.env['input']['currInput']) != 1: if len(self.env['input']['currInput']) != 1:
return return

View File

@ -47,27 +47,30 @@ class cursorManager():
return return
self.env['screenData']['oldCursorReview'] = None self.env['screenData']['oldCursorReview'] = None
self.env['screenData']['newCursorReview'] = None self.env['screenData']['newCursorReview'] = None
def isCursorHorizontalMove(self): def isCursorHorizontalMove(self):
return self.env['screenData']['newCursor']['x'] != self.env['screenData']['oldCursor']['x'] return self.env['screenData']['newCursor']['x'] != self.env['screenData']['oldCursor']['x']
def isCursorVerticalMove(self): def isCursorVerticalMove(self):
return self.env['screenData']['newCursor']['y'] != self.env['screenData']['oldCursor']['y'] return self.env['screenData']['newCursor']['y'] != self.env['screenData']['oldCursor']['y']
def isReviewMode(self): def isReviewMode(self):
return self.env['screenData']['newCursorReview'] != None return self.env['screenData']['newCursorReview'] != None
def enterReviewModeCurrTextCursor(self, overwrite=False): def enterReviewModeCurrTextCursor(self, overwrite=False):
if self.isReviewMode() and not overwrite: if self.isReviewMode() and not overwrite:
return return
self.env['screenData']['oldCursorReview'] = self.env['screenData']['newCursorReview'] self.env['screenData']['oldCursorReview'] = self.env['screenData']['newCursorReview']
if not self.env['screenData']['newCursorReview']: if not self.env['screenData']['newCursorReview']:
self.env['screenData']['newCursorReview'] = self.env['screenData']['newCursor'].copy() self.env['screenData']['newCursorReview'] = self.env['screenData']['newCursor'].copy()
def setReviewCursorPosition(self, x, y): def setReviewCursorPosition(self, x, y):
if not self.isReviewMode(): if not self.isReviewMode():
self.enterReviewModeCurrTextCursor() self.enterReviewModeCurrTextCursor()
self.env['screenData']['oldCursorReview'] = self.env['screenData']['newCursorReview'] self.env['screenData']['oldCursorReview'] = self.env['screenData']['newCursorReview']
self.env['screenData']['newCursorReview']['x'] = x self.env['screenData']['newCursorReview']['x'] = x
self.env['screenData']['newCursorReview']['y'] = y self.env['screenData']['newCursorReview']['y'] = y
def isApplicationWindowSet(self): def isApplicationWindowSet(self):
try: try:
currApp = self.env['runtime']['applicationManager'].getCurrentApplication() currApp = self.env['runtime']['applicationManager'].getCurrentApplication()

View File

@ -7,6 +7,7 @@
from core import debug from core import debug
def getPrevChar(currX,currY, currText): def getPrevChar(currX,currY, currText):
lineBreak = False
endOfScreen = False endOfScreen = False
if currText == '': if currText == '':
return -1, -1, '', endOfScreen return -1, -1, '', endOfScreen
@ -17,20 +18,20 @@ def getPrevChar(currX,currY, currText):
if y - 1 > 0: if y - 1 > 0:
y -= 1 y -= 1
x = len(wrappedLines[y]) - 1 x = len(wrappedLines[y]) - 1
lineBreak = True
else: else:
endOfScreen = True endOfScreen = True
else: else:
x -= 1 x -= 1
currChar = wrappedLines[y][x] currChar = wrappedLines[y][x]
return x, y, currChar, endOfScreen return x, y, currChar, endOfScreen, lineBreak
def getCurrentChar(currX,currY, currText): def getCurrentChar(currX,currY, currText):
endOfScreen = False
if currText == '': if currText == '':
return -1, -1, '', endOfScreen return -1, -1, '', endOfScreen
wrappedLines = currText.split('\n') wrappedLines = currText.split('\n')
currChar = wrappedLines[currY][currX] currChar = wrappedLines[currY][currX]
return currX, currY, currChar, endOfScreen return currX, currY, currChar
def getUpChar(currX,currY, currText): def getUpChar(currX,currY, currText):
endOfScreen = False endOfScreen = False
@ -70,6 +71,7 @@ def getLastCharInLine(currY, currText):
return currX, currY, currChar, endOfScreen return currX, currY, currChar, endOfScreen
def getNextChar(currX,currY, currText): def getNextChar(currX,currY, currText):
lineBreak = False
endOfScreen = False endOfScreen = False
if currText == '': if currText == '':
return -1, -1, '', endOfScreen return -1, -1, '', endOfScreen
@ -80,6 +82,7 @@ def getNextChar(currX,currY, currText):
if y + 1 < len(wrappedLines) - 1: if y + 1 < len(wrappedLines) - 1:
y += 1 y += 1
x = 0 x = 0
lineBreak = True
else: else:
endOfScreen = True endOfScreen = True
else: else:

View File

@ -22,7 +22,6 @@ def getPrevLine(currX,currY, currText):
return x, y, currLine, endOfScreen return x, y, currLine, endOfScreen
def getCurrentLine(currX,currY, currText): def getCurrentLine(currX,currY, currText):
endOfScreen = False
if currText == '': if currText == '':
return -1, -1, '', endOfScreen return -1, -1, '', endOfScreen
wrappedLines = currText.split('\n') wrappedLines = currText.split('\n')
@ -30,7 +29,7 @@ def getCurrentLine(currX,currY, currText):
y = currY y = currY
x = 0 x = 0
currLine = wrappedLines[y] currLine = wrappedLines[y]
return x, y, currLine, endOfScreen return x, y, currLine
def getNextLine(currX,currY, currText): def getNextLine(currX,currY, currText):
endOfScreen = False endOfScreen = False

View File

@ -5,108 +5,39 @@
# By Chrys, Storm Dragon, and contributers. # By Chrys, Storm Dragon, and contributers.
from core import debug from core import debug
# X Y Word END
# -1, -1, '', True
def getPrevWord(currX,currY, currText): def getPrevWord(currX,currY, currText):
lineBreak = False
endOfScreen = False
if currText == '': if currText == '':
return -1, -1, '' return -1, -1, '', endOfScreen
x, y, currWord = getCurrentWord(currX,currY,currText) x, y, currWord, endOfScreen = getCurrentWord(currX,currY,currText)
if endOfScreen:
return x, y, currWord, endOfScreen
wrappedLines = currText.split('\n') wrappedLines = currText.split('\n')
if (currWord == ''): return x, y, currWord, endOfScreen, lineBreak
return currX, currY, ''
while True:
if x < 2:
if y != 0:
y -= 1
else:
return currX, currY, ''
x = len(wrappedLines[y]) - 1
else:
x -= 1
if wrappedLines[y] != '':
break
x, y, currWord = getCurrentWord(x, y, currText)
if currWord == '':
return currX, currY, ''
return x, y, currWord
def getCurrentWord(currX,currY, currText): def getCurrentWord(currX,currY, currText):
lineBreak = False
endOfScreen = False
if currText == '': if currText == '':
return -1, -1, '' return -1, -1, '', endOfScreen
x = currX x = currX
y = currY y = currY
wrappedLines = currText.split('\n') wrappedLines = currText.split('\n')
wordFound = False
currWord = '' currWord = ''
currLine = wrappedLines[y].replace("\t"," ") currLine = wrappedLines[y].replace("\t"," ")
if currLine[x] == ' ' and x > 1: return x, y, currWord, endOfScreen, lineBreak
x = x - 2
while not wordFound:
x = currLine[:x].rfind(" ")
if x == -1:
x = 0
else:
x += 1
wordEnd = currLine[x + 1:].find(" ")
if wordEnd == -1:
wordEnd = len(currLine)
else:
wordEnd += x + 1
currWord = currLine[x:wordEnd]
wordFound = currWord.strip(" \t\n") != ''
if wordFound:
break
if x == 0:
if y != 0:
y -= 1
currLine = wrappedLines[y].replace("\t"," ")
else:
return currX, currY, ''
x = len(wrappedLines[y]) - 1
else:
x -= 1
return x, y, currWord
def getNextWord(currX,currY, currText): def getNextWord(currX,currY, currText):
lineBreak = False
endOfScreen = False
if currText == '': if currText == '':
return -1, -1, '' return -1, -1, '', endOfScreen
x = currX x = currX
y = currY y = currY
wrappedLines = currText.split('\n') wrappedLines = currText.split('\n')
wordFound = False
currWord = '' currWord = ''
currLine = wrappedLines[y].replace("\t"," ") currLine = wrappedLines[y].replace("\t"," ")
while not wordFound: return x, y, currWord, endOfScreen, lineBreak
xtmp = 0
if x + 1 >= len(currLine):
if y < len(wrappedLines):
y += 1
currLine = wrappedLines[y].replace("\t"," ")
else:
return currX, currY, ''
x = 0
else:
x += 1
xtmp = x
x = currLine[x:].find(" ")
if x == -1:
x = len(currLine)
continue
else:
if xtmp != 0:
xtmp += 1
x += xtmp
if x + 1 < len(currLine):
wordEnd = currLine[x + 1:].find(" ")
else:
wordEnd = -1
if wordEnd == -1:
wordEnd = len(currLine)
else:
wordEnd += x + 1
if wordEnd >= len(currLine) and y + 1 >= len(wrappedLines):
return currX, currY, ''
currWord = currLine[x:wordEnd]
wordFound = currWord.strip(" \t\n") != ''
if not wordFound:
x = wordEnd
return x, y, currWord

View File

@ -0,0 +1,112 @@
#!/bin/python
# -*- coding: utf-8 -*-
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
from core import debug
def getPrevWord(currX,currY, currText):
if currText == '':
return -1, -1, ''
x, y, currWord = getCurrentWord(currX,currY,currText)
wrappedLines = currText.split('\n')
if (currWord == ''):
return currX, currY, ''
while True:
if x < 2:
if y != 0:
y -= 1
else:
return currX, currY, ''
x = len(wrappedLines[y]) - 1
else:
x -= 1
if wrappedLines[y] != '':
break
x, y, currWord = getCurrentWord(x, y, currText)
if currWord == '':
return currX, currY, ''
return x, y, currWord
def getCurrentWord(currX,currY, currText):
if currText == '':
return -1, -1, ''
x = currX
y = currY
wrappedLines = currText.split('\n')
wordFound = False
currWord = ''
currLine = wrappedLines[y].replace("\t"," ")
if currLine[x] == ' ' and x > 1:
x = x - 2
while not wordFound:
x = currLine[:x].rfind(" ")
if x == -1:
x = 0
else:
x += 1
wordEnd = currLine[x + 1:].find(" ")
if wordEnd == -1:
wordEnd = len(currLine)
else:
wordEnd += x + 1
currWord = currLine[x:wordEnd]
wordFound = currWord.strip(" \t\n") != ''
if wordFound:
break
if x == 0:
if y != 0:
y -= 1
currLine = wrappedLines[y].replace("\t"," ")
else:
return currX, currY, ''
x = len(wrappedLines[y]) - 1
else:
x -= 1
return x, y, currWord
def getNextWord(currX,currY, currText):
if currText == '':
return -1, -1, ''
x = currX
y = currY
wrappedLines = currText.split('\n')
wordFound = False
currWord = ''
currLine = wrappedLines[y].replace("\t"," ")
while not wordFound:
xtmp = 0
if x + 1 >= len(currLine):
if y < len(wrappedLines):
y += 1
currLine = wrappedLines[y].replace("\t"," ")
else:
return currX, currY, ''
x = 0
else:
x += 1
xtmp = x
x = currLine[x:].find(" ")
if x == -1:
x = len(currLine)
continue
else:
if xtmp != 0:
xtmp += 1
x += xtmp
if x + 1 < len(currLine):
wordEnd = currLine[x + 1:].find(" ")
else:
wordEnd = -1
if wordEnd == -1:
wordEnd = len(currLine)
else:
wordEnd += x + 1
if wordEnd >= len(currLine) and y + 1 >= len(wrappedLines):
return currX, currY, ''
currWord = currLine[x:wordEnd]
wordFound = currWord.strip(" \t\n") != ''
if not wordFound:
x = wordEnd
return x, y, currWord

View File

@ -8,6 +8,7 @@ from core import debug
# X Y Word END # X Y Word END
# -1, -1, '', True # -1, -1, '', True
def getPrevWord(currX,currY, currText): def getPrevWord(currX,currY, currText):
lineBreak = False
endOfScreen = False endOfScreen = False
if currText == '': if currText == '':
return -1, -1, '', endOfScreen return -1, -1, '', endOfScreen
@ -15,10 +16,10 @@ def getPrevWord(currX,currY, currText):
if endOfScreen: if endOfScreen:
return x, y, currWord, endOfScreen return x, y, currWord, endOfScreen
wrappedLines = currText.split('\n') wrappedLines = currText.split('\n')
return x, y, currWord, endOfScreen, lineBreak
return x, y, currWord, endOfScreen
def getCurrentWord(currX,currY, currText): def getCurrentWord(currX,currY, currText):
lineBreak = False
endOfScreen = False endOfScreen = False
if currText == '': if currText == '':
return -1, -1, '', endOfScreen return -1, -1, '', endOfScreen
@ -27,9 +28,10 @@ def getCurrentWord(currX,currY, currText):
wrappedLines = currText.split('\n') wrappedLines = currText.split('\n')
currWord = '' currWord = ''
currLine = wrappedLines[y].replace("\t"," ") currLine = wrappedLines[y].replace("\t"," ")
return x, y, currWord, endOfScreen return x, y, currWord, endOfScreen, lineBreak
def getNextWord(currX,currY, currText): def getNextWord(currX,currY, currText):
lineBreak = False
endOfScreen = False endOfScreen = False
if currText == '': if currText == '':
return -1, -1, '', endOfScreen return -1, -1, '', endOfScreen
@ -38,4 +40,4 @@ def getNextWord(currX,currY, currText):
wrappedLines = currText.split('\n') wrappedLines = currText.split('\n')
currWord = '' currWord = ''
currLine = wrappedLines[y].replace("\t"," ") currLine = wrappedLines[y].replace("\t"," ")
return x, y, currWord, endOfScreen return x, y, currWord, endOfScreen, lineBreak