Manipulating statuses now seem to work, and update correctly.

This commit is contained in:
Veronica K. B. Olsen
2019-05-19 21:55:50 +02:00
parent 540aa7fcbc
commit edb6c41788
9 changed files with 114 additions and 172 deletions
+1 -2
View File
@@ -15,8 +15,7 @@ import nw
from os import path, mkdir, rename, unlink
from nw.tools.analyse import TextAnalysis
from nw.enum import nwAlert
from nw.enum import nwAlert
logger = logging.getLogger(__name__)
+26 -4
View File
@@ -352,13 +352,25 @@ class NWProject():
self.setProjectChanged(True)
return True
def setStatusColours(self, newCols, colChanged):
print(newCols,colChanged)
def setStatusColours(self, newCols):
replaceMap = self.statusItems.setNewEntries(newCols)
if self.projTree is not None:
for nwItem in self.projTree.values():
if nwItem.itemClass == nwItemClass.NOVEL:
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, colChanged):
print(newCols,colChanged)
def setImportColours(self, newCols,):
replaceMap = self.importItems.setNewEntries(newCols)
if self.projTree is not None:
for nwItem in self.projTree.values():
if nwItem.itemClass != nwItemClass.NOVEL:
if nwItem.itemStatus in replaceMap.keys():
nwItem.setStatus(replaceMap[nwItem.itemStatus])
self.setProjectChanged(True)
return
@@ -435,6 +447,16 @@ class NWProject():
return False
return True
def countStatus(self):
self.statusItems.resetCounts()
self.importItems.resetCounts()
for nwItem in self.projTree.values():
if nwItem.itemClass == nwItemClass.NOVEL:
self.statusItems.countEntry(nwItem.itemStatus)
else:
self.importItems.countEntry(nwItem.itemStatus)
return
##
# Internal Functions
##
+44 -14
View File
@@ -23,8 +23,9 @@ class NWStatus():
def __init__(self):
self.theLabels = []
self.theColours = []
self.theCounts = []
self.theMap = {}
self.theCount = 0
self.theLength = 0
self.theIndex = 0
return
@@ -33,8 +34,9 @@ class NWStatus():
if self.lookupEntry(theLabel) is None:
self.theLabels.append(theLabel)
self.theColours.append(theColours)
self.theMap[theLabel] = self.theCount
self.theCount += 1
self.theCounts.append(0)
self.theMap[theLabel] = self.theLength
self.theLength += 1
return True
def lookupEntry(self, theLabel):
@@ -44,34 +46,62 @@ class NWStatus():
return None
def checkEntry(self, theStatus):
theStatus = theStatus.strip()
if isinstance(theStatus, str):
theStatus = theStatus.strip()
if self.lookupEntry(theStatus) is not None:
return theStatus
theStatus = checkInt(theStatus, None, False)
if theStatus is None:
return None
if theStatus >= 0 and theStatus < self.theCount:
theStatus = checkInt(theStatus, 0, False)
if theStatus >= 0 and theStatus < self.theLength:
return self.theLabels[theStatus]
def setNewEntries(self, newList):
replaceMap = {}
if newList is not None:
self.theLabels = []
self.theColours = []
self.theCounts = []
self.theMap = {}
self.theLength = 0
self.theIndex = 0
for nName, nR, nG, nB, oName in newList:
self.addEntry(nName, (nR, nG, nB))
if nName != oName and oName is not None:
replaceMap[oName] = nName
return replaceMap
def resetCounts(self):
self.theCounts = [0]*self.theLength
return
def countEntry(self, theLabel):
theIndex = self.lookupEntry(theLabel)
if theIndex is not None:
self.theCounts[theIndex] += 1
return
##
# Iterator Bits
##
def __getitem__(self, n):
if n >= 0 and n < self.theCount:
return self.theLabels[n], self.theColours[n]
return None, None
if n >= 0 and n < self.theLength:
return self.theLabels[n], self.theColours[n], self.theCounts[n]
return None, None, None
def __iter__(self):
self.theIndex = 0
return self
def __next__(self):
if self.theIndex < self.theCount:
theLabel, theColour = self.__getitem__(self.theIndex)
if self.theIndex < self.theLength:
theLabel, theColour, theCount = self.__getitem__(self.theIndex)
self.theIndex += 1
return theLabel, theColour
return theLabel, theColour, theCount
else:
raise StopIteration