Mercurial > traipse_dev
comparison orpg/chat/chat_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 | c54768cffbd4 |
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: chat_msg.py | |
21 # Author: Ted Berg | |
22 # Maintainer: | |
23 # Version: | |
24 # $Id: chat_msg.py,v 1.15 2006/11/04 21:24:19 digitalxero Exp $ | |
25 # | |
26 # Description: Contains class definitions for manipulating <chat/> messages | |
27 # | |
28 # | |
29 | |
30 __version__ = "$Id: chat_msg.py,v 1.15 2006/11/04 21:24:19 digitalxero Exp $" | |
31 | |
32 import orpg.orpg_xml | |
33 from chat_version import CHAT_VERSION | |
34 | |
35 CHAT_MESSAGE = 1 | |
36 WHISPER_MESSAGE = 2 | |
37 EMOTE_MESSAGE = 3 | |
38 INFO_MESSAGE = 4 | |
39 SYSTEM_MESSAGE = 5 | |
40 WHISPER_EMOTE_MESSAGE = 6 | |
41 | |
42 class chat_msg: | |
43 def __init__(self,xml_text="<chat type=\"1\" version=\""+CHAT_VERSION+"\" alias=\"\" ></chat>"): | |
44 self.chat_dom = None | |
45 self.takexml(xml_text) | |
46 | |
47 def __del__(self): | |
48 if self.chat_dom: | |
49 self.chat_dom.unlink() | |
50 | |
51 def toxml(self): | |
52 return orpg.orpg_xml.toxml(self.chat_dom) | |
53 | |
54 def takexml(self,xml_text): | |
55 xml_dom = orpg.orpg_xml.parseXml(xml_text) | |
56 node_list = xml_dom.getElementsByTagName("chat") | |
57 if len(node_list) < 1: | |
58 print "Warning: no <chat/> elements found in DOM." | |
59 else: | |
60 if len(node_list) > 1: | |
61 print "Found more than one instance of <" + self.tagname + "/>. Taking first one" | |
62 self.takedom(node_list[0]) | |
63 | |
64 def takedom(self,xml_dom): | |
65 if self.chat_dom: | |
66 self.text_node = None | |
67 self.chat_dom.unlink() | |
68 self.chat_dom = xml_dom | |
69 self.text_node = orpg.orpg_xml.safe_get_text_node(self.chat_dom) | |
70 | |
71 def set_text(self,text): | |
72 text = orpg.orpg_xml.strip_text(text) | |
73 self.text_node._set_nodeValue(text) | |
74 | |
75 def set_type(self,type): | |
76 self.chat_dom.setAttribute("type",str(type)) | |
77 | |
78 def get_type(self): | |
79 return int(self.chat_dom.getAttribute("type")) | |
80 | |
81 def set_alias(self,alias): | |
82 self.chat_dom.setAttribute("alias",alias) | |
83 | |
84 def get_alias(self): | |
85 return self.chat_dom.getAttribute("alias") | |
86 | |
87 def get_text(self): | |
88 return self.text_node._get_nodeValue() | |
89 | |
90 def get_version(self): | |
91 return self.chat_dom.getAttribute("version") |