From b404a10285b61d0a643bb5c476058efe3e1202c0 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Tue, 18 Aug 2020 20:37:46 +0200 Subject: [PATCH] Fix the error message about the lookup for a None handle - issue #418 --- nw/gui/doceditor.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index 4cecfc7a..d10a4d6e 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -1936,6 +1936,7 @@ class GuiDocEditFooter(QWidget): self.theTheme = docEditor.theTheme self.optState = docEditor.theProject.optState self.theHandle = None + self.theItem = None # Make a QPalette that matches the Syntax Theme self.thePalette = QPalette() @@ -2009,27 +2010,33 @@ class GuiDocEditFooter(QWidget): """Set the handle that will populate the footer's data. """ self.theHandle = tHandle + if self.theHandle is None: + logger.verbose("No handle set, so clearing the editor footer") + self.theItem = None + else: + self.theItem = self.theProject.projTree[self.theHandle] + self.updateInfo() self.updateCounts() + return def updateInfo(self): """Update the content of text labels. """ - nwItem = self.theProject.projTree[self.theHandle] - if nwItem is None: - sIcon = QPixmap() - sText = "" + if self.theItem is None: + sIcon = QPixmap() + sText = "" else: - iStatus = nwItem.itemStatus - if nwItem.itemClass == nwItemClass.NOVEL: + iStatus = self.theItem.itemStatus + if self.theItem.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 + sText = self.theItem.itemStatus self.statusIcon.setPixmap(sIcon) self.statusText.setText(sText) @@ -2039,13 +2046,12 @@ class GuiDocEditFooter(QWidget): def updateCounts(self): """Update the word counts. """ - nwItem = self.theProject.projTree[self.theHandle] - if nwItem is None: + if self.theItem is None: wCount = 0 wDiff = 0 else: - wCount = nwItem.wordCount - wDiff = wCount - nwItem.initCount + wCount = self.theItem.wordCount + wDiff = wCount - self.theItem.initCount self.wordsText.setText("Words: {:n} ({:+n})".format(wCount, wDiff))