[Add] resedit: Recursive data loading implemented.
This commit is contained in:
parent
15082ba17d
commit
31b1f706e3
@ -19,46 +19,59 @@ def load(xmlfile, tag, has_name=True, do_array=None, do_special=None):
|
||||
# Name is stored as a property and not a node.
|
||||
if(has_name):
|
||||
name = xmlNode.attributes["name"].value
|
||||
|
||||
# Process the nodes.
|
||||
for bignode in filter(lambda x: x.nodeType==x.ELEMENT_NODE, xmlNode.childNodes):
|
||||
# Load the nodes.
|
||||
|
||||
# Figure out if we need an array or dictionary.
|
||||
if bignode.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):
|
||||
|
||||
# Big ugly hack to use list instead of array.
|
||||
if bignode.nodeName in do_array:
|
||||
use_array = True
|
||||
array.append(node.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
|
||||
|
||||
# Normal way (but will overwrite lists).
|
||||
else:
|
||||
section[node.nodeName] = node.firstChild.data
|
||||
|
||||
if use_array:
|
||||
mdic[bignode.nodeName] = array
|
||||
else:
|
||||
mdic[bignode.nodeName] = section
|
||||
|
||||
|
||||
# Append the element to the dictionary.
|
||||
for bignode in filter(lambda x: x.nodeType==x.ELEMENT_NODE, xmlNode.childNodes):
|
||||
mdic[bignode.nodeName], size = load_Tag(bignode, do_array, do_special)
|
||||
|
||||
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 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.
|
||||
elif use_array:
|
||||
array.append(child.firstChild.data)
|
||||
|
||||
# Uglier hack for special things.
|
||||
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[child.nodeName] = child.firstChild.data
|
||||
|
||||
i = i+1
|
||||
|
||||
# Return.
|
||||
if use_array:
|
||||
return array, i
|
||||
else:
|
||||
return section, i
|
||||
|
||||
def save(xmlfile, data, basetag, tag, has_name=True, do_array=None, do_special=None):
|
||||
"""
|
||||
do_array is a DICTIONARY, not a list here
|
||||
@ -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)
|
||||
txtnode = xml.createTextNode(str(value3))
|
||||
node2.appendChild(txtnode)
|
||||
|
||||
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.
@ -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.
Loading…
Reference in New Issue
Block a user