Make the editor dictionary internal
This commit is contained in:
@@ -152,7 +152,7 @@ class NWSpellEnchant(NWSpellCheck):
|
|||||||
|
|
||||||
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 = NWSpellEnchantDummy()
|
self.theDict = FakeEnchant()
|
||||||
self.spellLanguage = None
|
self.spellLanguage = None
|
||||||
|
|
||||||
self._readProjectDictionary(projectDict)
|
self._readProjectDictionary(projectDict)
|
||||||
@@ -208,7 +208,7 @@ class NWSpellEnchant(NWSpellCheck):
|
|||||||
|
|
||||||
# END Class NWSpellEnchant
|
# END Class NWSpellEnchant
|
||||||
|
|
||||||
class NWSpellEnchantDummy:
|
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):
|
||||||
@@ -223,7 +223,7 @@ class NWSpellEnchantDummy:
|
|||||||
def add_to_session(self, theWord):
|
def add_to_session(self, theWord):
|
||||||
return
|
return
|
||||||
|
|
||||||
# END Class NWSpellEnchantDummy
|
# END Class FakeEnchant
|
||||||
|
|
||||||
# =============================================================================================== #
|
# =============================================================================================== #
|
||||||
# Fallback SpellChecking Using difflib
|
# Fallback SpellChecking Using difflib
|
||||||
|
|||||||
@@ -207,7 +207,7 @@ class GuiProjectEditMain(QWidget):
|
|||||||
|
|
||||||
self.spellLang = QComboBox(self)
|
self.spellLang = QComboBox(self)
|
||||||
self.spellLang.setMaximumWidth(xW)
|
self.spellLang.setMaximumWidth(xW)
|
||||||
theDict = self.theParent.docEditor.theDict
|
theDict = self.theParent.docEditor.currentDictionary()
|
||||||
self.spellLang.addItem(self.tr("Default"), "None")
|
self.spellLang.addItem(self.tr("Default"), "None")
|
||||||
if theDict is not None:
|
if theDict is not None:
|
||||||
for spTag, spProv in theDict.listDictionaries():
|
for spTag, spProv in theDict.listDictionaries():
|
||||||
|
|||||||
+21
-13
@@ -64,6 +64,9 @@ class GuiDocEditor(QTextEdit):
|
|||||||
Qt.Key_PageUp, Qt.Key_PageDown
|
Qt.Key_PageUp, Qt.Key_PageDown
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Custom Signals
|
||||||
|
spellDictionaryChanged = pyqtSignal(str, str)
|
||||||
|
|
||||||
def __init__(self, theParent):
|
def __init__(self, theParent):
|
||||||
QTextEdit.__init__(self, theParent)
|
QTextEdit.__init__(self, theParent)
|
||||||
|
|
||||||
@@ -84,7 +87,7 @@ class GuiDocEditor(QTextEdit):
|
|||||||
self._docHeaders = [] # Record of headers in the file
|
self._docHeaders = [] # Record of headers in the file
|
||||||
|
|
||||||
self._spellCheck = False # Flag for spell checking enabled
|
self._spellCheck = False # Flag for spell checking enabled
|
||||||
self.theDict = None # The current spell check dictionary
|
self._theDict = None # The current spell check dictionary
|
||||||
self._nonWord = "\"'" # Characters to not include in spell checking
|
self._nonWord = "\"'" # Characters to not include in spell checking
|
||||||
|
|
||||||
# Document Variables
|
# Document Variables
|
||||||
@@ -579,6 +582,11 @@ class GuiDocEditor(QTextEdit):
|
|||||||
"""
|
"""
|
||||||
return self._qDocument.isEmpty()
|
return self._qDocument.isEmpty()
|
||||||
|
|
||||||
|
def currentDictionary(self):
|
||||||
|
"""Return the current dictionary object.
|
||||||
|
"""
|
||||||
|
return self._theDict
|
||||||
|
|
||||||
##
|
##
|
||||||
# Getters
|
# Getters
|
||||||
##
|
##
|
||||||
@@ -670,10 +678,10 @@ class GuiDocEditor(QTextEdit):
|
|||||||
else:
|
else:
|
||||||
theLang = self.theProject.projSpell
|
theLang = self.theProject.projSpell
|
||||||
|
|
||||||
self.theDict.setLanguage(theLang, self.theProject.projDict)
|
self._theDict.setLanguage(theLang, self.theProject.projDict)
|
||||||
theTag, theProvider = self.theDict.describeDict()
|
_, theProvider = self._theDict.describeDict()
|
||||||
|
|
||||||
self.theParent.statusBar.setLanguage(theLang, theProvider)
|
self.spellDictionaryChanged.emit(theLang, theProvider)
|
||||||
|
|
||||||
if not self._bigDoc:
|
if not self._bigDoc:
|
||||||
self.spellCheckDocument()
|
self.spellCheckDocument()
|
||||||
@@ -689,7 +697,7 @@ class GuiDocEditor(QTextEdit):
|
|||||||
if theMode is None:
|
if theMode is None:
|
||||||
theMode = not self._spellCheck
|
theMode = not self._spellCheck
|
||||||
|
|
||||||
if self.theDict.spellLanguage is None:
|
if self._theDict.spellLanguage is None:
|
||||||
theMode = False
|
theMode = False
|
||||||
|
|
||||||
self._spellCheck = theMode
|
self._spellCheck = theMode
|
||||||
@@ -987,7 +995,7 @@ class GuiDocEditor(QTextEdit):
|
|||||||
return
|
return
|
||||||
|
|
||||||
##
|
##
|
||||||
# Signals and Slots
|
# Slots
|
||||||
##
|
##
|
||||||
|
|
||||||
@pyqtSlot(int, int, int)
|
@pyqtSlot(int, int, int)
|
||||||
@@ -1092,14 +1100,14 @@ class GuiDocEditor(QTextEdit):
|
|||||||
|
|
||||||
if spellCheck:
|
if spellCheck:
|
||||||
logger.verbose("Looking up '%s' in the dictionary" % theWord)
|
logger.verbose("Looking up '%s' in the dictionary" % theWord)
|
||||||
spellCheck &= not self.theDict.checkWord(theWord)
|
spellCheck &= not self._theDict.checkWord(theWord)
|
||||||
|
|
||||||
if spellCheck:
|
if spellCheck:
|
||||||
mnuContext.addSeparator()
|
mnuContext.addSeparator()
|
||||||
mnuHead = QAction(self.tr("Spelling Suggestion(s)"), mnuContext)
|
mnuHead = QAction(self.tr("Spelling Suggestion(s)"), mnuContext)
|
||||||
mnuContext.addAction(mnuHead)
|
mnuContext.addAction(mnuHead)
|
||||||
|
|
||||||
theSuggest = self.theDict.suggestWords(theWord)[:15]
|
theSuggest = self._theDict.suggestWords(theWord)[:15]
|
||||||
if len(theSuggest) > 0:
|
if len(theSuggest) > 0:
|
||||||
for aWord in theSuggest:
|
for aWord in theSuggest:
|
||||||
mnuWord = QAction("%s %s" % (nwUnicode.U_ENDASH, aWord), mnuContext)
|
mnuWord = QAction("%s %s" % (nwUnicode.U_ENDASH, aWord), mnuContext)
|
||||||
@@ -1144,8 +1152,8 @@ class GuiDocEditor(QTextEdit):
|
|||||||
"""
|
"""
|
||||||
theWord = theCursor.selectedText().strip().strip(self._nonWord)
|
theWord = theCursor.selectedText().strip().strip(self._nonWord)
|
||||||
logger.debug("Added '%s' to project dictionary" % theWord)
|
logger.debug("Added '%s' to project dictionary" % theWord)
|
||||||
self.theDict.addWord(theWord)
|
self._theDict.addWord(theWord)
|
||||||
self.hLight.setDict(self.theDict)
|
self.hLight.setDict(self._theDict)
|
||||||
self.hLight.rehighlightBlock(theCursor.block())
|
self.hLight.rehighlightBlock(theCursor.block())
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -1816,11 +1824,11 @@ class GuiDocEditor(QTextEdit):
|
|||||||
"""
|
"""
|
||||||
if self.mainConf.spellTool == nwConst.SP_ENCHANT:
|
if self.mainConf.spellTool == nwConst.SP_ENCHANT:
|
||||||
from nw.core.spellcheck import NWSpellEnchant
|
from nw.core.spellcheck import NWSpellEnchant
|
||||||
self.theDict = NWSpellEnchant()
|
self._theDict = NWSpellEnchant()
|
||||||
else:
|
else:
|
||||||
self.theDict = NWSpellSimple()
|
self._theDict = NWSpellSimple()
|
||||||
|
|
||||||
self.hLight.setDict(self.theDict)
|
self.hLight.setDict(self._theDict)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
+4
-3
@@ -29,7 +29,7 @@ import logging
|
|||||||
|
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
from PyQt5.QtCore import QLocale
|
from PyQt5.QtCore import QLocale, pyqtSlot
|
||||||
from PyQt5.QtGui import QColor, QPainter
|
from PyQt5.QtGui import QColor, QPainter
|
||||||
from PyQt5.QtWidgets import qApp, QStatusBar, QLabel, QAbstractButton
|
from PyQt5.QtWidgets import qApp, QStatusBar, QLabel, QAbstractButton
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ class GuiMainStatus(QStatusBar):
|
|||||||
"""Reset all widgets on the status bar to default values.
|
"""Reset all widgets on the status bar to default values.
|
||||||
"""
|
"""
|
||||||
self.setRefTime(None)
|
self.setRefTime(None)
|
||||||
self.setLanguage(None)
|
self.setLanguage(None, "")
|
||||||
self.setStats(0, 0)
|
self.setStats(0, 0)
|
||||||
self.setProjectStatus(None)
|
self.setProjectStatus(None)
|
||||||
self.setDocumentStatus(None)
|
self.setDocumentStatus(None)
|
||||||
@@ -147,7 +147,8 @@ class GuiMainStatus(QStatusBar):
|
|||||||
qApp.processEvents()
|
qApp.processEvents()
|
||||||
return
|
return
|
||||||
|
|
||||||
def setLanguage(self, theLanguage, theProvider=""):
|
@pyqtSlot(str, str)
|
||||||
|
def setLanguage(self, theLanguage, theProvider):
|
||||||
"""Set the language code for the spell checker.
|
"""Set the language code for the spell checker.
|
||||||
"""
|
"""
|
||||||
if theLanguage is None:
|
if theLanguage is None:
|
||||||
|
|||||||
@@ -119,6 +119,9 @@ class GuiMain(QMainWindow):
|
|||||||
self.projMeta = GuiOutlineDetails(self)
|
self.projMeta = GuiOutlineDetails(self)
|
||||||
self.mainMenu = GuiMainMenu(self)
|
self.mainMenu = GuiMainMenu(self)
|
||||||
|
|
||||||
|
# Signals Between Main Elements
|
||||||
|
self.docEditor.spellDictionaryChanged.connect(self.statusBar.setLanguage)
|
||||||
|
|
||||||
# Minor GUI Elements
|
# Minor GUI Elements
|
||||||
self.statusIcons = []
|
self.statusIcons = []
|
||||||
self.importIcons = []
|
self.importIcons = []
|
||||||
|
|||||||
Reference in New Issue
Block a user