diff --git a/config/sound/default/mispell.opus b/config/sound/default/mispell.opus new file mode 100644 index 00000000..a4839140 Binary files /dev/null and b/config/sound/default/mispell.opus differ diff --git a/config/sound/default/mispell.wav b/config/sound/default/mispell.wav new file mode 100644 index 00000000..2497c3d3 Binary files /dev/null and b/config/sound/default/mispell.wav differ diff --git a/config/sound/default/soundicons.conf b/config/sound/default/soundicons.conf index 12b7c8c0..f2ccf032 100644 --- a/config/sound/default/soundicons.conf +++ b/config/sound/default/soundicons.conf @@ -44,3 +44,5 @@ ErrorScreen='ErrorScreen.opus' HasAttributes='HasAttributes.opus' # fenrir can promote strings if they appear on the screen. PromotedText='PromotedText.opus' +# missspelled indicator +mispell='mispell.opus' diff --git a/config/sound/template/soundicons.conf b/config/sound/template/soundicons.conf index 178a7f05..f8ff12f9 100644 --- a/config/sound/template/soundicons.conf +++ b/config/sound/template/soundicons.conf @@ -44,3 +44,5 @@ ErrorScreen='' HasAttributes='' # fenrir can promote strings if they appear on the screen. PromotedText='' +# misspelled indicator +mispell='' diff --git a/src/fenrir-package/commands/commands/spell_check.py b/src/fenrir-package/commands/commands/spell_check.py index c2090159..0d8a1f1c 100644 --- a/src/fenrir-package/commands/commands/spell_check.py +++ b/src/fenrir-package/commands/commands/spell_check.py @@ -5,11 +5,12 @@ try: import enchant initialized = True except: - print('nööP') + pass class command(): def __init__(self): - pass + self.language = '' + self.spellChecker = None def run(self, environment): if not environment['runtime']['settingsManager'].getSettingAsBool(environment, 'general', 'autoSpellCheck'): @@ -17,42 +18,26 @@ class command(): if not initialized: environment['runtime']['outputManager'].presentText(environment, 'pychant is not installed', interrupt=True) - return environment - 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 + return environment + if environment['runtime']['settingsManager'].getSetting(environment, 'general', 'spellCheckLanguage') != self.language: + try: + self.spellChecker = enchant.Dict(environment['runtime']['settingsManager'].getSetting(environment, 'general', 'spellCheckLanguage')) + self.language = environment['runtime']['settingsManager'].getSetting(environment, 'general', 'spellCheckLanguage') + except: + return environment + + if (environment['screenData']['newCursorReview'] != None): + cursorPos = environment['screenData']['newCursorReview'].copy() + else: + cursorPos = environment['screenData']['newCursor'].copy() # 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 + x, y, currWord = word_utils.getCurrentWord(cursorPos['x'], 0, newContent) if currWord != '': - if not spellChecker.check(currWord): - environment['runtime']['outputManager'].presentText(environment, 'misspelled', interrupt=True) + if not self.spellChecker.check(currWord): + environment['runtime']['outputManager'].presentText(environment, 'misspelled',soundIcon='mispell', interrupt=True) return environment def setCallback(self, callback): diff --git a/src/fenrir-package/commands/onScreenChanged/62000-spell_check.py b/src/fenrir-package/commands/onScreenChanged/62000-spell_check.py index c81fdb12..02fa03fb 100644 --- a/src/fenrir-package/commands/onScreenChanged/62000-spell_check.py +++ b/src/fenrir-package/commands/onScreenChanged/62000-spell_check.py @@ -5,20 +5,26 @@ try: import enchant initialized = True except: - print('nööP') + pass class command(): def __init__(self): - pass + self.language = '' + self.spellChecker = '' def run(self, environment): if not environment['runtime']['settingsManager'].getSettingAsBool(environment, 'general', 'autoSpellCheck'): return environment if not initialized: - return environment - spellChecker = enchant.Dict(environment['runtime']['settingsManager'].getSetting(environment, 'general', 'spellCheckLanguage')) - + return environment + if environment['runtime']['settingsManager'].getSetting(environment, 'general', 'spellCheckLanguage') != self.language: + try: + self.spellChecker = enchant.Dict(environment['runtime']['settingsManager'].getSetting(environment, 'general', 'spellCheckLanguage')) + self.language = environment['runtime']['settingsManager'].getSetting(environment, 'general', 'spellCheckLanguage') + except: + return environment + # just when cursor move worddetection is needed if environment['screenData']['newCursor']['x'] == environment['screenData']['oldCursor']['x']: return environment @@ -50,8 +56,8 @@ class command(): return environment if currWord != '': - if not spellChecker.check(currWord): - environment['runtime']['outputManager'].presentText(environment, 'misspelled', interrupt=True) + if not self.spellChecker.check(currWord): + environment['runtime']['outputManager'].presentText(environment, 'misspelled',soundIcon='mispell', interrupt=True) return environment def setCallback(self, callback):