Proagate word counts and save them for files.
This commit is contained in:
+16
-2
@@ -26,12 +26,16 @@ class WordCounter(QThread):
|
||||
self.theParent = theParent
|
||||
self.charCount = 0
|
||||
self.wordCount = 0
|
||||
self.paraCount = 0
|
||||
return
|
||||
|
||||
def run(self):
|
||||
|
||||
self.charCount = 0
|
||||
self.wordCount = 0
|
||||
self.paraCount = 0
|
||||
|
||||
prevEmpty = True
|
||||
|
||||
for n in range(self.theParent.theDoc.blockCount()):
|
||||
|
||||
@@ -39,30 +43,40 @@ class WordCounter(QThread):
|
||||
if not theBlock.isValid():
|
||||
continue
|
||||
|
||||
theText = theBlock.text()
|
||||
theLen = len(theText)
|
||||
countPara = True
|
||||
theText = theBlock.text()
|
||||
theLen = len(theText)
|
||||
|
||||
if theLen == 0:
|
||||
prevEmpty = True
|
||||
continue
|
||||
if theText[0] == "@" or theText[0] == "%":
|
||||
prevEmpty = True
|
||||
continue
|
||||
|
||||
if theText[0:5] == "#### ":
|
||||
self.wordCount -= 1
|
||||
self.charCount -= 5
|
||||
countPara = False
|
||||
elif theText[0:4] == "### ":
|
||||
self.wordCount -= 1
|
||||
self.charCount -= 4
|
||||
countPara = False
|
||||
elif theText[0:3] == "## ":
|
||||
self.wordCount -= 1
|
||||
self.charCount -= 3
|
||||
countPara = False
|
||||
elif theText[0:2] == "# ":
|
||||
self.wordCount -= 1
|
||||
self.charCount -= 2
|
||||
countPara = False
|
||||
|
||||
theBuff = theText.replace("–"," ").replace("—"," ")
|
||||
self.wordCount += len(theBuff.split())
|
||||
self.charCount += theLen
|
||||
if countPara and prevEmpty:
|
||||
self.paraCount += 1
|
||||
prevEmpty = countPara == False
|
||||
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user