2016-09-05 16:58:06 +02:00
|
|
|
#!/bin/python
|
|
|
|
from utils import word_utils
|
2016-09-05 21:19:47 +02:00
|
|
|
initialized = False
|
|
|
|
try:
|
|
|
|
import enchant
|
|
|
|
initialized = True
|
|
|
|
except:
|
2016-09-06 09:26:05 +02:00
|
|
|
pass
|
2016-09-05 21:19:47 +02:00
|
|
|
|
2016-09-05 16:58:06 +02:00
|
|
|
class command():
|
|
|
|
def __init__(self):
|
2016-09-06 09:26:05 +02:00
|
|
|
self.language = ''
|
2016-09-06 09:44:17 +02:00
|
|
|
self.spellChecker = ''
|
2016-09-05 16:58:06 +02:00
|
|
|
|
|
|
|
def run(self, environment):
|
|
|
|
if not environment['runtime']['settingsManager'].getSettingAsBool(environment, 'general', 'autoSpellCheck'):
|
|
|
|
return environment
|
2016-09-05 17:00:38 +02:00
|
|
|
|
2016-09-05 21:19:47 +02:00
|
|
|
if not initialized:
|
2016-09-06 09:26:05 +02:00
|
|
|
return environment
|
|
|
|
if environment['runtime']['settingsManager'].getSetting(environment, 'general', 'spellCheckLanguage') != self.language:
|
|
|
|
try:
|
2016-09-06 09:44:17 +02:00
|
|
|
self.spellChecker = enchant.Dict(environment['runtime']['settingsManager'].getSetting(environment, 'general', 'spellCheckLanguage'))
|
|
|
|
self.language = environment['runtime']['settingsManager'].getSetting(environment, 'general', 'spellCheckLanguage')
|
2016-09-06 09:26:05 +02:00
|
|
|
except:
|
|
|
|
return environment
|
|
|
|
|
2016-09-05 16:58:06 +02:00
|
|
|
# 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 != '':
|
2016-09-06 09:44:17 +02:00
|
|
|
if not self.spellChecker.check(currWord):
|
2016-09-06 14:01:49 +02:00
|
|
|
environment['runtime']['outputManager'].presentText(environment, 'misspelled',soundIcon='mispell', interrupt=True)
|
2016-09-05 16:58:06 +02:00
|
|
|
|
|
|
|
return environment
|
|
|
|
def setCallback(self, callback):
|
|
|
|
pass
|
|
|
|
def shutdown(self):
|
|
|
|
pass
|