Finished the GUI option for spell check provider

This commit is contained in:
Veronica K. B. Olsen
2019-11-07 20:00:19 +01:00
parent 334903daa9
commit f2265abf32
4 changed files with 48 additions and 17 deletions
+5 -4
View File
@@ -47,8 +47,7 @@ For the apt package manager on Debian systems, the following Python3 packages ar
These are optional, but recommended:
* `python3-enchant` for spell checking
* `python3-pycountry` for translating language codes to language names
* `python3-enchant` for better spell checking
* `python3-latexcodec` for escaping unicode characters in LaTeX export
* `python3-pandoc` for additional exports to Word, Open Office, eBooks, etc.
@@ -64,12 +63,14 @@ python3 -m pip install pyqt5
python3 -m pip install appdirs
python3 -m pip install lxml
python3 -m pip install pyenchant
python3 -m pip install pycountry
python3 -m pip install latexcodec
python3 -m pip install pypandoc
```
On Windows,`pyenchant` may cause problems.
I'm looking for a good alternative for spell checking.
If no external spell checking tool is installed, novelWriter will use a basic spell checker based on standard Python package `difflib`.
Currently, only English dictionaries are available, but more can be added to the `nw/assets/dict` folder.
See the RADME.md file in that folder for how to generate more dictionaries.
This option is both slow and limited.
Note: On Windows, make sure Python3 is in your PATH if you want to launch novelWriter from command line.
You can also right click the `novelWriter.py` file, create a shortcut, then right click again, select "Properties" and change the target to your python executable and `novelWriter.py`.
+1 -1
View File
@@ -536,7 +536,7 @@ class Config:
"""
try:
import pyenchant
import enchant
self.hasEnchant = True
logger.debug("Checking package pyenchant: Ok")
except:
+35 -9
View File
@@ -27,7 +27,7 @@ from PyQt5.QtWidgets import (
QFileDialog
)
from nw.tools import NWSpellCheck
from nw.tools import NWSpellCheck, NWSpellSimple, NWSpellEnchant
from nw.constants import nwAlert, nwQuotes
logger = logging.getLogger(__name__)
@@ -158,6 +158,7 @@ class GuiConfigEditGeneral(QWidget):
self.spellLangForm = QGridLayout(self)
self.spellLang.setLayout(self.spellLangForm)
self.spellLangList = QComboBox(self)
self.spellToolList = QComboBox(self)
self.spellToolList.addItem("Internal (difflib)", NWSpellCheck.SP_INTERNAL)
self.spellToolList.addItem("Spell Enchant (pyenchant)", NWSpellCheck.SP_ENCHANT)
@@ -169,12 +170,11 @@ class GuiConfigEditGeneral(QWidget):
theModel.item(idEnchant).setEnabled(self.mainConf.hasEnchant)
theModel.item(idSymSpell).setEnabled(self.mainConf.hasSymSpell)
self.spellLangList = QComboBox(self)
for spTag, spName in self.theParent.docEditor.theDict.listDictionaries():
self.spellLangList.addItem(spName, spTag)
spellIdx = self.spellLangList.findData(self.mainConf.spellLanguage)
if spellIdx != -1:
self.spellLangList.setCurrentIndex(spellIdx)
self.spellToolList.currentIndexChanged.connect(self._doUpdateSpellTool)
toolIdx = self.spellToolList.findData(self.mainConf.spellTool)
if toolIdx != -1:
self.spellToolList.setCurrentIndex(toolIdx)
self._doUpdateSpellTool(0)
self.spellLangForm.addWidget(QLabel("Provider"), 0, 0)
self.spellLangForm.addWidget(self.spellToolList, 0, 1)
@@ -243,8 +243,8 @@ class GuiConfigEditGeneral(QWidget):
self.outerBox.addWidget(self.guiLook, 0, 0)
self.outerBox.addWidget(self.spellLang, 1, 0)
self.outerBox.addWidget(self.autoSave, 2, 0)
self.outerBox.addWidget(self.projBackup, 3, 0)
self.outerBox.setColumnStretch(2, 1)
self.outerBox.addWidget(self.projBackup, 3, 0, 1, 2)
self.outerBox.setColumnStretch(1, 1)
self.outerBox.setRowStretch(4, 1)
self.setLayout(self.outerBox)
@@ -311,6 +311,32 @@ class GuiConfigEditGeneral(QWidget):
anItem.setFlags(anItem.flags() ^ Qt.ItemIsEnabled)
return theModel
def _doUpdateSpellTool(self, currIdx):
spellTool = self.spellToolList.currentData()
self._updateLanguageList(spellTool)
return
def _updateLanguageList(self, spellTool):
"""Updates the list of available spell checking dictionaries
available for the selected spell check tool. It will try to
preserve the language choice, if the language exists in the
updated list.
"""
if spellTool == NWSpellCheck.SP_ENCHANT:
theDict = NWSpellEnchant()
else:
theDict = NWSpellSimple()
self.spellLangList.clear()
for spTag, spName in theDict.listDictionaries():
self.spellLangList.addItem(spName, spTag)
spellIdx = self.spellLangList.findData(self.mainConf.spellLanguage)
if spellIdx != -1:
self.spellLangList.setCurrentIndex(spellIdx)
return
# END Class GuiConfigEditGeneral
class GuiConfigEditEditor(QWidget):
+7 -3
View File
@@ -64,10 +64,9 @@ class GuiDocEditor(QTextEdit):
self.qDocument = self.document()
self.qDocument.setDocumentMargin(self.mainConf.textMargin)
self.qDocument.contentsChange.connect(self._docChange)
self._setupSpellChecking()
# Syntax
self.hLight = GuiDocHighlighter(self.qDocument, self.theParent)
self.hLight.setDict(self.theDict)
# Context Menu
self.setContextMenuPolicy(Qt.CustomContextMenu)
@@ -138,7 +137,8 @@ class GuiDocEditor(QTextEdit):
created, and when the user changes the main editor preferences.
"""
# Reload dictionaries
# Reload spell check and dictionaries
self._setupSpellChecking()
self.setDictionaries()
# Set font
@@ -727,11 +727,15 @@ class GuiDocEditor(QTextEdit):
"""Create the spell checking object based on the spellTool
setting in config.
"""
if self.mainConf.spellTool == "enchant":
from nw.tools.spellenchant import NWSpellEnchant
self.theDict = NWSpellEnchant()
else:
self.theDict = NWSpellSimple()
self.hLight.setDict(self.theDict)
return
# END Class GuiDocEditor