From 47033d9f40dde7066aa9a611e552afe1b4305e57 Mon Sep 17 00:00:00 2001 From: chrys Date: Sun, 25 Sep 2016 15:20:47 +0200 Subject: [PATCH] initial single press integration --- .../commands/onInput/50000-char_echo.py | 35 +++++++++ .../commands/onInput/60000-word_echo.py | 55 ++++++++++++++ .../commands/onInput/62000-spell_check.py | 75 +++++++++++++++++++ .../onInput/65000-char_delete_echo.py | 42 +++++++++++ .../deactive/agetty.py | 33 ++++++++ .../deactive/bash.py | 33 ++++++++ .../deactive/default.py | 33 ++++++++ .../deactive/vim.py | 33 ++++++++ 8 files changed, 339 insertions(+) create mode 100644 src/fenrir-package/commands/onInput/50000-char_echo.py create mode 100644 src/fenrir-package/commands/onInput/60000-word_echo.py create mode 100644 src/fenrir-package/commands/onInput/62000-spell_check.py create mode 100644 src/fenrir-package/commands/onInput/65000-char_delete_echo.py create mode 100644 src/fenrir-package/commands/onSwitchApplicationProfile/deactive/agetty.py create mode 100644 src/fenrir-package/commands/onSwitchApplicationProfile/deactive/bash.py create mode 100644 src/fenrir-package/commands/onSwitchApplicationProfile/deactive/default.py create mode 100644 src/fenrir-package/commands/onSwitchApplicationProfile/deactive/vim.py diff --git a/src/fenrir-package/commands/onInput/50000-char_echo.py b/src/fenrir-package/commands/onInput/50000-char_echo.py new file mode 100644 index 00000000..9ed4232f --- /dev/null +++ b/src/fenrir-package/commands/onInput/50000-char_echo.py @@ -0,0 +1,35 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'No Description found' + + def run(self): + if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'charEcho'): + return + # detect deletion or chilling + if self.env['screenData']['newCursor']['x'] <= self.env['screenData']['oldCursor']['x']: + return + # is there any change? + if self.env['screenData']['newDelta'] == '': + 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['screenData']['newDelta']) > 3: + return + self.env['runtime']['outputManager'].presentText(self.env['screenData']['newDelta'], interrupt=True, ignorePunctuation=True) + + def setCallback(self, callback): + pass + diff --git a/src/fenrir-package/commands/onInput/60000-word_echo.py b/src/fenrir-package/commands/onInput/60000-word_echo.py new file mode 100644 index 00000000..46e17c9e --- /dev/null +++ b/src/fenrir-package/commands/onInput/60000-word_echo.py @@ -0,0 +1,55 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import word_utils + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'No Description found' + + def run(self): + if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'wordEcho'): + return + + # just when cursor move worddetection is needed + if self.env['screenData']['newCursor']['x'] == self.env['screenData']['oldCursor']['x']: + return + + # for now no new line + if self.env['screenData']['newCursor']['y'] != self.env['screenData']['oldCursor']['y']: + return + if len(self.env['screenData']['newDelta']) > 1: + return + + # first place could not be the end of a word + if self.env['screenData']['newCursor']['x'] == 0: + 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['screenData']['newDelta'] != '': + if not(newContent[self.env['screenData']['oldCursor']['x']].strip(" \t\n") == '' 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 currWord != '': + self.env['runtime']['outputManager'].presentText(currWord, interrupt=True) + + def setCallback(self, callback): + pass + diff --git a/src/fenrir-package/commands/onInput/62000-spell_check.py b/src/fenrir-package/commands/onInput/62000-spell_check.py new file mode 100644 index 00000000..dfc9be99 --- /dev/null +++ b/src/fenrir-package/commands/onInput/62000-spell_check.py @@ -0,0 +1,75 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import word_utils +initialized = False +try: + import enchant + initialized = True +except: + pass + +class command(): + def __init__(self): + self.language = '' + self.spellChecker = '' + def initialize(self, environment): + self.env = environment + self.updateSpellLanguage() + def shutdown(self): + pass + def getDescription(self): + return 'No Description found' + + def updateSpellLanguage(self): + self.spellChecker = enchant.Dict(self.env['runtime']['settingsManager'].getSetting('general', 'spellCheckLanguage')) + self.language = self.env['runtime']['settingsManager'].getSetting('general', 'spellCheckLanguage') + + def run(self): + if not self.env['runtime']['settingsManager'].getSettingAsBool('general', 'autoSpellCheck'): + return + + if not initialized: + return + if self.env['runtime']['settingsManager'].getSetting('general', 'spellCheckLanguage') != self.language: + try: + self.updateSpellLanguage() + except: + return + + # just when cursor move worddetection is needed + if self.env['screenData']['newCursor']['x'] == self.env['screenData']['oldCursor']['x']: + return + + # for now no new line + if self.env['screenData']['newCursor']['y'] != self.env['screenData']['oldCursor']['y']: + return + if len(self.env['screenData']['newDelta']) > 1: + return + + # first place could not be the end of a word + if self.env['screenData']['newCursor']['x'] == 0: + 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['screenData']['newDelta'] != '': + if not(newContent[self.env['screenData']['oldCursor']['x']].strip(" \t\n") == '' 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 currWord != '': + if not self.spellChecker.check(currWord): + self.env['runtime']['outputManager'].presentText('misspelled',soundIcon='mispell', interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir-package/commands/onInput/65000-char_delete_echo.py b/src/fenrir-package/commands/onInput/65000-char_delete_echo.py new file mode 100644 index 00000000..8fada66f --- /dev/null +++ b/src/fenrir-package/commands/onInput/65000-char_delete_echo.py @@ -0,0 +1,42 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'No Description found' + + def run(self): + if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'charDeleteEcho'): + return + + # detect typing or chilling + if self.env['screenData']['newCursor']['x'] >= self.env['screenData']['oldCursor']['x']: + return + + # More than just a deletion happend + if self.env['screenData']['newDelta'].strip() != '': + if self.env['screenData']['newDelta'] != self.env['screenData']['oldDelta']: + return + + # No deletion + if self.env['screenData']['newNegativeDelta'] == '': + return + # too much for a single backspace... + if len(self.env['screenData']['newNegativeDelta']) >= 5: + return + self.env['runtime']['outputManager'].presentText(self.env['screenData']['newNegativeDelta'], interrupt=True, ignorePunctuation=True) + + def setCallback(self, callback): + pass + diff --git a/src/fenrir-package/commands/onSwitchApplicationProfile/deactive/agetty.py b/src/fenrir-package/commands/onSwitchApplicationProfile/deactive/agetty.py new file mode 100644 index 00000000..6981dffb --- /dev/null +++ b/src/fenrir-package/commands/onSwitchApplicationProfile/deactive/agetty.py @@ -0,0 +1,33 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'No description found' + def load(self): + print('--------------') + print('agetty') + print('load old',self.env['screenData']['oldApplication']) + print('load new',self.env['screenData']['newApplication']) + print('--------------') + + def unload(self): + print('--------------') + print('agetty') + print('unload old',self.env['screenData']['oldApplication']) + print('unload new',self.env['screenData']['newApplication']) + print('--------------') + + def setCallback(self, callback): + pass diff --git a/src/fenrir-package/commands/onSwitchApplicationProfile/deactive/bash.py b/src/fenrir-package/commands/onSwitchApplicationProfile/deactive/bash.py new file mode 100644 index 00000000..3cd9d8d0 --- /dev/null +++ b/src/fenrir-package/commands/onSwitchApplicationProfile/deactive/bash.py @@ -0,0 +1,33 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'No description found' + def load(self): + print('--------------') + print('bash') + print('load old',self.env['screenData']['oldApplication']) + print('load new',self.env['screenData']['newApplication']) + print('--------------') + + def unload(self): + print('--------------') + print('bash') + print('unload old',self.env['screenData']['oldApplication']) + print('unload new',self.env['screenData']['newApplication']) + print('--------------') + + def setCallback(self, callback): + pass diff --git a/src/fenrir-package/commands/onSwitchApplicationProfile/deactive/default.py b/src/fenrir-package/commands/onSwitchApplicationProfile/deactive/default.py new file mode 100644 index 00000000..87326f4f --- /dev/null +++ b/src/fenrir-package/commands/onSwitchApplicationProfile/deactive/default.py @@ -0,0 +1,33 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'No description found' + def load(self): + print('--------------') + print('default') + print('load old',self.env['screenData']['oldApplication']) + print('load new',self.env['screenData']['newApplication']) + print('--------------') + + def unload(self): + print('--------------') + print('default') + print('unload old',self.env['screenData']['oldApplication']) + print('unload new',self.env['screenData']['newApplication']) + print('--------------') + + def setCallback(self, callback): + pass diff --git a/src/fenrir-package/commands/onSwitchApplicationProfile/deactive/vim.py b/src/fenrir-package/commands/onSwitchApplicationProfile/deactive/vim.py new file mode 100644 index 00000000..3f8563e4 --- /dev/null +++ b/src/fenrir-package/commands/onSwitchApplicationProfile/deactive/vim.py @@ -0,0 +1,33 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'No description found' + def load(self): + print('--------------') + print('vim') + print('load old',self.env['screenData']['oldApplication']) + print('load new',self.env['screenData']['newApplication']) + print('--------------') + + def unload(self): + print('--------------') + print('vim') + print('unload old',self.env['screenData']['oldApplication']) + print('unload new',self.env['screenData']['newApplication']) + print('--------------') + + def setCallback(self, callback): + pass