Started adding support for user word lists to the spell check text edits. eric7

Thu, 17 Jun 2021 18:56:21 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 17 Jun 2021 18:56:21 +0200
branch
eric7
changeset 8431
bed315a45088
parent 8430
14c69f0ccca5
child 8432
074407b4c107

Started adding support for user word lists to the spell check text edits.

eric7/EricWidgets/EricSpellCheckedTextEdit.py file | annotate | diff | comparison | revisions
eric7/UI/UserInterface.py file | annotate | diff | comparison | revisions
--- a/eric7/EricWidgets/EricSpellCheckedTextEdit.py	Wed Jun 16 19:21:45 2021 +0200
+++ b/eric7/EricWidgets/EricSpellCheckedTextEdit.py	Thu Jun 17 18:56:21 2021 +0200
@@ -39,22 +39,31 @@
         # default language to be used when no other is set
         DefaultLanguage = None
         
+        # default user lists
+        DefaultUserWordList = None
+        DefaultUserExceptionList = None
+        
         def __init__(self):
             """
             Constructor
             """
             self.__highlighter = EnchantHighlighter(self.document())
             try:
-                # Start with a default dictionary based on the current locale.
-                spellDict = (
-                    enchant.Dict(SpellCheckMixin.DefaultLanguage)
-                    if bool(SpellCheckMixin.DefaultLanguage) else
-                    enchant.Dict()
+                # Start with a default dictionary based on the current locale
+                # or the configured default language.
+                spellDict = enchant.DictWithPWL(
+                    SpellCheckMixin.DefaultLanguage,
+                    SpellCheckMixin.DefaultUserWordList,
+                    SpellCheckMixin.DefaultUserExceptionList
                 )
             except DictNotFoundError:
                 # Use English dictionary if no locale dictionary is available
                 # or the default one could not be found.
-                spellDict = enchant.Dict("en")
+                spellDict = enchant.DictWithPWL(
+                    "en",
+                    SpellCheckMixin.DefaultUserWordList,
+                    SpellCheckMixin.DefaultUserExceptionList
+                )
             self.__highlighter.setDict(spellDict)
         
         def contextMenuEvent(self, evt):
@@ -153,6 +162,7 @@
                 act.setData(language)
                 languageMenu.addAction(act)
             
+            # TODO: add action to add a word to the lists
             languageMenu.triggered.connect(self.__setLanguage)
             return languageMenu
         
@@ -241,7 +251,11 @@
             @type QAction
             """
             language = act.data()
-            self.__highlighter.setDict(enchant.Dict(language))
+            self.__highlighter.setDict(enchant.Dict(
+                language,
+                SpellCheckMixin.DefaultUserWordList,
+                SpellCheckMixin.DefaultUserExceptionList
+            ))
         
         @pyqtSlot(QAction)
         def __setFormat(self, act):
@@ -286,14 +300,21 @@
             self.__highlighter.setDict(spellDict)
         
         @classmethod
-        def setDefaultLanguage(cls, language):
+        def setDefaultLanguage(cls, language, pwl="", pel=""):
             """
             Class method to set the default spell-check language.
             
             @param language language to be set as default
             @type str
+            @param pwl file name of the personal word list
+            @type str
+            @param pel name of the personal exclude list
+            @type str
             """
             with contextlib.suppress(DictNotFoundError):
+                cls.DefaultUserWordList = pwl
+                cls.DefaultUserExceptionList = pel
+                
                 # set default language only, if a dictionary is available
                 enchant.Dict(language)
                 cls.DefaultLanguage = language
--- a/eric7/UI/UserInterface.py	Wed Jun 16 19:21:45 2021 +0200
+++ b/eric7/UI/UserInterface.py	Thu Jun 17 18:56:21 2021 +0200
@@ -745,8 +745,11 @@
         
         with contextlib.suppress(ImportError, AttributeError):
             from EricWidgets.EricSpellCheckedTextEdit import SpellCheckMixin
+            pwl = SpellChecker.getUserDictionaryPath(isException=False)
+            pel = SpellChecker.getUserDictionaryPath(isException=True)
             SpellCheckMixin.setDefaultLanguage(
-                Preferences.getEditor("SpellCheckingDefaultLanguage"))
+                Preferences.getEditor("SpellCheckingDefaultLanguage"),
+                pwl, pel)
         
         # attributes for the last shown configuration page and the
         # extended configuration entries
@@ -6208,8 +6211,11 @@
         
         with contextlib.suppress(ImportError, AttributeError):
             from EricWidgets.EricSpellCheckedTextEdit import SpellCheckMixin
+            pwl = SpellChecker.getUserDictionaryPath(isException=False)
+            pel = SpellChecker.getUserDictionaryPath(isException=True)
             SpellCheckMixin.setDefaultLanguage(
-                Preferences.getEditor("SpellCheckingDefaultLanguage"))
+                Preferences.getEditor("SpellCheckingDefaultLanguage"),
+                pwl, pel)
         
         if self.__layoutType == "Sidebars":
             delay = Preferences.getUI("SidebarDelay")

eric ide

mercurial