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
##