Added wrapper classes for spell checker so new libraries can be added

This commit is contained in:
Veronica K. B. Olsen
2019-06-11 20:27:29 +02:00
parent 3c2864f161
commit c48b1deb8f
10 changed files with 113 additions and 21 deletions
+20
View File
@@ -18,4 +18,24 @@ logger = logging.getLogger(__name__)
class NWSpellCheck():
theDict = None
def __init__(self):
return
def setLanguage(self, theLang, projectDict=None):
return
def checkWord(self, theWord):
return True
def suggestWords(self, theWord):
return []
def addWord(self, newWord):
return
def listDictionaries(self):
return []
# END Class NWSpellCheck
+52
View File
@@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-
"""novelWriter Spell Check Wrapper : pyEnchant
novelWriter Spell Check Wrapper : pyEnchant
===============================================
Wrapper class for spell checking with pyEnchant
File History:
Created: 2019-06-11 [0.1.5]
"""
import logging
import enchant
import nw
from nw.tools.spellcheck import NWSpellCheck
logger = logging.getLogger(__name__)
class NWSpellEnchant(NWSpellCheck):
def __init__(self):
NWSpellCheck.__init__(self)
logger.debug("Enchant spell checking activated")
return
def setLanguage(self, theLang, projectDict=None):
if projectDict is None:
self.theDict = enchant.Dict(theLang)
else:
self.theDict = enchant.DictWithPWL(theLang, projectDict)
logger.debug("Enchant spell checking for %s loaded" % theLang)
return
def checkWord(self, theWord):
return self.theDict.check(theWord)
def suggestWords(self, theWord):
return self.theDict.suggest(theWord)
def addWord(self, newWord):
self.theDict.add_to_pwl(newWord)
return
def listDictionaries(self):
retList = []
for spTag, spProvider in enchant.list_dicts():
retList.append((spTag, "%s [%s]" % (spTag, spProvider.name)))
return retList
# END Class NWSpellEnchant