@@ -99,9 +99,11 @@ def __init__(self, theParent):
9999 self .lastEdited = None # The handle of the last file to be edited
100100 self .lastViewed = None # The handle of the last file to be viewed
101101 self .lastWCount = 0 # The project word count from last session
102+ self .lastNovelWC = 0 # The novel files word count from last session
103+ self .lastNotesWC = 0 # The note files word count from last session
102104 self .currWCount = 0 # The project word count in current session
103- self .novelWCount = 0 # Total number of words in novel files
104- self .notesWCount = 0 # Total number of words in note files
105+ self .currNovelWC = 0 # The novel files word count in cutrent session
106+ self .currNotesWC = 0 # The note files word count in cutrent session
105107 self .doBackup = True # Run project backup on exit
106108
107109 # Internal Mapping
@@ -226,9 +228,11 @@ def clearProject(self):
226228 self .lastEdited = None
227229 self .lastViewed = None
228230 self .lastWCount = 0
231+ self .lastNovelWC = 0
232+ self .lastNotesWC = 0
229233 self .currWCount = 0
230- self .novelWCount = 0
231- self .notesWCount = 0
234+ self .currNovelWC = 0
235+ self .currNotesWC = 0
232236
233237 return
234238
@@ -566,9 +570,9 @@ def openProject(self, fileName, overrideLock=False):
566570 elif xItem .tag == "lastWordCount" :
567571 self .lastWCount = checkInt (xItem .text , 0 , False )
568572 elif xItem .tag == "novelWordCount" :
569- self .novelWCount = checkInt (xItem .text , 0 , False )
573+ self .lastNovelWC = checkInt (xItem .text , 0 , False )
570574 elif xItem .tag == "notesWordCount" :
571- self .notesWCount = checkInt (xItem .text , 0 , False )
575+ self .lastNotesWC = checkInt (xItem .text , 0 , False )
572576 elif xItem .tag == "status" :
573577 self .statusItems .unpackXML (xItem )
574578 elif xItem .tag == "importance" :
@@ -610,8 +614,8 @@ def openProject(self, fileName, overrideLock=False):
610614
611615 self ._scanProjectFolder ()
612616 self ._loadProjectLocalisation ()
617+ self .updateWordCounts ()
613618
614- self .currWCount = self .lastWCount
615619 self .projOpened = time ()
616620 self .projAltered = False
617621
@@ -652,11 +656,8 @@ def saveProject(self, autoSave=False):
652656 "timeStamp" : formatTimeStamp (saveTime ),
653657 })
654658
659+ self .updateWordCounts ()
655660 editTime = int (self .editTime + saveTime - self .projOpened )
656- wcNovel , wcNotes = self .projTree .sumWords ()
657- self .novelWCount = wcNovel
658- self .notesWCount = wcNotes
659- self .setProjectWordCount (wcNovel + wcNotes )
660661
661662 # Save Project Meta
662663 xProject = etree .SubElement (nwXML , "project" )
@@ -677,8 +678,8 @@ def saveProject(self, autoSave=False):
677678 self ._packProjectValue (xSettings , "lastEdited" , self .lastEdited )
678679 self ._packProjectValue (xSettings , "lastViewed" , self .lastViewed )
679680 self ._packProjectValue (xSettings , "lastWordCount" , self .currWCount )
680- self ._packProjectValue (xSettings , "novelWordCount" , wcNovel )
681- self ._packProjectValue (xSettings , "notesWordCount" , wcNotes )
681+ self ._packProjectValue (xSettings , "novelWordCount" , self . currNovelWC )
682+ self ._packProjectValue (xSettings , "notesWordCount" , self . currNotesWC )
682683 self ._packProjectKeyValue (xSettings , "autoReplace" , self .autoReplace )
683684
684685 xTitleFmt = etree .SubElement (xSettings , "titleFormat" )
@@ -1067,14 +1068,6 @@ def setLastViewed(self, tHandle):
10671068 self .setProjectChanged (True )
10681069 return True
10691070
1070- def setProjectWordCount (self , theCount ):
1071- """Set the current project word count.
1072- """
1073- if self .currWCount != theCount :
1074- self .currWCount = theCount
1075- self .setProjectChanged (True )
1076- return True
1077-
10781071 def setStatusColours (self , newCols ):
10791072 """Update the list of novel file status flags. Also iterate
10801073 through the project and replace keys that have been renamed.
@@ -1145,11 +1138,6 @@ def getAuthors(self):
11451138
11461139 return authString
11471140
1148- def getSessionWordCount (self ):
1149- """Returns the number of words added or removed this session.
1150- """
1151- return self .currWCount - self .lastWCount
1152-
11531141 def getCurrentEditTime (self ):
11541142 """Get the total project edit time, including the time spent in
11551143 the current session.
@@ -1202,6 +1190,18 @@ def getProjectItems(self):
12021190 # Class Methods
12031191 ##
12041192
1193+ def updateWordCounts (self ):
1194+ """Update the total word count values.
1195+ """
1196+ wcNovel , wcNotes = self .projTree .sumWords ()
1197+ wcTotal = wcNovel + wcNotes
1198+ if wcTotal != self .currWCount :
1199+ self .currNovelWC = wcNovel
1200+ self .currNotesWC = wcNotes
1201+ self .currWCount = wcTotal
1202+ self .setProjectChanged (True )
1203+ return
1204+
12051205 def countStatus (self ):
12061206 """Count how many times the various status flags are used in the
12071207 project tree. The counts themselves are kept in the NWStatus
@@ -1460,7 +1460,7 @@ def _appendSessionStats(self, idleTime):
14601460 isFile = os .path .isfile (sessionFile )
14611461
14621462 nowTime = time ()
1463- sessDiff = self .getSessionWordCount ()
1463+ sessDiff = self .currWCount - self . lastWCount
14641464 sessTime = nowTime - self .projOpened
14651465
14661466 logger .info ("The session lasted %d sec and added %d words" , int (sessTime ), sessDiff )
@@ -1481,8 +1481,8 @@ def _appendSessionStats(self, idleTime):
14811481 outFile .write ("%-19s %-19s %8d %8d %8d\n " % (
14821482 formatTimeStamp (self .projOpened ),
14831483 formatTimeStamp (nowTime ),
1484- self .novelWCount ,
1485- self .notesWCount ,
1484+ self .currNovelWC ,
1485+ self .currNotesWC ,
14861486 int (idleTime ),
14871487 ))
14881488
0 commit comments