eric7/EricWidgets/EricSpellCheckedTextEdit.py

branch
eric7
changeset 8901
adc47f306e51
parent 8881
54e42bc2437a
child 9021
62d6f565f740
--- 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

eric ide

mercurial