CHange how current word counts are handled
This commit is contained in:
+30
-20
@@ -94,9 +94,6 @@ class NWProject:
|
||||
self.spellCheck = False # Controls the spellcheck-as-you-type feature
|
||||
self.statusItems = None # Novel file progress status values
|
||||
self.importItems = None # Note file importance values
|
||||
self.currWCount = 0 # The project word count in current session
|
||||
self.currNovelWC = 0 # The novel files word count in cutrent session
|
||||
self.currNotesWC = 0 # The note files word count in cutrent session
|
||||
|
||||
# Internal Mapping
|
||||
self.tr = partial(QCoreApplication.translate, "NWProject")
|
||||
@@ -282,9 +279,6 @@ class NWProject:
|
||||
self.importItems.write(None, self.tr("Minor"), (200, 50, 0))
|
||||
self.importItems.write(None, self.tr("Major"), (200, 150, 0))
|
||||
self.importItems.write(None, self.tr("Main"), (50, 200, 0))
|
||||
self.currWCount = 0
|
||||
self.currNovelWC = 0
|
||||
self.currNotesWC = 0
|
||||
|
||||
return
|
||||
|
||||
@@ -330,7 +324,7 @@ class NWProject:
|
||||
titlePage = "#! %s\n\n" % (self._data.title if self._data.title else self._data.name)
|
||||
if self._data.authors:
|
||||
titlePage = "%s>> %s %s <<\n" % (
|
||||
titlePage, self.tr("By"), self._data.getAuthors(self.tr("and"))
|
||||
titlePage, self.tr("By"), self.getFormattedAuthors()
|
||||
)
|
||||
|
||||
aDoc = NWDoc(self, hTitlePage)
|
||||
@@ -658,9 +652,9 @@ class NWProject:
|
||||
self._packProjectValue(xSettings, "lastViewed", self._data.getLastHandle("viewer"))
|
||||
self._packProjectValue(xSettings, "lastNovel", self._data.getLastHandle("noveltree"))
|
||||
self._packProjectValue(xSettings, "lastOutline", self._data.getLastHandle("outline"))
|
||||
self._packProjectValue(xSettings, "lastWordCount", self.currWCount)
|
||||
self._packProjectValue(xSettings, "novelWordCount", self.currNovelWC)
|
||||
self._packProjectValue(xSettings, "notesWordCount", self.currNotesWC)
|
||||
self._packProjectValue(xSettings, "lastWordCount", self._data.getCurrCount("total"))
|
||||
self._packProjectValue(xSettings, "novelWordCount", self._data.getCurrCount("novel"))
|
||||
self._packProjectValue(xSettings, "notesWordCount", self._data.getCurrCount("notes"))
|
||||
self._packProjectKeyValue(xSettings, "autoReplace", self.autoReplace)
|
||||
|
||||
xTitleFmt = etree.SubElement(xSettings, "titleFormat")
|
||||
@@ -713,7 +707,9 @@ class NWProject:
|
||||
self._optState.saveSettings()
|
||||
|
||||
# Update recent projects
|
||||
self.mainConf.updateRecentCache(self.projPath, self._data.name, self.currWCount, saveTime)
|
||||
self.mainConf.updateRecentCache(
|
||||
self.projPath, self._data.name, self._data.getCurrCount("total"), saveTime
|
||||
)
|
||||
self.mainConf.saveRecentCache()
|
||||
|
||||
self._writeLockFile()
|
||||
@@ -1018,6 +1014,22 @@ class NWProject:
|
||||
# Getters
|
||||
##
|
||||
|
||||
def getFormattedAuthors(self):
|
||||
"""Return a formatted string of authors.
|
||||
"""
|
||||
authors = self._data.authors
|
||||
nAuth = len(authors)
|
||||
|
||||
result = ""
|
||||
if nAuth == 1:
|
||||
result = authors[0]
|
||||
elif nAuth > 1:
|
||||
result = "%s %s %s" % (
|
||||
", ".join(authors[0:-1]), self.tr("and"), authors[-1]
|
||||
)
|
||||
|
||||
return result
|
||||
|
||||
def getCurrentEditTime(self):
|
||||
"""Get the total project edit time, including the time spent in
|
||||
the current session.
|
||||
@@ -1074,12 +1086,9 @@ class NWProject:
|
||||
"""Update the total word count values.
|
||||
"""
|
||||
wcNovel, wcNotes = self._projTree.sumWords()
|
||||
wcTotal = wcNovel + wcNotes
|
||||
if wcTotal != self.currWCount:
|
||||
self.currNovelWC = wcNovel
|
||||
self.currNotesWC = wcNotes
|
||||
self.currWCount = wcTotal
|
||||
self.setProjectChanged(True)
|
||||
self._data.setCurrCount(wcNovel, "novel")
|
||||
self._data.setCurrCount(wcNotes, "notes")
|
||||
self._data.setCurrCount(wcNovel + wcNotes, "total")
|
||||
return
|
||||
|
||||
def countStatus(self):
|
||||
@@ -1361,7 +1370,8 @@ class NWProject:
|
||||
|
||||
nowTime = time()
|
||||
lastCount = self._data.getLastCount("total")
|
||||
sessDiff = self.currWCount - lastCount
|
||||
currCount = self._data.getCurrCount("total")
|
||||
sessDiff = currCount - lastCount
|
||||
sessTime = nowTime - self._projOpened
|
||||
|
||||
logger.info("The session lasted %d sec and added %d words", int(sessTime), sessDiff)
|
||||
@@ -1382,8 +1392,8 @@ class NWProject:
|
||||
outFile.write("%-19s %-19s %8d %8d %8d\n" % (
|
||||
formatTimeStamp(self._projOpened),
|
||||
formatTimeStamp(nowTime),
|
||||
self.currNovelWC,
|
||||
self.currNotesWC,
|
||||
self._data.getCurrCount("novel"),
|
||||
self._data.getCurrCount("notes"),
|
||||
int(idleTime),
|
||||
))
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@ class NWProjectData:
|
||||
self._spellLang = None
|
||||
self._lastHandle = {}
|
||||
self._lastCount = {}
|
||||
self._currCount = {}
|
||||
|
||||
# Internal
|
||||
self._changed = False
|
||||
@@ -137,20 +138,8 @@ class NWProjectData:
|
||||
def getLastCount(self, type):
|
||||
return self._lastCount.get(type, 0)
|
||||
|
||||
def getAuthors(self, trAnd="and"):
|
||||
"""Return a formatted string of authors.
|
||||
"""
|
||||
nAuth = len(self._authors)
|
||||
authors = ""
|
||||
|
||||
if nAuth == 1:
|
||||
authors = self._authors[0]
|
||||
elif nAuth > 1:
|
||||
authors = "%s %s %s" % (
|
||||
", ".join(self._authors[0:-1]), trAnd, self._authors[-1]
|
||||
)
|
||||
|
||||
return authors
|
||||
def getCurrCount(self, type):
|
||||
return self._currCount.get(type, 0)
|
||||
|
||||
##
|
||||
# Setters
|
||||
@@ -173,7 +162,7 @@ class NWProjectData:
|
||||
for author in value.splitlines():
|
||||
author = simplified(author)
|
||||
if author:
|
||||
self.addAuthor(author)
|
||||
self._authors.append(author)
|
||||
self._changed = True
|
||||
elif isinstance(value, list):
|
||||
self._authors = value
|
||||
@@ -224,4 +213,10 @@ class NWProjectData:
|
||||
self._changed = True
|
||||
return
|
||||
|
||||
def setCurrCount(self, value, type):
|
||||
if value != self._currCount.get(type, 0):
|
||||
self._currCount[type] = checkInt(value, 0)
|
||||
self._changed = True
|
||||
return
|
||||
|
||||
# END Class NWProjectData
|
||||
|
||||
@@ -262,7 +262,7 @@ class ToOdt(Tokenizer):
|
||||
|
||||
if self._headerText == "":
|
||||
theTitle = self.theProject.data.title
|
||||
theAuth = self.theProject.data.getAuthors(self.tr("and"))
|
||||
theAuth = self.theProject.getFormattedAuthors()
|
||||
self._headerText = f"{theTitle} / {theAuth} /"
|
||||
|
||||
# Create Roots
|
||||
|
||||
@@ -176,7 +176,7 @@ class GuiProjectDetailsMain(QWidget):
|
||||
self.projName.setWordWrap(True)
|
||||
|
||||
self.bookAuthors = QLabel(self.tr("By {0}").format(
|
||||
self.theProject.data.getAuthors(self.tr("and"))
|
||||
self.theProject.getFormattedAuthors()
|
||||
))
|
||||
authFont = self.bookAuthors.font()
|
||||
authFont.setPointSizeF(1.2*fPt)
|
||||
|
||||
@@ -1557,10 +1557,10 @@ class GuiMain(QMainWindow):
|
||||
|
||||
self.theProject.updateWordCounts()
|
||||
if self.mainConf.incNotesWCount:
|
||||
currWords = self.theProject.currWCount
|
||||
currWords = self.theProject.data.getCurrCount("total")
|
||||
diffWords = currWords - self.theProject.data.getLastCount("total")
|
||||
else:
|
||||
currWords = self.theProject.currNovelWC
|
||||
currWords = self.theProject.data.getCurrCount("novel")
|
||||
diffWords = currWords - self.theProject.data.getLastCount("novel")
|
||||
|
||||
self.mainStatus.setProjectStats(currWords, diffWords)
|
||||
|
||||
@@ -914,16 +914,16 @@ def testCoreProject_Methods(monkeypatch, mockGUI, tmpDir, fncDir, mockRnd):
|
||||
assert theProject.data.authors == ["Jane Doe", "John Doh"]
|
||||
|
||||
theProject.data.setAuthors("")
|
||||
assert theProject.data.getAuthors() == ""
|
||||
assert theProject.getFormattedAuthors() == ""
|
||||
|
||||
theProject.data.setAuthors("Jane Doe")
|
||||
assert theProject.data.getAuthors() == "Jane Doe"
|
||||
assert theProject.getFormattedAuthors() == "Jane Doe"
|
||||
|
||||
theProject.data.setAuthors("Jane Doe\nJohn Doh")
|
||||
assert theProject.data.getAuthors() == "Jane Doe and John Doh"
|
||||
assert theProject.getFormattedAuthors() == "Jane Doe and John Doh"
|
||||
|
||||
theProject.data.setAuthors("Jane Doe\nJohn Doh\nBod Owens")
|
||||
assert theProject.data.getAuthors() == "Jane Doe, John Doh and Bod Owens"
|
||||
assert theProject.getFormattedAuthors() == "Jane Doe, John Doh and Bod Owens"
|
||||
|
||||
# Edit Time
|
||||
theProject.data.setEditTime(1234)
|
||||
@@ -1004,7 +1004,7 @@ def testCoreProject_Methods(monkeypatch, mockGUI, tmpDir, fncDir, mockRnd):
|
||||
assert theProject.tree.handles() == oldOrder
|
||||
|
||||
# Session stats
|
||||
theProject.currWCount = 200
|
||||
theProject.data.setCurrCount(200, "total")
|
||||
theProject.data.setLastCount(100, "total")
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr("os.path.isdir", lambda *a, **k: False)
|
||||
@@ -1020,8 +1020,8 @@ def testCoreProject_Methods(monkeypatch, mockGUI, tmpDir, fncDir, mockRnd):
|
||||
statsFile = os.path.join(theProject.projMeta, nwFiles.SESS_STATS)
|
||||
|
||||
theProject._projOpened = 1600002000
|
||||
theProject.currNovelWC = 200
|
||||
theProject.currNotesWC = 100
|
||||
theProject._data.setCurrCount(200, "novel")
|
||||
theProject._data.setCurrCount(100, "notes")
|
||||
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr("novelwriter.core.project.time", lambda: 1600005600)
|
||||
|
||||
Reference in New Issue
Block a user