Finished the GUI option for spell check provider
This commit is contained in:
@@ -47,8 +47,7 @@ For the apt package manager on Debian systems, the following Python3 packages ar
|
|||||||
|
|
||||||
These are optional, but recommended:
|
These are optional, but recommended:
|
||||||
|
|
||||||
* `python3-enchant` for spell checking
|
* `python3-enchant` for better spell checking
|
||||||
* `python3-pycountry` for translating language codes to language names
|
|
||||||
* `python3-latexcodec` for escaping unicode characters in LaTeX export
|
* `python3-latexcodec` for escaping unicode characters in LaTeX export
|
||||||
* `python3-pandoc` for additional exports to Word, Open Office, eBooks, etc.
|
* `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 appdirs
|
||||||
python3 -m pip install lxml
|
python3 -m pip install lxml
|
||||||
python3 -m pip install pyenchant
|
python3 -m pip install pyenchant
|
||||||
python3 -m pip install pycountry
|
|
||||||
python3 -m pip install latexcodec
|
python3 -m pip install latexcodec
|
||||||
python3 -m pip install pypandoc
|
python3 -m pip install pypandoc
|
||||||
```
|
```
|
||||||
On Windows,`pyenchant` may cause problems.
|
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.
|
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`.
|
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
@@ -536,7 +536,7 @@ class Config:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import pyenchant
|
import enchant
|
||||||
self.hasEnchant = True
|
self.hasEnchant = True
|
||||||
logger.debug("Checking package pyenchant: Ok")
|
logger.debug("Checking package pyenchant: Ok")
|
||||||
except:
|
except:
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ from PyQt5.QtWidgets import (
|
|||||||
QFileDialog
|
QFileDialog
|
||||||
)
|
)
|
||||||
|
|
||||||
from nw.tools import NWSpellCheck
|
from nw.tools import NWSpellCheck, NWSpellSimple, NWSpellEnchant
|
||||||
from nw.constants import nwAlert, nwQuotes
|
from nw.constants import nwAlert, nwQuotes
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -158,6 +158,7 @@ class GuiConfigEditGeneral(QWidget):
|
|||||||
self.spellLangForm = QGridLayout(self)
|
self.spellLangForm = QGridLayout(self)
|
||||||
self.spellLang.setLayout(self.spellLangForm)
|
self.spellLang.setLayout(self.spellLangForm)
|
||||||
|
|
||||||
|
self.spellLangList = QComboBox(self)
|
||||||
self.spellToolList = QComboBox(self)
|
self.spellToolList = QComboBox(self)
|
||||||
self.spellToolList.addItem("Internal (difflib)", NWSpellCheck.SP_INTERNAL)
|
self.spellToolList.addItem("Internal (difflib)", NWSpellCheck.SP_INTERNAL)
|
||||||
self.spellToolList.addItem("Spell Enchant (pyenchant)", NWSpellCheck.SP_ENCHANT)
|
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(idEnchant).setEnabled(self.mainConf.hasEnchant)
|
||||||
theModel.item(idSymSpell).setEnabled(self.mainConf.hasSymSpell)
|
theModel.item(idSymSpell).setEnabled(self.mainConf.hasSymSpell)
|
||||||
|
|
||||||
self.spellLangList = QComboBox(self)
|
self.spellToolList.currentIndexChanged.connect(self._doUpdateSpellTool)
|
||||||
for spTag, spName in self.theParent.docEditor.theDict.listDictionaries():
|
toolIdx = self.spellToolList.findData(self.mainConf.spellTool)
|
||||||
self.spellLangList.addItem(spName, spTag)
|
if toolIdx != -1:
|
||||||
spellIdx = self.spellLangList.findData(self.mainConf.spellLanguage)
|
self.spellToolList.setCurrentIndex(toolIdx)
|
||||||
if spellIdx != -1:
|
self._doUpdateSpellTool(0)
|
||||||
self.spellLangList.setCurrentIndex(spellIdx)
|
|
||||||
|
|
||||||
self.spellLangForm.addWidget(QLabel("Provider"), 0, 0)
|
self.spellLangForm.addWidget(QLabel("Provider"), 0, 0)
|
||||||
self.spellLangForm.addWidget(self.spellToolList, 0, 1)
|
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.guiLook, 0, 0)
|
||||||
self.outerBox.addWidget(self.spellLang, 1, 0)
|
self.outerBox.addWidget(self.spellLang, 1, 0)
|
||||||
self.outerBox.addWidget(self.autoSave, 2, 0)
|
self.outerBox.addWidget(self.autoSave, 2, 0)
|
||||||
self.outerBox.addWidget(self.projBackup, 3, 0)
|
self.outerBox.addWidget(self.projBackup, 3, 0, 1, 2)
|
||||||
self.outerBox.setColumnStretch(2, 1)
|
self.outerBox.setColumnStretch(1, 1)
|
||||||
self.outerBox.setRowStretch(4, 1)
|
self.outerBox.setRowStretch(4, 1)
|
||||||
self.setLayout(self.outerBox)
|
self.setLayout(self.outerBox)
|
||||||
|
|
||||||
@@ -311,6 +311,32 @@ class GuiConfigEditGeneral(QWidget):
|
|||||||
anItem.setFlags(anItem.flags() ^ Qt.ItemIsEnabled)
|
anItem.setFlags(anItem.flags() ^ Qt.ItemIsEnabled)
|
||||||
return theModel
|
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
|
# END Class GuiConfigEditGeneral
|
||||||
|
|
||||||
class GuiConfigEditEditor(QWidget):
|
class GuiConfigEditEditor(QWidget):
|
||||||
|
|||||||
@@ -64,10 +64,9 @@ class GuiDocEditor(QTextEdit):
|
|||||||
self.qDocument = self.document()
|
self.qDocument = self.document()
|
||||||
self.qDocument.setDocumentMargin(self.mainConf.textMargin)
|
self.qDocument.setDocumentMargin(self.mainConf.textMargin)
|
||||||
self.qDocument.contentsChange.connect(self._docChange)
|
self.qDocument.contentsChange.connect(self._docChange)
|
||||||
self._setupSpellChecking()
|
|
||||||
|
|
||||||
|
# Syntax
|
||||||
self.hLight = GuiDocHighlighter(self.qDocument, self.theParent)
|
self.hLight = GuiDocHighlighter(self.qDocument, self.theParent)
|
||||||
self.hLight.setDict(self.theDict)
|
|
||||||
|
|
||||||
# Context Menu
|
# Context Menu
|
||||||
self.setContextMenuPolicy(Qt.CustomContextMenu)
|
self.setContextMenuPolicy(Qt.CustomContextMenu)
|
||||||
@@ -138,7 +137,8 @@ class GuiDocEditor(QTextEdit):
|
|||||||
created, and when the user changes the main editor preferences.
|
created, and when the user changes the main editor preferences.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Reload dictionaries
|
# Reload spell check and dictionaries
|
||||||
|
self._setupSpellChecking()
|
||||||
self.setDictionaries()
|
self.setDictionaries()
|
||||||
|
|
||||||
# Set font
|
# Set font
|
||||||
@@ -727,11 +727,15 @@ class GuiDocEditor(QTextEdit):
|
|||||||
"""Create the spell checking object based on the spellTool
|
"""Create the spell checking object based on the spellTool
|
||||||
setting in config.
|
setting in config.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if self.mainConf.spellTool == "enchant":
|
if self.mainConf.spellTool == "enchant":
|
||||||
from nw.tools.spellenchant import NWSpellEnchant
|
from nw.tools.spellenchant import NWSpellEnchant
|
||||||
self.theDict = NWSpellEnchant()
|
self.theDict = NWSpellEnchant()
|
||||||
else:
|
else:
|
||||||
self.theDict = NWSpellSimple()
|
self.theDict = NWSpellSimple()
|
||||||
|
|
||||||
|
self.hLight.setDict(self.theDict)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# END Class GuiDocEditor
|
# END Class GuiDocEditor
|
||||||
|
|||||||
Reference in New Issue
Block a user