From 591511fc7555fe6d3fc23c7778f988f1c92f5f05 Mon Sep 17 00:00:00 2001 From: chrys Date: Fri, 21 Oct 2016 17:21:39 +0200 Subject: [PATCH] port onInput to new return values --- config/settings/settings.conf | 2 +- src/fenrir/commands/onInput/10000-shut_up.py | 6 +- ...resent_char_if_cursor_change_horizontal.py | 12 +- ...-present_line_if_cursor_change_vertical.py | 8 +- .../commands/onInput/60000-word_echo.py | 25 ++-- .../commands/onInput/62000-spell_check.py | 8 +- src/fenrir/commands/onInput/72000-history.py | 4 +- src/fenrir/core/cursorManager.py | 5 +- src/fenrir/utils/char_utils.py | 9 +- src/fenrir/utils/line_utils.py | 3 +- src/fenrir/utils/word_utils.py | 103 +++------------- src/fenrir/utils/word_utils.py.bak | 112 ++++++++++++++++++ src/fenrir/utils/word_utils2.py | 10 +- 13 files changed, 178 insertions(+), 129 deletions(-) create mode 100644 src/fenrir/utils/word_utils.py.bak diff --git a/config/settings/settings.conf b/config/settings/settings.conf index e37308f5..4c2e50ef 100644 --- a/config/settings/settings.conf +++ b/config/settings/settings.conf @@ -96,7 +96,7 @@ interruptOnKeyPress=False doubleTapTimeout=0.2 [general] -debugLevel=0 +debugLevel=1 punctuationProfile=default punctuationLevel=some respectPunctuationPause=True diff --git a/src/fenrir/commands/onInput/10000-shut_up.py b/src/fenrir/commands/onInput/10000-shut_up.py index 09c47165..b2ba6fa6 100644 --- a/src/fenrir/commands/onInput/10000-shut_up.py +++ b/src/fenrir/commands/onInput/10000-shut_up.py @@ -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() diff --git a/src/fenrir/commands/onInput/45000-present_char_if_cursor_change_horizontal.py b/src/fenrir/commands/onInput/45000-present_char_if_cursor_change_horizontal.py index bfbddab6..52890f3c 100644 --- a/src/fenrir/commands/onInput/45000-present_char_if_cursor_change_horizontal.py +++ b/src/fenrir/commands/onInput/45000-present_char_if_cursor_change_horizontal.py @@ -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): diff --git a/src/fenrir/commands/onInput/55000-present_line_if_cursor_change_vertical.py b/src/fenrir/commands/onInput/55000-present_line_if_cursor_change_vertical.py index 5ba32f75..ce95e65e 100644 --- a/src/fenrir/commands/onInput/55000-present_line_if_cursor_change_vertical.py +++ b/src/fenrir/commands/onInput/55000-present_line_if_cursor_change_vertical.py @@ -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) diff --git a/src/fenrir/commands/onInput/60000-word_echo.py b/src/fenrir/commands/onInput/60000-word_echo.py index 025593e6..9b9564ad 100644 --- a/src/fenrir/commands/onInput/60000-word_echo.py +++ b/src/fenrir/commands/onInput/60000-word_echo.py @@ -6,6 +6,7 @@ from core import debug from utils import word_utils +import string class command(): def __init__(self): @@ -26,29 +27,27 @@ 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 + # 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']): - return + if not(newContent[self.env['screenData']['newCursor']['x']].isspace() and x != self.env['screenData']['newCursor']['x']): + return if currWord != '': self.env['runtime']['outputManager'].presentText(currWord, interrupt=True) diff --git a/src/fenrir/commands/onInput/62000-spell_check.py b/src/fenrir/commands/onInput/62000-spell_check.py index ca4c76b7..2024ea4f 100644 --- a/src/fenrir/commands/onInput/62000-spell_check.py +++ b/src/fenrir/commands/onInput/62000-spell_check.py @@ -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']): diff --git a/src/fenrir/commands/onInput/72000-history.py b/src/fenrir/commands/onInput/72000-history.py index 12bcd9d3..e86461d8 100644 --- a/src/fenrir/commands/onInput/72000-history.py +++ b/src/fenrir/commands/onInput/72000-history.py @@ -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 diff --git a/src/fenrir/core/cursorManager.py b/src/fenrir/core/cursorManager.py index a30d57c8..1fcaad0a 100644 --- a/src/fenrir/core/cursorManager.py +++ b/src/fenrir/core/cursorManager.py @@ -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() diff --git a/src/fenrir/utils/char_utils.py b/src/fenrir/utils/char_utils.py index caf90732..78d1950f 100644 --- a/src/fenrir/utils/char_utils.py +++ b/src/fenrir/utils/char_utils.py @@ -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: diff --git a/src/fenrir/utils/line_utils.py b/src/fenrir/utils/line_utils.py index 10ded91c..763b9042 100644 --- a/src/fenrir/utils/line_utils.py +++ b/src/fenrir/utils/line_utils.py @@ -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 diff --git a/src/fenrir/utils/word_utils.py b/src/fenrir/utils/word_utils.py index aa4d30d3..e2bcdbfb 100644 --- a/src/fenrir/utils/word_utils.py +++ b/src/fenrir/utils/word_utils.py @@ -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 diff --git a/src/fenrir/utils/word_utils.py.bak b/src/fenrir/utils/word_utils.py.bak new file mode 100644 index 00000000..aa4d30d3 --- /dev/null +++ b/src/fenrir/utils/word_utils.py.bak @@ -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 diff --git a/src/fenrir/utils/word_utils2.py b/src/fenrir/utils/word_utils2.py index 5fe69264..e2bcdbfb 100644 --- a/src/fenrir/utils/word_utils2.py +++ b/src/fenrir/utils/word_utils2.py @@ -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