From 823426f4f8ee7ccdcd3fd3be2ed37f7716725737 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" Date: Sun, 19 May 2019 22:49:24 +0200 Subject: [PATCH] Loading and saving of status and importance now works --- nw/project/project.py | 15 ++++++++--- nw/project/status.py | 46 ++++++++++++++++++++++++++++++++ sample/sampleNovel/nwProject.nwx | 29 +++++++++++++++----- 3 files changed, 79 insertions(+), 11 deletions(-) diff --git a/nw/project/project.py b/nw/project/project.py index 2d75f1b7..aece184c 100644 --- a/nw/project/project.py +++ b/nw/project/project.py @@ -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,): diff --git a/nw/project/status.py b/nw/project/status.py index 0fef9eb1..1d19bf34 100644 --- a/nw/project/status.py +++ b/nw/project/status.py @@ -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 ## diff --git a/sample/sampleNovel/nwProject.nwx b/sample/sampleNovel/nwProject.nwx index 89cd44e8..c68ec5b0 100644 --- a/sample/sampleNovel/nwProject.nwx +++ b/sample/sampleNovel/nwProject.nwx @@ -1,5 +1,5 @@ - + Sample Project Sample Project @@ -8,8 +8,23 @@ True - 4cd0bd12b087d + 636b6aa9b697b 636b6aa9b697b + + New + Notes + Started + 1st Draft + 2nd Draft + 3rd Draft + Finished + + + None + Minor + Major + Main + @@ -23,7 +38,7 @@ Title Page FILE NOVEL - Draft + Started False TITLE 23 @@ -35,14 +50,14 @@ Some Chapter FOLDER NOVEL - Note + Notes True New Scene FILE NOVEL - Draft + Started False SCENE 2571 @@ -54,7 +69,7 @@ File With Stuff FILE NOVEL - Note + Notes False SCENE 578 @@ -66,7 +81,7 @@ New File FILE NOVEL - Note + Notes False SCENE 69