From 8d71a2385b2805a4fc17952140aa4c4f66cd547f Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sun, 14 Jun 2020 22:01:58 +0200 Subject: [PATCH 1/5] Minimal doc editor footer bar --- nw/gui/doceditor.py | 125 +++++++++++++++++++++++++++++++++++++++++--- nw/gui/docviewer.py | 5 +- nw/guimain.py | 2 + 3 files changed, 123 insertions(+), 9 deletions(-) diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index 4c5d5ce7..25ae5cbb 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -34,7 +34,7 @@ from time import time from PyQt5.QtCore import Qt, QSize, QThread, QTimer, pyqtSlot from PyQt5.QtGui import ( - QTextCursor, QTextOption, QKeySequence, QFont, QColor, QPalette, + QTextCursor, QTextOption, QKeySequence, QFont, QColor, QPalette, QIcon, QTextDocument, QCursor ) from PyQt5.QtWidgets import ( @@ -45,7 +45,7 @@ from PyQt5.QtWidgets import ( from nw.core import NWDoc from nw.gui.dochighlight import GuiDocHighlighter from nw.core import NWSpellSimple, countWords -from nw.constants import nwUnicode, nwDocAction +from nw.constants import nwUnicode, nwDocAction, nwItemClass logger = logging.getLogger(__name__) @@ -87,6 +87,7 @@ class GuiDocEditor(QTextEdit): # Document Title self.docHeader = GuiDocEditHeader(self) + self.docFooter = GuiDocEditFooter(self) # Syntax self.hLight = GuiDocHighlighter(self.qDocument, self.theParent) @@ -267,6 +268,7 @@ class GuiDocEditor(QTextEdit): self.setReadOnly(False) self.docHeader.setTitleFromHandle(self.theHandle) + self.docFooter.setHandle(self.theHandle) self.updateDocMargins() self.hLight.spellCheck = spTemp qApp.restoreOverrideCursor() @@ -332,17 +334,19 @@ class GuiDocEditor(QTextEdit): tB = self.frameWidth() tW = self.width() - 2*tB - sW tH = self.docHeader.height() + fH = self.docFooter.height() + fY = self.height() - fH - tB tT = cM - tH + bT = cM - fH self.docHeader.setGeometry(tB, tB, tW, tH) - self.setViewportMargins(0, tH, 0, 0) + self.docFooter.setGeometry(tB, fY, tW, fH) + self.setViewportMargins(0, tH, 0, fH) docFormat = self.qDocument.rootFrame().frameFormat() docFormat.setLeftMargin(tM) docFormat.setRightMargin(tM) - if tT > 0: - docFormat.setTopMargin(tT) - else: - docFormat.setTopMargin(0) + docFormat.setTopMargin(max(0, tT)) + docFormat.setBottomMargin(max(0, bT)) # Updating root frame triggers a QTextDocument->contentsChange # signal, which we do not want as it re-runs the syntax @@ -1230,6 +1234,11 @@ class WordCounter(QThread): ## END Class WordCounter +# =============================================================================================== # +# The Embedded Document Header +# Only used by DocEditor, and is at a fixed position in the QTextBrowser's viewport +# =============================================================================================== # + class GuiDocEditHeader(QWidget): def __init__(self, docEditor): @@ -1384,3 +1393,105 @@ class GuiDocEditHeader(QWidget): return # END Class GuiDocEditHeader + +# =============================================================================================== # +# The Embedded Document Footer +# Only used by DocEditor, and is at a fixed position in the QTextEdit's viewport +# =============================================================================================== # + +class GuiDocEditFooter(QWidget): + + def __init__(self, docEditor): + QWidget.__init__(self, docEditor) + + logger.debug("Initialising GuiDocEditFooter ...") + + self.mainConf = nw.CONFIG + self.docEditor = docEditor + self.theParent = docEditor.theParent + self.theProject = docEditor.theProject + self.theTheme = docEditor.theTheme + self.optState = docEditor.theProject.optState + self.theHandle = None + + # Make a QPalette that matches the Syntax Theme + self.thePalette = QPalette() + self.thePalette.setColor(QPalette.Window, QColor(*self.theTheme.colBack)) + self.thePalette.setColor(QPalette.Text, QColor(*self.theTheme.colText)) + + self.sPx = int(round(0.8*self.theTheme.baseIconSize)) + fPx = int(0.9*self.theTheme.fontPixelSize) + bSp = self.mainConf.pxInt(2) + hSp = self.mainConf.pxInt(8) + + lblFont = self.font() + lblFont.setPointSizeF(0.9*self.theTheme.fontPointSize) + + # Main Widget Settings + self.setContentsMargins(0, 0, 0, 0) + self.setAutoFillBackground(True) + self.setPalette(self.thePalette) + + buttonStyle = ( + "QToolButton {{border: none; background: transparent;}} " + "QToolButton:hover {{border: none; background: rgba({0},{1},{2},0.2);}}" + ).format(*self.theTheme.colText) + + # Status + self.statusIcon = QLabel("") + self.statusIcon.setAlignment(Qt.AlignLeft | Qt.AlignBaseline) + + self.statusName = QLabel("Status") + self.statusName.setIndent(0) + self.statusName.setMargin(0) + self.statusName.setContentsMargins(0, 0, 0, 0) + self.statusName.setAutoFillBackground(True) + self.statusName.setFixedHeight(fPx) + self.statusName.setAlignment(Qt.AlignLeft | Qt.AlignTop) + self.statusName.setPalette(self.thePalette) + self.statusName.setFont(lblFont) + self.statusName.setAlignment(Qt.AlignLeft | Qt.AlignBaseline) + + # Assemble Layout + self.outerBox = QHBoxLayout() + self.outerBox.setSpacing(bSp) + self.outerBox.addWidget(self.statusIcon) + self.outerBox.addWidget(self.statusName) + self.outerBox.addStretch(1) + self.setLayout(self.outerBox) + + logger.debug("GuiDocEditFooter initialisation complete") + + return + + ## + # Methods + ## + + def setHandle(self, tHandle): + """Set the handle that will populate the footer's data. + """ + self.theHandle = tHandle + nwItem = self.theProject.projTree[tHandle] + if nwItem is None: + return False + + iStatus = nwItem.itemStatus + if nwItem.itemClass == nwItemClass.NOVEL: + iStatus = self.theProject.statusItems.checkEntry(iStatus) + theIcon = self.theParent.statusIcons[iStatus] + else: + iStatus = self.theProject.importItems.checkEntry(iStatus) + theIcon = self.theParent.importIcons[iStatus] + + self.statusIcon.setPixmap(theIcon.pixmap(self.sPx, self.sPx)) + self.statusName.setText(nwItem.itemStatus) + + return True + + def updateStatus(self): + """Update the content of the status and importance menus. + """ + return + +# END Class GuiDocEditFooter diff --git a/nw/gui/docviewer.py b/nw/gui/docviewer.py index 1059c277..18a7ab10 100644 --- a/nw/gui/docviewer.py +++ b/nw/gui/docviewer.py @@ -236,13 +236,14 @@ class GuiDocViewer(QTextBrowser): else: sW = 0 + cM = self.mainConf.getTextMargin() tB = self.frameWidth() tW = self.width() - 2*tB - sW tH = self.docHeader.height() fH = self.docFooter.height() fY = self.height() - fH - tB - tT = self.mainConf.getTextMargin() - tH - bT = self.mainConf.getTextMargin() - fH + tT = cM - tH + bT = cM - fH self.docHeader.setGeometry(tB, tB, tW, tH) self.docFooter.setGeometry(tB, fY, tW, fH) self.setViewportMargins(0, tH, 0, fH) diff --git a/nw/guimain.py b/nw/guimain.py index cb2f19a2..4bd58176 100644 --- a/nw/guimain.py +++ b/nw/guimain.py @@ -304,6 +304,7 @@ class GuiMain(QMainWindow): self.saveProject() self.hasProject = True self.statusBar.setRefTime(self.theProject.projOpened) + self.docEditor.docFooter.updateStatus() else: return False @@ -423,6 +424,7 @@ class GuiMain(QMainWindow): self.rebuildTree() self.docEditor.setDictionaries() self.docEditor.setSpellCheck(self.theProject.spellCheck) + self.docEditor.docFooter.updateStatus() self.mainMenu.setAutoOutline(self.theProject.autoOutline) self.statusBar.setRefTime(self.theProject.projOpened) From 7d30a2c044e200f4af0594379c10271de22f0c09 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sat, 27 Jun 2020 19:29:41 +0200 Subject: [PATCH 2/5] Added word count to the document footer --- nw/gui/doceditor.py | 113 ++++++++++++++++++++++++++++---------------- nw/guimain.py | 2 - 2 files changed, 73 insertions(+), 42 deletions(-) diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index 28a1ad2b..4b74bb1b 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -37,7 +37,7 @@ from time import time from PyQt5.QtCore import Qt, QSize, QThread, QTimer, pyqtSlot, QRegExp from PyQt5.QtGui import ( QTextCursor, QTextOption, QKeySequence, QFont, QColor, QPalette, QIcon, - QTextDocument, QCursor + QTextDocument, QCursor, QPixmap ) from PyQt5.QtWidgets import ( qApp, QTextEdit, QAction, QMenu, QShortcut, QMessageBox, QWidget, QLabel, @@ -49,7 +49,7 @@ from nw.core import NWDoc, NWSpellSimple, countWords from nw.gui.dochighlight import GuiDocHighlighter from nw.common import transferCase from nw.constants import ( - nwAlert, nwUnicode, nwDocAction, nwDocInsert, nwInsertSymbols + nwAlert, nwUnicode, nwDocAction, nwDocInsert, nwInsertSymbols, nwItemClass ) logger = logging.getLogger(__name__) @@ -161,6 +161,7 @@ class GuiDocEditor(QTextEdit): self.setDocumentChanged(False) self.docHeader.setTitleFromHandle(self.theHandle) + self.docFooter.setHandle(self.theHandle) return True @@ -357,11 +358,7 @@ class GuiDocEditor(QTextEdit): else: rH = 0 -<<<<<<< HEAD self.setViewportMargins(tM, max(cM, tH, rH), tM, max(cM, fH)) -======= - self.setViewportMargins(tM, max(cM, tH, rH), tM, cM) ->>>>>>> master return @@ -779,6 +776,7 @@ class GuiDocEditor(QTextEdit): self.theHandle, self.charCount, self.wordCount, self.paraCount ) self._checkDocSize(self.charCount) + self.docFooter.updateInfo() return @@ -1674,11 +1672,6 @@ class GuiDocEditSearch(QFrame): # Only used by DocEditor, and is at a fixed position in the QTextEdit's viewport # =============================================================================================== # -# =============================================================================================== # -# The Embedded Document Header -# Only used by DocEditor, and is at a fixed position in the QTextBrowser's viewport -# =============================================================================================== # - class GuiDocEditHeader(QWidget): def __init__(self, docEditor): @@ -1852,16 +1845,18 @@ class GuiDocEditFooter(QWidget): self.theProject = docEditor.theProject self.theTheme = docEditor.theTheme self.optState = docEditor.theProject.optState - self.theHandle = None + + self.theHandle = None + self.initWords = 0 # Make a QPalette that matches the Syntax Theme self.thePalette = QPalette() self.thePalette.setColor(QPalette.Window, QColor(*self.theTheme.colBack)) self.thePalette.setColor(QPalette.Text, QColor(*self.theTheme.colText)) - self.sPx = int(round(0.8*self.theTheme.baseIconSize)) + self.sPx = int(round(0.9*self.theTheme.baseIconSize)) fPx = int(0.9*self.theTheme.fontPixelSize) - bSp = self.mainConf.pxInt(2) + bSp = self.mainConf.pxInt(4) hSp = self.mainConf.pxInt(8) lblFont = self.font() @@ -1879,25 +1874,45 @@ class GuiDocEditFooter(QWidget): # Status self.statusIcon = QLabel("") - self.statusIcon.setAlignment(Qt.AlignLeft | Qt.AlignBaseline) + self.statusIcon.setContentsMargins(0, 0, 0, 0) + self.statusIcon.setFixedHeight(self.sPx) + self.statusIcon.setAlignment(Qt.AlignLeft | Qt.AlignTop) - self.statusName = QLabel("Status") - self.statusName.setIndent(0) - self.statusName.setMargin(0) - self.statusName.setContentsMargins(0, 0, 0, 0) - self.statusName.setAutoFillBackground(True) - self.statusName.setFixedHeight(fPx) - self.statusName.setAlignment(Qt.AlignLeft | Qt.AlignTop) - self.statusName.setPalette(self.thePalette) - self.statusName.setFont(lblFont) - self.statusName.setAlignment(Qt.AlignLeft | Qt.AlignBaseline) + self.statusText = QLabel("Status") + self.statusText.setIndent(0) + self.statusText.setMargin(0) + self.statusText.setContentsMargins(0, 0, 0, 0) + self.statusText.setAutoFillBackground(True) + self.statusText.setFixedHeight(fPx) + self.statusText.setAlignment(Qt.AlignLeft | Qt.AlignTop) + self.statusText.setPalette(self.thePalette) + self.statusText.setFont(lblFont) + + # Words + self.wordsIcon = QLabel("") + self.wordsIcon.setPixmap(self.theTheme.getPixmap("status_stats", (self.sPx, self.sPx))) + self.wordsIcon.setContentsMargins(0, 0, 0, 0) + self.wordsIcon.setFixedHeight(self.sPx) + self.wordsIcon.setAlignment(Qt.AlignLeft | Qt.AlignTop) + + self.wordsText = QLabel("Words: 0") + self.wordsText.setIndent(0) + self.wordsText.setMargin(0) + self.wordsText.setContentsMargins(0, 0, 0, 0) + self.wordsText.setAutoFillBackground(True) + self.wordsText.setFixedHeight(fPx) + self.wordsText.setAlignment(Qt.AlignLeft | Qt.AlignTop) + self.wordsText.setPalette(self.thePalette) + self.wordsText.setFont(lblFont) # Assemble Layout self.outerBox = QHBoxLayout() self.outerBox.setSpacing(bSp) self.outerBox.addWidget(self.statusIcon) - self.outerBox.addWidget(self.statusName) + self.outerBox.addWidget(self.statusText) self.outerBox.addStretch(1) + self.outerBox.addWidget(self.wordsIcon) + self.outerBox.addWidget(self.wordsText) self.setLayout(self.outerBox) logger.debug("GuiDocEditFooter initialisation complete") @@ -1912,26 +1927,44 @@ class GuiDocEditFooter(QWidget): """Set the handle that will populate the footer's data. """ self.theHandle = tHandle - nwItem = self.theProject.projTree[tHandle] + + nwItem = self.theProject.projTree[self.theHandle] if nwItem is None: - return False - - iStatus = nwItem.itemStatus - if nwItem.itemClass == nwItemClass.NOVEL: - iStatus = self.theProject.statusItems.checkEntry(iStatus) - theIcon = self.theParent.statusIcons[iStatus] + self.initWords = 0 else: - iStatus = self.theProject.importItems.checkEntry(iStatus) - theIcon = self.theParent.importIcons[iStatus] + self.initWords = nwItem.wordCount - self.statusIcon.setPixmap(theIcon.pixmap(self.sPx, self.sPx)) - self.statusName.setText(nwItem.itemStatus) + self.updateInfo() - return True + return - def updateStatus(self): - """Update the content of the status and importance menus. + def updateInfo(self): + """Update the content of text labels. """ + nwItem = self.theProject.projTree[self.theHandle] + if nwItem is None: + sIcon = QPixmap() + sText = "" + wCount = 0 + wDiff = 0 + else: + wCount = nwItem.wordCount + wDiff = wCount - self.initWords + iStatus = nwItem.itemStatus + if nwItem.itemClass == nwItemClass.NOVEL: + iStatus = self.theProject.statusItems.checkEntry(iStatus) + theIcon = self.theParent.statusIcons[iStatus] + else: + iStatus = self.theProject.importItems.checkEntry(iStatus) + theIcon = self.theParent.importIcons[iStatus] + sIcon = theIcon.pixmap(self.sPx, self.sPx) + sText = nwItem.itemStatus + + self.statusIcon.setPixmap(sIcon) + self.statusText.setText(sText) + + self.wordsText.setText("Words: {:n} ({:+n})".format(wCount, wDiff)) + return # END Class GuiDocEditFooter diff --git a/nw/guimain.py b/nw/guimain.py index 35abab3b..091c659d 100644 --- a/nw/guimain.py +++ b/nw/guimain.py @@ -293,7 +293,6 @@ class GuiMain(QMainWindow): self.saveProject() self.hasProject = True self.statusBar.setRefTime(self.theProject.projOpened) - self.docEditor.docFooter.updateStatus() else: return False @@ -413,7 +412,6 @@ class GuiMain(QMainWindow): self.rebuildTree() self.docEditor.setDictionaries() self.docEditor.setSpellCheck(self.theProject.spellCheck) - self.docEditor.docFooter.updateStatus() self.mainMenu.setAutoOutline(self.theProject.autoOutline) self.statusBar.setRefTime(self.theProject.projOpened) From 243d9dd85a3ecd5f3019527e3602874b1afd0975 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sat, 27 Jun 2020 19:41:41 +0200 Subject: [PATCH 3/5] Remove doc word count from main statusbar, and added support for session word count for documents --- nw/core/item.py | 15 +++++++++++---- nw/core/tree.py | 1 + nw/gui/doceditor.py | 23 +++++++---------------- nw/gui/statusbar.py | 18 ++---------------- 4 files changed, 21 insertions(+), 36 deletions(-) diff --git a/nw/core/item.py b/nw/core/item.py index 4dd9ddb9..0eb4ef26 100644 --- a/nw/core/item.py +++ b/nw/core/item.py @@ -53,10 +53,11 @@ class NWItem(): self.isExported = True # Document Meta Data - self.charCount = 0 - self.wordCount = 0 - self.paraCount = 0 - self.cursorPos = 0 + self.charCount = 0 # Current character count + self.wordCount = 0 # Current word count + self.paraCount = 0 # Current paragraph count + self.initCount = 0 # Initial word count + self.cursorPos = 0 # Last cursor position return @@ -274,4 +275,10 @@ class NWItem(): self.cursorPos = checkInt(thePosition, 0) return + def saveInitialCount(self): + """Set the initial word count. + """ + self.initCount = self.wordCount + return + # END Class NWItem diff --git a/nw/core/tree.py b/nw/core/tree.py index beb5d2e3..e786a727 100644 --- a/nw/core/tree.py +++ b/nw/core/tree.py @@ -134,6 +134,7 @@ class NWTree(): nwItem = NWItem(self.theProject) if nwItem.unpackXML(xItem): self.append(nwItem.itemHandle, nwItem.parHandle, nwItem) + nwItem.saveInitialCount() return True diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index 4b74bb1b..e412d902 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -769,7 +769,6 @@ class GuiDocEditor(QTextEdit): self.nwDocument.theItem.setWordCount(self.wordCount) self.nwDocument.theItem.setParaCount(self.paraCount) - self.theParent.statusBar.setCounts(self.charCount, self.wordCount, self.paraCount) self.theParent.treeView.propagateCount(self.theHandle, self.wordCount) self.theParent.treeView.projectWordCount() self.theParent.treeMeta.updateCounts( @@ -1845,9 +1844,7 @@ class GuiDocEditFooter(QWidget): self.theProject = docEditor.theProject self.theTheme = docEditor.theTheme self.optState = docEditor.theProject.optState - - self.theHandle = None - self.initWords = 0 + self.theHandle = None # Make a QPalette that matches the Syntax Theme self.thePalette = QPalette() @@ -1927,15 +1924,7 @@ class GuiDocEditFooter(QWidget): """Set the handle that will populate the footer's data. """ self.theHandle = tHandle - - nwItem = self.theProject.projTree[self.theHandle] - if nwItem is None: - self.initWords = 0 - else: - self.initWords = nwItem.wordCount - self.updateInfo() - return def updateInfo(self): @@ -1947,9 +1936,8 @@ class GuiDocEditFooter(QWidget): sText = "" wCount = 0 wDiff = 0 + else: - wCount = nwItem.wordCount - wDiff = wCount - self.initWords iStatus = nwItem.itemStatus if nwItem.itemClass == nwItemClass.NOVEL: iStatus = self.theProject.statusItems.checkEntry(iStatus) @@ -1957,8 +1945,11 @@ class GuiDocEditFooter(QWidget): else: iStatus = self.theProject.importItems.checkEntry(iStatus) theIcon = self.theParent.importIcons[iStatus] - sIcon = theIcon.pixmap(self.sPx, self.sPx) - sText = nwItem.itemStatus + + sIcon = theIcon.pixmap(self.sPx, self.sPx) + sText = nwItem.itemStatus + wCount = nwItem.wordCount + wDiff = wCount - nwItem.initCount self.statusIcon.setPixmap(sIcon) self.statusText.setText(sText) diff --git a/nw/gui/statusbar.py b/nw/gui/statusbar.py index c851a218..040125aa 100644 --- a/nw/gui/statusbar.py +++ b/nw/gui/statusbar.py @@ -51,9 +51,6 @@ class GuiMainStatus(QStatusBar): self.theTheme = theParent.theTheme self.refTime = None - self.charCount = 0 - self.wordCount = 0 - self.paraCount = 0 self.projWords = 0 self.sessWords = 0 @@ -134,7 +131,6 @@ class GuiMainStatus(QStatusBar): """ self.setRefTime(None) self.setStats(0, 0) - self.setCounts(0, 0, 0) self.setProjectStatus(None) self.setDocumentStatus(None) self._updateTime() @@ -186,15 +182,6 @@ class GuiMainStatus(QStatusBar): self._updateStats() return - def setCounts(self, cC, wC, pC): - """Set the current document statistics. - """ - self.charCount = cC - self.wordCount = wC - self.paraCount = pC - self._updateStats() - return - ## # Internal Functions ## @@ -203,12 +190,11 @@ class GuiMainStatus(QStatusBar): """Update statistics. """ self.statsText.setToolTip( - "D: Document word count
P: Project word count (session change)" + "Project word count (session change)" ) self.statsText.setText(( - "D:{wC:n} P:{pWC:n} ({sWC:+n})" + "Words: {pWC:n} ({sWC:+n})" ).format( - wC = self.wordCount, pWC = self.projWords, sWC = self.sessWords, )) From c0074ca269383e173af261cc70c076bf281e5632 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sat, 27 Jun 2020 19:49:06 +0200 Subject: [PATCH 4/5] Update count and infor separately, and make sure info is updated on item edit --- nw/gui/doceditor.py | 29 +++++++++++++++++++---------- nw/gui/docviewer.py | 2 +- nw/guimain.py | 4 ++-- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index e412d902..5c23e513 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -362,12 +362,13 @@ class GuiDocEditor(QTextEdit): return - def updateDocTitle(self, tHandle): + def updateDocInfo(self, tHandle): """Called when an item label is changed to check if the document title bar needs updating, """ if tHandle == self.theHandle: self.docHeader.setTitleFromHandle(self.theHandle) + self.docFooter.updateInfo() self.updateDocMargins() return @@ -775,7 +776,7 @@ class GuiDocEditor(QTextEdit): self.theHandle, self.charCount, self.wordCount, self.paraCount ) self._checkDocSize(self.charCount) - self.docFooter.updateInfo() + self.docFooter.updateCounts() return @@ -1925,6 +1926,7 @@ class GuiDocEditFooter(QWidget): """ self.theHandle = tHandle self.updateInfo() + self.updateCounts() return def updateInfo(self): @@ -1934,9 +1936,6 @@ class GuiDocEditFooter(QWidget): if nwItem is None: sIcon = QPixmap() sText = "" - wCount = 0 - wDiff = 0 - else: iStatus = nwItem.itemStatus if nwItem.itemClass == nwItemClass.NOVEL: @@ -1945,15 +1944,25 @@ class GuiDocEditFooter(QWidget): else: iStatus = self.theProject.importItems.checkEntry(iStatus) theIcon = self.theParent.importIcons[iStatus] - - sIcon = theIcon.pixmap(self.sPx, self.sPx) - sText = nwItem.itemStatus - wCount = nwItem.wordCount - wDiff = wCount - nwItem.initCount + sIcon = theIcon.pixmap(self.sPx, self.sPx) + sText = nwItem.itemStatus self.statusIcon.setPixmap(sIcon) self.statusText.setText(sText) + return + + def updateCounts(self): + """Update the word counts. + """ + nwItem = self.theProject.projTree[self.theHandle] + if nwItem is None: + wCount = 0 + wDiff = 0 + else: + wCount = nwItem.wordCount + wDiff = wCount - nwItem.initCount + self.wordsText.setText("Words: {:n} ({:+n})".format(wCount, wDiff)) return diff --git a/nw/gui/docviewer.py b/nw/gui/docviewer.py index 17a7c079..863d2bf6 100644 --- a/nw/gui/docviewer.py +++ b/nw/gui/docviewer.py @@ -251,7 +251,7 @@ class GuiDocViewer(QTextBrowser): return - def updateDocTitle(self, tHandle): + def updateDocInfo(self, tHandle): """Called when an item label is changed to check if the document title bar needs updating, """ diff --git a/nw/guimain.py b/nw/guimain.py index 091c659d..5c0714d4 100644 --- a/nw/guimain.py +++ b/nw/guimain.py @@ -676,8 +676,8 @@ class GuiMain(QMainWindow): if dlgProj.exec_(): self.treeView.setTreeItemValues(tHandle) self.treeMeta.updateViewBox(tHandle) - self.docEditor.updateDocTitle(tHandle) - self.docViewer.updateDocTitle(tHandle) + self.docEditor.updateDocInfo(tHandle) + self.docViewer.updateDocInfo(tHandle) return From e9d21db263c3ae8ed2f665958363f928b62ad4a9 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sat, 27 Jun 2020 19:56:38 +0200 Subject: [PATCH 5/5] Updated test --- tests/test_gui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_gui.py b/tests/test_gui.py index d52c4250..6ee01405 100644 --- a/tests/test_gui.py +++ b/tests/test_gui.py @@ -391,7 +391,7 @@ def testItemEditor(qtbot, nwTempGUI, nwRef, nwTemp): itemEdit._doClose() # Check that the header is updated - nwGUI.docEditor.updateDocTitle("31489056e0916") + nwGUI.docEditor.updateDocInfo("31489056e0916") assert nwGUI.docEditor.docHeader.theTitle.text() == "Novel › New Chapter › Just a Page" assert not nwGUI.docEditor.setCursorLine("where?") assert nwGUI.docEditor.setCursorLine(2)