Use actual novel word count in project details, and update index test

This commit is contained in:
Veronica K. B. Olsen
2021-01-11 21:02:45 +01:00
parent b5e11f2303
commit 981e26e1b6
3 changed files with 114 additions and 34 deletions
+34 -31
View File
@@ -292,10 +292,12 @@ class NWIndex():
"updated" : round(time()),
}
if itemLayout == nwItemLayout.NOTE:
self._novelIndex.pop(tHandle, None)
self._noteIndex[tHandle] = {}
isNovel = False
else:
self._novelIndex[tHandle] = {}
self._noteIndex.pop(tHandle, None)
isNovel = True
# Also clear references to file in tag index
@@ -580,34 +582,26 @@ class NWIndex():
they appear in the tree view and in the respective document
files, but skipping all note files.
"""
for tItem in self.theProject.projTree:
if tItem is None:
continue
if not tItem.isExported and skipExcluded:
continue
tHandle = tItem.itemHandle
if tHandle not in self._novelIndex:
continue
for tHandle in self._listNovelHandles(skipExcluded):
for sTitle in sorted(self._novelIndex[tHandle]):
tKey = "%s:%s" % (tHandle, sTitle)
yield tKey, tHandle, sTitle, self._novelIndex[tHandle][sTitle]
def getNovelCounts(self, skipExcluded=True):
def getNovelWordCount(self, skipExcluded=True):
"""Count the number of words in the novel project.
"""
wCount = 0
for tHandle in self._listNovelHandles(skipExcluded):
for sTitle in self._novelIndex[tHandle]:
wCount += self._novelIndex[tHandle][sTitle]["wCount"]
return wCount
def getNovelTitleCounts(self, skipExcluded=True):
"""Count the number of titles in the novel project.
"""
hCount = [0, 0, 0, 0, 0]
for tItem in self.theProject.projTree:
if tItem is None:
continue
if not tItem.isExported and skipExcluded:
continue
tHandle = tItem.itemHandle
if tHandle not in self._novelIndex:
continue
for tHandle in self._listNovelHandles(skipExcluded):
for sTitle in self._novelIndex[tHandle]:
theData = self._novelIndex[tHandle][sTitle]
iLevel = self.H_LEVEL.get(theData["level"], 0)
@@ -621,16 +615,7 @@ class NWIndex():
tOrder = []
tData = {}
pKey = None
for tItem in self.theProject.projTree:
if tItem is None:
continue
if not tItem.isExported and skipExcluded:
continue
tHandle = tItem.itemHandle
if tHandle not in self._novelIndex:
continue
for tHandle in self._listNovelHandles(skipExcluded):
for sTitle in sorted(self._novelIndex[tHandle]):
tKey = "%s:%s" % (tHandle, sTitle)
theData = self._novelIndex[tHandle][sTitle]
@@ -740,4 +725,22 @@ class NWIndex():
return theRef[1], theRef[0], theRef[3]
return None, 0, "T000000"
##
# Internal Functions
##
def _listNovelHandles(self, skipExcluded):
"""Return a list of all handles that exist in the novel index.
"""
theHandles = []
for tItem in self.theProject.projTree:
if tItem is None:
continue
if not tItem.isExported and skipExcluded:
continue
if tItem.itemHandle in self._novelIndex:
theHandles.append(tItem.itemHandle)
return theHandles
# END Class NWIndex
+3 -2
View File
@@ -168,10 +168,11 @@ class GuiProjectDetailsMain(QWidget):
# Stats
# =====
hCounts = self.theIndex.getNovelCounts()
hCounts = self.theIndex.getNovelTitleCounts()
nwCount = self.theIndex.getNovelWordCount()
self.wordCountLbl = QLabel("<b>Words:</b>")
self.wordCountVal = QLabel(f"{self.theProject.currWCount:n}")
self.wordCountVal = QLabel(f"{nwCount:n}")
self.chapCountLbl = QLabel("<b>Chapters:</b>")
self.chapCountVal = QLabel(f"{hCounts[2]:n}")