Mercurial > traipse_dev
comparison orpg/gametree/nodehandlers/chatmacro.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 | c5bc2abaf7f8 |
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: chatmacro.py | |
21 # Author: Chris Davis | |
22 # Maintainer: | |
23 # Version: | |
24 # $Id: chatmacro.py,v 1.15 2006/11/15 12:11:23 digitalxero Exp $ | |
25 # | |
26 # Description: The file contains code for the form based nodehanlers | |
27 # | |
28 | |
29 __version__ = "$Id: chatmacro.py,v 1.15 2006/11/15 12:11:23 digitalxero Exp $" | |
30 | |
31 from core import * | |
32 | |
33 ########################## | |
34 ## text node handler | |
35 ########################## | |
36 class macro_handler(node_handler): | |
37 """ A nodehandler for text blocks. Will open text in a text frame | |
38 <nodehandler name='?' module='chatmacro' class='macro_handler'> | |
39 <text>some text here</text> | |
40 </nodehandler > | |
41 """ | |
42 def __init__(self,xml_dom,tree_node): | |
43 node_handler.__init__(self,xml_dom,tree_node) | |
44 self.text_elem = self.master_dom.getElementsByTagName('text')[0] | |
45 self.text = safe_get_text_node(self.text_elem) | |
46 | |
47 def set_text(self,txt): | |
48 self.text._set_nodeValue(txt) | |
49 | |
50 def on_use(self,evt): | |
51 txt = self.text._get_nodeValue() | |
52 actionlist = txt.split("\n") | |
53 for line in actionlist: | |
54 if(line != ""): | |
55 if line[0] != "/": ## it's not a slash command | |
56 action = self.chat.ParsePost(line, True, True) | |
57 else: | |
58 action = line | |
59 self.chat.chat_cmds.docmd(action) | |
60 return 1 | |
61 | |
62 def get_design_panel(self,parent): | |
63 return macro_edit_panel(parent,self) | |
64 | |
65 def tohtml(self): | |
66 title = self.master_dom.getAttribute("name") | |
67 txt = self.text._get_nodeValue() | |
68 txt = string.replace(txt,'\n',"<br />") | |
69 return "<P><b>"+title+":</b><br />"+txt | |
70 | |
71 P_TITLE = wx.NewId() | |
72 P_BODY = wx.NewId() | |
73 B_CHAT = wx.NewId() | |
74 | |
75 class macro_edit_panel(wx.Panel): | |
76 def __init__(self, parent, handler): | |
77 wx.Panel.__init__(self, parent, -1) | |
78 self.handler = handler | |
79 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Chat Macro"), wx.VERTICAL) | |
80 self.text = {} | |
81 self.text[P_TITLE] = wx.TextCtrl(self, P_TITLE, handler.master_dom.getAttribute('name')) | |
82 self.text[P_BODY] = wx.TextCtrl(self, P_BODY, handler.text._get_nodeValue(), style=wx.TE_MULTILINE) | |
83 | |
84 #P_BODY : wx.TextCtrl(self, P_BODY,handler.text._get_nodeValue(), style=wx.TE_MULTILINE) | |
85 | |
86 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND) | |
87 sizer.Add(self.text[P_TITLE], 0, wx.EXPAND) | |
88 sizer.Add(wx.StaticText(self, -1, "Text Body:"), 0, wx.EXPAND) | |
89 sizer.Add(self.text[P_BODY], 1, wx.EXPAND) | |
90 sizer.Add(wx.Button(self, B_CHAT, "Send To Chat"),0,wx.EXPAND) | |
91 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE) | |
92 self.Bind(wx.EVT_TEXT, self.on_text, id=P_BODY) | |
93 self.Bind(wx.EVT_BUTTON, self.handler.on_use, id=B_CHAT) | |
94 self.SetSizer(sizer) | |
95 self.SetAutoLayout(True) | |
96 self.Fit() | |
97 | |
98 def on_text(self,evt): | |
99 id = evt.GetId() | |
100 txt = self.text[id].GetValue() | |
101 if txt == "": | |
102 return | |
103 if id == P_TITLE: | |
104 self.handler.master_dom.setAttribute('name',txt) | |
105 self.handler.rename(txt) | |
106 elif id == P_BODY: | |
107 self.handler.set_text(txt) |