Restore some of the old spell check information in the status bar

This commit is contained in:
Veronica K. B. Olsen
2021-02-15 22:29:05 +01:00
parent ed356ba85d
commit 2e4148a9eb
6 changed files with 54 additions and 9 deletions
+5 -4
View File
@@ -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():
+1 -1
View File
@@ -62,7 +62,7 @@ class NWIndex():
# TimeStamps
self._timeNovel = 0
self._timeNotes = 0
self._timeNotes = 0
self._timeIndex = 0
return
+27
View File
@@ -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
+3 -1
View File
@@ -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()
+7 -3
View File
@@ -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
+11
View File
@@ -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