Loading and saving of status and importance now works

This commit is contained in:
Veronica K. B. Olsen
2019-05-19 22:49:24 +02:00
parent fdd9c58235
commit 823426f4f8
3 changed files with 79 additions and 11 deletions
+11 -4
View File
@@ -55,8 +55,8 @@ class NWProject():
# Project Settings
self.spellCheck = False
self.statusItems = NWStatus()
self.importItems = NWStatus()
self.statusItems = None
self.importItems = None
self.lastEdited = None
self.lastViewed = None
@@ -214,6 +214,10 @@ class NWProject():
self.lastEdited = checkString(xItem.text,None,True)
if xItem.tag == "lastViewed":
self.lastViewed = checkString(xItem.text,None,True)
if xItem.tag == "status":
self.statusItems.unpackEntries(xItem)
if xItem.tag == "importance":
self.importItems.unpackEntries(xItem)
elif xChild.tag == "content":
logger.debug("Found project content")
for xItem in xChild:
@@ -275,6 +279,11 @@ class NWProject():
self._saveProjectValue(xSettings,"lastEdited",self.lastEdited)
self._saveProjectValue(xSettings,"lastViewed",self.lastViewed)
xStatus = etree.SubElement(xSettings,"status")
self.statusItems.packEntries(xStatus)
xStatus = etree.SubElement(xSettings,"importance")
self.importItems.packEntries(xStatus)
# Save Tree Content
logger.debug("Writing project content")
xContent = etree.SubElement(nwXML,"content",attrib={"count":str(len(self.treeOrder))})
@@ -360,8 +369,6 @@ class NWProject():
if nwItem.itemStatus in replaceMap.keys():
nwItem.setStatus(replaceMap[nwItem.itemStatus])
self.setProjectChanged(True)
print(self.statusItems.theLabels)
print(self.statusItems.theColours)
return
def setImportColours(self, newCols,):
+46
View File
@@ -13,6 +13,8 @@
import logging
import nw
from lxml import etree
from nw.enum import nwItemClass
from nw.common import checkInt
@@ -84,6 +86,50 @@ class NWStatus():
self.theCounts[theIndex] += 1
return
def packEntries(self, xParent):
for n in range(self.theLength):
xSub = etree.SubElement(xParent,"entry",attrib={
"red" : str(self.theColours[n][0]),
"green" : str(self.theColours[n][1]),
"blue" : str(self.theColours[n][2]),
})
xSub.text = self.theLabels[n]
return True
def unpackEntries(self, xParent):
theLabels = []
theColours = []
for xChild in xParent:
theLabels.append(xChild.text)
if "red" in xChild.attrib:
cR = checkInt(xChild.attrib["red"],0,False)
else:
cR = 0
if "green" in xChild.attrib:
cG = checkInt(xChild.attrib["green"],0,False)
else:
cG = 0
if "blue" in xChild.attrib:
cB = checkInt(xChild.attrib["blue"],0,False)
else:
cB = 0
theColours.append((cR,cG,cB))
if len(theLabels) > 0:
self.theLabels = []
self.theColours = []
self.theCounts = []
self.theMap = {}
self.theLength = 0
self.theIndex = 0
for n in range(len(theLabels)):
self.addEntry(theLabels[n], theColours[n])
return True
##
# Iterator Bits
##
+22 -7
View File
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<novelWriterXML appVersion="0.1.3" fileVersion="1.0" timeStamp="2019-05-19 19:03:13">
<novelWriterXML appVersion="0.1.3" fileVersion="1.0" timeStamp="2019-05-19 22:48:37">
<project>
<name>Sample Project</name>
<title>Sample Project</title>
@@ -8,8 +8,23 @@
</project>
<settings>
<spellCheck>True</spellCheck>
<lastEdited>4cd0bd12b087d</lastEdited>
<lastEdited>636b6aa9b697b</lastEdited>
<lastViewed>636b6aa9b697b</lastViewed>
<status>
<entry blue="100" green="100" red="100">New</entry>
<entry blue="0" green="50" red="200">Notes</entry>
<entry blue="0" green="60" red="182">Started</entry>
<entry blue="0" green="129" red="193">1st Draft</entry>
<entry blue="0" green="129" red="193">2nd Draft</entry>
<entry blue="0" green="129" red="193">3rd Draft</entry>
<entry blue="58" green="180" red="58">Finished</entry>
</status>
<importance>
<entry blue="100" green="100" red="100">None</entry>
<entry blue="0" green="71" red="143">Minor</entry>
<entry blue="180" green="0" red="60">Major</entry>
<entry blue="154" green="0" red="103">Main</entry>
</importance>
</settings>
<content count="14">
<item handle="7031beac91f75" order="0" parent="None">
@@ -23,7 +38,7 @@
<name>Title Page</name>
<type>FILE</type>
<class>NOVEL</class>
<status>Draft</status>
<status>Started</status>
<expanded>False</expanded>
<layout>TITLE</layout>
<charCount>23</charCount>
@@ -35,14 +50,14 @@
<name>Some Chapter</name>
<type>FOLDER</type>
<class>NOVEL</class>
<status>Note</status>
<status>Notes</status>
<expanded>True</expanded>
</item>
<item handle="96b68994dfa3d" order="0" parent="e7ded148d6e4a">
<name>New Scene</name>
<type>FILE</type>
<class>NOVEL</class>
<status>Draft</status>
<status>Started</status>
<expanded>False</expanded>
<layout>SCENE</layout>
<charCount>2571</charCount>
@@ -54,7 +69,7 @@
<name>File With Stuff</name>
<type>FILE</type>
<class>NOVEL</class>
<status>Note</status>
<status>Notes</status>
<expanded>False</expanded>
<layout>SCENE</layout>
<charCount>578</charCount>
@@ -66,7 +81,7 @@
<name>New File</name>
<type>FILE</type>
<class>NOVEL</class>
<status>Note</status>
<status>Notes</status>
<expanded>False</expanded>
<layout>SCENE</layout>
<charCount>69</charCount>