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"
|
PROJ_DICT = "wordlist.txt"
|
||||||
SESS_INFO = "sessionInfo.log"
|
SESS_INFO = "sessionInfo.log"
|
||||||
INDEX_FILE = "tagsIndex.json"
|
INDEX_FILE = "tagsIndex.json"
|
||||||
|
META_FILE = "projectMeta.json"
|
||||||
EXPORT_OPT = "exportOptions.json"
|
EXPORT_OPT = "exportOptions.json"
|
||||||
TLINE_OPT = "timelineOptions.json"
|
TLINE_OPT = "timelineOptions.json"
|
||||||
SLOG_OPT = "sessionLogOptions.json"
|
SLOG_OPT = "sessionLogOptions.json"
|
||||||
|
|||||||
@@ -140,6 +140,13 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
|||||||
0 : self.hStyles["hidden"],
|
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+
|
# Trailing Spaces, 2+
|
||||||
self.hRules.append((
|
self.hRules.append((
|
||||||
|
|||||||
+5
-5
@@ -523,17 +523,17 @@ class GuiMain(QMainWindow):
|
|||||||
theDoc = NWDoc(self.theProject, self)
|
theDoc = NWDoc(self.theProject, self)
|
||||||
theText = theDoc.openDocument(tHandle, False)
|
theText = theDoc.openDocument(tHandle, False)
|
||||||
|
|
||||||
# Run Word Count
|
# Build tag index
|
||||||
cC, wC, pC = countWords(theText)
|
self.theIndex.scanText(tHandle, theText)
|
||||||
|
|
||||||
|
# Get Word Counts
|
||||||
|
cC, wC, pC = self.theIndex.getCounts(tHandle)
|
||||||
tItem.setCharCount(cC)
|
tItem.setCharCount(cC)
|
||||||
tItem.setWordCount(wC)
|
tItem.setWordCount(wC)
|
||||||
tItem.setParaCount(pC)
|
tItem.setParaCount(pC)
|
||||||
self.treeView.propagateCount(tHandle, wC)
|
self.treeView.propagateCount(tHandle, wC)
|
||||||
self.treeView.projectWordCount()
|
self.treeView.projectWordCount()
|
||||||
|
|
||||||
# Build tag index
|
|
||||||
self.theIndex.scanText(tHandle, theText)
|
|
||||||
|
|
||||||
nDone += 1
|
nDone += 1
|
||||||
if dlgProg.wasCanceled():
|
if dlgProg.wasCanceled():
|
||||||
break
|
break
|
||||||
|
|||||||
+74
-12
@@ -19,6 +19,7 @@ from os import path
|
|||||||
from nw.constants import (
|
from nw.constants import (
|
||||||
nwFiles, nwKeyWords, nwItemType, nwItemClass, nwAlert
|
nwFiles, nwKeyWords, nwItemType, nwItemClass, nwAlert
|
||||||
)
|
)
|
||||||
|
from nw.tools import countWords
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -60,6 +61,10 @@ class NWIndex():
|
|||||||
self.novelIndex = {}
|
self.novelIndex = {}
|
||||||
self.noteIndex = {}
|
self.noteIndex = {}
|
||||||
|
|
||||||
|
# Meta Data
|
||||||
|
self.textCounts = {}
|
||||||
|
self.fileSynopsis = {}
|
||||||
|
|
||||||
# Lists
|
# Lists
|
||||||
self.novelList = []
|
self.novelList = []
|
||||||
|
|
||||||
@@ -70,10 +75,12 @@ class NWIndex():
|
|||||||
##
|
##
|
||||||
|
|
||||||
def clearIndex(self):
|
def clearIndex(self):
|
||||||
self.tagIndex = {}
|
self.tagIndex = {}
|
||||||
self.refIndex = {}
|
self.refIndex = {}
|
||||||
self.novelIndex = {}
|
self.novelIndex = {}
|
||||||
self.noteIndex = {}
|
self.noteIndex = {}
|
||||||
|
self.textCounts = {}
|
||||||
|
self.fileSynopsis = {}
|
||||||
return
|
return
|
||||||
|
|
||||||
def deleteHandle(self, tHandle):
|
def deleteHandle(self, tHandle):
|
||||||
@@ -101,7 +108,10 @@ class NWIndex():
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
theData = {}
|
theData = {}
|
||||||
|
loadsOK = False
|
||||||
indexFile = path.join(self.theProject.projMeta, nwFiles.INDEX_FILE)
|
indexFile = path.join(self.theProject.projMeta, nwFiles.INDEX_FILE)
|
||||||
|
metaFile = path.join(self.theProject.projMeta, nwFiles.META_FILE)
|
||||||
|
|
||||||
if path.isfile(indexFile):
|
if path.isfile(indexFile):
|
||||||
logger.debug("Loading index file")
|
logger.debug("Loading index file")
|
||||||
try:
|
try:
|
||||||
@@ -122,11 +132,29 @@ class NWIndex():
|
|||||||
if "noteIndex" in theData.keys():
|
if "noteIndex" in theData.keys():
|
||||||
self.noteIndex = theData["noteIndex"]
|
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):
|
def saveIndex(self):
|
||||||
"""Save the current index as a json file in the project meta
|
"""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)
|
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:
|
if self.mainConf.debugInfo:
|
||||||
nIndent = 2
|
nIndent = 2
|
||||||
else:
|
else:
|
||||||
nIndent = None
|
nIndent = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(indexFile,mode="w+",encoding="utf8") as outFile:
|
with open(indexFile,mode="w+",encoding="utf8") as outFile:
|
||||||
outFile.write(json.dumps({
|
outFile.write(json.dumps({
|
||||||
@@ -152,6 +183,17 @@ class NWIndex():
|
|||||||
logger.error(str(e))
|
logger.error(str(e))
|
||||||
return False
|
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
|
return True
|
||||||
|
|
||||||
def checkIndex(self):
|
def checkIndex(self):
|
||||||
@@ -180,6 +222,10 @@ class NWIndex():
|
|||||||
if len(tEntry) != 4:
|
if len(tEntry) != 4:
|
||||||
self.indexBroken = True
|
self.indexBroken = True
|
||||||
|
|
||||||
|
for tHandle in self.textCounts:
|
||||||
|
if len(self.textCounts[tHandle]) != 3:
|
||||||
|
self.indexBroken = True
|
||||||
|
|
||||||
if self.indexBroken:
|
if self.indexBroken:
|
||||||
self.clearIndex()
|
self.clearIndex()
|
||||||
self.theParent.makeAlert(
|
self.theParent.makeAlert(
|
||||||
@@ -230,17 +276,23 @@ class NWIndex():
|
|||||||
nLine = 0
|
nLine = 0
|
||||||
nTitle = 0
|
nTitle = 0
|
||||||
for aLine in theText.splitlines():
|
for aLine in theText.splitlines():
|
||||||
aLine = aLine.strip()
|
aLine = aLine
|
||||||
nLine += 1
|
nLine += 1
|
||||||
nChar = len(aLine)
|
nChar = len(aLine.strip())
|
||||||
if nChar == 0: continue
|
if nChar == 0: continue
|
||||||
if aLine[0] == "#":
|
if aLine.startswith(r"#"):
|
||||||
isTitle = self.indexTitle(tHandle, isNovel, aLine, nLine, itemLayout)
|
isTitle = self.indexTitle(tHandle, isNovel, aLine, nLine, itemLayout)
|
||||||
if isTitle:
|
if isTitle:
|
||||||
nTitle = nLine
|
nTitle = nLine
|
||||||
elif aLine[0] == "@":
|
elif aLine.startswith(r"@"):
|
||||||
self.indexNoteRef(tHandle, aLine, nLine, nTitle)
|
self.indexNoteRef(tHandle, aLine, nLine, nTitle)
|
||||||
self.indexTag(tHandle, aLine, nLine, itemClass)
|
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
|
return True
|
||||||
|
|
||||||
@@ -386,6 +438,16 @@ class NWIndex():
|
|||||||
# Extract Data
|
# 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):
|
def buildNovelList(self):
|
||||||
"""Build a list of the content of the novel.
|
"""Build a list of the content of the novel.
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -3,4 +3,4 @@
|
|||||||
@pov: Jane
|
@pov: Jane
|
||||||
@location: Earth
|
@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'?>
|
<?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>
|
<project>
|
||||||
<name>Sample Project</name>
|
<name>Sample Project</name>
|
||||||
<title>Sample Project</title>
|
<title>Sample Project</title>
|
||||||
@@ -9,9 +9,9 @@
|
|||||||
</project>
|
</project>
|
||||||
<settings>
|
<settings>
|
||||||
<spellCheck>True</spellCheck>
|
<spellCheck>True</spellCheck>
|
||||||
<lastEdited>96b68994dfa3d</lastEdited>
|
<lastEdited>6a2d6d5f4f401</lastEdited>
|
||||||
<lastViewed>b3e74dbc1f584</lastViewed>
|
<lastViewed>b3e74dbc1f584</lastViewed>
|
||||||
<lastWordCount>855</lastWordCount>
|
<lastWordCount>849</lastWordCount>
|
||||||
<autoReplace>
|
<autoReplace>
|
||||||
<A>B</A>
|
<A>B</A>
|
||||||
<B>E</B>
|
<B>E</B>
|
||||||
@@ -70,7 +70,7 @@
|
|||||||
<charCount>12</charCount>
|
<charCount>12</charCount>
|
||||||
<wordCount>3</wordCount>
|
<wordCount>3</wordCount>
|
||||||
<paraCount>0</paraCount>
|
<paraCount>0</paraCount>
|
||||||
<cursorPos>45</cursorPos>
|
<cursorPos>211</cursorPos>
|
||||||
</item>
|
</item>
|
||||||
<item handle="636b6aa9b697b" order="1" parent="e7ded148d6e4a">
|
<item handle="636b6aa9b697b" order="1" parent="e7ded148d6e4a">
|
||||||
<name>Making a Scene</name>
|
<name>Making a Scene</name>
|
||||||
@@ -118,7 +118,7 @@
|
|||||||
<charCount>1692</charCount>
|
<charCount>1692</charCount>
|
||||||
<wordCount>313</wordCount>
|
<wordCount>313</wordCount>
|
||||||
<paraCount>6</paraCount>
|
<paraCount>6</paraCount>
|
||||||
<cursorPos>216</cursorPos>
|
<cursorPos>144</cursorPos>
|
||||||
</item>
|
</item>
|
||||||
<item handle="88706ddc78b1b" order="5" parent="e7ded148d6e4a">
|
<item handle="88706ddc78b1b" order="5" parent="e7ded148d6e4a">
|
||||||
<name>Chapter Two</name>
|
<name>Chapter Two</name>
|
||||||
@@ -239,9 +239,9 @@
|
|||||||
<status>New</status>
|
<status>New</status>
|
||||||
<expanded>False</expanded>
|
<expanded>False</expanded>
|
||||||
<layout>SCENE</layout>
|
<layout>SCENE</layout>
|
||||||
<charCount>30</charCount>
|
<charCount>0</charCount>
|
||||||
<wordCount>6</wordCount>
|
<wordCount>0</wordCount>
|
||||||
<paraCount>1</paraCount>
|
<paraCount>0</paraCount>
|
||||||
<cursorPos>36</cursorPos>
|
<cursorPos>36</cursorPos>
|
||||||
</item>
|
</item>
|
||||||
</content>
|
</content>
|
||||||
|
|||||||
Reference in New Issue
Block a user