Add a signal for updated word counts
This commit is contained in:
+4
-3
@@ -67,6 +67,7 @@ class GuiDocEditor(QTextEdit):
|
||||
# Custom Signals
|
||||
spellDictionaryChanged = pyqtSignal(str, str)
|
||||
docEditedStatusChanged = pyqtSignal(bool)
|
||||
docCountsChanged = pyqtSignal(str, int, int, int)
|
||||
|
||||
def __init__(self, theParent):
|
||||
QTextEdit.__init__(self, theParent)
|
||||
@@ -1193,9 +1194,9 @@ class GuiDocEditor(QTextEdit):
|
||||
self._nwItem.setWordCount(wCount)
|
||||
self._nwItem.setParaCount(pCount)
|
||||
|
||||
self.theParent.treeView.propagateCount(self._docHandle, wCount)
|
||||
self.theParent.treeView.projectWordCount()
|
||||
self.theParent.treeMeta.updateCounts(self._docHandle, cCount, wCount, pCount)
|
||||
# Must not be emitted if docHandle is None!
|
||||
self.docCountsChanged.emit(self._docHandle, cCount, wCount, pCount)
|
||||
|
||||
self._checkDocSize(self._qDocument.characterCount())
|
||||
self.docFooter.updateCounts()
|
||||
|
||||
|
||||
+17
-12
@@ -27,7 +27,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import nw
|
||||
import logging
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtCore import Qt, pyqtSlot
|
||||
from PyQt5.QtGui import QFont, QPixmap
|
||||
from PyQt5.QtWidgets import QWidget, QGridLayout, QLabel
|
||||
|
||||
@@ -212,17 +212,6 @@ class GuiItemDetails(QWidget):
|
||||
|
||||
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):
|
||||
"""Populate the details box from a given handle.
|
||||
"""
|
||||
@@ -281,4 +270,20 @@ class GuiItemDetails(QWidget):
|
||||
|
||||
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
|
||||
|
||||
+23
-2
@@ -30,7 +30,7 @@ import logging
|
||||
|
||||
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.QtWidgets import (
|
||||
QTreeWidget, QTreeWidgetItem, QAbstractItemView, QMenu, QAction
|
||||
@@ -51,6 +51,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
|
||||
novelItemChanged = pyqtSignal()
|
||||
noteItemChanged = pyqtSignal()
|
||||
projectWordCountChanged = pyqtSignal(int, int)
|
||||
|
||||
def __init__(self, theParent):
|
||||
QTreeWidget.__init__(self, theParent)
|
||||
@@ -674,7 +675,8 @@ class GuiProjectTree(QTreeWidget):
|
||||
|
||||
self.theProject.setProjectWordCount(nWords)
|
||||
sWords = self.theProject.getSessionWordCount()
|
||||
self.theParent.statusBar.setStats(nWords, sWords)
|
||||
|
||||
self.projectWordCountChanged.emit(nWords, sWords)
|
||||
|
||||
return
|
||||
|
||||
@@ -779,6 +781,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
# Slots
|
||||
##
|
||||
|
||||
@pyqtSlot("QPoint")
|
||||
def _rightClickMenu(self, clickPos):
|
||||
"""The user right clicked an element in the project tree, so we
|
||||
open a context menu in-place.
|
||||
@@ -795,6 +798,14 @@ class GuiProjectTree(QTreeWidget):
|
||||
|
||||
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
|
||||
##
|
||||
@@ -1171,6 +1182,7 @@ class GuiProjectTreeMenu(QMenu):
|
||||
# Slots
|
||||
##
|
||||
|
||||
@pyqtSlot()
|
||||
def _doOpenItem(self):
|
||||
"""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)
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def _doViewItem(self):
|
||||
"""Forward the view document call to the main GUI window.
|
||||
"""
|
||||
@@ -1185,6 +1198,7 @@ class GuiProjectTreeMenu(QMenu):
|
||||
self.theTree.theParent.viewDocument(self.theItem.itemHandle)
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def _doEditItem(self):
|
||||
"""Forward the edit item call to the main GUI window.
|
||||
"""
|
||||
@@ -1192,6 +1206,7 @@ class GuiProjectTreeMenu(QMenu):
|
||||
self.theTree.theParent.editItem()
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def _doMakeFile(self):
|
||||
"""Forward the new file call to the project tree.
|
||||
"""
|
||||
@@ -1199,6 +1214,7 @@ class GuiProjectTreeMenu(QMenu):
|
||||
self.theTree.newTreeItem(nwItemType.FILE, None)
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def _doMakeFolder(self):
|
||||
"""Forward the new folder call to the project tree.
|
||||
"""
|
||||
@@ -1206,6 +1222,7 @@ class GuiProjectTreeMenu(QMenu):
|
||||
self.theTree.newTreeItem(nwItemType.FOLDER, None)
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def _doToggleExported(self):
|
||||
"""Flip the isExported flag of the current item.
|
||||
"""
|
||||
@@ -1214,6 +1231,7 @@ class GuiProjectTreeMenu(QMenu):
|
||||
self.theTree.setTreeItemValues(self.theItem.itemHandle)
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def _doDeleteItem(self):
|
||||
"""Forward the delete item call to the project tree.
|
||||
"""
|
||||
@@ -1221,18 +1239,21 @@ class GuiProjectTreeMenu(QMenu):
|
||||
self.theTree.deleteItem()
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def _doEmptyTrash(self):
|
||||
"""Forward the empty trash call to the project tree.
|
||||
"""
|
||||
self.theTree.emptyTrash()
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def _doMoveUp(self):
|
||||
"""Forward the move item call to the project tree.
|
||||
"""
|
||||
self.theTree.moveTreeItem(-1)
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def _doMoveDown(self):
|
||||
"""Forward the move item call to the project tree.
|
||||
"""
|
||||
|
||||
+9
-8
@@ -125,7 +125,7 @@ class GuiMainStatus(QStatusBar):
|
||||
"""
|
||||
self.setRefTime(None)
|
||||
self.setLanguage(None, "")
|
||||
self.setStats(0, 0)
|
||||
self.doUpdateProjectStats(0, 0)
|
||||
self.setProjectStatus(nwState.NONE)
|
||||
self.setDocumentStatus(nwState.NONE)
|
||||
self.updateTime()
|
||||
@@ -160,13 +160,6 @@ class GuiMainStatus(QStatusBar):
|
||||
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
|
||||
|
||||
def setUserIdle(self, userIdle):
|
||||
"""Change the idle status icon.
|
||||
"""
|
||||
@@ -218,6 +211,14 @@ class GuiMainStatus(QStatusBar):
|
||||
|
||||
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.
|
||||
|
||||
+10
-6
@@ -119,9 +119,16 @@ class GuiMain(QMainWindow):
|
||||
self.projMeta = GuiOutlineDetails(self)
|
||||
self.mainMenu = GuiMainMenu(self)
|
||||
|
||||
# Signals Between Main Elements
|
||||
# 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
|
||||
self.statusIcons = []
|
||||
@@ -231,9 +238,6 @@ class GuiMain(QMainWindow):
|
||||
self.docEditor.closeSearch()
|
||||
|
||||
# Initialise the Project Tree
|
||||
self.treeView.itemSelectionChanged.connect(self._treeSingleClick)
|
||||
self.treeView.itemDoubleClicked.connect(self._treeDoubleClick)
|
||||
self.treeView.novelItemChanged.connect(self._treeNovelItemChanged)
|
||||
self.rebuildTrees()
|
||||
|
||||
# Set Main Window Elements
|
||||
@@ -524,7 +528,7 @@ class GuiMain(QMainWindow):
|
||||
self.docEditor.setSpellCheck(self.theProject.spellCheck)
|
||||
self.mainMenu.setAutoOutline(self.theProject.autoOutline)
|
||||
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
|
||||
if self.theProject.lastEdited is not None:
|
||||
@@ -882,7 +886,7 @@ class GuiMain(QMainWindow):
|
||||
self.treeView.saveTreeOrder()
|
||||
self.theIndex.clearIndex()
|
||||
|
||||
for nDone, tItem in enumerate(self.theProject.projTree):
|
||||
for tItem in self.theProject.projTree:
|
||||
|
||||
if tItem is not None:
|
||||
self.setStatus(self.tr("Indexing: '{0}'").format(tItem.itemName))
|
||||
|
||||
Reference in New Issue
Block a user