Generating the data for the timeline now works. Probably a bit fragile and in need of more checks.

This commit is contained in:
Veronica K. B. Olsen
2019-05-31 20:34:31 +02:00
parent 67c2912c7f
commit 57c03a2c5c
7 changed files with 101 additions and 55 deletions
+9 -17
View File
@@ -84,11 +84,6 @@ class GuiTimeLineView(QDialog):
self.theMatrix["tags"].append(tTag)
self.numCols += 1
# theTable = [[0]*(self.numCols-1)]*(self.numRows-1)
# for i in range(self.numCols):
# for j in range(self.numRows):
return
def _buildNovelList(self):
@@ -105,18 +100,15 @@ class GuiTimeLineView(QDialog):
newItem = QTableWidgetItem(" "*iDepth + iTitle)
self.mainTable.setItem(n+1, 0, newItem)
theTag = self.theMatrix["tags"][0]
theMap = self.theIndex.buildTagNovelMap(theTag)
newItem = QTableWidgetItem(theTag)
self.mainTable.setItem(0, 1, newItem)
for n in range(self.numRows-1):
newItem = QTableWidgetItem(str(theMap[n]))
self.mainTable.setItem(n+1, 1, newItem)
# for n in range(self.numCols-1):
# iTag = self.theMatrix["tags"][n]
# newItem = QTableWidgetItem(iTag)
# self.mainTable.setItem(0, n+1, newItem)
theMap = self.theIndex.buildTagNovelMap(self.theMatrix["tags"])
nCol = 1
for theTag, theCols in theMap.items():
newItem = QTableWidgetItem(theTag)
self.mainTable.setItem(0, nCol, newItem)
for n in range(self.numRows-1):
newItem = QTableWidgetItem(str(theCols[n]))
self.mainTable.setItem(n+1, nCol, newItem)
nCol += 1
return
+45 -31
View File
@@ -48,13 +48,13 @@ class NWIndex():
NOTE_KEYS = [TAG_KEY]
NOVEL_KEYS = [PLOT_KEY, POV_KEY, CHAR_KEY, WORLD_KEY, TIME_KEY, OBJECT_KEY, CUSTOM_KEY]
TAG_CLASS = {
POV_KEY : nwItemClass.CHARACTER,
CHAR_KEY : nwItemClass.CHARACTER,
PLOT_KEY : nwItemClass.PLOT,
TIME_KEY : nwItemClass.TIMELINE,
WORLD_KEY : nwItemClass.WORLD,
OBJECT_KEY : nwItemClass.OBJECT,
CUSTOM_KEY : nwItemClass.CUSTOM,
CHAR_KEY : [nwItemClass.CHARACTER, 1],
POV_KEY : [nwItemClass.CHARACTER, 2],
PLOT_KEY : [nwItemClass.PLOT, 1],
TIME_KEY : [nwItemClass.TIMELINE, 1],
WORLD_KEY : [nwItemClass.WORLD, 1],
OBJECT_KEY : [nwItemClass.OBJECT, 1],
CUSTOM_KEY : [nwItemClass.CUSTOM, 1],
}
def __init__(self, theProject, theParent):
@@ -66,7 +66,7 @@ class NWIndex():
# Indices
self.tagIndex = {}
self.noteIndex = {}
self.refIndex = {}
self.novelIndex = {}
# Lists
@@ -76,7 +76,7 @@ class NWIndex():
def clearIndex(self):
self.tagIndex = {}
self.noteIndex = {}
self.refIndex = {}
self.novelIndex = {}
return
@@ -101,8 +101,8 @@ class NWIndex():
if "tagIndex" in theData.keys():
self.tagIndex = theData["tagIndex"]
if "noteIndex" in theData.keys():
self.noteIndex = theData["noteIndex"]
if "refIndex" in theData.keys():
self.refIndex = theData["refIndex"]
if "novelIndex" in theData.keys():
self.novelIndex = theData["novelIndex"]
@@ -122,7 +122,7 @@ class NWIndex():
with open(indexFile,mode="w+") as outFile:
outFile.write(json.dumps({
"tagIndex" : self.tagIndex,
"noteIndex" : self.noteIndex,
"refIndex" : self.refIndex,
"novelIndex" : self.novelIndex,
}, indent=nIndent))
except Exception as e:
@@ -149,7 +149,7 @@ class NWIndex():
# Check file type, and reset its old index
if itemClass == nwItemClass.NOVEL:
self.novelIndex[tHandle] = []
self.noteIndex[tHandle] = []
self.refIndex[tHandle] = []
isNovel = True
else:
isNovel = False
@@ -162,7 +162,8 @@ class NWIndex():
for aTag in clearTags:
self.tagIndex.pop(aTag)
nLine = 0
nLine = 0
nTitle = 0
for aLine in theText.splitlines():
aLine = aLine.strip()
nLine += 1
@@ -170,10 +171,12 @@ class NWIndex():
if nChar == 0: continue
if aLine[0] == "#":
if isNovel:
self.indexTitle(tHandle, aLine, nLine, itemLayout)
isTitle = self.indexTitle(tHandle, aLine, nLine, itemLayout)
if isTitle:
nTitle = nLine
elif aLine[0] == "@":
if isNovel:
self.indexNoteRef(tHandle, aLine, nLine)
self.indexNoteRef(tHandle, aLine, nLine, nTitle)
else:
self.indexTag(tHandle, aLine, nLine, itemClass)
@@ -201,7 +204,7 @@ class NWIndex():
return True
def indexNoteRef(self, tHandle, aLine, nLine):
def indexNoteRef(self, tHandle, aLine, nLine, nTitle):
isValid, theBits, thePos = self.scanThis(aLine)
if not isValid or len(theBits) == 0:
@@ -210,7 +213,7 @@ class NWIndex():
theKey = theBits[0]
if theKey in self.NOVEL_KEYS:
for aVal in theBits[1:]:
self.noteIndex[tHandle].append([nLine, theKey, aVal])
self.refIndex[tHandle].append([nLine, theKey, aVal, nTitle])
return True
@@ -295,7 +298,7 @@ class NWIndex():
for n in range(1,nBits):
if theBits[n] in self.tagIndex:
isGood[n] = self.TAG_CLASS[theBits[0]].name == self.tagIndex[theBits[n]][2]
isGood[n] = self.TAG_CLASS[theBits[0]][0].name == self.tagIndex[theBits[n]][2]
return isGood
@@ -305,29 +308,40 @@ class NWIndex():
def buildNovelList(self):
self.novelList = []
self.novelList = []
self.novelOrder = []
for tHandle in self.theProject.treeOrder:
if tHandle not in self.novelIndex:
continue
for tEntry in self.novelIndex[tHandle]:
self.novelList.append(tEntry)
self.novelOrder.append("%s:%d" % (tHandle,tEntry[0]))
return True
def buildTagNovelMap(self, theTag):
def buildTagNovelMap(self, theTags):
tagList = []
if theTag not in self.tagIndex:
return tagList
tagMap = {}
tagClass = {}
try:
tagClass = nwItemClass[self.tagIndex[theTag][2]]
except:
logger.error("Could not map '%s' to nwItemClass" % self.tagIndex[theTag][2])
return tagList
for theTag in theTags:
tagMap[theTag] = [0]*len(self.novelOrder)
try:
tagClass[theTag] = nwItemClass[self.tagIndex[theTag][2]]
except:
logger.error("Could not map '%s' to nwItemClass" % self.tagIndex[theTag][2])
tagClass[theTag] = None
tagList = [0]*len(self.novelList)
for tHandle in self.refIndex:
for nLine, tKey, tTag, nTitle in self.refIndex[tHandle]:
if tTag in tagMap.keys() and tKey in self.TAG_CLASS:
try:
nPos = self.novelOrder.index("%s:%d" % (tHandle, nTitle))
if self.TAG_CLASS[tKey][0] == tagClass[tTag]:
tagMap[tTag][nPos] = self.TAG_CLASS[tKey][1]
except:
logger.error("Could not find '%s:%d' in novelOrder" % (tHandle, nTitle))
return tagList
return tagMap
# END Class NWIndex
@@ -4,7 +4,7 @@
% Begin Meta
@pov: Jane
@char: Jane, John
@char: John
@location: Earth
% End Meta
@@ -1,3 +1,6 @@
# This is a New File!
@pov: John
@location: Space
Although, not so new now that it has text in it an everything …
@@ -0,0 +1,6 @@
# Space
@tag: Space
This is somewhere in outer space.
+19
View File
@@ -134,3 +134,22 @@ Start: 2019-05-30 21:59:33 End: 2019-05-30 22:00:08 Words: 0
Start: 2019-05-30 22:00:27 End: 2019-05-30 22:01:18 Words: 0
Start: 2019-05-30 22:01:35 End: 2019-05-30 22:01:57 Words: 0
Start: 2019-05-30 22:02:05 End: 2019-05-30 22:02:24 Words: 0
Start: 2019-05-30 22:07:43 End: 2019-05-30 22:08:48 Words: 0
Start: 2019-05-30 22:18:15 End: 2019-05-30 22:18:24 Words: 0
Start: 2019-05-31 00:01:48 End: 2019-05-31 00:01:57 Words: 0
Start: 2019-05-31 00:10:01 End: 2019-05-31 00:10:07 Words: 0
Start: 2019-05-31 00:11:12 End: 2019-05-31 00:11:21 Words: 0
Start: 2019-05-31 00:11:49 End: 2019-05-31 00:12:04 Words: 0
Start: 2019-05-31 00:12:42 End: 2019-05-31 00:13:24 Words: 0
Start: 2019-05-31 00:38:11 End: 2019-05-31 00:38:38 Words: 0
Start: 2019-05-31 00:39:35 End: 2019-05-31 00:40:23 Words: 0
Start: 2019-05-31 00:40:27 End: 2019-05-31 00:40:54 Words: 0
Start: 2019-05-31 00:56:15 End: 2019-05-31 00:56:23 Words: 0
Start: 2019-05-31 00:59:56 End: 2019-05-31 01:00:05 Words: 0
Start: 2019-05-31 01:00:39 End: 2019-05-31 01:00:56 Words: 0
Start: 2019-05-31 19:10:29 End: 2019-05-31 19:21:11 Words: 0
Start: 2019-05-31 19:50:56 End: 2019-05-31 19:51:03 Words: 0
Start: 2019-05-31 19:58:24 End: 2019-05-31 19:59:04 Words: 0
Start: 2019-05-31 20:11:22 End: 2019-05-31 20:11:56 Words: 0
Start: 2019-05-31 20:23:06 End: 2019-05-31 20:23:18 Words: 0
Start: 2019-05-31 20:23:56 End: 2019-05-31 20:27:02 Words: 7
+18 -6
View File
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<novelWriterXML appVersion="0.1.4" fileVersion="1.0" timeStamp="2019-05-30 22:02:24">
<novelWriterXML appVersion="0.1.4" fileVersion="1.0" timeStamp="2019-05-31 20:26:54">
<project>
<name>Sample Project</name>
<title>Sample Project</title>
@@ -8,9 +8,9 @@
</project>
<settings>
<spellCheck>True</spellCheck>
<lastEdited>bb2c23b3c42cc</lastEdited>
<lastEdited>bc0cbd2a407f3</lastEdited>
<lastViewed>None</lastViewed>
<lastWordCount>558</lastWordCount>
<lastWordCount>565</lastWordCount>
<status>
<entry blue="100" green="100" red="100">New</entry>
<entry blue="0" green="50" red="200">Notes</entry>
@@ -27,7 +27,7 @@
<entry blue="175" green="0" red="117">Main</entry>
</importance>
</settings>
<content count="14">
<content count="15">
<item handle="7031beac91f75" order="0" parent="None">
<name>Novel</name>
<type>ROOT</type>
@@ -76,7 +76,7 @@
<charCount>656</charCount>
<wordCount>121</wordCount>
<paraCount>5</paraCount>
<cursorPos>69</cursorPos>
<cursorPos>77</cursorPos>
</item>
<item handle="bc0cbd2a407f3" order="2" parent="e7ded148d6e4a">
<name>New File</name>
@@ -88,7 +88,7 @@
<charCount>82</charCount>
<wordCount>19</wordCount>
<paraCount>1</paraCount>
<cursorPos>0</cursorPos>
<cursorPos>69</cursorPos>
</item>
<item handle="f6622b4617424" order="1" parent="None">
<name>Characters</name>
@@ -147,6 +147,18 @@
<paraCount>1</paraCount>
<cursorPos>20</cursorPos>
</item>
<item handle="f1471bef9f2ae" order="1" parent="15c4492bd5107">
<name>Space</name>
<type>FILE</type>
<class>WORLD</class>
<status>None</status>
<expanded>False</expanded>
<layout>NOTE</layout>
<charCount>38</charCount>
<wordCount>7</wordCount>
<paraCount>1</paraCount>
<cursorPos>57</cursorPos>
</item>
<item handle="98acd8c76c93a" order="3" parent="None">
<name>Trash</name>
<type>TRASH</type>