From 2e4148a9eb9f51a997266e9c18e90ef4102a8e0c Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Mon, 15 Feb 2021 22:29:05 +0100 Subject: [PATCH] Restore some of the old spell check information in the status bar --- nw/config.py | 9 +++++---- nw/core/index.py | 2 +- nw/core/spellcheck.py | 27 +++++++++++++++++++++++++++ nw/gui/doceditor.py | 4 +++- nw/gui/statusbar.py | 10 +++++++--- tests/test_core/test_core_spell.py | 11 +++++++++++ 6 files changed, 54 insertions(+), 9 deletions(-) diff --git a/nw/config.py b/nw/config.py index 8af44ab1..a4f483a4 100644 --- a/nw/config.py +++ b/nw/config.py @@ -94,7 +94,7 @@ class Config: ## Localisation self.qLocal = QLocale.system() - self.guiLang = self.qLocal.bcp47Name() + self.guiLang = self.qLocal.name() self.qtLangPath = QLibraryInfo.location(QLibraryInfo.TranslationsPath) self.nwLangPath = None self.qtTrans = {} @@ -374,9 +374,10 @@ class Config: self.qtTrans = {} langList = [ - (self.qtLangPath, "qt"), - (self.qtLangPath, "qtbase"), - (self.nwLangPath, "nw"), + (self.qtLangPath, "qt"), # Qt 4.x + (self.qtLangPath, "qtbase"), # Qt 5.x + (self.nwLangPath, "qtbase"), # Alternative Qt 5.x + (self.nwLangPath, "nw"), # novelWriter ] for lngPath, lngBase in langList: for lngCode in self.qLocal.uiLanguages(): diff --git a/nw/core/index.py b/nw/core/index.py index 83abc3ce..f6bdf0ae 100644 --- a/nw/core/index.py +++ b/nw/core/index.py @@ -62,7 +62,7 @@ class NWIndex(): # TimeStamps self._timeNovel = 0 - self._timeNotes = 0 + self._timeNotes = 0 self._timeIndex = 0 return diff --git a/nw/core/spellcheck.py b/nw/core/spellcheck.py index 720d8616..f03fc034 100644 --- a/nw/core/spellcheck.py +++ b/nw/core/spellcheck.py @@ -82,6 +82,11 @@ class NWSpellCheck(): """ return [] + def describeDict(self): + """Dummy function. + """ + return "", "" + ## # Internal Functions ## @@ -182,8 +187,24 @@ class NWSpellEnchant(NWSpellCheck): retList.append((spTag, spProvider.name)) except Exception: logger.error("Failed to list languages for enchant spell checking") + return retList + def describeDict(self): + """Return the tag and provider of the currently loaded + dictionary. + """ + try: + spTag = self.theDict.tag + spName = self.theDict.provider.name + except Exception: + logger.error("Failed to extract information about the dictionary") + nw.logException() + spTag = "" + spName = "" + + return spTag, spName + # END Class NWSpellEnchant class NWSpellEnchantDummy: @@ -303,4 +324,10 @@ class NWSpellSimple(NWSpellCheck): return retList + def describeDict(self): + """Return the tag and provider of the currently loaded + dictionary. + """ + return self.theLang, "" + # END Class NWSpellSimple diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index 7adccb4a..f374bd95 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -603,7 +603,9 @@ class GuiDocEditor(QTextEdit): theLang = self.theProject.projLang self.theDict.setLanguage(theLang, self.theProject.projDict) - self.theParent.statusBar.setLanguage(theLang) + theTag, theProvider = self.theDict.describeDict() + + self.theParent.statusBar.setLanguage(theLang, theProvider) if not self.bigDoc: self.spellCheckDocument() diff --git a/nw/gui/statusbar.py b/nw/gui/statusbar.py index 3cb19be8..5502d79c 100644 --- a/nw/gui/statusbar.py +++ b/nw/gui/statusbar.py @@ -147,16 +147,20 @@ class GuiMainStatus(QStatusBar): qApp.processEvents() return - def setLanguage(self, theLang): + def setLanguage(self, theLang, theProvider=""): """Set the language code for the spell checker. """ if theLang is None: self.langText.setText(self.tr("None")) + self.langText.setToolTip("") else: qLocal = QLocale(theLang) spLang = qLocal.nativeLanguageName().title() - spName = qLocal.bcp47Name() - self.langText.setText("%s (%s)" % (spLang, spName)) + self.langText.setText(spLang) + if theProvider: + self.langText.setToolTip("%s (%s)" % (theLang, theProvider)) + else: + self.langText.setToolTip(theLang) return diff --git a/tests/test_core/test_core_spell.py b/tests/test_core/test_core_spell.py index d01bb681..113ed343 100644 --- a/tests/test_core/test_core_spell.py +++ b/tests/test_core/test_core_spell.py @@ -45,6 +45,7 @@ def testCoreSpell_Super(monkeypatch, tmpDir, tmpConf): assert spChk.checkWord("") assert spChk.suggestWords("") == [] assert spChk.listDictionaries() == [] + assert spChk.describeDict() == ("", "") # Add a word to the user's dictionary assert spChk._readProjectDictionary("dummy") is False @@ -86,6 +87,7 @@ def testCoreSpell_Enchant(monkeypatch, tmpDir, tmpConf): assert spChk.checkWord("") assert spChk.suggestWords("") == [] assert spChk.listDictionaries() == [] + assert spChk.describeDict() == ("", "") monkeypatch.undo() @@ -109,6 +111,10 @@ def testCoreSpell_Enchant(monkeypatch, tmpDir, tmpConf): dList = spChk.listDictionaries() assert len(dList) > 0 + aTag, aName = spChk.describeDict() + assert aTag == "en" + assert aName != "" + # END Test testCoreSpell_Enchant @pytest.mark.core @@ -169,4 +175,9 @@ def testCoreSpell_Simple(monkeypatch, tmpDir, tmpConf): # List dictionaries assert spChk.listDictionaries() == [("en", "difflib")] + # Description + aTag, aName = spChk.describeDict() + assert aTag == "en" + assert aName == "" + # END Test testCoreSpell_Simple