Wed, 05 Jan 2022 11:53:28 +0100
Added code to EricSpellCheckedTextEdit in order to cope with the situation where the spellchecking libraries (like aspell or hunspell) are not installed.
eric7/EricWidgets/EricSpellCheckedTextEdit.py | file | annotate | diff | comparison | revisions |
--- a/eric7/EricWidgets/EricSpellCheckedTextEdit.py Tue Jan 04 17:13:35 2022 +0100 +++ b/eric7/EricWidgets/EricSpellCheckedTextEdit.py Wed Jan 05 11:53:28 2022 +0100 @@ -55,13 +55,19 @@ SpellCheckMixin.DefaultUserExceptionList ) except DictNotFoundError: - # Use English dictionary if no locale dictionary is available - # or the default one could not be found. - spellDict = enchant.DictWithPWL( - "en", - SpellCheckMixin.DefaultUserWordList, - SpellCheckMixin.DefaultUserExceptionList - ) + try: + # Use English dictionary if no locale dictionary is + # available or the default one could not be found. + spellDict = enchant.DictWithPWL( + "en", + SpellCheckMixin.DefaultUserWordList, + SpellCheckMixin.DefaultUserExceptionList + ) + except DictNotFoundError: + # Still no dictionary could be found. Forget about spell + # checking. + spellDict = None + self.__highlighter.setDict(spellDict) def contextMenuEvent(self, evt): @@ -452,6 +458,7 @@ QSyntaxHighlighter.__init__(self, *args) self.__spellDict = None + self.__tokenizer = None self.__chunkers = [] def chunkers(self): @@ -489,17 +496,21 @@ @param spellDict spelling dictionary @type enchant.Dict """ - try: - self.__tokenizer = enchant.tokenize.get_tokenizer( - spellDict.tag, - chunkers=self.__chunkers, - filters=EnchantHighlighter.TokenFilters) - except TokenizerNotFoundError: - # Fall back to the "good for most euro languages" - # English tokenizer - self.__tokenizer = enchant.tokenize.get_tokenizer( - chunkers=self.__chunkers, - filters=EnchantHighlighter.TokenFilters) + if spellDict: + try: + self.__tokenizer = enchant.tokenize.get_tokenizer( + spellDict.tag, + chunkers=self.__chunkers, + filters=EnchantHighlighter.TokenFilters) + except TokenizerNotFoundError: + # Fall back to the "good for most euro languages" + # English tokenizer + self.__tokenizer = enchant.tokenize.get_tokenizer( + chunkers=self.__chunkers, + filters=EnchantHighlighter.TokenFilters) + else: + self.__tokenizer = None + self.__spellDict = spellDict self.rehighlight() @@ -512,7 +523,7 @@ @type str """ """Overridden QSyntaxHighlighter method to apply the highlight""" - if not self.__spellDict: + if self.__spellDict is None or self.__tokenizer is None: return # Build a list of all misspelled words and highlight them