Add dictionary information function to the spell check classes
This commit is contained in:
+29
-1
@@ -87,6 +87,11 @@ class NWSpellCheck():
|
|||||||
"""
|
"""
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
def describeDict(self):
|
||||||
|
"""Dummy function.
|
||||||
|
"""
|
||||||
|
return "", ""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def expandLanguage(spTag):
|
def expandLanguage(spTag):
|
||||||
"""Translate a language tag to something more user friendly.
|
"""Translate a language tag to something more user friendly.
|
||||||
@@ -187,6 +192,21 @@ class NWSpellEnchant(NWSpellCheck):
|
|||||||
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 as e:
|
||||||
|
logger.error("Failed to extract information about the dictionary")
|
||||||
|
logger.error(str(e))
|
||||||
|
spTag = ""
|
||||||
|
spName = ""
|
||||||
|
|
||||||
|
return spTag, spName
|
||||||
|
|
||||||
# END Class NWSpellEnchant
|
# END Class NWSpellEnchant
|
||||||
|
|
||||||
class NWSpellEnchantDummy:
|
class NWSpellEnchantDummy:
|
||||||
@@ -221,12 +241,14 @@ class NWSpellSimple(NWSpellCheck):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
NWSpellCheck.__init__(self)
|
NWSpellCheck.__init__(self)
|
||||||
|
self.theLang = ""
|
||||||
logger.debug("Simple spell checking activated")
|
logger.debug("Simple spell checking activated")
|
||||||
return
|
return
|
||||||
|
|
||||||
def setLanguage(self, theLang, projectDict=None):
|
def setLanguage(self, theLang, projectDict=None):
|
||||||
"""Load a dictionary as a list from the app assets folder.
|
"""Load a dictionary as a list from the app assets folder.
|
||||||
"""
|
"""
|
||||||
|
self.theLang = theLang
|
||||||
self.WORDS = []
|
self.WORDS = []
|
||||||
dictFile = os.path.join(self.mainConf.dictPath, theLang+".dict")
|
dictFile = os.path.join(self.mainConf.dictPath, theLang+".dict")
|
||||||
try:
|
try:
|
||||||
@@ -305,9 +327,15 @@ class NWSpellSimple(NWSpellCheck):
|
|||||||
if theBits[1] != ".dict":
|
if theBits[1] != ".dict":
|
||||||
continue
|
continue
|
||||||
|
|
||||||
spName = "%s [Internal]" % self.expandLanguage(theBits[0])
|
spName = "%s [internal]" % self.expandLanguage(theBits[0])
|
||||||
retList.append((theBits[0], spName))
|
retList.append((theBits[0], spName))
|
||||||
|
|
||||||
return retList
|
return retList
|
||||||
|
|
||||||
|
def describeDict(self):
|
||||||
|
"""Return the tag and provider of the currently loaded
|
||||||
|
dictionary.
|
||||||
|
"""
|
||||||
|
return self.theLang, "internal"
|
||||||
|
|
||||||
# END Class NWSpellSimple
|
# END Class NWSpellSimple
|
||||||
|
|||||||
@@ -377,6 +377,10 @@ def testSpellEnchant(nwTemp, nwConf):
|
|||||||
dList = spChk.listDictionaries()
|
dList = spChk.listDictionaries()
|
||||||
assert len(dList) > 0
|
assert len(dList) > 0
|
||||||
|
|
||||||
|
aTag, aName = spChk.describeDict()
|
||||||
|
assert aTag == "en"
|
||||||
|
assert aName != ""
|
||||||
|
|
||||||
@pytest.mark.project
|
@pytest.mark.project
|
||||||
def testSpellSimple(nwTemp, nwConf):
|
def testSpellSimple(nwTemp, nwConf):
|
||||||
wList = os.path.join(nwTemp, "wordlist.txt")
|
wList = os.path.join(nwTemp, "wordlist.txt")
|
||||||
@@ -402,6 +406,10 @@ def testSpellSimple(nwTemp, nwConf):
|
|||||||
dList = spChk.listDictionaries()
|
dList = spChk.listDictionaries()
|
||||||
assert len(dList) > 0
|
assert len(dList) > 0
|
||||||
|
|
||||||
|
aTag, aName = spChk.describeDict()
|
||||||
|
assert aTag == "en"
|
||||||
|
assert aName == "internal"
|
||||||
|
|
||||||
@pytest.mark.project
|
@pytest.mark.project
|
||||||
def testProjectOptions(nwDummy, nwLipsum):
|
def testProjectOptions(nwDummy, nwLipsum):
|
||||||
"""Test the class that holds all the GUI state user options that are
|
"""Test the class that holds all the GUI state user options that are
|
||||||
|
|||||||
Reference in New Issue
Block a user