Added spell checker
This commit is contained in:
parent
5116a224e3
commit
6cf3397f36
@ -1,6 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import logging
|
||||
log = logging.getLogger("extra.SpellChecker.spellChecker")
|
||||
import wx_ui
|
||||
import widgetUtils
|
||||
import output
|
||||
@ -9,7 +8,8 @@ import languageHandler
|
||||
from enchant.checker import SpellChecker
|
||||
from enchant.errors import DictNotFoundError
|
||||
from enchant import tokenize
|
||||
import twitterFilter
|
||||
|
||||
log = logging.getLogger("extra.SpellChecker.spellChecker")
|
||||
|
||||
class spellChecker(object):
|
||||
def __init__(self, text, dictionary):
|
||||
@ -19,12 +19,13 @@ class spellChecker(object):
|
||||
try:
|
||||
if config.app["app-settings"]["language"] == "system":
|
||||
log.debug("Using the system language")
|
||||
self.checker = SpellChecker(filters=[twitterFilter.TwitterFilter, tokenize.EmailFilter, tokenize.URLFilter])
|
||||
self.checker = SpellChecker(languageHandler.curLang, filters=[tokenize.EmailFilter, tokenize.URLFilter])
|
||||
else:
|
||||
log.debug("Using language: %s" % (languageHandler.getLanguage(),))
|
||||
self.checker = SpellChecker(languageHandler.getLanguage(), filters=[twitterFilter.TwitterFilter, tokenize.EmailFilter, tokenize.URLFilter])
|
||||
self.checker = SpellChecker(languageHandler.curLang, filters=[tokenize.EmailFilter, tokenize.URLFilter])
|
||||
self.checker.set_text(text)
|
||||
except DictNotFoundError:
|
||||
print "no dict"
|
||||
log.exception("Dictionary for language %s not found." % (dictionary,))
|
||||
wx_ui.dict_not_found_error()
|
||||
self.active = False
|
||||
@ -51,8 +52,6 @@ class spellChecker(object):
|
||||
log.debug("Process finished.")
|
||||
wx_ui.finished()
|
||||
self.dialog.Destroy()
|
||||
# except AttributeError:
|
||||
# pass
|
||||
|
||||
def ignore(self, ev):
|
||||
self.check()
|
||||
|
@ -1,15 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import re
|
||||
from enchant.tokenize import Filter
|
||||
|
||||
class TwitterFilter(Filter):
|
||||
"""Filter skipping over twitter usernames and hashtags.
|
||||
This filter skips any words matching the following regular expression:
|
||||
^[#@](\S){1, }$
|
||||
That is, any words that resemble users and hashtags.
|
||||
"""
|
||||
_pattern = re.compile(r"^[#@](\S){1,}$")
|
||||
def _skip(self,word):
|
||||
if self._pattern.match(word):
|
||||
return True
|
||||
return False
|
@ -18,6 +18,7 @@
|
||||
############################################################
|
||||
import wx
|
||||
import application
|
||||
|
||||
class spellCheckerDialog(wx.Dialog):
|
||||
def __init__(self):
|
||||
super(spellCheckerDialog, self).__init__(None, 1)
|
||||
@ -56,7 +57,6 @@ class spellCheckerDialog(wx.Dialog):
|
||||
panel.SetSizer(sizer)
|
||||
self.SetClientSize(sizer.CalcMin())
|
||||
|
||||
|
||||
def get_response(self):
|
||||
return self.ShowModal()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user