Avoid crash on spellcheck by ensuring enchant dictionary exists

See issue #273.
This commit is contained in:
Curtis Gedak 2018-01-15 11:54:04 -07:00
parent 62a8a136c0
commit 43c077552a

View file

@ -427,14 +427,15 @@ class textEditView(QTextEdit):
def setDict(self, d): def setDict(self, d):
self.currentDict = d self.currentDict = d
self._dict = enchant.Dict(d) if d and enchant.dict_exists(d):
self._dict = enchant.Dict(d)
if self.highlighter: if self.highlighter:
self.highlighter.rehighlight() self.highlighter.rehighlight()
def toggleSpellcheck(self, v): def toggleSpellcheck(self, v):
self.spellcheck = v self.spellcheck = v
if enchant and self.spellcheck and not self._dict: if enchant and self.spellcheck and not self._dict:
if self.currentDict: if self.currentDict and enchant.dict_exists(self.currentDict):
self._dict = enchant.Dict(self.currentDict) self._dict = enchant.Dict(self.currentDict)
elif enchant.get_default_language() and enchant.dict_exists(enchant.get_default_language()): elif enchant.get_default_language() and enchant.dict_exists(enchant.get_default_language()):
self._dict = enchant.Dict(enchant.get_default_language()) self._dict = enchant.Dict(enchant.get_default_language())