diff --git a/config/settings/settings.conf b/config/settings/settings.conf index 2cb8a902..850f3635 100644 --- a/config/settings/settings.conf +++ b/config/settings/settings.conf @@ -85,6 +85,8 @@ numberOfClipboards=10 # define the current fenrir key fenrirKeys=KEY_KP0 timeFormat=%H:%M:%P +autoSpellCheck=True +spellCheckLanguage=en_US [promote] enabled=True diff --git a/config/settings/settings.conf.chrys b/config/settings/settings.conf.chrys index ed14a008..4d2ae46c 100644 --- a/config/settings/settings.conf.chrys +++ b/config/settings/settings.conf.chrys @@ -44,6 +44,8 @@ numberOfClipboards=10 fenrirKeys=KEY_KP0 timeFormat=%H:%M:%P dateFormat="%A, %B %d, %Y" +autoSpellCheck=True +spellCheckLanguage=en_US [promote] enabled=True diff --git a/config/settings/settings.conf.orig b/config/settings/settings.conf.orig index 7de76fb8..d93e8f73 100644 --- a/config/settings/settings.conf.orig +++ b/config/settings/settings.conf.orig @@ -84,6 +84,8 @@ numberOfClipboards=10 fenrirKeys=KEY_KP0 timeFormat=%H:%M%P dateFormat="%A, %B %d, %Y" +autoSpellCheck=True +spellCheckLanguage=en_US [promote] enabled=True diff --git a/config/settings/settings.conf.storm b/config/settings/settings.conf.storm index bcbeb8bf..80a87293 100644 --- a/config/settings/settings.conf.storm +++ b/config/settings/settings.conf.storm @@ -44,6 +44,8 @@ numberOfClipboards=10 fenrirKeys=KEY_KP0 timeFormat=%H:%M:%P dateFormat="%A, %B %d, %Y" +autoSpellCheck=True +spellCheckLanguage=en_US [promote] enabled=True diff --git a/src/fenrir-package/commands/onScreenChanged/62000-spell_check.py b/src/fenrir-package/commands/onScreenChanged/62000-spell_check.py new file mode 100644 index 00000000..ba597aaf --- /dev/null +++ b/src/fenrir-package/commands/onScreenChanged/62000-spell_check.py @@ -0,0 +1,60 @@ +#!/bin/python +from utils import word_utils + +class command(): + def __init__(self): + self.initialized = False + try: + import enchant + self.initialized = True + except: + pass + + def run(self, environment): + if not environment['runtime']['settingsManager'].getSettingAsBool(environment, 'general', 'autoSpellCheck'): + return environment + + if not self.initialized: + environment['runtime']['outputManager'].presentText(environment, 'pychant is not installed', interrupt=True) + + spellChecker = enchant.Dict(environment['runtime']['settingsManager'].getSetting(environment, 'general', 'spellCheckLanguage')) + + # just when cursor move worddetection is needed + if environment['screenData']['newCursor']['x'] == environment['screenData']['oldCursor']['x']: + return environment + + # for now no new line + if environment['screenData']['newCursor']['y'] != environment['screenData']['oldCursor']['y']: + return environment + if len(environment['screenData']['newDelta']) > 1: + return environment + + # TTY Change is no new word + if environment['screenData']['newTTY'] != environment['screenData']['oldTTY']: + return environment + + # first place could not be the end of a word + if environment['screenData']['newCursor']['x'] == 0: + return environment + + # get the word + newContent = environment['screenData']['newContentText'].split('\n')[environment['screenData']['newCursor']['y']] + x, y, currWord = word_utils.getCurrentWord(environment['screenData']['newCursor']['x'], 0, newContent) + # was this a typed word? + if environment['screenData']['newDelta'] != '': + if not(newContent[environment['screenData']['oldCursor']['x']].strip() == '' and x != environment['screenData']['oldCursor']['x']): + return environment + else: + # or just arrow arround? + if not(newContent[environment['screenData']['newCursor']['x']].strip() == '' and x != environment['screenData']['newCursor']['x']): + return environment + + if currWord != '': + if not spellChecker.check(currWord): + environment['runtime']['outputManager'].presentText(environment, 'misspelled', interrupt=True) + + return environment + def setCallback(self, callback): + pass + def shutdown(self): + pass