Finish the word list dialog and make it possible to reload the user dictionary with pyenchant

This commit is contained in:
Veronica K. B. Olsen
2021-02-12 19:40:10 +01:00
parent 6e64ede90b
commit b115d4f02d
3 changed files with 88 additions and 8 deletions
+11 -1
View File
@@ -123,6 +123,7 @@ class NWSpellCheck():
if len(theLine) > 0 and theLine not in self.projDict:
self.projDict.append(theLine)
logger.debug("Project word list contains %d words" % len(self.projDict))
except Exception:
logger.error("Failed to load project word list")
nw.logException()
@@ -141,6 +142,7 @@ class NWSpellEnchant(NWSpellCheck):
def __init__(self):
NWSpellCheck.__init__(self)
logger.debug("Enchant spell checking activated")
self.theBroker = None
return
def setLanguage(self, theLang, projectDict=None):
@@ -150,9 +152,15 @@ class NWSpellEnchant(NWSpellCheck):
"""
try:
import enchant
self.theDict = enchant.Dict(theLang)
if self.theBroker is not None:
logger.verbose("Deleting old pyenchant Broker")
del self.theBroker
self.theBroker = enchant.Broker()
self.theDict = self.theBroker.request_dict(theLang)
self.spellLanguage = theLang
logger.debug("Enchant spell checking for language %s loaded" % theLang)
except Exception:
logger.error("Failed to load enchant spell checking for language %s" % theLang)
self.theDict = NWSpellEnchantDummy()
@@ -258,9 +266,11 @@ class NWSpellSimple(NWSpellCheck):
if len(theLine) == 0 or theLine.startswith("#"):
continue
self.WORDS.append(theLine.strip().lower())
logger.debug("Spell check word list for language %s loaded" % theLang)
logger.debug("Word list contains %d words" % len(self.WORDS))
self.spellLanguage = theLang
except Exception:
logger.error("Failed to load spell check word list for language %s" % theLang)
nw.logException()