From 1a521758d14e2f9febb9e194b7b5742f4ab18017 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Thu, 7 May 2020 01:25:09 +0200 Subject: [PATCH] Moved the unpacking of XML data into the NWItem class --- nw/project/item.py | 22 ++++++++++++++++++++++ nw/project/project.py | 15 ++------------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/nw/project/item.py b/nw/project/item.py index f404eda7..5295092e 100644 --- a/nw/project/item.py +++ b/nw/project/item.py @@ -99,6 +99,28 @@ class NWItem(): xSub = self._subPack(xPack,"cursorPos", text=str(self.cursorPos), none=False) return xPack + def unpackXML(self, xItem): + """Sets the values from an XML entry of type 'item'. + """ + + if xItem.tag != "item": + logger.error("XML entry is not an NWItem") + return False + + if "handle" in xItem.attrib: + self.itemHandle = xItem.attrib["handle"] + else: + logger.error("XML item entry does not have a handle") + return False + + if "parent" in xItem.attrib: + self.parHandle = xItem.attrib["parent"] + + for xValue in xItem: + self.setFromTag(xValue.tag, xValue.text) + + return True + @staticmethod def _subPack(xParent, name, attrib=None, text=None, none=True): if not none and (text == None or text == "None"): diff --git a/nw/project/project.py b/nw/project/project.py index 45294564..674cba92 100644 --- a/nw/project/project.py +++ b/nw/project/project.py @@ -334,20 +334,9 @@ class NWProject(): elif xChild.tag == "content": logger.debug("Found project content") for xItem in xChild: - itemAttrib = xItem.attrib - if "handle" in xItem.attrib: - tHandle = itemAttrib["handle"] - else: - logger.error("Skipping entry missing handle") - continue - if "parent" in xItem.attrib: - pHandle = itemAttrib["parent"] - else: - pHandle = None nwItem = NWItem(self) - for xValue in xItem: - nwItem.setFromTag(xValue.tag,xValue.text) - self._appendItem(tHandle,pHandle,nwItem) + if nwItem.unpackXML(xItem): + self._appendItem(nwItem.itemHandle, nwItem.parHandle, nwItem) self.optState.loadSettings()