From d9b1363788aa4904bcae91819b27ff2fc3efcbf6 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Wed, 7 Oct 2020 23:35:09 +0200 Subject: [PATCH 1/3] Use markContentsDirty when possible also for document viewer --- nw/gui/docviewer.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/nw/gui/docviewer.py b/nw/gui/docviewer.py index 2d24efc1..49f9c9da 100644 --- a/nw/gui/docviewer.py +++ b/nw/gui/docviewer.py @@ -34,10 +34,10 @@ import logging from PyQt5.QtCore import Qt, QUrl, QSize, pyqtSlot from PyQt5.QtGui import ( - QTextOption, QFont, QPalette, QColor, QTextCursor, QIcon + QTextOption, QFont, QPalette, QColor, QTextCursor, QIcon, QCursor ) from PyQt5.QtWidgets import ( - QTextBrowser, QWidget, QScrollArea, QLabel, QHBoxLayout, QToolButton, + qApp, QTextBrowser, QWidget, QScrollArea, QLabel, QHBoxLayout, QToolButton, QAction, QMenu ) @@ -124,11 +124,15 @@ class GuiDocViewer(QTextBrowser): theOpt.setAlignment(Qt.AlignJustify) self.qDocument.setDefaultTextOption(theOpt) + # Refresh the tab stops + if self.mainConf.verQtValue >= 51000: + self.setTabStopDistance(self.mainConf.getTabWidth()) + else: + self.setTabStopWidth(self.mainConf.getTabWidth()) + # If we have a document open, we should reload it in case the font changed if self.theHandle is not None: - tHandle = self.theHandle - self.clearViewer() - self.loadText(tHandle) + self.redrawText() return True @@ -144,6 +148,8 @@ class GuiDocViewer(QTextBrowser): return False logger.debug("Generating preview for item %s" % tHandle) + qApp.setOverrideCursor(QCursor(Qt.WaitCursor)) + sPos = self.verticalScrollBar().value() aDoc = ToHtml(self.theProject, self.theParent) aDoc.setPreview(True, self.mainConf.viewComments, self.mainConf.viewSynopsis) @@ -195,7 +201,8 @@ class GuiDocViewer(QTextBrowser): # Since we change the content while it may still be rendering, we mark # the document dirty again to make sure it's re-rendered properly. - self.qDocument.markContentsDirty(0, self.qDocument.characterCount()) + self.redrawText() + qApp.restoreOverrideCursor() return True @@ -205,6 +212,12 @@ class GuiDocViewer(QTextBrowser): self.loadText(self.theHandle, updateHistory=False) return + def redrawText(self): + """Redraw the text by marking the document content as "dirty". + """ + self.qDocument.markContentsDirty(0, self.qDocument.characterCount()) + return + def loadFromTag(self, theTag): """Load text in the document from a reference given by a meta tag rather than a known handle. This function depends on the From 214323fa6e553487628bd0ef95bceef27e7c1bd1 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Wed, 7 Oct 2020 23:50:34 +0200 Subject: [PATCH 2/3] Add spin cursor to build tool print, and add formatting to project tree words column --- nw/gui/build.py | 2 ++ nw/gui/projtree.py | 13 ++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/nw/gui/build.py b/nw/gui/build.py index aea1f237..ad9af97b 100644 --- a/nw/gui/build.py +++ b/nw/gui/build.py @@ -899,8 +899,10 @@ class GuiBuildNovel(QDialog): def _doPrintPreview(self, thePrinter): """Connect the print preview painter to the document viewer. """ + qApp.setOverrideCursor(QCursor(Qt.WaitCursor)) thePrinter.setOrientation(QPrinter.Portrait) self.docView.qDocument.print(thePrinter) + qApp.restoreOverrideCursor() return def _selectFont(self): diff --git a/nw/gui/projtree.py b/nw/gui/projtree.py index dfada052..858948dc 100644 --- a/nw/gui/projtree.py +++ b/nw/gui/projtree.py @@ -401,7 +401,7 @@ class GuiProjectTree(QTreeWidget): if nwItemS is None: return False - wCount = int(trItemS.text(self.C_COUNT)) + wCount = int(trItemS.data(self.C_COUNT, Qt.UserRole)) if nwItemS.itemType == nwItemType.FILE: logger.debug("User requested file %s moved to trash" % tHandle) trItemP = trItemS.parent() @@ -550,12 +550,13 @@ class GuiProjectTree(QTreeWidget): """ tItem = self._getTreeItem(tHandle) if tItem is not None: - tItem.setText(self.C_COUNT, str(theCount)) + tItem.setText(self.C_COUNT, f"{theCount:n}") + tItem.setData(self.C_COUNT, Qt.UserRole, int(theCount)) pItem = tItem.parent() if pItem is not None: pCount = 0 for i in range(pItem.childCount()): - pCount += int(pItem.child(i).text(self.C_COUNT)) + pCount += int(pItem.child(i).data(self.C_COUNT, Qt.UserRole)) pHandle = pItem.data(self.C_NAME, Qt.UserRole) if not nDepth > nwConst.maxDepth + 1 and pHandle != "": @@ -575,7 +576,7 @@ class GuiProjectTree(QTreeWidget): tItem = self.topLevelItem(n) if tItem == self.orphRoot: continue - nWords += int(tItem.text(self.C_COUNT)) + nWords += int(tItem.data(self.C_COUNT, Qt.UserRole)) self.theProject.setProjectWordCount(nWords) sWords = self.theProject.getSessionWordCount() @@ -715,7 +716,7 @@ class GuiProjectTree(QTreeWidget): self.makeAlert("The item cannot be moved to that location.", nwAlert.ERROR) return - wCount = int(sItem.text(self.C_COUNT)) + wCount = int(sItem.data(self.C_COUNT, Qt.UserRole)) isSame = snItem.itemClass == dnItem.itemClass isNone = snItem.itemClass == nwItemClass.NO_CLASS isNote = snItem.itemLayout == nwItemLayout.NOTE @@ -809,6 +810,7 @@ class GuiProjectTree(QTreeWidget): newItem.setTextAlignment(self.C_FLAGS, Qt.AlignLeft | Qt.AlignVCenter) newItem.setData(self.C_NAME, Qt.UserRole, tHandle) + newItem.setData(self.C_COUNT, Qt.UserRole, 0) self.theMap[tHandle] = newItem if pHandle is None: @@ -881,6 +883,7 @@ class GuiProjectTree(QTreeWidget): self.orphRoot = newItem newItem.setExpanded(True) newItem.setData(self.C_NAME, Qt.UserRole, "") + newItem.setData(self.C_COUNT, Qt.UserRole, 0) newItem.setIcon(self.C_NAME, self.theTheme.getIcon("proj_orphan")) return From b40e4635d9cde3096c864b63eb6c3526f46cfecc Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Thu, 8 Oct 2020 00:06:17 +0200 Subject: [PATCH 3/3] Further number formatting improvements --- nw/gui/doceditor.py | 4 ++-- nw/gui/docviewer.py | 6 ------ nw/gui/itemdetails.py | 12 ++++++------ nw/gui/outline.py | 6 +++--- nw/gui/projsettings.py | 6 +++--- nw/gui/writingstats.py | 9 +++++---- 6 files changed, 19 insertions(+), 24 deletions(-) diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index f805e5ae..ba0b1945 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -2273,10 +2273,10 @@ class GuiDocEditFooter(QWidget): wCount = self.theItem.wordCount wDiff = wCount - self.theItem.initCount - self.wordsText.setText("Words: {:n} ({:+n})".format(wCount, wDiff)) + self.wordsText.setText(f"Words: {wCount:n} ({wDiff:+n})") byteSize = self.docEditor.qDocument.characterCount() - self.wordsText.setToolTip("Document size is {:n} bytes".format(byteSize)) + self.wordsText.setToolTip(f"Document size is {byteSize:n} bytes") return diff --git a/nw/gui/docviewer.py b/nw/gui/docviewer.py index 49f9c9da..b7404e9c 100644 --- a/nw/gui/docviewer.py +++ b/nw/gui/docviewer.py @@ -502,12 +502,6 @@ class GuiDocViewer(QTextBrowser): "mark {{" " color: rgb({eColR},{eColG},{eColB});" "}}\n" - "table {{" - " margin: 10px 0px;" - "}}\n" - "td {{" - " padding: 0px 4px;" - "}}\n" ".tags {{" " color: rgb({kColR},{kColG},{kColB});" " font-wright: bold;" diff --git a/nw/gui/itemdetails.py b/nw/gui/itemdetails.py index f64d570b..6d5cbcb5 100644 --- a/nw/gui/itemdetails.py +++ b/nw/gui/itemdetails.py @@ -195,9 +195,9 @@ class GuiItemDetails(QWidget): we're already showing. """ if tHandle == self.theHandle: - self.cCountData.setText("{:n}".format(cC)) - self.wCountData.setText("{:n}".format(wC)) - self.pCountData.setText("{:n}".format(pC)) + self.cCountData.setText(f"{cC:n}") + self.wCountData.setText(f"{wC:n}") + self.pCountData.setText(f"{pC:n}") return def updateViewBox(self, tHandle): @@ -252,9 +252,9 @@ class GuiItemDetails(QWidget): self.layoutData.setText(nwLabels.LAYOUT_NAME[nwItem.itemLayout]) if nwItem.itemType == nwItemType.FILE: - self.cCountData.setText("{:n}".format(nwItem.charCount)) - self.wCountData.setText("{:n}".format(nwItem.wordCount)) - self.pCountData.setText("{:n}".format(nwItem.paraCount)) + self.cCountData.setText(f"{nwItem.charCount:n}") + self.wCountData.setText(f"{nwItem.wordCount:n}") + self.pCountData.setText(f"{nwItem.paraCount:n}") else: self.cCountData.setText("–") self.wCountData.setText("–") diff --git a/nw/gui/outline.py b/nw/gui/outline.py index fcee1d8c..6d524992 100644 --- a/nw/gui/outline.py +++ b/nw/gui/outline.py @@ -431,9 +431,9 @@ class GuiOutline(QTreeWidget): newItem.setText(self.colIndex[nwOutline.LINE], sTitle[1:].lstrip("0")) newItem.setData(self.colIndex[nwOutline.LINE], Qt.UserRole, sTitle) newItem.setText(self.colIndex[nwOutline.SYNOP], novIdx["synopsis"]) - newItem.setText(self.colIndex[nwOutline.CCOUNT], str(novIdx["cCount"])) - newItem.setText(self.colIndex[nwOutline.WCOUNT], str(novIdx["wCount"])) - newItem.setText(self.colIndex[nwOutline.PCOUNT], str(novIdx["pCount"])) + newItem.setText(self.colIndex[nwOutline.CCOUNT], "{:n}".format(novIdx["cCount"])) + newItem.setText(self.colIndex[nwOutline.WCOUNT], "{:n}".format(novIdx["wCount"])) + newItem.setText(self.colIndex[nwOutline.PCOUNT], "{:n}".format(novIdx["pCount"])) newItem.setTextAlignment(self.colIndex[nwOutline.CCOUNT], Qt.AlignRight) newItem.setTextAlignment(self.colIndex[nwOutline.WCOUNT], Qt.AlignRight) newItem.setTextAlignment(self.colIndex[nwOutline.PCOUNT], Qt.AlignRight) diff --git a/nw/gui/projsettings.py b/nw/gui/projsettings.py index 998ec83c..30d9ad54 100644 --- a/nw/gui/projsettings.py +++ b/nw/gui/projsettings.py @@ -282,15 +282,15 @@ class GuiProjectEditMeta(QWidget): self.nRootLabel = QLabel("Root folders:") self.nRootLabel.setIndent(xInd) - self.nRootValue = QLabel("{:n}".format(nR)) + self.nRootValue = QLabel(f"{nR:n}") self.nDirLabel = QLabel("Folders:") self.nDirLabel.setIndent(xInd) - self.nDirValue = QLabel("{:n}".format(nD)) + self.nDirValue = QLabel(f"{nD:n}") self.nFileLabel = QLabel("Documents:") self.nFileLabel.setIndent(xInd) - self.nFileValue = QLabel("{:n}".format(nF)) + self.nFileValue = QLabel(f"{nF:n}") self.wordsLabel = QLabel("Word count:") self.wordsLabel.setIndent(xInd) diff --git a/nw/gui/writingstats.py b/nw/gui/writingstats.py index 1d634ec6..ccf1ce18 100644 --- a/nw/gui/writingstats.py +++ b/nw/gui/writingstats.py @@ -454,10 +454,11 @@ class GuiWritingStats(QDialog): ) return False + ttWords = ttNovel + ttNotes self.labelTotal.setText(self._formatTime(ttTime)) - self.novelWords.setText("{:n}".format(ttNovel)) - self.notesWords.setText("{:n}".format(ttNotes)) - self.totalWords.setText("{:n}".format(ttNovel + ttNotes)) + self.novelWords.setText(f"{ttNovel:n}") + self.notesWords.setText(f"{ttNotes:n}") + self.totalWords.setText(f"{ttWords:n}") return True @@ -544,7 +545,7 @@ class GuiWritingStats(QDialog): newItem = QTreeWidgetItem() newItem.setText(self.C_TIME, sStart) newItem.setText(self.C_LENGTH, self._formatTime(sDiff)) - newItem.setText(self.C_COUNT, "{:n}".format(nWords)) + newItem.setText(self.C_COUNT, f"{nWords:n}") if nWords > 0 and listMax > 0: theBar = self.barImage.scaled(