Completed the pyenchant wrapper class

This commit is contained in:
Veronica K. B. Olsen
2019-06-11 20:52:24 +02:00
parent c48b1deb8f
commit 59ba847c0f
6 changed files with 41 additions and 10 deletions
+9 -5
View File
@@ -80,12 +80,16 @@ Most shortcuts are labelled with the corresponding dropdown menu entry.
## Dependencies
For the apt package manager, the following Python3 packages are needed.
For the apt package manager, the following Python3 packages are needed:
* python3-pyqt5
* python3-appdirs
* python3-lxml
* python3-enchant
* `python3-pyqt5` for the GUI
* `python3-appdirs` for locating the system's config folder
* `python3-lxml` for writing project files
These are optional, but recommended:
* `python3-enchant` for spell checking
* `python3-pycountry` for translating language codes to language names
Alternatively, the packages can be installed with `pip` by running
```
+1 -1
View File
@@ -520,7 +520,7 @@ class GuiMain(QMainWindow):
def closeMain(self):
if self.mainConf.showGUI:
if self.mainConf.showGUI and self.hasProject:
msgBox = QMessageBox()
msgRes = msgBox.question(
self, "Exit", "Do you want to save changes and exit?"
+21 -2
View File
@@ -14,6 +14,12 @@ import logging
import enchant
import nw
try:
import pycountry
hasPyCountry = True
except:
hasPyCountry = False
from nw.tools.spellcheck import NWSpellCheck
logger = logging.getLogger(__name__)
@@ -30,7 +36,7 @@ class NWSpellEnchant(NWSpellCheck):
self.theDict = enchant.Dict(theLang)
else:
self.theDict = enchant.DictWithPWL(theLang, projectDict)
logger.debug("Enchant spell checking for %s loaded" % theLang)
logger.debug("Enchant spell checking for language %s loaded" % theLang)
return
def checkWord(self, theWord):
@@ -46,7 +52,20 @@ class NWSpellEnchant(NWSpellCheck):
def listDictionaries(self):
retList = []
for spTag, spProvider in enchant.list_dicts():
retList.append((spTag, "%s [%s]" % (spTag, spProvider.name)))
if hasPyCountry:
spList = []
try:
langObj = pycountry.languages.get(alpha_2 = spTag[:2])
spList.append(langObj.name)
except:
spList.append(spTag[:2])
if len(spTag) > 3:
spList.append("(%s)" % spTag[3:])
spList.append("[%s]" % spProvider.name)
spName = " ".join(spList)
else:
spName = "%s [%s]" % (spTag, spProvider.name)
retList.append((spTag, spName))
return retList
# END Class NWSpellEnchant
+1
View File
@@ -2,3 +2,4 @@ pyqt5
appdirs
lxml
pyenchant
pycountry
+7
View File
@@ -210,3 +210,10 @@ Start: 2019-06-10 21:48:51 End: 2019-06-10 21:49:07 Words: 0
Start: 2019-06-10 22:17:58 End: 2019-06-10 22:18:44 Words: 0
Start: 2019-06-10 22:46:35 End: 2019-06-10 22:49:34 Words: 0
Start: 2019-06-11 14:44:55 End: 2019-06-11 14:53:47 Words: 0
Start: 2019-06-11 19:26:07 End: 2019-06-11 19:26:18 Words: 0
Start: 2019-06-11 19:26:44 End: 2019-06-11 19:26:50 Words: 0
Start: 2019-06-11 19:30:30 End: 2019-06-11 19:30:37 Words: 0
Start: 2019-06-11 19:31:16 End: 2019-06-11 19:31:50 Words: 0
Start: 2019-06-11 20:04:39 End: 2019-06-11 20:05:00 Words: 0
Start: 2019-06-11 20:05:04 End: 2019-06-11 20:08:49 Words: 0
Start: 2019-06-11 20:20:52 End: 2019-06-11 20:21:18 Words: 0
+2 -2
View File
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<novelWriterXML appVersion="0.1.5" fileVersion="1.0" timeStamp="2019-06-11 14:46:19">
<novelWriterXML appVersion="0.1.5" fileVersion="1.0" timeStamp="2019-06-11 20:21:18">
<project>
<name>Sample Project</name>
<title>Sample Project</title>
@@ -80,7 +80,7 @@
<charCount>736</charCount>
<wordCount>137</wordCount>
<paraCount>6</paraCount>
<cursorPos>738</cursorPos>
<cursorPos>473</cursorPos>
</item>
<item handle="bc0cbd2a407f3" order="2" parent="e7ded148d6e4a">
<name>New File</name>