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