Fix issue #1096 and remove a couple of error ourputs
This commit is contained in:
@@ -360,7 +360,7 @@ class Config:
|
|||||||
# Check the availability of optional packages
|
# Check the availability of optional packages
|
||||||
self._checkOptionalPackages()
|
self._checkOptionalPackages()
|
||||||
|
|
||||||
if self.spellLanguage is None:
|
if not self.spellLanguage:
|
||||||
self.spellLanguage = "en"
|
self.spellLanguage = "en"
|
||||||
|
|
||||||
# Look for a PDF version of the manual
|
# Look for a PDF version of the manual
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from collections import namedtuple
|
||||||
|
|
||||||
from novelwriter.error import logException
|
from novelwriter.error import logException
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -46,36 +48,47 @@ class NWSpellEnchant():
|
|||||||
return
|
return
|
||||||
|
|
||||||
##
|
##
|
||||||
# Getters and Setters
|
# Properties
|
||||||
##
|
##
|
||||||
|
|
||||||
|
@property
|
||||||
def spellLanguage(self):
|
def spellLanguage(self):
|
||||||
return self._spellLanguage
|
return self._spellLanguage
|
||||||
|
|
||||||
|
##
|
||||||
|
# Setters
|
||||||
|
##
|
||||||
|
|
||||||
def setLanguage(self, theLang, projectDict=None):
|
def setLanguage(self, theLang, projectDict=None):
|
||||||
"""Load a dictionary for the language specified in the config.
|
"""Load a dictionary for the language specified in the config.
|
||||||
If that fails, we load a mock dictionary so that lookups don't
|
If that fails, we load a mock dictionary so that lookups don't
|
||||||
crash.
|
crash. Note that enchant will allow loading an empty string as
|
||||||
|
a tag, but this will fail later on. See issue #1096.
|
||||||
"""
|
"""
|
||||||
|
self._theBroker = None
|
||||||
|
self._theDict = None
|
||||||
|
self._spellLanguage = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import enchant
|
import enchant
|
||||||
if self._theBroker is not None:
|
|
||||||
logger.debug("Deleting old pyenchant broker")
|
|
||||||
del self._theBroker
|
|
||||||
|
|
||||||
self._theBroker = enchant.Broker()
|
if theLang and enchant.dict_exists(theLang):
|
||||||
self._theDict = self._theBroker.request_dict(theLang)
|
self._theBroker = enchant.Broker()
|
||||||
self._spellLanguage = theLang
|
self._theDict = self._theBroker.request_dict(theLang)
|
||||||
logger.debug("Enchant spell checking for language '%s' loaded", theLang)
|
self._spellLanguage = theLang
|
||||||
|
logger.debug("Enchant spell checking for language '%s' loaded", theLang)
|
||||||
|
else:
|
||||||
|
logger.warning("Enchant found no dictionary for language '%s'", theLang)
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.error("Failed to load enchant spell checking for language '%s'", theLang)
|
logger.error("Failed to load enchant spell checking for language '%s'", theLang)
|
||||||
self._theDict = FakeEnchant()
|
|
||||||
self._spellLanguage = None
|
|
||||||
|
|
||||||
self._readProjectDictionary(projectDict)
|
if self._theDict is None:
|
||||||
for pWord in self._projDict:
|
self._theDict = FakeEnchant()
|
||||||
self._theDict.add_to_session(pWord)
|
else:
|
||||||
|
self._readProjectDictionary(projectDict)
|
||||||
|
for pWord in self._projDict:
|
||||||
|
self._theDict.add_to_session(pWord)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -189,6 +202,9 @@ class FakeEnchant:
|
|||||||
"""Fallback for when Enchant is selected, but not installed.
|
"""Fallback for when Enchant is selected, but not installed.
|
||||||
"""
|
"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.tag = ""
|
||||||
|
self.provider = namedtuple("provider", "name")
|
||||||
|
self.provider.name = ""
|
||||||
return
|
return
|
||||||
|
|
||||||
def check(self, theWord):
|
def check(self, theWord):
|
||||||
|
|||||||
@@ -718,7 +718,7 @@ class GuiDocEditor(QTextEdit):
|
|||||||
), nwAlert.INFO)
|
), nwAlert.INFO)
|
||||||
theMode = False
|
theMode = False
|
||||||
|
|
||||||
if self.spEnchant.spellLanguage() is None:
|
if self.spEnchant.spellLanguage is None:
|
||||||
theMode = False
|
theMode = False
|
||||||
|
|
||||||
self._spellCheck = theMode
|
self._spellCheck = theMode
|
||||||
|
|||||||
Reference in New Issue
Block a user