156
|
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 """
|
164
|
42 def __init__(self,xml,tree_node):
|
|
43 node_handler.__init__(self,xml,tree_node)
|
|
44 self.xml = xml
|
|
45 self.text_elem = self.xml.find('text')
|
|
46 self.text = self.text_elem.text
|
156
|
47
|
|
48 def set_text(self,txt):
|
164
|
49 self.text = txt
|
156
|
50
|
|
51 def on_use(self,evt):
|
164
|
52 txt = self.text
|
156
|
53 actionlist = txt.split("\n")
|
|
54 for line in actionlist:
|
|
55 if(line != ""):
|
|
56 if line[0] != "/": ## it's not a slash command
|
|
57 action = self.chat.ParsePost(line, True, True)
|
|
58 else:
|
|
59 action = line
|
|
60 self.chat.chat_cmds.docmd(action)
|
|
61 return 1
|
|
62
|
|
63 def get_design_panel(self,parent):
|
|
64 return macro_edit_panel(parent,self)
|
|
65
|
|
66 def tohtml(self):
|
164
|
67 title = self.xml.get("name")
|
|
68 txt = self.text
|
156
|
69 txt = string.replace(txt,'\n',"<br />")
|
|
70 return "<P><b>"+title+":</b><br />"+txt
|
|
71
|
|
72 P_TITLE = wx.NewId()
|
|
73 P_BODY = wx.NewId()
|
|
74 B_CHAT = wx.NewId()
|
|
75
|
|
76 class macro_edit_panel(wx.Panel):
|
|
77 def __init__(self, parent, handler):
|
|
78 wx.Panel.__init__(self, parent, -1)
|
|
79 self.handler = handler
|
|
80 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Chat Macro"), wx.VERTICAL)
|
|
81 self.text = {}
|
164
|
82 self.text[P_TITLE] = wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
|
|
83 self.text[P_BODY] = wx.TextCtrl(self, P_BODY, handler.text, style=wx.TE_MULTILINE)
|
156
|
84 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
|
|
85 sizer.Add(self.text[P_TITLE], 0, wx.EXPAND)
|
|
86 sizer.Add(wx.StaticText(self, -1, "Text Body:"), 0, wx.EXPAND)
|
|
87 sizer.Add(self.text[P_BODY], 1, wx.EXPAND)
|
|
88 sizer.Add(wx.Button(self, B_CHAT, "Send To Chat"),0,wx.EXPAND)
|
|
89 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
|
|
90 self.Bind(wx.EVT_TEXT, self.on_text, id=P_BODY)
|
|
91 self.Bind(wx.EVT_BUTTON, self.handler.on_use, id=B_CHAT)
|
|
92 self.SetSizer(sizer)
|
|
93 self.SetAutoLayout(True)
|
|
94 self.Fit()
|
|
95
|
|
96 def on_text(self,evt):
|
|
97 id = evt.GetId()
|
|
98 txt = self.text[id].GetValue()
|
|
99 if txt == "": return
|
|
100 if id == P_TITLE:
|
164
|
101 self.handler.xml.setAttribute('name',txt)
|
156
|
102 self.handler.rename(txt)
|
|
103 elif id == P_BODY: self.handler.set_text(txt)
|