From d63f0d686f3d815a6370c50d4e400e222a4bdb5d Mon Sep 17 00:00:00 2001 From: chrys Date: Fri, 10 Nov 2017 22:56:51 +0100 Subject: [PATCH 1/2] initial detectoin --- .../commands/onCursorChange/45000-char_echo.py | 3 ++- ...present_char_if_cursor_change_horizontal.py | 3 ++- .../commands/onScreenUpdate/70000-incoming.py | 18 ++++++++++-------- src/fenrir/screenDriver/vcsaDriver.py | 13 ++++++++++--- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/fenrir/commands/onCursorChange/45000-char_echo.py b/src/fenrir/commands/onCursorChange/45000-char_echo.py index e84eb6ef..f52c2c3a 100644 --- a/src/fenrir/commands/onCursorChange/45000-char_echo.py +++ b/src/fenrir/commands/onCursorChange/45000-char_echo.py @@ -26,7 +26,8 @@ class command(): if not self.env['runtime']['screenManager'].isDelta(): return # big changes are no char (but the value is bigger than one maybe the differ needs longer than you can type, so a little strange random buffer for now) - if len(self.env['screen']['newDelta'].strip(' \n\t')) > 1: + xMove = abs(self.env['screen']['newCursor']['x'] - self.env['screen']['oldCursor']['x']) + if not( (xMove >= 1) and xMove == len(self.env['screen']['newDelta'])): return # filter unneded space on word begin currDelta = self.env['screen']['newDelta'] diff --git a/src/fenrir/commands/onCursorChange/50000-present_char_if_cursor_change_horizontal.py b/src/fenrir/commands/onCursorChange/50000-present_char_if_cursor_change_horizontal.py index 1a684f13..ab09adaa 100644 --- a/src/fenrir/commands/onCursorChange/50000-present_char_if_cursor_change_horizontal.py +++ b/src/fenrir/commands/onCursorChange/50000-present_char_if_cursor_change_horizontal.py @@ -33,6 +33,7 @@ class command(): # is it a horizontal change? if not self.env['runtime']['cursorManager'].isCursorHorizontalMove(): return + # echo word insteed of char if self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'wordEcho'): if abs(self.env['screen']['oldCursor']['x'] - self.env['screen']['newCursor']['x']) != 1: @@ -42,7 +43,7 @@ class command(): word_utils.getCurrentWord(self.env['screen']['newCursor']['x'], 0, newContent) if self.env['screen']['newCursor']['x'] == x: return - x, y, currChar = char_utils.getCurrentChar(self.env['screen']['newCursor']['x'], self.env['screen']['newCursor']['y'], self.env['screen']['newContentText']) + x, y, currChar = char_utils.getCurrentChar(self.env['screen']['newCursor']['x'], self.env['screen']['newCursor']['y'], self.env['screen']['newContentText']) if not currChar.isspace(): self.env['runtime']['outputManager'].presentText(currChar, interrupt=True, ignorePunctuation=True, announceCapital=True, flush=False) def setCallback(self, callback): diff --git a/src/fenrir/commands/onScreenUpdate/70000-incoming.py b/src/fenrir/commands/onScreenUpdate/70000-incoming.py index 1b1ec0d9..7f8c1a85 100644 --- a/src/fenrir/commands/onScreenUpdate/70000-incoming.py +++ b/src/fenrir/commands/onScreenUpdate/70000-incoming.py @@ -20,16 +20,18 @@ class command(): if not self.env['runtime']['settingsManager'].getSettingAsBool('speech', 'autoReadIncoming'): return # is there something to read? - if not self.env['runtime']['screenManager'].isDelta(): + if not self.env['runtime']['screenManager'].isDelta(ignoreSpace=True): return # this must be a keyecho or something - if len(self.env['screen']['newDelta'].strip(' \n\t')) <= 1: - if abs(self.env['screen']['newCursor']['x'] - self.env['screen']['oldCursor']['x']) >= 1: - # if len(self.env['screen']['newDelta'].strip(' \n\t0123456789')) <= 2: - return - if abs(self.env['screen']['newCursor']['y'] - self.env['screen']['oldCursor']['y']) == 1: - # if len(self.env['screen']['newDelta'].strip(' \n\t0123456789')) <= 2: - return + #if len(self.env['screen']['newDelta'].strip(' \n\t')) <= 1: + xMove = abs(self.env['screen']['newCursor']['x'] - self.env['screen']['oldCursor']['x']) + yMove = abs(self.env['screen']['newCursor']['y'] - self.env['screen']['oldCursor']['y']) + if (xMove >= 1) and xMove == len(self.env['screen']['newDelta']): + # if len(self.env['screen']['newDelta'].strip(' \n\t0123456789')) <= 2: + return + #if yMove == 1: + # if len(self.env['screen']['newDelta'].strip(' \n\t0123456789')) <= 2: + # return self.env['runtime']['outputManager'].presentText(self.env['screen']['newDelta'], interrupt=False, flush=False) def setCallback(self, callback): diff --git a/src/fenrir/screenDriver/vcsaDriver.py b/src/fenrir/screenDriver/vcsaDriver.py index 0adc50c9..871ab4b6 100644 --- a/src/fenrir/screenDriver/vcsaDriver.py +++ b/src/fenrir/screenDriver/vcsaDriver.py @@ -329,6 +329,7 @@ class driver(screenDriver): oldScreenText = re.sub(' +',' ',self.env['runtime']['screenManager'].getWindowAreaInText(self.env['screen']['oldContentText'])) newScreenText = re.sub(' +',' ',self.env['runtime']['screenManager'].getWindowAreaInText(self.env['screen']['newContentText'])) typing = False + diffList = [] if (self.env['screen']['oldContentText'] != self.env['screen']['newContentText']): if self.env['screen']['newContentText'] != '' and self.env['screen']['oldContentText'] == '': if oldScreenText == '' and\ @@ -337,7 +338,7 @@ class driver(screenDriver): else: cursorLineStart = self.env['screen']['newCursor']['y'] * self.env['screen']['columns'] + self.env['screen']['newCursor']['y'] cursorLineEnd = cursorLineStart + self.env['screen']['columns'] - if abs(self.env['screen']['oldCursor']['x'] - self.env['screen']['newCursor']['x']) == 1 and \ + if abs(self.env['screen']['oldCursor']['x'] - self.env['screen']['newCursor']['x']) >= 1 and \ self.env['screen']['oldCursor']['y'] == self.env['screen']['newCursor']['y'] and \ self.env['screen']['newContentText'][:cursorLineStart] == self.env['screen']['oldContentText'][:cursorLineStart] and \ self.env['screen']['newContentText'][cursorLineEnd:] == self.env['screen']['oldContentText'][cursorLineEnd:]: @@ -352,13 +353,19 @@ class driver(screenDriver): newScreenText = self.env['screen']['newContentText'][cursorLineStartOffset:cursorLineEndOffset] #newScreenText = re.sub(' +',' ',newScreenText) diff = difflib.ndiff(oldScreenText, newScreenText) + diffList = list(diff) + tempNewDelta = ''.join(x[2:] for x in diffList if x[0] == '+') + print(tempNewDelta, newScreenText[self.env['screen']['oldCursor']['x'] :self.env['screen']['newCursor']['x'] ]) + if tempNewDelta != ''.join(newScreenText[self.env['screen']['oldCursor']['x']:self.env['screen']['newCursor']['x']]): + diffList = [' +' + self.env['screen']['newContentText'].split('\n')[self.env['screen']['newCursor']['y']]] + print(diffList) typing = True else: diff = difflib.ndiff( oldScreenText.split('\n'),\ newScreenText.split('\n')) - diffList = list(diff) - + diffList = list(diff) + if self.env['runtime']['settingsManager'].getSetting('general', 'newLinePause') and not typing: self.env['screen']['newDelta'] = '\n'.join(x[2:] for x in diffList if x[0] == '+') else: From 8c7dfd8c5dfc950337d10964ea711d0820943dbe Mon Sep 17 00:00:00 2001 From: chrys Date: Fri, 10 Nov 2017 23:05:58 +0100 Subject: [PATCH 2/2] remove debug --- src/fenrir/screenDriver/vcsaDriver.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/fenrir/screenDriver/vcsaDriver.py b/src/fenrir/screenDriver/vcsaDriver.py index 871ab4b6..d7a8ed6a 100644 --- a/src/fenrir/screenDriver/vcsaDriver.py +++ b/src/fenrir/screenDriver/vcsaDriver.py @@ -355,10 +355,10 @@ class driver(screenDriver): diff = difflib.ndiff(oldScreenText, newScreenText) diffList = list(diff) tempNewDelta = ''.join(x[2:] for x in diffList if x[0] == '+') - print(tempNewDelta, newScreenText[self.env['screen']['oldCursor']['x'] :self.env['screen']['newCursor']['x'] ]) - if tempNewDelta != ''.join(newScreenText[self.env['screen']['oldCursor']['x']:self.env['screen']['newCursor']['x']]): - diffList = [' +' + self.env['screen']['newContentText'].split('\n')[self.env['screen']['newCursor']['y']]] - print(diffList) + + if tempNewDelta != ''.join(newScreenText[self.env['screen']['oldCursor']['x']:self.env['screen']['newCursor']['x']].rstrip()): + diffList = ['+ ' + self.env['screen']['newContentText'].split('\n')[self.env['screen']['newCursor']['y']]] + typing = True else: diff = difflib.ndiff( oldScreenText.split('\n'),\