[Add] resedit: Recursive data loading implemented.

This commit is contained in:
Allanis 2013-04-19 18:55:50 +01:00
parent 15082ba17d
commit 31b1f706e3
4 changed files with 61 additions and 38 deletions

View File

@ -20,44 +20,57 @@ def load(xmlfile, tag, has_name=True, do_array=None, do_special=None):
if(has_name):
name = xmlNode.attributes["name"].value
# Process the nodes.
# Append the element to the dictionary.
for bignode in filter(lambda x: x.nodeType==x.ELEMENT_NODE, xmlNode.childNodes):
# Load the nodes.
mdic[bignode.nodeName], size = load_Tag(bignode, do_array, do_special)
# Figure out if we need an array or dictionary.
if bignode.nodeName in do_array:
dictionary[name] = mdic
dom.unlink()
return dictionary
def load_Tag(node, do_array=None, do_special=None):
i = 0
# Figure out if we need an array or dic.
if node.nodeName in do_array:
array = []
use_array = True
else:
section = {}
use_array = False
for node in filter(lambda x: x.nodeType==x.ELEMENT_NODE,
bignode.childNodes):
for child in filter(lambda x: x.nodeType == x.ELEMENT_NODE, node.childNodes):
n = 0
if node.nodeName not in do_array and \
do_special != None and \
node.nodeName not in do_special.keys():
children, n = load_Tag(child, do_array, do_special)
# Just slap the children on.
if n > 0:
section[child.nodeName] = children
# Big ugly hack to use list instead of array.
if bignode.nodeName in do_array:
use_array = True
array.append(node.firstChild.data)
elif use_array:
array.append(child.firstChild.data)
# Uglier hack for special things.
elif do_special != None and bignode.nodeName in do_special.keys():
section[node.firstChild.data] = node.attributes[do_special[bignode.nodeName]].value
elif do_special != None and node.nodeName in do_special.keys():
section[child.firstChild.data] = \
child.attributes[do_special[node.nodeName]].value
# Normal way (but will overwrite lists).
else:
section[node.nodeName] = node.firstChild.data
section[child.nodeName] = child.firstChild.data
i = i+1
# Return.
if use_array:
mdic[bignode.nodeName] = array
return array, i
else:
mdic[bignode.nodeName] = section
# Append the element to the dictionary.
dictionary[name] = mdic
dom.unlink()
return dictionary
return section, i
def save(xmlfile, data, basetag, tag, has_name=True, do_array=None, do_special=None):
"""
@ -97,8 +110,17 @@ def save(xmlfile, data, basetag, tag, has_name=True, do_array=None, do_special=N
else:
for key3, value3 in value2.items():
node2 = xml.createElement(key3)
if isinstance(value3, dict):
for key4, value4 in value3.items():
node3 = xml.createElement(key4)
txtnode = xml.createTextNode(str(value4))
node3.appendChild(txtnode)
node2.appendChild(node3)
else:
txtnode = xml.createTextNode(str(value3))
node2.appendChild(txtnode)
node.appendChild(node2)
elem.appendChild(node)

Binary file not shown.

View File

@ -104,7 +104,8 @@ class Space:
hooks = {
"butNew":["clicked", self.__pnew],
"trePlanets":["button-release-event", self.__pupdate],
"comSystem":["changed", self.__pnewSys]
"comSystem":["changed", self.__pnewSys],
"butSave":["clicked", self.savePlanets]
}
for key, val in hooks.items():
self.__pwidget(key).connect(val[0], val[1])
@ -273,7 +274,7 @@ class Space:
wgt.pack_start(cell, True)
wgt.add_attribute(cell, 'text', 0)
wgt.set_model(combo)
self.__genPlanerTree()
self.__genPlanetTree()
i = 0
for row in combo:
if row[0] == self.planetTree[self.cur_planet]:

Binary file not shown.