Merge pull request #779 from vkbo/editor_cleanup
Editor Code Improvements
This commit is contained in:
+1
-1
@@ -1109,7 +1109,7 @@ class NWProject():
|
|||||||
information to the GUI statusbar.
|
information to the GUI statusbar.
|
||||||
"""
|
"""
|
||||||
self.projChanged = bValue
|
self.projChanged = bValue
|
||||||
self.theParent.setProjectStatus(self.projChanged)
|
self.theParent.statusBar.doUpdateProjectStatus(bValue)
|
||||||
if bValue:
|
if bValue:
|
||||||
# If we've changed the project at all, this should be True
|
# If we've changed the project at all, this should be True
|
||||||
self.projAltered = True
|
self.projAltered = True
|
||||||
|
|||||||
@@ -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():
|
||||||
|
|||||||
@@ -112,6 +112,14 @@ class nwAlert(Enum):
|
|||||||
|
|
||||||
# END Enum nwAlert
|
# END Enum nwAlert
|
||||||
|
|
||||||
|
class nwState(Enum):
|
||||||
|
|
||||||
|
NONE = 0
|
||||||
|
BAD = 1
|
||||||
|
GOOD = 2
|
||||||
|
|
||||||
|
# END Enum nwState
|
||||||
|
|
||||||
class nwWidget(Enum):
|
class nwWidget(Enum):
|
||||||
|
|
||||||
TREE = 1
|
TREE = 1
|
||||||
|
|||||||
+263
-229
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -876,7 +876,7 @@ class GuiDocViewHeader(QWidget):
|
|||||||
def _refreshDocument(self):
|
def _refreshDocument(self):
|
||||||
"""Reload the content of the document.
|
"""Reload the content of the document.
|
||||||
"""
|
"""
|
||||||
if self.docViewer.theHandle == self.theParent.docEditor.theHandle:
|
if self.docViewer.theHandle == self.theParent.docEditor.docHandle():
|
||||||
self.theParent.saveDocument()
|
self.theParent.saveDocument()
|
||||||
self.docViewer.reloadText()
|
self.docViewer.reloadText()
|
||||||
return
|
return
|
||||||
|
|||||||
+17
-12
@@ -27,7 +27,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
import nw
|
import nw
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from PyQt5.QtCore import Qt
|
from PyQt5.QtCore import Qt, pyqtSlot
|
||||||
from PyQt5.QtGui import QFont, QPixmap
|
from PyQt5.QtGui import QFont, QPixmap
|
||||||
from PyQt5.QtWidgets import QWidget, QGridLayout, QLabel
|
from PyQt5.QtWidgets import QWidget, QGridLayout, QLabel
|
||||||
|
|
||||||
@@ -212,17 +212,6 @@ class GuiItemDetails(QWidget):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def updateCounts(self, tHandle, cC, wC, pC):
|
|
||||||
"""Update the counts if the handle is the same as the one we're
|
|
||||||
already showing. Otherwise, do nothing.
|
|
||||||
"""
|
|
||||||
if tHandle == self.theHandle:
|
|
||||||
self.cCountData.setText(f"{cC:n}")
|
|
||||||
self.wCountData.setText(f"{wC:n}")
|
|
||||||
self.pCountData.setText(f"{pC:n}")
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
def updateViewBox(self, tHandle):
|
def updateViewBox(self, tHandle):
|
||||||
"""Populate the details box from a given handle.
|
"""Populate the details box from a given handle.
|
||||||
"""
|
"""
|
||||||
@@ -281,4 +270,20 @@ class GuiItemDetails(QWidget):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
##
|
||||||
|
# Slots
|
||||||
|
##
|
||||||
|
|
||||||
|
@pyqtSlot(str, int, int, int)
|
||||||
|
def doUpdateCounts(self, tHandle, cC, wC, pC):
|
||||||
|
"""Update the counts if the handle is the same as the one we're
|
||||||
|
already showing. Otherwise, do nothing.
|
||||||
|
"""
|
||||||
|
if tHandle == self.theHandle:
|
||||||
|
self.cCountData.setText(f"{cC:n}")
|
||||||
|
self.wCountData.setText(f"{wC:n}")
|
||||||
|
self.pCountData.setText(f"{pC:n}")
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
# END Class GuiItemDetails
|
# END Class GuiItemDetails
|
||||||
|
|||||||
+24
-3
@@ -30,7 +30,7 @@ import logging
|
|||||||
|
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
from PyQt5.QtCore import Qt, QSize, pyqtSignal
|
from PyQt5.QtCore import Qt, QSize, pyqtSignal, pyqtSlot
|
||||||
from PyQt5.QtGui import QIcon
|
from PyQt5.QtGui import QIcon
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
QTreeWidget, QTreeWidgetItem, QAbstractItemView, QMenu, QAction
|
QTreeWidget, QTreeWidgetItem, QAbstractItemView, QMenu, QAction
|
||||||
@@ -51,6 +51,7 @@ class GuiProjectTree(QTreeWidget):
|
|||||||
|
|
||||||
novelItemChanged = pyqtSignal()
|
novelItemChanged = pyqtSignal()
|
||||||
noteItemChanged = pyqtSignal()
|
noteItemChanged = pyqtSignal()
|
||||||
|
projectWordCountChanged = pyqtSignal(int, int)
|
||||||
|
|
||||||
def __init__(self, theParent):
|
def __init__(self, theParent):
|
||||||
QTreeWidget.__init__(self, theParent)
|
QTreeWidget.__init__(self, theParent)
|
||||||
@@ -524,7 +525,7 @@ class GuiProjectTree(QTreeWidget):
|
|||||||
tIndex = trItemP.indexOfChild(trItemS)
|
tIndex = trItemP.indexOfChild(trItemS)
|
||||||
trItemC = trItemP.takeChild(tIndex)
|
trItemC = trItemP.takeChild(tIndex)
|
||||||
|
|
||||||
if self.theParent.docEditor.theHandle == tHandle:
|
if self.theParent.docEditor.docHandle() == tHandle:
|
||||||
self.theParent.closeDocument()
|
self.theParent.closeDocument()
|
||||||
|
|
||||||
delDoc = NWDoc(self.theProject, tHandle)
|
delDoc = NWDoc(self.theProject, tHandle)
|
||||||
@@ -674,7 +675,8 @@ class GuiProjectTree(QTreeWidget):
|
|||||||
|
|
||||||
self.theProject.setProjectWordCount(nWords)
|
self.theProject.setProjectWordCount(nWords)
|
||||||
sWords = self.theProject.getSessionWordCount()
|
sWords = self.theProject.getSessionWordCount()
|
||||||
self.theParent.statusBar.setStats(nWords, sWords)
|
|
||||||
|
self.projectWordCountChanged.emit(nWords, sWords)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -779,6 +781,7 @@ class GuiProjectTree(QTreeWidget):
|
|||||||
# Slots
|
# Slots
|
||||||
##
|
##
|
||||||
|
|
||||||
|
@pyqtSlot("QPoint")
|
||||||
def _rightClickMenu(self, clickPos):
|
def _rightClickMenu(self, clickPos):
|
||||||
"""The user right clicked an element in the project tree, so we
|
"""The user right clicked an element in the project tree, so we
|
||||||
open a context menu in-place.
|
open a context menu in-place.
|
||||||
@@ -795,6 +798,14 @@ class GuiProjectTree(QTreeWidget):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@pyqtSlot(str, int, int, int)
|
||||||
|
def doUpdateCounts(self, tHandle, cCount, wCount, pCount):
|
||||||
|
"""Slot for updating the word count of a specific item.
|
||||||
|
"""
|
||||||
|
self.propagateCount(tHandle, wCount)
|
||||||
|
self.projectWordCount()
|
||||||
|
return
|
||||||
|
|
||||||
##
|
##
|
||||||
# Events
|
# Events
|
||||||
##
|
##
|
||||||
@@ -1171,6 +1182,7 @@ class GuiProjectTreeMenu(QMenu):
|
|||||||
# Slots
|
# Slots
|
||||||
##
|
##
|
||||||
|
|
||||||
|
@pyqtSlot()
|
||||||
def _doOpenItem(self):
|
def _doOpenItem(self):
|
||||||
"""Forward the open document call to the main GUI window.
|
"""Forward the open document call to the main GUI window.
|
||||||
"""
|
"""
|
||||||
@@ -1178,6 +1190,7 @@ class GuiProjectTreeMenu(QMenu):
|
|||||||
self.theTree.theParent.openDocument(self.theItem.itemHandle, doScroll=False)
|
self.theTree.theParent.openDocument(self.theItem.itemHandle, doScroll=False)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@pyqtSlot()
|
||||||
def _doViewItem(self):
|
def _doViewItem(self):
|
||||||
"""Forward the view document call to the main GUI window.
|
"""Forward the view document call to the main GUI window.
|
||||||
"""
|
"""
|
||||||
@@ -1185,6 +1198,7 @@ class GuiProjectTreeMenu(QMenu):
|
|||||||
self.theTree.theParent.viewDocument(self.theItem.itemHandle)
|
self.theTree.theParent.viewDocument(self.theItem.itemHandle)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@pyqtSlot()
|
||||||
def _doEditItem(self):
|
def _doEditItem(self):
|
||||||
"""Forward the edit item call to the main GUI window.
|
"""Forward the edit item call to the main GUI window.
|
||||||
"""
|
"""
|
||||||
@@ -1192,6 +1206,7 @@ class GuiProjectTreeMenu(QMenu):
|
|||||||
self.theTree.theParent.editItem()
|
self.theTree.theParent.editItem()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@pyqtSlot()
|
||||||
def _doMakeFile(self):
|
def _doMakeFile(self):
|
||||||
"""Forward the new file call to the project tree.
|
"""Forward the new file call to the project tree.
|
||||||
"""
|
"""
|
||||||
@@ -1199,6 +1214,7 @@ class GuiProjectTreeMenu(QMenu):
|
|||||||
self.theTree.newTreeItem(nwItemType.FILE, None)
|
self.theTree.newTreeItem(nwItemType.FILE, None)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@pyqtSlot()
|
||||||
def _doMakeFolder(self):
|
def _doMakeFolder(self):
|
||||||
"""Forward the new folder call to the project tree.
|
"""Forward the new folder call to the project tree.
|
||||||
"""
|
"""
|
||||||
@@ -1206,6 +1222,7 @@ class GuiProjectTreeMenu(QMenu):
|
|||||||
self.theTree.newTreeItem(nwItemType.FOLDER, None)
|
self.theTree.newTreeItem(nwItemType.FOLDER, None)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@pyqtSlot()
|
||||||
def _doToggleExported(self):
|
def _doToggleExported(self):
|
||||||
"""Flip the isExported flag of the current item.
|
"""Flip the isExported flag of the current item.
|
||||||
"""
|
"""
|
||||||
@@ -1214,6 +1231,7 @@ class GuiProjectTreeMenu(QMenu):
|
|||||||
self.theTree.setTreeItemValues(self.theItem.itemHandle)
|
self.theTree.setTreeItemValues(self.theItem.itemHandle)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@pyqtSlot()
|
||||||
def _doDeleteItem(self):
|
def _doDeleteItem(self):
|
||||||
"""Forward the delete item call to the project tree.
|
"""Forward the delete item call to the project tree.
|
||||||
"""
|
"""
|
||||||
@@ -1221,18 +1239,21 @@ class GuiProjectTreeMenu(QMenu):
|
|||||||
self.theTree.deleteItem()
|
self.theTree.deleteItem()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@pyqtSlot()
|
||||||
def _doEmptyTrash(self):
|
def _doEmptyTrash(self):
|
||||||
"""Forward the empty trash call to the project tree.
|
"""Forward the empty trash call to the project tree.
|
||||||
"""
|
"""
|
||||||
self.theTree.emptyTrash()
|
self.theTree.emptyTrash()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@pyqtSlot()
|
||||||
def _doMoveUp(self):
|
def _doMoveUp(self):
|
||||||
"""Forward the move item call to the project tree.
|
"""Forward the move item call to the project tree.
|
||||||
"""
|
"""
|
||||||
self.theTree.moveTreeItem(-1)
|
self.theTree.moveTreeItem(-1)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@pyqtSlot()
|
||||||
def _doMoveDown(self):
|
def _doMoveDown(self):
|
||||||
"""Forward the move item call to the project tree.
|
"""Forward the move item call to the project tree.
|
||||||
"""
|
"""
|
||||||
|
|||||||
+65
-43
@@ -29,11 +29,12 @@ 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
|
||||||
|
|
||||||
from nw.common import formatTime
|
from nw.common import formatTime
|
||||||
|
from nw.enum import nwState
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -123,10 +124,10 @@ 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.doUpdateProjectStats(0, 0)
|
||||||
self.setProjectStatus(None)
|
self.setProjectStatus(nwState.NONE)
|
||||||
self.setDocumentStatus(None)
|
self.setDocumentStatus(nwState.NONE)
|
||||||
self.updateTime()
|
self.updateTime()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -147,40 +148,16 @@ class GuiMainStatus(QStatusBar):
|
|||||||
qApp.processEvents()
|
qApp.processEvents()
|
||||||
return
|
return
|
||||||
|
|
||||||
def setLanguage(self, theLanguage, theProvider=""):
|
def setProjectStatus(self, theState):
|
||||||
"""Set the language code for the spell checker.
|
|
||||||
"""
|
|
||||||
if theLanguage is None:
|
|
||||||
self.langText.setText(self.tr("None"))
|
|
||||||
self.langText.setToolTip("")
|
|
||||||
else:
|
|
||||||
qLocal = QLocale(theLanguage)
|
|
||||||
spLang = qLocal.nativeLanguageName().title()
|
|
||||||
self.langText.setText(spLang)
|
|
||||||
if theProvider:
|
|
||||||
self.langText.setToolTip("%s (%s)" % (theLanguage, theProvider))
|
|
||||||
else:
|
|
||||||
self.langText.setToolTip(theLanguage)
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
def setProjectStatus(self, isChanged):
|
|
||||||
"""Set the project status colour icon.
|
"""Set the project status colour icon.
|
||||||
"""
|
"""
|
||||||
self.projIcon.setState(isChanged)
|
self.projIcon.setState(theState)
|
||||||
return
|
return
|
||||||
|
|
||||||
def setDocumentStatus(self, isChanged):
|
def setDocumentStatus(self, theState):
|
||||||
"""Set the document status colour icon.
|
"""Set the document status colour icon.
|
||||||
"""
|
"""
|
||||||
self.docIcon.setState(isChanged)
|
self.docIcon.setState(theState)
|
||||||
return
|
|
||||||
|
|
||||||
def setStats(self, pWC, sWC):
|
|
||||||
"""Set the current project statistics.
|
|
||||||
"""
|
|
||||||
self.statsText.setText(self.tr("Words: {0} ({1})").format(f"{pWC:n}", f"{sWC:+n}"))
|
|
||||||
self.statsText.setToolTip(self.tr("Project word count (session change)"))
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def setUserIdle(self, userIdle):
|
def setUserIdle(self, userIdle):
|
||||||
@@ -212,16 +189,60 @@ class GuiMainStatus(QStatusBar):
|
|||||||
self.timeText.setText(formatTime(sessTime))
|
self.timeText.setText(formatTime(sessTime))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
##
|
||||||
|
# Slots
|
||||||
|
##
|
||||||
|
|
||||||
|
@pyqtSlot(str, str)
|
||||||
|
def setLanguage(self, theLanguage, theProvider):
|
||||||
|
"""Set the language code for the spell checker.
|
||||||
|
"""
|
||||||
|
if theLanguage == "None":
|
||||||
|
self.langText.setText(self.tr("None"))
|
||||||
|
self.langText.setToolTip("")
|
||||||
|
else:
|
||||||
|
qLocal = QLocale(theLanguage)
|
||||||
|
spLang = qLocal.nativeLanguageName().title()
|
||||||
|
self.langText.setText(spLang)
|
||||||
|
if theProvider:
|
||||||
|
self.langText.setToolTip("%s (%s)" % (theLanguage, theProvider))
|
||||||
|
else:
|
||||||
|
self.langText.setToolTip(theLanguage)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
@pyqtSlot(int, int)
|
||||||
|
def doUpdateProjectStats(self, pWC, sWC):
|
||||||
|
"""Update the current project statistics.
|
||||||
|
"""
|
||||||
|
self.statsText.setText(self.tr("Words: {0} ({1})").format(f"{pWC:n}", f"{sWC:+n}"))
|
||||||
|
self.statsText.setToolTip(self.tr("Project word count (session change)"))
|
||||||
|
return
|
||||||
|
|
||||||
|
@pyqtSlot(bool)
|
||||||
|
def doUpdateProjectStatus(self, isChanged):
|
||||||
|
"""Slot for updating the project status.
|
||||||
|
"""
|
||||||
|
self.setProjectStatus(nwState.GOOD if isChanged else nwState.BAD)
|
||||||
|
return
|
||||||
|
|
||||||
|
@pyqtSlot(bool)
|
||||||
|
def doUpdateDocumentStatus(self, isChanged):
|
||||||
|
"""Slot for updating the document status.
|
||||||
|
"""
|
||||||
|
self.setDocumentStatus(nwState.GOOD if isChanged else nwState.BAD)
|
||||||
|
return
|
||||||
|
|
||||||
# END Class GuiMainStatus
|
# END Class GuiMainStatus
|
||||||
|
|
||||||
class StatusLED(QAbstractButton):
|
class StatusLED(QAbstractButton):
|
||||||
|
|
||||||
def __init__(self, colNone, colTrue, colFalse, sW, sH, parent=None):
|
def __init__(self, colNone, colGood, colBad, sW, sH, parent=None):
|
||||||
super().__init__(parent=parent)
|
super().__init__(parent=parent)
|
||||||
|
|
||||||
self.colNone = colNone
|
self._colNone = colNone
|
||||||
self.colTrue = colTrue
|
self._colGood = colGood
|
||||||
self.colFalse = colFalse
|
self._colBad = colBad
|
||||||
self._theCol = colNone
|
self._theCol = colNone
|
||||||
|
|
||||||
self.setFixedWidth(sW)
|
self.setFixedWidth(sW)
|
||||||
@@ -236,11 +257,12 @@ class StatusLED(QAbstractButton):
|
|||||||
def setState(self, theState):
|
def setState(self, theState):
|
||||||
"""Set the colour state.
|
"""Set the colour state.
|
||||||
"""
|
"""
|
||||||
self._theCol = self.colNone
|
if theState == nwState.GOOD:
|
||||||
if theState is True:
|
self._theCol = self._colGood
|
||||||
self._theCol = self.colTrue
|
elif theState == nwState.BAD:
|
||||||
elif theState is False:
|
self._theCol = self._colBad
|
||||||
self._theCol = self.colFalse
|
else:
|
||||||
|
self._theCol = self._colNone
|
||||||
|
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
@@ -250,7 +272,7 @@ class StatusLED(QAbstractButton):
|
|||||||
# Events
|
# Events
|
||||||
##
|
##
|
||||||
|
|
||||||
def paintEvent(self, event):
|
def paintEvent(self, _):
|
||||||
"""Drawing the LED.
|
"""Drawing the LED.
|
||||||
"""
|
"""
|
||||||
qPalette = self.palette()
|
qPalette = self.palette()
|
||||||
|
|||||||
+24
-17
@@ -49,7 +49,7 @@ from nw.dialogs import (
|
|||||||
)
|
)
|
||||||
from nw.tools import GuiBuildNovel, GuiProjectWizard, GuiWritingStats
|
from nw.tools import GuiBuildNovel, GuiProjectWizard, GuiWritingStats
|
||||||
from nw.core import NWProject, NWIndex
|
from nw.core import NWProject, NWIndex
|
||||||
from nw.enum import nwItemType, nwItemClass, nwAlert, nwWidget
|
from nw.enum import nwItemType, nwItemClass, nwAlert, nwWidget, nwState
|
||||||
from nw.common import getGuiItem, hexToInt
|
from nw.common import getGuiItem, hexToInt
|
||||||
from nw.constants import nwLists
|
from nw.constants import nwLists
|
||||||
|
|
||||||
@@ -119,6 +119,17 @@ class GuiMain(QMainWindow):
|
|||||||
self.projMeta = GuiOutlineDetails(self)
|
self.projMeta = GuiOutlineDetails(self)
|
||||||
self.mainMenu = GuiMainMenu(self)
|
self.mainMenu = GuiMainMenu(self)
|
||||||
|
|
||||||
|
# Connect Signals Between Main Elements
|
||||||
|
self.docEditor.spellDictionaryChanged.connect(self.statusBar.setLanguage)
|
||||||
|
self.docEditor.docEditedStatusChanged.connect(self.statusBar.doUpdateDocumentStatus)
|
||||||
|
self.docEditor.docCountsChanged.connect(self.treeMeta.doUpdateCounts)
|
||||||
|
self.docEditor.docCountsChanged.connect(self.treeView.doUpdateCounts)
|
||||||
|
|
||||||
|
self.treeView.itemSelectionChanged.connect(self._treeSingleClick)
|
||||||
|
self.treeView.itemDoubleClicked.connect(self._treeDoubleClick)
|
||||||
|
self.treeView.novelItemChanged.connect(self._treeNovelItemChanged)
|
||||||
|
self.treeView.projectWordCountChanged.connect(self.statusBar.doUpdateProjectStats)
|
||||||
|
|
||||||
# Minor GUI Elements
|
# Minor GUI Elements
|
||||||
self.statusIcons = []
|
self.statusIcons = []
|
||||||
self.importIcons = []
|
self.importIcons = []
|
||||||
@@ -227,9 +238,6 @@ class GuiMain(QMainWindow):
|
|||||||
self.docEditor.closeSearch()
|
self.docEditor.closeSearch()
|
||||||
|
|
||||||
# Initialise the Project Tree
|
# Initialise the Project Tree
|
||||||
self.treeView.itemSelectionChanged.connect(self._treeSingleClick)
|
|
||||||
self.treeView.itemDoubleClicked.connect(self._treeDoubleClick)
|
|
||||||
self.treeView.novelItemChanged.connect(self._treeNovelItemChanged)
|
|
||||||
self.rebuildTrees()
|
self.rebuildTrees()
|
||||||
|
|
||||||
# Set Main Window Elements
|
# Set Main Window Elements
|
||||||
@@ -267,7 +275,6 @@ class GuiMain(QMainWindow):
|
|||||||
|
|
||||||
# Forward Functions
|
# Forward Functions
|
||||||
self.setStatus = self.statusBar.setStatus
|
self.setStatus = self.statusBar.setStatus
|
||||||
self.setProjectStatus = self.statusBar.setProjectStatus
|
|
||||||
|
|
||||||
# Force a show of the GUI
|
# Force a show of the GUI
|
||||||
self.show()
|
self.show()
|
||||||
@@ -377,8 +384,8 @@ class GuiMain(QMainWindow):
|
|||||||
self.docEditor.setDictionaries()
|
self.docEditor.setDictionaries()
|
||||||
self.rebuildIndex(beQuiet=True)
|
self.rebuildIndex(beQuiet=True)
|
||||||
self.statusBar.setRefTime(self.theProject.projOpened)
|
self.statusBar.setRefTime(self.theProject.projOpened)
|
||||||
self.statusBar.setProjectStatus(True)
|
self.statusBar.setProjectStatus(nwState.GOOD)
|
||||||
self.statusBar.setDocumentStatus(None)
|
self.statusBar.setDocumentStatus(nwState.NONE)
|
||||||
self.statusBar.setStatus(self.tr("New project created ..."))
|
self.statusBar.setStatus(self.tr("New project created ..."))
|
||||||
self._updateWindowTitle(self.theProject.projName)
|
self._updateWindowTitle(self.theProject.projName)
|
||||||
else:
|
else:
|
||||||
@@ -407,7 +414,7 @@ class GuiMain(QMainWindow):
|
|||||||
if not msgYes:
|
if not msgYes:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if self.docEditor.docChanged:
|
if self.docEditor.docChanged():
|
||||||
self.saveDocument()
|
self.saveDocument()
|
||||||
|
|
||||||
if self.theProject.projAltered:
|
if self.theProject.projAltered:
|
||||||
@@ -520,7 +527,7 @@ class GuiMain(QMainWindow):
|
|||||||
self.docEditor.setSpellCheck(self.theProject.spellCheck)
|
self.docEditor.setSpellCheck(self.theProject.spellCheck)
|
||||||
self.mainMenu.setAutoOutline(self.theProject.autoOutline)
|
self.mainMenu.setAutoOutline(self.theProject.autoOutline)
|
||||||
self.statusBar.setRefTime(self.theProject.projOpened)
|
self.statusBar.setRefTime(self.theProject.projOpened)
|
||||||
self.statusBar.setStats(self.theProject.currWCount, 0)
|
self.statusBar.doUpdateProjectStats(self.theProject.currWCount, 0)
|
||||||
|
|
||||||
# Restore previously open documents, if any
|
# Restore previously open documents, if any
|
||||||
if self.theProject.lastEdited is not None:
|
if self.theProject.lastEdited is not None:
|
||||||
@@ -576,7 +583,7 @@ class GuiMain(QMainWindow):
|
|||||||
self.toggleFocusMode()
|
self.toggleFocusMode()
|
||||||
|
|
||||||
self.docEditor.saveCursorPosition()
|
self.docEditor.saveCursorPosition()
|
||||||
if self.docEditor.docChanged:
|
if self.docEditor.docChanged():
|
||||||
self.saveDocument()
|
self.saveDocument()
|
||||||
self.docEditor.clearEditor()
|
self.docEditor.clearEditor()
|
||||||
|
|
||||||
@@ -658,7 +665,7 @@ class GuiMain(QMainWindow):
|
|||||||
|
|
||||||
if self.docEditor.hasFocus():
|
if self.docEditor.hasFocus():
|
||||||
logger.verbose("Trying editor document")
|
logger.verbose("Trying editor document")
|
||||||
tHandle = self.docEditor.theHandle
|
tHandle = self.docEditor.docHandle()
|
||||||
|
|
||||||
if tHandle is not None:
|
if tHandle is not None:
|
||||||
self.saveDocument()
|
self.saveDocument()
|
||||||
@@ -727,7 +734,7 @@ class GuiMain(QMainWindow):
|
|||||||
], nwAlert.ERROR)
|
], nwAlert.ERROR)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if self.docEditor.theHandle is None:
|
if self.docEditor.docHandle() is None:
|
||||||
self.makeAlert(
|
self.makeAlert(
|
||||||
self.tr("Please open a document to import the text file into."),
|
self.tr("Please open a document to import the text file into."),
|
||||||
nwAlert.ERROR
|
nwAlert.ERROR
|
||||||
@@ -822,7 +829,7 @@ class GuiMain(QMainWindow):
|
|||||||
|
|
||||||
if tHandle is None:
|
if tHandle is None:
|
||||||
if self.docEditor.anyFocus() or self.isFocusMode:
|
if self.docEditor.anyFocus() or self.isFocusMode:
|
||||||
tHandle = self.docEditor.theHandle
|
tHandle = self.docEditor.docHandle()
|
||||||
else:
|
else:
|
||||||
tHandle = self.treeView.getSelectedHandle()
|
tHandle = self.treeView.getSelectedHandle()
|
||||||
|
|
||||||
@@ -878,7 +885,7 @@ class GuiMain(QMainWindow):
|
|||||||
self.treeView.saveTreeOrder()
|
self.treeView.saveTreeOrder()
|
||||||
self.theIndex.clearIndex()
|
self.theIndex.clearIndex()
|
||||||
|
|
||||||
for nDone, tItem in enumerate(self.theProject.projTree):
|
for tItem in self.theProject.projTree:
|
||||||
|
|
||||||
if tItem is not None:
|
if tItem is not None:
|
||||||
self.setStatus(self.tr("Indexing: '{0}'").format(tItem.itemName))
|
self.setStatus(self.tr("Indexing: '{0}'").format(tItem.itemName))
|
||||||
@@ -1218,7 +1225,7 @@ class GuiMain(QMainWindow):
|
|||||||
"""Main GUI Focus Mode hides tree, view pane and optionally also
|
"""Main GUI Focus Mode hides tree, view pane and optionally also
|
||||||
statusbar and menu.
|
statusbar and menu.
|
||||||
"""
|
"""
|
||||||
if self.docEditor.theHandle is None:
|
if self.docEditor.docHandle() is None:
|
||||||
logger.error("No document open, so not activating Focus Mode")
|
logger.error("No document open, so not activating Focus Mode")
|
||||||
self.mainMenu.setFocusMode(self.isFocusMode)
|
self.mainMenu.setFocusMode(self.isFocusMode)
|
||||||
return False
|
return False
|
||||||
@@ -1385,7 +1392,7 @@ class GuiMain(QMainWindow):
|
|||||||
"""Triggered by the auto-save document timer to save the
|
"""Triggered by the auto-save document timer to save the
|
||||||
document.
|
document.
|
||||||
"""
|
"""
|
||||||
if self.hasProject and self.docEditor.docChanged:
|
if self.hasProject and self.docEditor.docChanged():
|
||||||
logger.debug("Autosaving document")
|
logger.debug("Autosaving document")
|
||||||
self.saveDocument()
|
self.saveDocument()
|
||||||
return
|
return
|
||||||
@@ -1477,7 +1484,7 @@ class GuiMain(QMainWindow):
|
|||||||
return
|
return
|
||||||
|
|
||||||
currTime = time()
|
currTime = time()
|
||||||
editIdle = currTime - self.docEditor.lastActive > self.mainConf.userIdleTime
|
editIdle = currTime - self.docEditor.lastActive() > self.mainConf.userIdleTime
|
||||||
userIdle = qApp.applicationState() != Qt.ApplicationActive
|
userIdle = qApp.applicationState() != Qt.ApplicationActive
|
||||||
|
|
||||||
if editIdle or userIdle:
|
if editIdle or userIdle:
|
||||||
|
|||||||
+3
-3
@@ -54,9 +54,6 @@ class MockGuiMain():
|
|||||||
def setStatus(self, theMessage):
|
def setStatus(self, theMessage):
|
||||||
return
|
return
|
||||||
|
|
||||||
def setProjectStatus(self, isChanged):
|
|
||||||
return
|
|
||||||
|
|
||||||
def openProject(self, projPath):
|
def openProject(self, projPath):
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -89,6 +86,9 @@ class MockStatusBar():
|
|||||||
def setStatus(self, theText):
|
def setStatus(self, theText):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def doUpdateProjectStatus(self, theStatus):
|
||||||
|
return
|
||||||
|
|
||||||
# END Class MockStatusBar
|
# END Class MockStatusBar
|
||||||
|
|
||||||
class MockApp:
|
class MockApp:
|
||||||
|
|||||||
@@ -292,9 +292,9 @@ def testGuiEditor_Main(qtbot, monkeypatch, nwGUI, fncDir, fncProj, refDir, outDi
|
|||||||
qtbot.wait(stepDelay)
|
qtbot.wait(stepDelay)
|
||||||
|
|
||||||
# Save the document
|
# Save the document
|
||||||
assert nwGUI.docEditor.docChanged
|
assert nwGUI.docEditor.docChanged()
|
||||||
assert nwGUI.saveDocument()
|
assert nwGUI.saveDocument()
|
||||||
assert not nwGUI.docEditor.docChanged
|
assert not nwGUI.docEditor.docChanged()
|
||||||
qtbot.wait(stepDelay)
|
qtbot.wait(stepDelay)
|
||||||
nwGUI.rebuildIndex()
|
nwGUI.rebuildIndex()
|
||||||
qtbot.wait(stepDelay)
|
qtbot.wait(stepDelay)
|
||||||
@@ -503,7 +503,7 @@ def testGuiEditor_Search(qtbot, monkeypatch, nwGUI, nwLipsum):
|
|||||||
|
|
||||||
# Next Match
|
# Next Match
|
||||||
nwGUI.mainMenu.aFindNext.activate(QAction.Trigger)
|
nwGUI.mainMenu.aFindNext.activate(QAction.Trigger)
|
||||||
assert nwGUI.docEditor.theHandle == "2426c6f0ca922" # Next document
|
assert nwGUI.docEditor.docHandle() == "2426c6f0ca922" # Next document
|
||||||
nwGUI.mainMenu.aFindNext.activate(QAction.Trigger)
|
nwGUI.mainMenu.aFindNext.activate(QAction.Trigger)
|
||||||
assert abs(nwGUI.docEditor.getCursorPosition() - 620) < 3
|
assert abs(nwGUI.docEditor.getCursorPosition() - 620) < 3
|
||||||
nwGUI.mainMenu.aFindNext.activate(QAction.Trigger)
|
nwGUI.mainMenu.aFindNext.activate(QAction.Trigger)
|
||||||
|
|||||||
@@ -97,9 +97,9 @@ def testGuiNovelTree_TreeItems(qtbot, caplog, monkeypatch, nwGUI, nwMinimal):
|
|||||||
# Double-click item
|
# Double-click item
|
||||||
scItem.setSelected(True)
|
scItem.setSelected(True)
|
||||||
assert scItem.isSelected()
|
assert scItem.isSelected()
|
||||||
assert nwGUI.docEditor.theHandle is None
|
assert nwGUI.docEditor.docHandle() is None
|
||||||
nwTree._treeDoubleClick(scItem, 0)
|
nwTree._treeDoubleClick(scItem, 0)
|
||||||
assert nwGUI.docEditor.theHandle == "8c659a11cd429"
|
assert nwGUI.docEditor.docHandle() == "8c659a11cd429"
|
||||||
|
|
||||||
# Open item with middle mouse button
|
# Open item with middle mouse button
|
||||||
scItem.setSelected(True)
|
scItem.setSelected(True)
|
||||||
|
|||||||
Reference in New Issue
Block a user