Added spell checker
This commit is contained in:
parent
5116a224e3
commit
6cf3397f36
@ -1,6 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import logging
|
import logging
|
||||||
log = logging.getLogger("extra.SpellChecker.spellChecker")
|
|
||||||
import wx_ui
|
import wx_ui
|
||||||
import widgetUtils
|
import widgetUtils
|
||||||
import output
|
import output
|
||||||
@ -9,7 +8,8 @@ import languageHandler
|
|||||||
from enchant.checker import SpellChecker
|
from enchant.checker import SpellChecker
|
||||||
from enchant.errors import DictNotFoundError
|
from enchant.errors import DictNotFoundError
|
||||||
from enchant import tokenize
|
from enchant import tokenize
|
||||||
import twitterFilter
|
|
||||||
|
log = logging.getLogger("extra.SpellChecker.spellChecker")
|
||||||
|
|
||||||
class spellChecker(object):
|
class spellChecker(object):
|
||||||
def __init__(self, text, dictionary):
|
def __init__(self, text, dictionary):
|
||||||
@ -19,12 +19,13 @@ class spellChecker(object):
|
|||||||
try:
|
try:
|
||||||
if config.app["app-settings"]["language"] == "system":
|
if config.app["app-settings"]["language"] == "system":
|
||||||
log.debug("Using the system language")
|
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:
|
else:
|
||||||
log.debug("Using language: %s" % (languageHandler.getLanguage(),))
|
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)
|
self.checker.set_text(text)
|
||||||
except DictNotFoundError:
|
except DictNotFoundError:
|
||||||
|
print "no dict"
|
||||||
log.exception("Dictionary for language %s not found." % (dictionary,))
|
log.exception("Dictionary for language %s not found." % (dictionary,))
|
||||||
wx_ui.dict_not_found_error()
|
wx_ui.dict_not_found_error()
|
||||||
self.active = False
|
self.active = False
|
||||||
@ -51,8 +52,6 @@ class spellChecker(object):
|
|||||||
log.debug("Process finished.")
|
log.debug("Process finished.")
|
||||||
wx_ui.finished()
|
wx_ui.finished()
|
||||||
self.dialog.Destroy()
|
self.dialog.Destroy()
|
||||||
# except AttributeError:
|
|
||||||
# pass
|
|
||||||
|
|
||||||
def ignore(self, ev):
|
def ignore(self, ev):
|
||||||
self.check()
|
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 wx
|
||||||
import application
|
import application
|
||||||
|
|
||||||
class spellCheckerDialog(wx.Dialog):
|
class spellCheckerDialog(wx.Dialog):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(spellCheckerDialog, self).__init__(None, 1)
|
super(spellCheckerDialog, self).__init__(None, 1)
|
||||||
@ -56,7 +57,6 @@ class spellCheckerDialog(wx.Dialog):
|
|||||||
panel.SetSizer(sizer)
|
panel.SetSizer(sizer)
|
||||||
self.SetClientSize(sizer.CalcMin())
|
self.SetClientSize(sizer.CalcMin())
|
||||||
|
|
||||||
|
|
||||||
def get_response(self):
|
def get_response(self):
|
||||||
return self.ShowModal()
|
return self.ShowModal()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user