From e841e0211aa58f31f98c7584829bf40f338a4e01 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Fri, 15 Nov 2019 21:39:06 +0100 Subject: [PATCH] We should read back the language dictionary setting from the spell class before updating status bar --- nw/gui/elements/doceditor.py | 2 +- nw/gui/statusbar.py | 5 ++++- nw/tools/spellcheck.py | 8 ++++---- nw/tools/spellenchant.py | 2 ++ nw/tools/spellsimple.py | 4 +++- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/nw/gui/elements/doceditor.py b/nw/gui/elements/doceditor.py index c961f301..3d0446e1 100644 --- a/nw/gui/elements/doceditor.py +++ b/nw/gui/elements/doceditor.py @@ -315,7 +315,7 @@ class GuiDocEditor(QTextEdit): def setDictionaries(self): self.theDict.setLanguage(self.mainConf.spellLanguage, self.theProject.projDict) - self.theParent.statusBar.setLanguage(self.mainConf.spellLanguage) + self.theParent.statusBar.setLanguage(self.theDict.spellLanguage) return True def setSpellCheck(self, theMode): diff --git a/nw/gui/statusbar.py b/nw/gui/statusbar.py index 08b30870..81dd6a7c 100644 --- a/nw/gui/statusbar.py +++ b/nw/gui/statusbar.py @@ -116,7 +116,10 @@ class GuiMainStatus(QStatusBar): return def setLanguage(self, theLanguage): - self.langBox.setText(NWSpellCheck.expandLanguage(theLanguage)) + if theLanguage is None: + self.langBox.setText("None") + else: + self.langBox.setText(NWSpellCheck.expandLanguage(theLanguage)) return def setProjectStatus(self, isChanged): diff --git a/nw/tools/spellcheck.py b/nw/tools/spellcheck.py index fd5142c8..ec95a4f6 100644 --- a/nw/tools/spellcheck.py +++ b/nw/tools/spellcheck.py @@ -29,6 +29,7 @@ class NWSpellCheck(): def __init__(self): self.mainConf = nw.CONFIG self.projectDict = None + self.spellLanguage = None return def setLanguage(self, theLang, projectDict=None): @@ -45,11 +46,10 @@ class NWSpellCheck(): newWord = newWord.strip() self.PROJW.append(newWord) try: - with open(self.projectDict,mode="w+",encoding="utf-8") as outFile: - for pWord in self.PROJW: - outFile.write("%s\n" % pWord) + with open(self.projectDict,mode="a+",encoding="utf-8") as outFile: + outFile.write("%s\n" % newWord) except Exception as e: - logger.error("Failed to write to project word list at %s" % str(self.projectDict)) + logger.error("Failed to add word to project word list %s" % str(self.projectDict)) logger.error(str(e)) return diff --git a/nw/tools/spellenchant.py b/nw/tools/spellenchant.py index 1bff2329..7c60c8dd 100644 --- a/nw/tools/spellenchant.py +++ b/nw/tools/spellenchant.py @@ -32,10 +32,12 @@ class NWSpellEnchant(NWSpellCheck): """ try: self.theDict = enchant.Dict(theLang) + self.spellLanguage = theLang logger.debug("Enchant spell checking for language %s loaded" % theLang) except: logger.error("Failed to load enchant spell checking for language %s" % theLang) self.theDict = NWSpellEnchantDummy() + self.spellLanguage = None self._readProjectDictionary(projectDict) for pWord in self.PROJW: diff --git a/nw/tools/spellsimple.py b/nw/tools/spellsimple.py index d98947e5..ab4bf52c 100644 --- a/nw/tools/spellsimple.py +++ b/nw/tools/spellsimple.py @@ -41,9 +41,11 @@ class NWSpellSimple(NWSpellCheck): self.WORDS.append(theLine.strip().lower()) logger.debug("Spell check word list for language %s loaded" % theLang) logger.debug("Word list contains %d words" % len(self.WORDS)) + self.spellLanguage = theLang except Exception as e: logger.error("Failed to load spell check word list for language %s" % theLang) logger.error(str(e)) + self.spellLanguage = None self._readProjectDictionary(projectDict) for pWord in self.PROJW: @@ -104,7 +106,7 @@ class NWSpellSimple(NWSpellCheck): if theBits[1] != ".dict": continue - spName = "%s [nternal]" % self.expandLanguage(theBits[0]) + spName = "%s [Internal]" % self.expandLanguage(theBits[0]) retList.append((theBits[0], spName)) return retList