comparison orpg/mapper/miniatures_msg.py @ 20:072ffc1d466f traipse_dev

2nd attempt. Still untested.
author sirebral
date Sat, 25 Jul 2009 19:23:25 -0500
parents 78407d627cba
children 36919b8a3ef9
comparison
equal deleted inserted replaced
19:78407d627cba 20:072ffc1d466f
34 34
35 def __init__(self,reentrant_lock_object = None): 35 def __init__(self,reentrant_lock_object = None):
36 self.tagname = "miniature" # set this to be for minis. Tagname gets used in some base class functions. 36 self.tagname = "miniature" # set this to be for minis. Tagname gets used in some base class functions.
37 map_element_msg_base.__init__(self,reentrant_lock_object) # call base class 37 map_element_msg_base.__init__(self,reentrant_lock_object) # call base class
38 38
39
40
41 # convenience method to use if only this mini is modified 39 # convenience method to use if only this mini is modified
42 # outputs a <map/> element containing only the changes to this mini 40 # outputs a <map/> element containing only the changes to this mini
43 def standalone_update_text(self,update_id_string): 41 def standalone_update_text(self,update_id_string):
44 buffer = "<map id='" + update_id_string + "'>" 42 buffer = "<map id='" + update_id_string + "'>"
45 buffer += "<miniatures>" 43 buffer += "<miniatures>"
49 47
50 # convenience method to use if only this mini is modified 48 # convenience method to use if only this mini is modified
51 # outputs a <map/> element that deletes this mini 49 # outputs a <map/> element that deletes this mini
52 def standalone_delete_text(self,update_id_string): 50 def standalone_delete_text(self,update_id_string):
53 buffer = None 51 buffer = None
54
55 if self._props.has_key("id"): 52 if self._props.has_key("id"):
56 buffer = "<map id='" + update_id_string + "'>" 53 buffer = "<map id='" + update_id_string + "'>"
57 buffer += "<miniatures>" 54 buffer += "<miniatures>"
58 buffer += "<miniature action='del' id='" + self._props("id") + "'/>" 55 buffer += "<miniature action='del' id='" + self._props("id") + "'/>"
59 buffer += "</miniatures></map>" 56 buffer += "</miniatures></map>"
60
61 return buffer 57 return buffer
62 58
63 # convenience method to use if only this mini is modified 59 # convenience method to use if only this mini is modified
64 # outputs a <map/> element to add this mini 60 # outputs a <map/> element to add this mini
65 def standalone_add_text(self,update_id_string): 61 def standalone_add_text(self,update_id_string):
73 return map_element_msg_base.get_all_xml(self,action,output_action) 69 return map_element_msg_base.get_all_xml(self,action,output_action)
74 70
75 def get_changed_xml(self,action="update",output_action=1): 71 def get_changed_xml(self,action="update",output_action=1):
76 return map_element_msg_base.get_changed_xml(self,action,output_action) 72 return map_element_msg_base.get_changed_xml(self,action,output_action)
77 73
78
79
80 class minis_msg(map_element_msg_base): 74 class minis_msg(map_element_msg_base):
81 75
82 def __init__(self,reentrant_lock_object = None): 76 def __init__(self,reentrant_lock_object = None):
83 self.tagname = "miniatures" 77 self.tagname = "miniatures"
84 map_element_msg_base.__init__(self,reentrant_lock_object) 78 map_element_msg_base.__init__(self,reentrant_lock_object)
90 for k in xml_dom.getAttributeKeys(): 84 for k in xml_dom.getAttributeKeys():
91 self.init_prop(k,xml_dom.getAttribute(k)) 85 self.init_prop(k,xml_dom.getAttribute(k))
92 86
93 for c in xml_dom._get_childNodes(): 87 for c in xml_dom._get_childNodes():
94 mini = mini_msg(self.p_lock) 88 mini = mini_msg(self.p_lock)
95 89 try: mini.init_from_dom(c)
96 try: 90 except Exception, e: print e; continue
97 mini.init_from_dom(c)
98 except Exception, e:
99 print e
100 continue
101
102 id = mini.get_prop("id") 91 id = mini.get_prop("id")
103 action = mini.get_prop("action") 92 action = mini.get_prop("action")
104 93
105 94 if action == "new": self.children[id] = mini
106 if action == "new":
107 self.children[id] = mini
108
109 elif action == "del": 95 elif action == "del":
110 if self.children.has_key(id): 96 if self.children.has_key(id):
111 self.children[id] = None 97 self.children[id] = None
112 del self.children[id] 98 del self.children[id]
113 99
114 elif action == "update": 100 elif action == "update":
115 if self.children.has_key(id): 101 if self.children.has_key(id):
116 self.children[id].init_props(mini.get_all_props()) 102 self.children[id].init_props(mini.get_all_props())
117
118 else: 103 else:
119 self.p_lock.release() 104 self.p_lock.release()
120 raise Exception, 105 raise Exception, "Error attempting to initialize a " + self.tagname + " from a non-<" + self.tagname + "/> element"
121 "Error attempting to initialize a " + self.tagname + " from a non-<" + self.tagname + "/> element"
122 self.p_lock.release() 106 self.p_lock.release()
123
124
125 107
126 def set_from_dom(self,xml_dom): 108 def set_from_dom(self,xml_dom):
127 self.p_lock.acquire() 109 self.p_lock.acquire()
128 if xml_dom.tagName == self.tagname: 110 if xml_dom.tagName == self.tagname:
129 if xml_dom.getAttributeKeys(): 111 if xml_dom.getAttributeKeys():
131 self.set_prop(k,xml_dom.getAttribute(k)) 113 self.set_prop(k,xml_dom.getAttribute(k))
132 114
133 for c in xml_dom._get_childNodes(): 115 for c in xml_dom._get_childNodes():
134 mini = mini_msg(self.p_lock) 116 mini = mini_msg(self.p_lock)
135 117
136 try: 118 try: mini.set_from_dom(c)
137 mini.set_from_dom(c) 119 except Exception, e: print e; continue
138 except Exception, e:
139 print e
140 continue
141
142 id = mini.get_prop("id") 120 id = mini.get_prop("id")
143 action = mini.get_prop("action") 121 action = mini.get_prop("action")
144 122 if action == "new": self.children[id] = mini
145 if action == "new":
146 self.children[id] = mini
147
148 elif action == "del": 123 elif action == "del":
149 if self.children.has_key(id): 124 if self.children.has_key(id):
150 self.children[id] = None 125 self.children[id] = None
151 del self.children[id] 126 del self.children[id]
152
153 elif action == "update": 127 elif action == "update":
154 if self.children.has_key(id): 128 if self.children.has_key(id):
155 self.children[id].set_props(mini.get_all_props()) 129 self.children[id].set_props(mini.get_all_props())
156
157 else: 130 else:
158 self.p_lock.release() 131 self.p_lock.release()
159 raise Exception, "Error attempting to set a " + self.tagname + " from a non-<" + self.tagname + "/> element" 132 raise Exception, "Error attempting to set a " + self.tagname + " from a non-<" + self.tagname + "/> element"
160 self.p_lock.release() 133 self.p_lock.release()