2016-02-13 17:06:36 -06:00
|
|
|
# -*- coding: utf-8 -*-
|
2019-01-02 04:42:53 +03:00
|
|
|
from __future__ import unicode_literals
|
2019-12-03 09:59:54 -06:00
|
|
|
import os
|
2016-02-13 17:06:36 -06:00
|
|
|
import logging
|
|
|
|
import widgetUtils
|
|
|
|
import output
|
|
|
|
import config
|
|
|
|
import languageHandler
|
2019-12-03 09:59:54 -06:00
|
|
|
from platform_utils import paths
|
|
|
|
from . import checker
|
2019-01-02 04:42:53 +03:00
|
|
|
from . import wx_ui
|
2016-02-16 17:20:55 -06:00
|
|
|
|
|
|
|
log = logging.getLogger("extra.SpellChecker.spellChecker")
|
2016-02-13 17:06:36 -06:00
|
|
|
|
|
|
|
class spellChecker(object):
|
2019-12-03 09:59:54 -06:00
|
|
|
def __init__(self, text):
|
2016-02-16 17:20:55 -06:00
|
|
|
super(spellChecker, self).__init__()
|
|
|
|
self.active = True
|
2019-12-03 09:59:54 -06:00
|
|
|
self.checker = checker.SpellChecker()
|
|
|
|
log.debug("Using language: %s" % (languageHandler.getLanguage(),))
|
2016-02-16 17:20:55 -06:00
|
|
|
try:
|
2019-12-03 12:06:36 -06:00
|
|
|
self.checker.set_language(languageHandler.curLang::2])
|
2019-12-03 09:59:54 -06:00
|
|
|
except ValueError:
|
|
|
|
log.exception("Dictionary for language %s not found." % (languageHandler.curLang,))
|
2016-02-16 17:20:55 -06:00
|
|
|
wx_ui.dict_not_found_error()
|
|
|
|
self.active = False
|
2019-12-03 09:59:54 -06:00
|
|
|
self.checker.set_text(text)
|
|
|
|
self.generator = self.checker.check_words()
|
2016-02-16 17:20:55 -06:00
|
|
|
if self.active == True:
|
|
|
|
log.debug("Creating dialog...")
|
|
|
|
self.dialog = wx_ui.spellCheckerDialog()
|
|
|
|
widgetUtils.connect_event(self.dialog.ignore, widgetUtils.BUTTON_PRESSED, self.ignore)
|
|
|
|
widgetUtils.connect_event(self.dialog.ignoreAll, widgetUtils.BUTTON_PRESSED, self.ignoreAll)
|
|
|
|
widgetUtils.connect_event(self.dialog.replace, widgetUtils.BUTTON_PRESSED, self.replace)
|
|
|
|
widgetUtils.connect_event(self.dialog.replaceAll, widgetUtils.BUTTON_PRESSED, self.replaceAll)
|
|
|
|
self.check()
|
|
|
|
self.dialog.get_response()
|
2019-12-03 09:59:54 -06:00
|
|
|
self.fixed_text = self.checker.text
|
2016-02-13 17:06:36 -06:00
|
|
|
|
2016-02-16 17:20:55 -06:00
|
|
|
def check(self):
|
|
|
|
try:
|
2019-12-03 09:59:54 -06:00
|
|
|
suggestions, context, self.wordIndex = next(self.generator)
|
2019-01-02 04:42:53 +03:00
|
|
|
textToSay = _("Misspelled word: %s") % (self.checker.word,)
|
2019-12-03 09:59:54 -06:00
|
|
|
context = context
|
2016-02-16 17:20:55 -06:00
|
|
|
self.dialog.set_title(textToSay)
|
|
|
|
output.speak(textToSay)
|
2019-12-03 09:59:54 -06:00
|
|
|
self.dialog.set_word_and_suggestions(word=self.checker.word, context=context, suggestions=[suggestion.term for suggestion in suggestions])
|
2016-02-16 17:20:55 -06:00
|
|
|
except StopIteration:
|
|
|
|
log.debug("Process finished.")
|
|
|
|
wx_ui.finished()
|
|
|
|
self.dialog.Destroy()
|
2016-02-13 17:06:36 -06:00
|
|
|
|
2016-02-16 17:20:55 -06:00
|
|
|
def ignore(self, ev):
|
|
|
|
self.check()
|
2016-02-13 17:06:36 -06:00
|
|
|
|
2016-02-16 17:20:55 -06:00
|
|
|
def ignoreAll(self, ev):
|
2019-12-03 09:59:54 -06:00
|
|
|
self.checker.ignore_word(word=self.checker.word)
|
2016-02-16 17:20:55 -06:00
|
|
|
self.check()
|
2016-02-13 17:06:36 -06:00
|
|
|
|
2016-02-16 17:20:55 -06:00
|
|
|
def replace(self, ev):
|
|
|
|
self.checker.replace(self.dialog.get_selected_suggestion())
|
|
|
|
self.check()
|
2016-02-13 17:06:36 -06:00
|
|
|
|
2016-02-16 17:20:55 -06:00
|
|
|
def replaceAll(self, ev):
|
2019-12-03 09:59:54 -06:00
|
|
|
self.checker.replace_all(self.dialog.get_selected_suggestion())
|
2016-02-25 05:08:56 -06:00
|
|
|
self.check()
|
|
|
|
|
|
|
|
def clean(self):
|
|
|
|
if hasattr(self, "dialog"):
|
|
|
|
self.dialog.Destroy()
|