Finished adding the saving of tree state.
This commit is contained in:
+6
-5
@@ -30,6 +30,7 @@ class GuiDocTree(QTreeWidget):
|
||||
self.theProject = theProject
|
||||
self.theMap = {}
|
||||
|
||||
self.setStyleSheet("QTreeWidget {font-size: 13px;}")
|
||||
self.setColumnCount(4)
|
||||
self.setHeaderLabels(["Name","","","Handle"])
|
||||
if not self.debugGUI:
|
||||
@@ -47,17 +48,17 @@ class GuiDocTree(QTreeWidget):
|
||||
return
|
||||
|
||||
def saveTreeOrder(self):
|
||||
|
||||
theList = []
|
||||
for i in range(self.topLevelItemCount()):
|
||||
theList = self._scanChildren(theList, self.topLevelItem(i))
|
||||
|
||||
print(theList)
|
||||
|
||||
self.theProject.setTreeOrder(theList)
|
||||
return True
|
||||
|
||||
def _scanChildren(self, theList, theItem):
|
||||
theList.append(theItem.text(3))
|
||||
tHandle = theItem.text(3)
|
||||
nwItem = self.theProject.projTree[tHandle]
|
||||
nwItem.setExpanded(theItem.isExpanded())
|
||||
theList.append(tHandle)
|
||||
for i in range(theItem.childCount()):
|
||||
self._scanChildren(theList, theItem.child(i))
|
||||
return theList
|
||||
|
||||
@@ -38,6 +38,7 @@ class NWItem():
|
||||
self.itemOrder = None
|
||||
self.itemType = None
|
||||
self.itemClass = None
|
||||
self.isExpanded = False
|
||||
|
||||
return
|
||||
|
||||
@@ -87,6 +88,10 @@ class NWItem():
|
||||
self.itemClass = None
|
||||
return
|
||||
|
||||
def setExpanded(self, expState):
|
||||
self.isExpanded = expState
|
||||
return
|
||||
|
||||
def getType(self):
|
||||
if self.itemType == self.TYPE_ROOT: return "ROOT"
|
||||
if self.itemType == self.TYPE_FOLDER: return "FOLDER"
|
||||
|
||||
@@ -70,7 +70,7 @@ class NWProject():
|
||||
|
||||
def newProject(self):
|
||||
self.projTree = {}
|
||||
self.treeOrder - []
|
||||
self.treeOrder = []
|
||||
self.projPath = None
|
||||
self.projFile = "nwProject.nwx"
|
||||
self.projName = ""
|
||||
@@ -155,7 +155,7 @@ class NWProject():
|
||||
# Save Tree Content
|
||||
xContent = etree.SubElement(nwXML,"content",attrib={"count":str(len(self.projTree))})
|
||||
itemIdx = 0
|
||||
for tHandle in self.projTree.keys():
|
||||
for tHandle in self.treeOrder:
|
||||
nwItem = self.projTree[tHandle]
|
||||
xItem = etree.SubElement(xContent,"item",attrib={
|
||||
"handle" : str(tHandle),
|
||||
@@ -169,6 +169,8 @@ class NWProject():
|
||||
if nwItem.getClass() is not "NONE":
|
||||
xItemClass = etree.SubElement(xItem,"class")
|
||||
xItemClass.text = str(nwItem.getClass())
|
||||
if nwItem.isExpanded:
|
||||
xItemExpanded = etree.SubElement(xItem,"expanded")
|
||||
|
||||
# Write the xml tree to file
|
||||
with open(path.join(self.projPath,self.projFile),"wb") as outFile:
|
||||
@@ -211,7 +213,7 @@ class NWProject():
|
||||
def setTreeOrder(self, newOrder):
|
||||
if len(self.treeOrder) != len(newOrder):
|
||||
logger.warning("Size of new and old tree order does not match")
|
||||
self.treeOrder - newOrder
|
||||
self.treeOrder = newOrder
|
||||
return True
|
||||
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user