--- 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