Added synopsis keyword and a meta file and dictiopnaries to hold the data
This commit is contained in:
@@ -26,6 +26,7 @@ class nwFiles():
|
||||
PROJ_DICT = "wordlist.txt"
|
||||
SESS_INFO = "sessionInfo.log"
|
||||
INDEX_FILE = "tagsIndex.json"
|
||||
META_FILE = "projectMeta.json"
|
||||
EXPORT_OPT = "exportOptions.json"
|
||||
TLINE_OPT = "timelineOptions.json"
|
||||
SLOG_OPT = "sessionLogOptions.json"
|
||||
|
||||
@@ -140,6 +140,13 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
||||
0 : self.hStyles["hidden"],
|
||||
}
|
||||
))
|
||||
self.hRules.append((
|
||||
r"^(%)(synopsis:\s+)(.*)$", {
|
||||
1 : self.hStyles["hidden"],
|
||||
2 : self.hStyles["keyword"],
|
||||
3 : self.hStyles["hidden"],
|
||||
}
|
||||
))
|
||||
|
||||
# Trailing Spaces, 2+
|
||||
self.hRules.append((
|
||||
|
||||
+5
-5
@@ -523,17 +523,17 @@ class GuiMain(QMainWindow):
|
||||
theDoc = NWDoc(self.theProject, self)
|
||||
theText = theDoc.openDocument(tHandle, False)
|
||||
|
||||
# Run Word Count
|
||||
cC, wC, pC = countWords(theText)
|
||||
# Build tag index
|
||||
self.theIndex.scanText(tHandle, theText)
|
||||
|
||||
# Get Word Counts
|
||||
cC, wC, pC = self.theIndex.getCounts(tHandle)
|
||||
tItem.setCharCount(cC)
|
||||
tItem.setWordCount(wC)
|
||||
tItem.setParaCount(pC)
|
||||
self.treeView.propagateCount(tHandle, wC)
|
||||
self.treeView.projectWordCount()
|
||||
|
||||
# Build tag index
|
||||
self.theIndex.scanText(tHandle, theText)
|
||||
|
||||
nDone += 1
|
||||
if dlgProg.wasCanceled():
|
||||
break
|
||||
|
||||
+74
-12
@@ -19,6 +19,7 @@ from os import path
|
||||
from nw.constants import (
|
||||
nwFiles, nwKeyWords, nwItemType, nwItemClass, nwAlert
|
||||
)
|
||||
from nw.tools import countWords
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -60,6 +61,10 @@ class NWIndex():
|
||||
self.novelIndex = {}
|
||||
self.noteIndex = {}
|
||||
|
||||
# Meta Data
|
||||
self.textCounts = {}
|
||||
self.fileSynopsis = {}
|
||||
|
||||
# Lists
|
||||
self.novelList = []
|
||||
|
||||
@@ -70,10 +75,12 @@ class NWIndex():
|
||||
##
|
||||
|
||||
def clearIndex(self):
|
||||
self.tagIndex = {}
|
||||
self.refIndex = {}
|
||||
self.novelIndex = {}
|
||||
self.noteIndex = {}
|
||||
self.tagIndex = {}
|
||||
self.refIndex = {}
|
||||
self.novelIndex = {}
|
||||
self.noteIndex = {}
|
||||
self.textCounts = {}
|
||||
self.fileSynopsis = {}
|
||||
return
|
||||
|
||||
def deleteHandle(self, tHandle):
|
||||
@@ -101,7 +108,10 @@ class NWIndex():
|
||||
"""
|
||||
|
||||
theData = {}
|
||||
loadsOK = False
|
||||
indexFile = path.join(self.theProject.projMeta, nwFiles.INDEX_FILE)
|
||||
metaFile = path.join(self.theProject.projMeta, nwFiles.META_FILE)
|
||||
|
||||
if path.isfile(indexFile):
|
||||
logger.debug("Loading index file")
|
||||
try:
|
||||
@@ -122,11 +132,29 @@ class NWIndex():
|
||||
if "noteIndex" in theData.keys():
|
||||
self.noteIndex = theData["noteIndex"]
|
||||
|
||||
self.checkIndex()
|
||||
loadsOK = True
|
||||
|
||||
return True
|
||||
if path.isfile(indexFile):
|
||||
logger.debug("Loading meta file")
|
||||
try:
|
||||
with open(metaFile,mode="r",encoding="utf8") as inFile:
|
||||
theJson = inFile.read()
|
||||
theData = json.loads(theJson)
|
||||
except Exception as e:
|
||||
logger.error("Failed to load meta file")
|
||||
logger.error(str(e))
|
||||
return False
|
||||
|
||||
return False
|
||||
if "textCounts" in theData.keys():
|
||||
self.textCounts = theData["textCounts"]
|
||||
if "fileSynopsis" in theData.keys():
|
||||
self.fileSynopsis = theData["fileSynopsis"]
|
||||
|
||||
loadsOK &= True
|
||||
|
||||
self.checkIndex()
|
||||
|
||||
return loadsOK
|
||||
|
||||
def saveIndex(self):
|
||||
"""Save the current index as a json file in the project meta
|
||||
@@ -134,11 +162,14 @@ class NWIndex():
|
||||
"""
|
||||
|
||||
indexFile = path.join(self.theProject.projMeta, nwFiles.INDEX_FILE)
|
||||
logger.debug("Saving index file")
|
||||
metaFile = path.join(self.theProject.projMeta, nwFiles.META_FILE)
|
||||
|
||||
logger.debug("Saving index and meta files")
|
||||
if self.mainConf.debugInfo:
|
||||
nIndent = 2
|
||||
else:
|
||||
nIndent = None
|
||||
|
||||
try:
|
||||
with open(indexFile,mode="w+",encoding="utf8") as outFile:
|
||||
outFile.write(json.dumps({
|
||||
@@ -152,6 +183,17 @@ class NWIndex():
|
||||
logger.error(str(e))
|
||||
return False
|
||||
|
||||
try:
|
||||
with open(metaFile,mode="w+",encoding="utf8") as outFile:
|
||||
outFile.write(json.dumps({
|
||||
"textCounts" : self.textCounts,
|
||||
"fileSynopsis" : self.fileSynopsis,
|
||||
}, indent=nIndent))
|
||||
except Exception as e:
|
||||
logger.error("Failed to save meta file")
|
||||
logger.error(str(e))
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def checkIndex(self):
|
||||
@@ -180,6 +222,10 @@ class NWIndex():
|
||||
if len(tEntry) != 4:
|
||||
self.indexBroken = True
|
||||
|
||||
for tHandle in self.textCounts:
|
||||
if len(self.textCounts[tHandle]) != 3:
|
||||
self.indexBroken = True
|
||||
|
||||
if self.indexBroken:
|
||||
self.clearIndex()
|
||||
self.theParent.makeAlert(
|
||||
@@ -230,17 +276,23 @@ class NWIndex():
|
||||
nLine = 0
|
||||
nTitle = 0
|
||||
for aLine in theText.splitlines():
|
||||
aLine = aLine.strip()
|
||||
aLine = aLine
|
||||
nLine += 1
|
||||
nChar = len(aLine)
|
||||
nChar = len(aLine.strip())
|
||||
if nChar == 0: continue
|
||||
if aLine[0] == "#":
|
||||
if aLine.startswith(r"#"):
|
||||
isTitle = self.indexTitle(tHandle, isNovel, aLine, nLine, itemLayout)
|
||||
if isTitle:
|
||||
nTitle = nLine
|
||||
elif aLine[0] == "@":
|
||||
elif aLine.startswith(r"@"):
|
||||
self.indexNoteRef(tHandle, aLine, nLine, nTitle)
|
||||
self.indexTag(tHandle, aLine, nLine, itemClass)
|
||||
elif aLine.startswith(r"%synopsis:"):
|
||||
self.fileSynopsis[tHandle] = aLine[10:].strip()
|
||||
|
||||
# Run word counter
|
||||
cC, wC, pC = countWords(theText)
|
||||
self.textCounts[tHandle] = [cC, wC, pC]
|
||||
|
||||
return True
|
||||
|
||||
@@ -386,6 +438,16 @@ class NWIndex():
|
||||
# Extract Data
|
||||
##
|
||||
|
||||
def getCounts(self, tHandle):
|
||||
cC = 0
|
||||
wC = 0
|
||||
pC = 0
|
||||
if tHandle in self.textCounts:
|
||||
cC = self.textCounts[tHandle][0]
|
||||
wC = self.textCounts[tHandle][1]
|
||||
pC = self.textCounts[tHandle][2]
|
||||
return cC, wC, pC
|
||||
|
||||
def buildNovelList(self):
|
||||
"""Build a list of the content of the novel.
|
||||
"""
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
@pov: Jane
|
||||
@location: Earth
|
||||
|
||||
% We can add a chapter file, but keep the scene files separate. In the chapter file we can set the meta data that applies to the whole chapter if we wish.
|
||||
%synopsis: We can add a chapter file, but keep the scene files separate. In the chapter file we can set the meta data that applies to the whole chapter if we wish to.
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<novelWriterXML appVersion="0.4.0" fileVersion="1.0" timeStamp="2019-11-07 22:03:42">
|
||||
<novelWriterXML appVersion="0.4.1" fileVersion="1.0" timeStamp="2019-11-10 17:08:04">
|
||||
<project>
|
||||
<name>Sample Project</name>
|
||||
<title>Sample Project</title>
|
||||
@@ -9,9 +9,9 @@
|
||||
</project>
|
||||
<settings>
|
||||
<spellCheck>True</spellCheck>
|
||||
<lastEdited>96b68994dfa3d</lastEdited>
|
||||
<lastEdited>6a2d6d5f4f401</lastEdited>
|
||||
<lastViewed>b3e74dbc1f584</lastViewed>
|
||||
<lastWordCount>855</lastWordCount>
|
||||
<lastWordCount>849</lastWordCount>
|
||||
<autoReplace>
|
||||
<A>B</A>
|
||||
<B>E</B>
|
||||
@@ -70,7 +70,7 @@
|
||||
<charCount>12</charCount>
|
||||
<wordCount>3</wordCount>
|
||||
<paraCount>0</paraCount>
|
||||
<cursorPos>45</cursorPos>
|
||||
<cursorPos>211</cursorPos>
|
||||
</item>
|
||||
<item handle="636b6aa9b697b" order="1" parent="e7ded148d6e4a">
|
||||
<name>Making a Scene</name>
|
||||
@@ -118,7 +118,7 @@
|
||||
<charCount>1692</charCount>
|
||||
<wordCount>313</wordCount>
|
||||
<paraCount>6</paraCount>
|
||||
<cursorPos>216</cursorPos>
|
||||
<cursorPos>144</cursorPos>
|
||||
</item>
|
||||
<item handle="88706ddc78b1b" order="5" parent="e7ded148d6e4a">
|
||||
<name>Chapter Two</name>
|
||||
@@ -239,9 +239,9 @@
|
||||
<status>New</status>
|
||||
<expanded>False</expanded>
|
||||
<layout>SCENE</layout>
|
||||
<charCount>30</charCount>
|
||||
<wordCount>6</wordCount>
|
||||
<paraCount>1</paraCount>
|
||||
<charCount>0</charCount>
|
||||
<wordCount>0</wordCount>
|
||||
<paraCount>0</paraCount>
|
||||
<cursorPos>36</cursorPos>
|
||||
</item>
|
||||
</content>
|
||||
|
||||
Reference in New Issue
Block a user