Mercurial > traipse
comparison orpg/mapper/whiteboard_msg.py @ 0:4385a7d0efd1 grumpy-goblin
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
author | sirebral |
---|---|
date | Tue, 14 Jul 2009 16:41:58 -0500 |
parents | |
children | 211ac836b6a0 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4385a7d0efd1 |
---|---|
1 # Copyright (C) 2000-2001 The OpenRPG Project | |
2 # | |
3 # openrpg-dev@lists.sourceforge.net | |
4 # | |
5 # This program is free software; you can redistribute it and/or modify | |
6 # it under the terms of the GNU General Public License as published by | |
7 # the Free Software Foundation; either version 2 of the License, or | |
8 # (at your option) any later version. | |
9 # | |
10 # This program is distributed in the hope that it will be useful, | |
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 # GNU General Public License for more details. | |
14 # | |
15 # You should have received a copy of the GNU General Public License | |
16 # along with this program; if not, write to the Free Software | |
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
18 # -- | |
19 # | |
20 # File: mapper/whiteboard_msg.py | |
21 # Author: Chris Davis | |
22 # Maintainer: | |
23 # Version: | |
24 # $Id: whiteboard_msg.py,v 1.12 2007/03/09 14:11:56 digitalxero Exp $ | |
25 # | |
26 # Description: This file contains some of the basic definitions for the chat | |
27 # utilities in the orpg project. | |
28 # | |
29 __version__ = "$Id: whiteboard_msg.py,v 1.12 2007/03/09 14:11:56 digitalxero Exp $" | |
30 | |
31 from base_msg import * | |
32 | |
33 class item_msg(map_element_msg_base): | |
34 | |
35 def __init__(self,reentrant_lock_object = None, tagname = "line"): | |
36 self.tagname = tagname # set this to be for items. Tagname gets used in some base class functions. | |
37 map_element_msg_base.__init__(self,reentrant_lock_object) # call base class | |
38 | |
39 # convenience method to use if only this item is modified | |
40 # outputs a <map/> element containing only the changes to this item | |
41 def standalone_update_text(self,update_id_string): | |
42 buffer = "<map id='" + update_id_string + "'>" | |
43 buffer += "<whiteboard>" | |
44 buffer += self.get_changed_xml() | |
45 buffer += "</whiteboad></map>" | |
46 return buffer | |
47 | |
48 # convenience method to use if only this item is modified | |
49 # outputs a <map/> element that deletes this item | |
50 def standalone_delete_text(self,update_id_string): | |
51 buffer = None | |
52 if self._props.has_key("id"): | |
53 buffer = "<map id='" + update_id_string + "'>" | |
54 buffer += "<whiteboard>" | |
55 buffer += "<"+self.tagname+" action='del' id='" + self._props("id") + "'/>" | |
56 buffer += "</whiteboard></map>" | |
57 return buffer | |
58 | |
59 # convenience method to use if only this item is modified | |
60 # outputs a <map/> element to add this item | |
61 def standalone_add_text(self,update_id_string): | |
62 buffer = "<map id='" + update_id_string + "'>" | |
63 buffer += "<whiteboard>" | |
64 buffer += self.get_all_xml() | |
65 buffer += "</whiteboard></map>" | |
66 return buffer | |
67 | |
68 def get_all_xml(self,action="new",output_action=1): | |
69 return map_element_msg_base.get_all_xml(self,action,output_action) | |
70 | |
71 def get_changed_xml(self,action="update",output_action=1): | |
72 return map_element_msg_base.get_changed_xml(self,action,output_action) | |
73 | |
74 class whiteboard_msg(map_element_msg_base): | |
75 | |
76 def __init__(self,reentrant_lock_object = None): | |
77 self.tagname = "whiteboard" | |
78 map_element_msg_base.__init__(self,reentrant_lock_object) | |
79 | |
80 def init_from_dom(self,xml_dom): | |
81 self.p_lock.acquire() | |
82 if xml_dom.tagName == self.tagname: | |
83 if xml_dom.getAttributeKeys(): | |
84 for k in xml_dom.getAttributeKeys(): | |
85 self.init_prop(k,xml_dom.getAttribute(k)) | |
86 for c in xml_dom._get_childNodes(): | |
87 item = item_msg(self.p_lock,c._get_nodeName()) | |
88 try: | |
89 item.init_from_dom(c) | |
90 except Exception, e: | |
91 print e | |
92 continue | |
93 id = item.get_prop("id") | |
94 action = item.get_prop("action") | |
95 if action == "new": | |
96 self.children[id] = item | |
97 elif action == "del": | |
98 if self.children.has_key(id): | |
99 self.children[id] = None | |
100 del self.children[id] | |
101 elif action == "update": | |
102 if self.children.has_key(id): | |
103 self.children[id].init_props(item.get_all_props()) | |
104 else: | |
105 self.p_lock.release() | |
106 raise Exception, "Error attempting to initialize a " + self.tagname + " from a non-<" + self.tagname + "/> element in whiteboard" | |
107 self.p_lock.release() | |
108 | |
109 def set_from_dom(self,xml_dom): | |
110 self.p_lock.acquire() | |
111 if xml_dom.tagName == self.tagname: | |
112 if xml_dom.getAttributeKeys(): | |
113 for k in xml_dom.getAttributeKeys(): | |
114 self.set_prop(k,xml_dom.getAttribute(k)) | |
115 for c in xml_dom._get_childNodes(): | |
116 item = item_msg(self.p_lock, c._get_nodeName()) | |
117 try: | |
118 item.set_from_dom(c) | |
119 except Exception, e: | |
120 print e | |
121 continue | |
122 id = item.get_prop("id") | |
123 action = item.get_prop("action") | |
124 if action == "new": | |
125 self.children[id] = item | |
126 elif action == "del": | |
127 if self.children.has_key(id): | |
128 self.children[id] = None | |
129 del self.children[id] | |
130 elif action == "update": | |
131 if self.children.has_key(id): | |
132 self.children[id].set_props(item.get_all_props()) | |
133 else: | |
134 self.p_lock.release() | |
135 raise Exception, "Error attempting to set a " + self.tagname + " from a non-<" + self.tagname + "/> element" | |
136 self.p_lock.release() |