Moved item status recrod keeping into a separate iterable class
This commit is contained in:
+8
-4
@@ -26,7 +26,9 @@ class NWItem():
|
||||
|
||||
MAX_DEPTH = 8
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, theProject):
|
||||
|
||||
self.theProject = theProject
|
||||
|
||||
self.itemName = ""
|
||||
self.itemHandle = None
|
||||
@@ -35,7 +37,7 @@ class NWItem():
|
||||
self.itemType = nwItemType.NO_TYPE
|
||||
self.itemClass = nwItemClass.NO_CLASS
|
||||
self.itemLayout = nwItemLayout.NO_LAYOUT
|
||||
self.itemStatus = 0
|
||||
self.itemStatus = None
|
||||
self.isExpanded = False
|
||||
|
||||
# Document Meta Data
|
||||
@@ -158,8 +160,10 @@ class NWItem():
|
||||
return
|
||||
|
||||
def setStatus(self, theStatus):
|
||||
theStatus = checkInt(theStatus,0)
|
||||
self.itemStatus = theStatus
|
||||
if self.itemClass == nwItemClass.NOVEL:
|
||||
self.itemStatus = self.theProject.statusItems.checkEntry(theStatus)
|
||||
else:
|
||||
self.itemStatus = self.theProject.importItems.checkEntry(theStatus)
|
||||
return
|
||||
|
||||
def setExpanded(self, expState):
|
||||
|
||||
+31
-30
@@ -13,15 +13,16 @@
|
||||
import logging
|
||||
import nw
|
||||
|
||||
from os import path, mkdir, listdir
|
||||
from lxml import etree
|
||||
from hashlib import sha256
|
||||
from datetime import datetime
|
||||
from time import time
|
||||
from os import path, mkdir, listdir
|
||||
from lxml import etree
|
||||
from hashlib import sha256
|
||||
from datetime import datetime
|
||||
from time import time
|
||||
|
||||
from nw.enum import nwItemType, nwItemClass, nwItemLayout, nwAlert
|
||||
from nw.common import checkString, checkBool
|
||||
from nw.project.item import NWItem
|
||||
from nw.enum import nwItemType, nwItemClass, nwItemLayout, nwAlert
|
||||
from nw.common import checkString, checkBool
|
||||
from nw.project.item import NWItem
|
||||
from nw.project.status import NWStatus
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -54,8 +55,8 @@ class NWProject():
|
||||
|
||||
# Project Settings
|
||||
self.spellCheck = False
|
||||
self.statusCols = None
|
||||
self.importCols = None
|
||||
self.statusItems = NWStatus()
|
||||
self.importItems = NWStatus()
|
||||
self.lastEdited = None
|
||||
self.lastViewed = None
|
||||
|
||||
@@ -75,7 +76,7 @@ class NWProject():
|
||||
if not self.checkRootUnique(rootClass):
|
||||
self.makeAlert("Duplicate root item detected!", nwAlert.ERROR)
|
||||
return None
|
||||
newItem = NWItem()
|
||||
newItem = NWItem(self)
|
||||
newItem.setName(rootName)
|
||||
newItem.setType(nwItemType.ROOT)
|
||||
newItem.setClass(rootClass)
|
||||
@@ -83,7 +84,7 @@ class NWProject():
|
||||
return newItem.itemHandle
|
||||
|
||||
def newFolder(self, folderName, folderClass, pHandle):
|
||||
newItem = NWItem()
|
||||
newItem = NWItem(self)
|
||||
newItem.setName(folderName)
|
||||
newItem.setType(nwItemType.FOLDER)
|
||||
newItem.setClass(folderClass)
|
||||
@@ -91,7 +92,7 @@ class NWProject():
|
||||
return newItem.itemHandle
|
||||
|
||||
def newFile(self, fileName, fileClass, pHandle):
|
||||
newItem = NWItem()
|
||||
newItem = NWItem(self)
|
||||
newItem.setName(fileName)
|
||||
newItem.setType(nwItemType.FILE)
|
||||
if fileClass == nwItemClass.NOVEL:
|
||||
@@ -103,7 +104,7 @@ class NWProject():
|
||||
return newItem.itemHandle
|
||||
|
||||
def addTrash(self):
|
||||
newItem = NWItem()
|
||||
newItem = NWItem(self)
|
||||
newItem.setName("Trash")
|
||||
newItem.setType(nwItemType.TRASH)
|
||||
newItem.setClass(nwItemClass.TRASH)
|
||||
@@ -144,18 +145,16 @@ class NWProject():
|
||||
self.bookTitle = ""
|
||||
self.bookAuthors = []
|
||||
self.spellCheck = False
|
||||
self.statusCols = [
|
||||
("New", 100,100,100),
|
||||
("Note", 200, 50, 0),
|
||||
("Draft", 200,150, 0),
|
||||
("Finished", 50,200, 0),
|
||||
]
|
||||
self.importCols = [
|
||||
("None", 100,100,100),
|
||||
("Minor", 200, 50, 0),
|
||||
("Major", 200,150, 0),
|
||||
("Main", 50,200, 0),
|
||||
]
|
||||
self.statusItems = NWStatus()
|
||||
self.statusItems.addEntry("New", (100,100,100))
|
||||
self.statusItems.addEntry("Note", (200, 50, 0))
|
||||
self.statusItems.addEntry("Draft", (200,150, 0))
|
||||
self.statusItems.addEntry("Finished",( 50,200, 0))
|
||||
self.importItems = NWStatus()
|
||||
self.importItems.addEntry("None", (100,100,100))
|
||||
self.importItems.addEntry("Minor", (200, 50, 0))
|
||||
self.importItems.addEntry("Major", (200,150, 0))
|
||||
self.importItems.addEntry("Main", ( 50,200, 0))
|
||||
|
||||
return
|
||||
|
||||
@@ -228,7 +227,7 @@ class NWProject():
|
||||
pHandle = itemAttrib["parent"]
|
||||
else:
|
||||
pHandle = None
|
||||
nwItem = NWItem()
|
||||
nwItem = NWItem(self)
|
||||
for xValue in xItem:
|
||||
nwItem.setFromTag(xValue.tag,xValue.text)
|
||||
self._appendItem(tHandle,pHandle,nwItem)
|
||||
@@ -353,11 +352,13 @@ class NWProject():
|
||||
self.setProjectChanged(True)
|
||||
return True
|
||||
|
||||
def setStatusColours(self, newCols):
|
||||
def setStatusColours(self, newCols, colChanged):
|
||||
print(newCols,colChanged)
|
||||
self.setProjectChanged(True)
|
||||
return
|
||||
|
||||
def setImportColours(self, newCols):
|
||||
def setImportColours(self, newCols, colChanged):
|
||||
print(newCols,colChanged)
|
||||
self.setProjectChanged(True)
|
||||
return
|
||||
|
||||
@@ -500,7 +501,7 @@ class NWProject():
|
||||
nOrph = 0
|
||||
for oHandle in orphanFiles:
|
||||
nOrph += 1
|
||||
orItem = NWItem()
|
||||
orItem = NWItem(self)
|
||||
orItem.setName("Orphaned File %d" % nOrph)
|
||||
orItem.setType(nwItemType.FILE)
|
||||
orItem.setClass(nwItemClass.NO_CLASS)
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""novelWriter Item Status
|
||||
|
||||
novelWriter – Item Status
|
||||
===========================
|
||||
Class holding the project's item statuses
|
||||
|
||||
File History:
|
||||
Created: 2019-05-19 [0.1.3]
|
||||
|
||||
"""
|
||||
|
||||
import logging
|
||||
import nw
|
||||
|
||||
from nw.enum import nwItemClass
|
||||
from nw.common import checkInt
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class NWStatus():
|
||||
|
||||
def __init__(self):
|
||||
self.theLabels = []
|
||||
self.theColours = []
|
||||
self.theMap = {}
|
||||
self.theCount = 0
|
||||
self.theIndex = 0
|
||||
return
|
||||
|
||||
def addEntry(self, theLabel, theColours):
|
||||
theLabel = theLabel.strip()
|
||||
if self.lookupEntry(theLabel) is None:
|
||||
self.theLabels.append(theLabel)
|
||||
self.theColours.append(theColours)
|
||||
self.theMap[theLabel] = self.theCount
|
||||
self.theCount += 1
|
||||
return True
|
||||
|
||||
def lookupEntry(self, theLabel):
|
||||
theLabel = theLabel.strip()
|
||||
if theLabel in self.theMap.keys():
|
||||
return self.theMap[theLabel]
|
||||
return None
|
||||
|
||||
def checkEntry(self, theStatus):
|
||||
theStatus = theStatus.strip()
|
||||
if isinstance(theStatus, str):
|
||||
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:
|
||||
return self.theLabels[theStatus]
|
||||
|
||||
##
|
||||
# Iterator Bits
|
||||
##
|
||||
|
||||
def __getitem__(self, n):
|
||||
if n >= 0 and n < self.theCount:
|
||||
return self.theLabels[n], self.theColours[n]
|
||||
return None, None
|
||||
|
||||
def __iter__(self):
|
||||
self.theIndex = 0
|
||||
return self
|
||||
|
||||
def __next__(self):
|
||||
if self.theIndex < self.theCount:
|
||||
theLabel, theColour = self.__getitem__(self.theIndex)
|
||||
self.theIndex += 1
|
||||
return theLabel, theColour
|
||||
else:
|
||||
raise StopIteration
|
||||
|
||||
# END Class NWStatus
|
||||
Reference in New Issue
Block a user