[Add] resedit: Save uhm, kinda works.
This commit is contained in:
parent
17e5164ab4
commit
c6161c8acd
@ -36,6 +36,45 @@ def load(xmlfile, tag, has_name=True, do_array=None):
|
|||||||
dom.unlink()
|
dom.unlink()
|
||||||
return dictionary
|
return dictionary
|
||||||
|
|
||||||
def save(xmlfile, basetag, tag, has_name=True):
|
def save(xmlfile, data, basetag, tag, has_name=True, do_array=None):
|
||||||
print "TODO"
|
"""
|
||||||
|
do_array is a DICTIONARY, not a list here
|
||||||
|
"""
|
||||||
|
xml = minidom.Document()
|
||||||
|
|
||||||
|
base = xml.createElement(basetag)
|
||||||
|
|
||||||
|
for key, value in data.items():
|
||||||
|
|
||||||
|
elem = xml.createElement(tag)
|
||||||
|
if has_name:
|
||||||
|
elem.setAttribute("name", key)
|
||||||
|
|
||||||
|
for key2, value2 in value.items():
|
||||||
|
node = xml.createElement(key2)
|
||||||
|
|
||||||
|
# Check if it needs to parse an array instead of a dictionary.
|
||||||
|
if do_array != None and key2 in do_array.keys():
|
||||||
|
for text in value2:
|
||||||
|
node2 = xml.createElement(do_array[key2])
|
||||||
|
txtnode = xml.createTextNode(text)
|
||||||
|
node2.appendChild(txtnode)
|
||||||
|
node.appendChild(node2)
|
||||||
|
|
||||||
|
# Standard dictionary approach.
|
||||||
|
else:
|
||||||
|
for key3, value3 in value2.items():
|
||||||
|
node2 = xml.createElement(key3)
|
||||||
|
txtnode = xml.createTextNode(value3)
|
||||||
|
node2.appendChild(txtnode)
|
||||||
|
node.appendChild(node2)
|
||||||
|
|
||||||
|
elem.appendChild(node)
|
||||||
|
base.appendChild(elem)
|
||||||
|
xml.appendChild(base)
|
||||||
|
|
||||||
|
fp = open(xmlfile, "w")
|
||||||
|
xml.writexml(fp, "", "", "\n" "UTF-8")
|
||||||
|
|
||||||
|
xml.unlink()
|
||||||
|
|
||||||
|
Binary file not shown.
@ -6,6 +6,5 @@ import space
|
|||||||
universe = space.space()
|
universe = space.space()
|
||||||
universe.loadSystems("../../dat/ssys.xml")
|
universe.loadSystems("../../dat/ssys.xml")
|
||||||
universe.loadPlanets("../../dat/planet.xml")
|
universe.loadPlanets("../../dat/planet.xml")
|
||||||
universe.debug()
|
|
||||||
universe.window()
|
universe.window()
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
|
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
|
||||||
<!--Generated with glade3 3.4.1 on Thu Feb 7 11:50:56 2008 -->
|
|
||||||
<glade-interface>
|
<glade-interface>
|
||||||
<widget class="GtkWindow" id="winSystems">
|
<widget class="GtkWindow" id="winSystems">
|
||||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
||||||
@ -19,7 +18,7 @@
|
|||||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
||||||
<child>
|
<child>
|
||||||
<widget class="GtkTreeView" id="treSystems">
|
<widget class="GtkTreeView" id="treSystems">
|
||||||
<property name="width_request">100</property>
|
<property name="width_request">200</property>
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
||||||
@ -44,7 +43,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="x">31</property>
|
<property name="x">31</property>
|
||||||
<property name="y">26</property>
|
<property name="y">25</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
@ -58,7 +57,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="x">95</property>
|
<property name="x">95</property>
|
||||||
<property name="y">31</property>
|
<property name="y">30</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
@ -125,8 +124,8 @@
|
|||||||
<property name="adjustment">0 0 100 1 10 10</property>
|
<property name="adjustment">0 0 100 1 10 10</property>
|
||||||
</widget>
|
</widget>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="x">117</property>
|
<property name="x">120</property>
|
||||||
<property name="y">79</property>
|
<property name="y">80</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
@ -139,7 +138,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="x">29</property>
|
<property name="x">29</property>
|
||||||
<property name="y">114</property>
|
<property name="y">115</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
@ -152,8 +151,8 @@
|
|||||||
<property name="adjustment">0 0 100 1 10 10</property>
|
<property name="adjustment">0 0 100 1 10 10</property>
|
||||||
</widget>
|
</widget>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="x">119</property>
|
<property name="x">120</property>
|
||||||
<property name="y">113</property>
|
<property name="y">110</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
@ -180,7 +179,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="x">120</property>
|
<property name="x">120</property>
|
||||||
<property name="y">143</property>
|
<property name="y">140</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
@ -215,14 +214,14 @@
|
|||||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
||||||
</widget>
|
</widget>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="x">5</property>
|
<property name="x">4</property>
|
||||||
<property name="y">169</property>
|
<property name="y">162</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<widget class="GtkTreeView" id="treJumps">
|
<widget class="GtkTreeView" id="treJumps">
|
||||||
<property name="width_request">193</property>
|
<property name="width_request">193</property>
|
||||||
<property name="height_request">86</property>
|
<property name="height_request">110</property>
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
||||||
@ -230,7 +229,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="x">10</property>
|
<property name="x">10</property>
|
||||||
<property name="y">205</property>
|
<property name="y">181</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
@ -246,13 +245,13 @@
|
|||||||
</widget>
|
</widget>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="x">25</property>
|
<property name="x">25</property>
|
||||||
<property name="y">298</property>
|
<property name="y">300</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<widget class="GtkButton" id="butRmJump">
|
<widget class="GtkButton" id="butRmJump">
|
||||||
<property name="width_request">70</property>
|
<property name="width_request">70</property>
|
||||||
<property name="height_request">29</property>
|
<property name="height_request">27</property>
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="receives_default">True</property>
|
<property name="receives_default">True</property>
|
||||||
@ -262,20 +261,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="x">121</property>
|
<property name="x">121</property>
|
||||||
<property name="y">298</property>
|
<property name="y">300</property>
|
||||||
</packing>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<widget class="GtkLabel" id="label5">
|
|
||||||
<property name="width_request">126</property>
|
|
||||||
<property name="height_request">20</property>
|
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
|
||||||
<property name="label" translatable="yes">Jumps</property>
|
|
||||||
</widget>
|
|
||||||
<packing>
|
|
||||||
<property name="x">44</property>
|
|
||||||
<property name="y">184</property>
|
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
@ -322,7 +308,7 @@
|
|||||||
<child>
|
<child>
|
||||||
<widget class="GtkButton" id="butDone">
|
<widget class="GtkButton" id="butDone">
|
||||||
<property name="width_request">83</property>
|
<property name="width_request">83</property>
|
||||||
<property name="height_request">41</property>
|
<property name="height_request">38</property>
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="receives_default">True</property>
|
<property name="receives_default">True</property>
|
||||||
@ -332,7 +318,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="x">322</property>
|
<property name="x">322</property>
|
||||||
<property name="y">288</property>
|
<property name="y">290</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
</widget>
|
</widget>
|
||||||
|
@ -25,16 +25,16 @@ class space:
|
|||||||
|
|
||||||
|
|
||||||
def saveSystems(self, xmlfile):
|
def saveSystems(self, xmlfile):
|
||||||
print "TODO"
|
data.save("ssys.xml", self.systems, "Systems", "ssys", True,
|
||||||
|
{ "jumps":"jump", "fleets":"fleet", "planets":"planet" })
|
||||||
|
|
||||||
def loadPlanets(self, xmlfile):
|
def loadPlanets(self, xmlfile):
|
||||||
self.planets = data.load(xmlfile, "planet", True, ["commodities"])
|
self.planets = data.load(xmlfile, "planet", True, ["commodities"])
|
||||||
|
|
||||||
|
|
||||||
def savePlanets(self, xmlfile):
|
def savePlanets(self, xmlfile):
|
||||||
print "TODO"
|
data.save("planet.xml", self.planets, "Planets", "planet", True,
|
||||||
|
{ "commodities":"commodity" })
|
||||||
|
|
||||||
def window(self):
|
def window(self):
|
||||||
"""
|
"""
|
||||||
@ -45,8 +45,10 @@ class space:
|
|||||||
|
|
||||||
# Hook events and stuff.
|
# Hook events and stuff.
|
||||||
self.__swidget("winSystems").connect("destroy", self.__done)
|
self.__swidget("winSystems").connect("destroy", self.__done)
|
||||||
self.__swidget("butDone").connect("clicked", self.__done)
|
|
||||||
self.__swidget("treSystems").connect("row-activated", self.__update)
|
self.__swidget("treSystems").connect("row-activated", self.__update)
|
||||||
|
# Buttons.
|
||||||
|
self.__swidget("butDone").connect("clicked", self.__done)
|
||||||
|
self.__swidget("butSave").connect("clicked", self.saveSystems)
|
||||||
|
|
||||||
# Populate the tree.
|
# Populate the tree.
|
||||||
self.tree_systems = gtk.TreeStore(str)
|
self.tree_systems = gtk.TreeStore(str)
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user