port onInput to new return values
This commit is contained in:
parent
4a46858bd0
commit
591511fc75
@ -96,7 +96,7 @@ interruptOnKeyPress=False
|
||||
doubleTapTimeout=0.2
|
||||
|
||||
[general]
|
||||
debugLevel=0
|
||||
debugLevel=1
|
||||
punctuationProfile=default
|
||||
punctuationLevel=some
|
||||
respectPunctuationPause=True
|
||||
|
@ -17,13 +17,13 @@ class command():
|
||||
return ''
|
||||
|
||||
def run(self):
|
||||
if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'interruptOnKeyPress'):
|
||||
return
|
||||
if self.env['runtime']['inputManager'].noKeyPressed():
|
||||
return
|
||||
if len(self.env['input']['prevDeepestInput']) > len(self.env['input']['currInput']):
|
||||
return
|
||||
if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'interruptOnKeyPress'):
|
||||
return
|
||||
if self.env['screenData']['newTTY'] != self.env['screenData']['oldTTY']:
|
||||
if self.environment['runtime']['screenManager'].isScreenChange():
|
||||
return
|
||||
self.env['runtime']['outputManager'].interruptOutput()
|
||||
|
||||
|
@ -18,22 +18,22 @@ class command():
|
||||
return ''
|
||||
|
||||
def run(self):
|
||||
if self.environment['runtime']['screenManager'].isScreenChange():
|
||||
if self.env['runtime']['screenManager'].isScreenChange():
|
||||
return
|
||||
if self.env['runtime']['inputManager'].noKeyPressed():
|
||||
return
|
||||
# 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
|
||||
if self.environment['runtime']['screenManager'].isNegativeDelta():
|
||||
if self.env['runtime']['screenManager'].isNegativeDelta():
|
||||
return
|
||||
# is a vertical change?
|
||||
if self.environment['runtime']['cursorManager'].isCursorVerticalMove():
|
||||
if self.env['runtime']['cursorManager'].isCursorVerticalMove():
|
||||
return
|
||||
# is it a horizontal change?
|
||||
if not self.environment['runtime']['cursorManager'].isCursorHorizontalMove():
|
||||
if not self.env['runtime']['cursorManager'].isCursorHorizontalMove():
|
||||
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():
|
||||
self.env['runtime']['outputManager'].presentText(currChar, interrupt=True, ignorePunctuation=True, announceCapital=True)
|
||||
def setCallback(self, callback):
|
||||
|
@ -20,15 +20,15 @@ class command():
|
||||
def run(self):
|
||||
if self.env['runtime']['inputManager'].noKeyPressed():
|
||||
return
|
||||
if self.environment['runtime']['screenManager'].isScreenChange():
|
||||
if self.env['runtime']['screenManager'].isScreenChange():
|
||||
return
|
||||
if self.environment['runtime']['screenManager'].isDelta():
|
||||
if self.env['runtime']['screenManager'].isDelta():
|
||||
return
|
||||
# is a vertical change?
|
||||
if not self.environment['runtime']['cursorManager'].isCursorVerticalMove():
|
||||
if not self.env['runtime']['cursorManager'].isCursorVerticalMove():
|
||||
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():
|
||||
self.env['runtime']['outputManager'].presentText("blank", soundIcon='EmptyLine', interrupt=True)
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
from core import debug
|
||||
from utils import word_utils
|
||||
import string
|
||||
|
||||
class command():
|
||||
def __init__(self):
|
||||
@ -26,28 +27,26 @@ class command():
|
||||
return
|
||||
|
||||
# just when cursor move worddetection is needed
|
||||
if not self.environment['runtime']['cursorManager'].isCursorHorizontalMove():
|
||||
if not self.env['runtime']['cursorManager'].isCursorHorizontalMove():
|
||||
return
|
||||
if self.env['runtime']['inputManager'].noKeyPressed():
|
||||
return
|
||||
# for now no new line
|
||||
if self.environment['runtime']['cursorManager'].isCursorVerticalMove():
|
||||
if self.env['runtime']['cursorManager'].isCursorVerticalMove():
|
||||
return
|
||||
# is there a delta bigger than keyecho?
|
||||
if len(self.env['screenData']['newDelta']) > 1:
|
||||
return
|
||||
|
||||
|
||||
# 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)
|
||||
x, y, currWord = 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']):
|
||||
if self.env['runtime']['screenManager'].isDelta():
|
||||
# is there a delta bigger than keyecho?
|
||||
if len(self.env['screenData']['newDelta']) > 1:
|
||||
return
|
||||
if not(newContent[self.env['screenData']['oldCursor']['x']].isspace() and x != self.env['screenData']['oldCursor']['x']):
|
||||
return
|
||||
else:
|
||||
# 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
|
||||
|
||||
if currWord != '':
|
||||
|
@ -45,17 +45,17 @@ class command():
|
||||
return
|
||||
|
||||
# just when cursor move worddetection is needed
|
||||
if not self.environment['runtime']['cursorManager'].isCursorHorizontalMove():
|
||||
if not self.env['runtime']['cursorManager'].isCursorHorizontalMove():
|
||||
return
|
||||
|
||||
# for now no new line
|
||||
if self.environment['runtime']['cursorManager'].isCursorVerticalMove():
|
||||
if self.env['runtime']['cursorManager'].isCursorVerticalMove():
|
||||
return
|
||||
# more than a keyecho?
|
||||
if len(self.env['screenData']['newDelta']) > 1:
|
||||
return
|
||||
# deletion
|
||||
if self.environment['runtime']['screenManager'].isNegativeDelta():
|
||||
if self.env['runtime']['screenManager'].isNegativeDelta():
|
||||
return
|
||||
# first place could not be the end of a word
|
||||
if self.env['screenData']['newCursor']['x'] == 0:
|
||||
@ -63,7 +63,7 @@ class command():
|
||||
|
||||
# get the word (just for speedup only look at current line
|
||||
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?
|
||||
if self.env['screenData']['newDelta'] != '':
|
||||
if not(newContent[self.env['screenData']['oldCursor']['x']] in string.whitespace + '!"#$%&()*+,-./:;<=>?@[\\]^_{|}~' and x != self.env['screenData']['oldCursor']['x']):
|
||||
|
@ -19,9 +19,9 @@ class command():
|
||||
def run(self):
|
||||
if self.env['runtime']['inputManager'].noKeyPressed():
|
||||
return
|
||||
if self.env['screenData']['newTTY'] != self.env['screenData']['oldTTY']:
|
||||
if self.env['runtime']['screenManager'].isScreenChange():
|
||||
return
|
||||
if self.env['screenData']['newCursor']['y'] != self.env['screenData']['oldCursor']['y']:
|
||||
if self.env['runtime']['cursorManager'].isCursorVerticalMove():
|
||||
return
|
||||
if len(self.env['input']['currInput']) != 1:
|
||||
return
|
||||
|
@ -47,27 +47,30 @@ class cursorManager():
|
||||
return
|
||||
self.env['screenData']['oldCursorReview'] = None
|
||||
self.env['screenData']['newCursorReview'] = None
|
||||
|
||||
def isCursorHorizontalMove(self):
|
||||
return self.env['screenData']['newCursor']['x'] != self.env['screenData']['oldCursor']['x']
|
||||
|
||||
def isCursorVerticalMove(self):
|
||||
return self.env['screenData']['newCursor']['y'] != self.env['screenData']['oldCursor']['y']
|
||||
|
||||
|
||||
def isReviewMode(self):
|
||||
return self.env['screenData']['newCursorReview'] != None
|
||||
|
||||
def enterReviewModeCurrTextCursor(self, overwrite=False):
|
||||
if self.isReviewMode() and not overwrite:
|
||||
return
|
||||
self.env['screenData']['oldCursorReview'] = self.env['screenData']['newCursorReview']
|
||||
if not self.env['screenData']['newCursorReview']:
|
||||
self.env['screenData']['newCursorReview'] = self.env['screenData']['newCursor'].copy()
|
||||
|
||||
def setReviewCursorPosition(self, x, y):
|
||||
if not self.isReviewMode():
|
||||
self.enterReviewModeCurrTextCursor()
|
||||
self.env['screenData']['oldCursorReview'] = self.env['screenData']['newCursorReview']
|
||||
self.env['screenData']['newCursorReview']['x'] = x
|
||||
self.env['screenData']['newCursorReview']['y'] = y
|
||||
|
||||
def isApplicationWindowSet(self):
|
||||
try:
|
||||
currApp = self.env['runtime']['applicationManager'].getCurrentApplication()
|
||||
|
@ -7,6 +7,7 @@
|
||||
from core import debug
|
||||
|
||||
def getPrevChar(currX,currY, currText):
|
||||
lineBreak = False
|
||||
endOfScreen = False
|
||||
if currText == '':
|
||||
return -1, -1, '', endOfScreen
|
||||
@ -17,20 +18,20 @@ def getPrevChar(currX,currY, currText):
|
||||
if y - 1 > 0:
|
||||
y -= 1
|
||||
x = len(wrappedLines[y]) - 1
|
||||
lineBreak = True
|
||||
else:
|
||||
endOfScreen = True
|
||||
else:
|
||||
x -= 1
|
||||
currChar = wrappedLines[y][x]
|
||||
return x, y, currChar, endOfScreen
|
||||
return x, y, currChar, endOfScreen, lineBreak
|
||||
|
||||
def getCurrentChar(currX,currY, currText):
|
||||
endOfScreen = False
|
||||
if currText == '':
|
||||
return -1, -1, '', endOfScreen
|
||||
wrappedLines = currText.split('\n')
|
||||
currChar = wrappedLines[currY][currX]
|
||||
return currX, currY, currChar, endOfScreen
|
||||
return currX, currY, currChar
|
||||
|
||||
def getUpChar(currX,currY, currText):
|
||||
endOfScreen = False
|
||||
@ -70,6 +71,7 @@ def getLastCharInLine(currY, currText):
|
||||
return currX, currY, currChar, endOfScreen
|
||||
|
||||
def getNextChar(currX,currY, currText):
|
||||
lineBreak = False
|
||||
endOfScreen = False
|
||||
if currText == '':
|
||||
return -1, -1, '', endOfScreen
|
||||
@ -80,6 +82,7 @@ def getNextChar(currX,currY, currText):
|
||||
if y + 1 < len(wrappedLines) - 1:
|
||||
y += 1
|
||||
x = 0
|
||||
lineBreak = True
|
||||
else:
|
||||
endOfScreen = True
|
||||
else:
|
||||
|
@ -22,7 +22,6 @@ def getPrevLine(currX,currY, currText):
|
||||
return x, y, currLine, endOfScreen
|
||||
|
||||
def getCurrentLine(currX,currY, currText):
|
||||
endOfScreen = False
|
||||
if currText == '':
|
||||
return -1, -1, '', endOfScreen
|
||||
wrappedLines = currText.split('\n')
|
||||
@ -30,7 +29,7 @@ def getCurrentLine(currX,currY, currText):
|
||||
y = currY
|
||||
x = 0
|
||||
currLine = wrappedLines[y]
|
||||
return x, y, currLine, endOfScreen
|
||||
return x, y, currLine
|
||||
|
||||
def getNextLine(currX,currY, currText):
|
||||
endOfScreen = False
|
||||
|
@ -5,108 +5,39 @@
|
||||
# By Chrys, Storm Dragon, and contributers.
|
||||
|
||||
from core import debug
|
||||
|
||||
# X Y Word END
|
||||
# -1, -1, '', True
|
||||
def getPrevWord(currX,currY, currText):
|
||||
lineBreak = False
|
||||
endOfScreen = False
|
||||
if currText == '':
|
||||
return -1, -1, ''
|
||||
x, y, currWord = getCurrentWord(currX,currY,currText)
|
||||
return -1, -1, '', endOfScreen
|
||||
x, y, currWord, endOfScreen = getCurrentWord(currX,currY,currText)
|
||||
if endOfScreen:
|
||||
return x, y, currWord, endOfScreen
|
||||
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
|
||||
return x, y, currWord, endOfScreen, lineBreak
|
||||
|
||||
def getCurrentWord(currX,currY, currText):
|
||||
lineBreak = False
|
||||
endOfScreen = False
|
||||
if currText == '':
|
||||
return -1, -1, ''
|
||||
return -1, -1, '', endOfScreen
|
||||
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
|
||||
return x, y, currWord, endOfScreen, lineBreak
|
||||
|
||||
def getNextWord(currX,currY, currText):
|
||||
lineBreak = False
|
||||
endOfScreen = False
|
||||
if currText == '':
|
||||
return -1, -1, ''
|
||||
return -1, -1, '', endOfScreen
|
||||
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
|
||||
return x, y, currWord, endOfScreen, lineBreak
|
||||
|
112
src/fenrir/utils/word_utils.py.bak
Normal file
112
src/fenrir/utils/word_utils.py.bak
Normal 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
|
@ -8,6 +8,7 @@ from core import debug
|
||||
# X Y Word END
|
||||
# -1, -1, '', True
|
||||
def getPrevWord(currX,currY, currText):
|
||||
lineBreak = False
|
||||
endOfScreen = False
|
||||
if currText == '':
|
||||
return -1, -1, '', endOfScreen
|
||||
@ -15,10 +16,10 @@ def getPrevWord(currX,currY, currText):
|
||||
if endOfScreen:
|
||||
return x, y, currWord, endOfScreen
|
||||
wrappedLines = currText.split('\n')
|
||||
|
||||
return x, y, currWord, endOfScreen
|
||||
return x, y, currWord, endOfScreen, lineBreak
|
||||
|
||||
def getCurrentWord(currX,currY, currText):
|
||||
lineBreak = False
|
||||
endOfScreen = False
|
||||
if currText == '':
|
||||
return -1, -1, '', endOfScreen
|
||||
@ -27,9 +28,10 @@ def getCurrentWord(currX,currY, currText):
|
||||
wrappedLines = currText.split('\n')
|
||||
currWord = ''
|
||||
currLine = wrappedLines[y].replace("\t"," ")
|
||||
return x, y, currWord, endOfScreen
|
||||
return x, y, currWord, endOfScreen, lineBreak
|
||||
|
||||
def getNextWord(currX,currY, currText):
|
||||
lineBreak = False
|
||||
endOfScreen = False
|
||||
if currText == '':
|
||||
return -1, -1, '', endOfScreen
|
||||
@ -38,4 +40,4 @@ def getNextWord(currX,currY, currText):
|
||||
wrappedLines = currText.split('\n')
|
||||
currWord = ''
|
||||
currLine = wrappedLines[y].replace("\t"," ")
|
||||
return x, y, currWord, endOfScreen
|
||||
return x, y, currWord, endOfScreen, lineBreak
|
||||
|
Loading…
Reference in New Issue
Block a user