From 6373b3d8b82606f02452bb32b0dbb5f12cd81b76 Mon Sep 17 00:00:00 2001 From: chrys Date: Sat, 6 Aug 2016 04:34:37 +0200 Subject: [PATCH] major rework, performance boost and bigger accuracy --- config/settings/settings.conf | 18 +++++---------- .../commands/onInput/10000-shut_up.py | 1 + .../commands/onInput/70000-speak_incomming.py | 21 ------------------ .../commands/onInput/__init__.py | 0 ...0-read_char_if_cursor_change_horizontal.py | 5 ++++- ...000-read_line_if_cursor_change_vertical.py | 1 + .../65000-speak_key_echo.py | 1 + .../69000-speak_word_echo.py | 4 ++-- .../onScreenChanged/70000-speak_incomming.py | 14 ++++++------ .../80000-speak_tty_change.py | 0 src/fenrir-package/fenrir.py | 8 ++----- src/fenrir-package/screen/linux.py | 22 +++++++++++-------- 12 files changed, 37 insertions(+), 58 deletions(-) delete mode 100644 src/fenrir-package/commands/onInput/70000-speak_incomming.py delete mode 100755 src/fenrir-package/commands/onInput/__init__.py rename src/fenrir-package/commands/{onInput => onScreenChanged}/54000-read_char_if_cursor_change_horizontal.py (83%) rename src/fenrir-package/commands/{onInput => onScreenChanged}/55000-read_line_if_cursor_change_vertical.py (97%) rename src/fenrir-package/commands/{onInput => onScreenChanged}/65000-speak_key_echo.py (97%) rename src/fenrir-package/commands/{onInput => onScreenChanged}/69000-speak_word_echo.py (93%) rename src/fenrir-package/commands/{onInput => onScreenChanged}/80000-speak_tty_change.py (100%) diff --git a/config/settings/settings.conf b/config/settings/settings.conf index 533beb41..482e233d 100644 --- a/config/settings/settings.conf +++ b/config/settings/settings.conf @@ -1,4 +1,3 @@ - [sound] enabled=True driver=sox @@ -6,17 +5,13 @@ theme=default [speech] enabled=True -#driver=espeak -#language=en-us -#voice=en-us -driver=speechd -#rate=800 -rate=50 -volume=100 +driver=espeak +rate=800 pitch=50 module=espeak -voice=de -language=de +voice=en-us +language=en-us +volume=200 [braille] enabled=False @@ -28,9 +23,8 @@ driver=linux [keyboard] keyboardLayout=desktop charEcho=False -wordEcho=True +wordEcho=False [general] debugLevel=0 punctuationLevel=1 - diff --git a/src/fenrir-package/commands/onInput/10000-shut_up.py b/src/fenrir-package/commands/onInput/10000-shut_up.py index d4466512..dbc35088 100644 --- a/src/fenrir-package/commands/onInput/10000-shut_up.py +++ b/src/fenrir-package/commands/onInput/10000-shut_up.py @@ -4,6 +4,7 @@ class command(): def __init__(self): pass def run(self, environment): + return environment if environment['screenData']['newCursor'] == environment['screenData']['oldCursor'] and\ environment['screenData']['newDelta'] == environment['screenData']['oldDelta']: return environment diff --git a/src/fenrir-package/commands/onInput/70000-speak_incomming.py b/src/fenrir-package/commands/onInput/70000-speak_incomming.py deleted file mode 100644 index 4bf968ec..00000000 --- a/src/fenrir-package/commands/onInput/70000-speak_incomming.py +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/python - -class command(): - def __init__(self): - pass - def run(self, environment): - if environment['screenData']['newCursor']['x'] > environment['screenData']['oldCursor']['x']: - return environment - - if environment['screenData']['newTTY'] != environment['screenData']['oldTTY']: - return environment - if environment['screenData']['newDelta'] == environment['screenData']['oldDelta']: - return environment - - environment['runtime']['outputManager'].presentText(environment, environment['screenData']['newDelta'], interrupt=True) - - return environment - def setCallback(self, callback): - pass - def shutdown(self): - pass diff --git a/src/fenrir-package/commands/onInput/__init__.py b/src/fenrir-package/commands/onInput/__init__.py deleted file mode 100755 index e69de29b..00000000 diff --git a/src/fenrir-package/commands/onInput/54000-read_char_if_cursor_change_horizontal.py b/src/fenrir-package/commands/onScreenChanged/54000-read_char_if_cursor_change_horizontal.py similarity index 83% rename from src/fenrir-package/commands/onInput/54000-read_char_if_cursor_change_horizontal.py rename to src/fenrir-package/commands/onScreenChanged/54000-read_char_if_cursor_change_horizontal.py index 7cf94560..05890302 100644 --- a/src/fenrir-package/commands/onInput/54000-read_char_if_cursor_change_horizontal.py +++ b/src/fenrir-package/commands/onScreenChanged/54000-read_char_if_cursor_change_horizontal.py @@ -4,6 +4,9 @@ class command(): def __init__(self): pass def run(self, environment): + + if environment['screenData']['newDelta'] != environment['screenData']['oldDelta']: + return environment if environment['screenData']['newCursor']['y'] != environment['screenData']['oldCursor']['y'] or\ environment['screenData']['newCursor']['x'] == environment['screenData']['oldCursor']['x']: return environment @@ -11,7 +14,7 @@ class command(): pass #environment['runtime']['outputManager'].presentText(environment, "blank",True) else: - environment['runtime']['outputManager'].presentText(environment, environment['screenData']['newContentText'].split('\n')[environment['screenData']['newCursor']['y']][environment['screenData']['newCursor']['x']],True) + environment['runtime']['outputManager'].presentText(environment, environment['screenData']['newContentText'].split('\n')[environment['screenData']['newCursor']['y']][environment['screenData']['newCursor']['x']],interrupt=True) return environment def setCallback(self, callback): diff --git a/src/fenrir-package/commands/onInput/55000-read_line_if_cursor_change_vertical.py b/src/fenrir-package/commands/onScreenChanged/55000-read_line_if_cursor_change_vertical.py similarity index 97% rename from src/fenrir-package/commands/onInput/55000-read_line_if_cursor_change_vertical.py rename to src/fenrir-package/commands/onScreenChanged/55000-read_line_if_cursor_change_vertical.py index f0dacf7d..9d7a4536 100644 --- a/src/fenrir-package/commands/onInput/55000-read_line_if_cursor_change_vertical.py +++ b/src/fenrir-package/commands/onScreenChanged/55000-read_line_if_cursor_change_vertical.py @@ -4,6 +4,7 @@ class command(): def __init__(self): pass def run(self, environment): + if environment['screenData']['newDelta'] != environment['screenData']['oldDelta']: return environment if environment['screenData']['newCursor']['y'] == environment['screenData']['oldCursor']['y']: diff --git a/src/fenrir-package/commands/onInput/65000-speak_key_echo.py b/src/fenrir-package/commands/onScreenChanged/65000-speak_key_echo.py similarity index 97% rename from src/fenrir-package/commands/onInput/65000-speak_key_echo.py rename to src/fenrir-package/commands/onScreenChanged/65000-speak_key_echo.py index 1fab1a14..f953dbdf 100644 --- a/src/fenrir-package/commands/onInput/65000-speak_key_echo.py +++ b/src/fenrir-package/commands/onScreenChanged/65000-speak_key_echo.py @@ -4,6 +4,7 @@ class command(): def __init__(self): pass def run(self, environment): + if not environment['runtime']['settingsManager'].getSettingAsBool(environment, 'keyboard', 'charEcho'): return environment if environment['screenData']['newCursor']['x'] <= environment['screenData']['oldCursor']['x']: diff --git a/src/fenrir-package/commands/onInput/69000-speak_word_echo.py b/src/fenrir-package/commands/onScreenChanged/69000-speak_word_echo.py similarity index 93% rename from src/fenrir-package/commands/onInput/69000-speak_word_echo.py rename to src/fenrir-package/commands/onScreenChanged/69000-speak_word_echo.py index a95f658a..a4e4a82c 100644 --- a/src/fenrir-package/commands/onInput/69000-speak_word_echo.py +++ b/src/fenrir-package/commands/onScreenChanged/69000-speak_word_echo.py @@ -5,7 +5,7 @@ class command(): def __init__(self): pass def run(self, environment): - + return environment if not environment['runtime']['settingsManager'].getSettingAsBool(environment, 'keyboard', 'wordEcho') and\ environment['screenData']['newCursor']['x'] <= environment['screenData']['oldCursor']['x']: return environment @@ -22,7 +22,7 @@ class command(): if environment['screenData']['newCursor']['x'] > 0 and \ newContent[environment['screenData']['newCursor']['x'] - 1] == ' ': environment['runtime']['outputManager'].presentText(environment, currWord, interrupt=True) - + print('word') return environment def setCallback(self, callback): pass diff --git a/src/fenrir-package/commands/onScreenChanged/70000-speak_incomming.py b/src/fenrir-package/commands/onScreenChanged/70000-speak_incomming.py index 46fda75b..3b0489cf 100644 --- a/src/fenrir-package/commands/onScreenChanged/70000-speak_incomming.py +++ b/src/fenrir-package/commands/onScreenChanged/70000-speak_incomming.py @@ -4,16 +4,16 @@ class command(): def __init__(self): pass def run(self, environment): - if not environment['runtime']['settingsManager'].getSettingAsBool(environment, 'keyboard', 'charEcho') and\ - environment['screenData']['newCursor']['x'] - environment['screenData']['oldCursor']['x'] ==1: + if environment['screenData']['newCursor']['x'] > environment['screenData']['oldCursor']['x']: return environment - ttyChanged = environment['screenData']['newTTY'] != environment['screenData']['oldTTY'] - if environment['screenData']['newDelta'] == environment['screenData']['oldDelta'] and \ - not ttyChanged: + if environment['screenData']['newTTY'] != environment['screenData']['oldTTY']: return environment - - environment['runtime']['outputManager'].presentText(environment, environment['screenData']['newDelta'], soundIconName='', interrupt=ttyChanged) + if environment['screenData']['newDelta'] == environment['screenData']['oldDelta']: + return environment + + environment['runtime']['outputManager'].presentText(environment, environment['screenData']['newDelta'], interrupt=False) + return environment def setCallback(self, callback): pass diff --git a/src/fenrir-package/commands/onInput/80000-speak_tty_change.py b/src/fenrir-package/commands/onScreenChanged/80000-speak_tty_change.py similarity index 100% rename from src/fenrir-package/commands/onInput/80000-speak_tty_change.py rename to src/fenrir-package/commands/onScreenChanged/80000-speak_tty_change.py diff --git a/src/fenrir-package/fenrir.py b/src/fenrir-package/fenrir.py index eea0e550..223f2c97 100755 --- a/src/fenrir-package/fenrir.py +++ b/src/fenrir-package/fenrir.py @@ -31,13 +31,9 @@ class fenrir(): self.environment, timeout = self.environment['runtime']['inputManager'].getKeyPressed(self.environment) self.environment = self.environment['runtime']['commandManager'].getCommandForShortcut(self.environment) self.environment = self.environment['runtime']['screenDriver'].analyzeScreen(self.environment, 'onInput') - if not timeout: - self.environment = self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onInput') - else: - self.environment = self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onScreenChanged') + self.environment = self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onInput') + self.environment = self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onScreenChanged') if self.environment['commandInfo']['currCommand'] != '': - self.environment['input']['currShortcut'] = {} - self.environment['input']['currShortcutString'] = '' self.handleCommands() self.environment['runtime']['globalLock'].release() diff --git a/src/fenrir-package/screen/linux.py b/src/fenrir-package/screen/linux.py index 32c2a169..37afcefe 100644 --- a/src/fenrir-package/screen/linux.py +++ b/src/fenrir-package/screen/linux.py @@ -64,19 +64,23 @@ class screen(): # changes on the screen if (environment['screenData']['oldContentText'] != environment['screenData']['newContentText']) and \ (environment['screenData']['newContentText'] != '' ): -# diff = difflib.ndiff(environment['screenData']['oldContentText'], environment['screenData']['newContentText']) if environment['screenData']['oldContentText'] == '' and\ environment['screenData']['newContentText'] != '': environment['screenData']['newDelta'] = environment['screenData']['newContentText'] else: diffStart = 0 - lastLine = len(environment['screenData']['newContentText']) - environment['screenData']['columns'] - if environment['screenData']['newContentText'][:lastLine] == environment['screenData']['oldContentText'][:lastLine]: - diffStart = lastLine + 1 - - diff = difflib.ndiff(re.sub('[ \t]+', ' ', environment['screenData']['oldContentText'][diffStart:]),\ - re.sub('[ \t]+', ' ', environment['screenData']['newContentText'][diffStart:])) - environment['screenData']['newDelta'] = ''.join(x[2:] for x in diff if x.startswith('+ ')) - environment['screenData']['newNegativeDelta'] = ''.join(x[2:] for x in diff if x.startswith('- ')) + if environment['screenData']['oldCursor']['x'] != environment['screenData']['newCursor']['x'] and \ + environment['screenData']['oldCursor']['y'] == environment['screenData']['newCursor']['y'] and \ + environment['screenData']['newContentText'][:environment['screenData']['newCursor']['y']] == environment['screenData']['oldContentText'][:environment['screenData']['newCursor']['y']]: + diffStart = environment['screenData']['newCursor']['y'] * environment['screenData']['newCursor']['x'] + environment['screenData']['newCursor']['y'] + diff = difflib.ndiff(environment['screenData']['oldContentText'][diffStart:],\ + environment['screenData']['newContentText'][diffStart:]) + else: + diff = difflib.ndiff( environment['screenData']['oldContentText'][diffStart:].splitlines(),\ + environment['screenData']['newContentText'][diffStart:].splitlines()) + + diffList = list(diff) + environment['screenData']['newDelta'] = ''.join(x[2:] for x in diffList if x.startswith('+ ')) + environment['screenData']['newNegativeDelta'] = ''.join(x[2:] for x in diffList if x.startswith('- ')) return environment