From 8f439f4a2a38cdb01a37063f3126a66bc89eb3dc Mon Sep 17 00:00:00 2001 From: chrys Date: Tue, 6 Sep 2016 23:57:15 +0200 Subject: [PATCH] add remove from spellcheck dict command --- .../commands/remove_word_from_spell_check.py | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/fenrir-package/commands/commands/remove_word_from_spell_check.py diff --git a/src/fenrir-package/commands/commands/remove_word_from_spell_check.py b/src/fenrir-package/commands/commands/remove_word_from_spell_check.py new file mode 100644 index 00000000..e8c4e618 --- /dev/null +++ b/src/fenrir-package/commands/commands/remove_word_from_spell_check.py @@ -0,0 +1,46 @@ +#!/bin/python +from utils import word_utils +initialized = False +try: + import enchant + initialized = True +except: + pass + +class command(): + def __init__(self): + self.language = '' + self.spellChecker = None + + def run(self, environment): + if not initialized: + environment['runtime']['outputManager'].presentText(environment, 'pychant is not installed', interrupt=True) + 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')[cursorPos['y']] + x, y, currWord = word_utils.getCurrentWord(cursorPos['x'], 0, newContent) + + if currWord != '': + if self.spellChecker.is_removed(currWord): + environment['runtime']['outputManager'].presentText(environment, currWord + ' is already removed from dict',soundIcon='Cancel', interrupt=True) + else: + self.spellChecker.remove(currWord) + environment['runtime']['outputManager'].presentText(environment, currWord + ' removed',soundIcon='Accept', interrupt=True) + + return environment + def setCallback(self, callback): + pass + def shutdown(self): + pass