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 ## Localisation
self.qLocal = QLocale.system() self.qLocal = QLocale.system()
self.guiLang = self.qLocal.bcp47Name() self.guiLang = self.qLocal.name()
self.qtLangPath = QLibraryInfo.location(QLibraryInfo.TranslationsPath) self.qtLangPath = QLibraryInfo.location(QLibraryInfo.TranslationsPath)
self.nwLangPath = None self.nwLangPath = None
self.qtTrans = {} self.qtTrans = {}
@@ -374,9 +374,10 @@ class Config:
self.qtTrans = {} self.qtTrans = {}
langList = [ langList = [
(self.qtLangPath, "qt"), (self.qtLangPath, "qt"), # Qt 4.x
(self.qtLangPath, "qtbase"), (self.qtLangPath, "qtbase"), # Qt 5.x
(self.nwLangPath, "nw"), (self.nwLangPath, "qtbase"), # Alternative Qt 5.x
(self.nwLangPath, "nw"), # novelWriter
] ]
for lngPath, lngBase in langList: for lngPath, lngBase in langList:
for lngCode in self.qLocal.uiLanguages(): for lngCode in self.qLocal.uiLanguages():
+1 -1
View File
@@ -62,7 +62,7 @@ class NWIndex():
# TimeStamps # TimeStamps
self._timeNovel = 0 self._timeNovel = 0
self._timeNotes = 0 self._timeNotes = 0
self._timeIndex = 0 self._timeIndex = 0
return return
+27
View File
@@ -82,6 +82,11 @@ class NWSpellCheck():
""" """
return [] return []
def describeDict(self):
"""Dummy function.
"""
return "", ""
## ##
# Internal Functions # Internal Functions
## ##
@@ -182,8 +187,24 @@ class NWSpellEnchant(NWSpellCheck):
retList.append((spTag, spProvider.name)) retList.append((spTag, spProvider.name))
except Exception: except Exception:
logger.error("Failed to list languages for enchant spell checking") logger.error("Failed to list languages for enchant spell checking")
return retList 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 # END Class NWSpellEnchant
class NWSpellEnchantDummy: class NWSpellEnchantDummy:
@@ -303,4 +324,10 @@ class NWSpellSimple(NWSpellCheck):
return retList return retList
def describeDict(self):
"""Return the tag and provider of the currently loaded
dictionary.
"""
return self.theLang, ""
# END Class NWSpellSimple # END Class NWSpellSimple
+3 -1
View File
@@ -603,7 +603,9 @@ class GuiDocEditor(QTextEdit):
theLang = self.theProject.projLang theLang = self.theProject.projLang
self.theDict.setLanguage(theLang, self.theProject.projDict) 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: if not self.bigDoc:
self.spellCheckDocument() self.spellCheckDocument()
+7 -3
View File
@@ -147,16 +147,20 @@ class GuiMainStatus(QStatusBar):
qApp.processEvents() qApp.processEvents()
return return
def setLanguage(self, theLang): def setLanguage(self, theLang, theProvider=""):
"""Set the language code for the spell checker. """Set the language code for the spell checker.
""" """
if theLang is None: if theLang is None:
self.langText.setText(self.tr("None")) self.langText.setText(self.tr("None"))
self.langText.setToolTip("")
else: else:
qLocal = QLocale(theLang) qLocal = QLocale(theLang)
spLang = qLocal.nativeLanguageName().title() spLang = qLocal.nativeLanguageName().title()
spName = qLocal.bcp47Name() self.langText.setText(spLang)
self.langText.setText("%s (%s)" % (spLang, spName)) if theProvider:
self.langText.setToolTip("%s (%s)" % (theLang, theProvider))
else:
self.langText.setToolTip(theLang)
return return
+11
View File
@@ -45,6 +45,7 @@ def testCoreSpell_Super(monkeypatch, tmpDir, tmpConf):
assert spChk.checkWord("") assert spChk.checkWord("")
assert spChk.suggestWords("") == [] assert spChk.suggestWords("") == []
assert spChk.listDictionaries() == [] assert spChk.listDictionaries() == []
assert spChk.describeDict() == ("", "")
# Add a word to the user's dictionary # Add a word to the user's dictionary
assert spChk._readProjectDictionary("dummy") is False assert spChk._readProjectDictionary("dummy") is False
@@ -86,6 +87,7 @@ def testCoreSpell_Enchant(monkeypatch, tmpDir, tmpConf):
assert spChk.checkWord("") assert spChk.checkWord("")
assert spChk.suggestWords("") == [] assert spChk.suggestWords("") == []
assert spChk.listDictionaries() == [] assert spChk.listDictionaries() == []
assert spChk.describeDict() == ("", "")
monkeypatch.undo() monkeypatch.undo()
@@ -109,6 +111,10 @@ def testCoreSpell_Enchant(monkeypatch, tmpDir, tmpConf):
dList = spChk.listDictionaries() dList = spChk.listDictionaries()
assert len(dList) > 0 assert len(dList) > 0
aTag, aName = spChk.describeDict()
assert aTag == "en"
assert aName != ""
# END Test testCoreSpell_Enchant # END Test testCoreSpell_Enchant
@pytest.mark.core @pytest.mark.core
@@ -169,4 +175,9 @@ def testCoreSpell_Simple(monkeypatch, tmpDir, tmpConf):
# List dictionaries # List dictionaries
assert spChk.listDictionaries() == [("en", "difflib")] assert spChk.listDictionaries() == [("en", "difflib")]
# Description
aTag, aName = spChk.describeDict()
assert aTag == "en"
assert aName == ""
# END Test testCoreSpell_Simple # END Test testCoreSpell_Simple