annotate orpg/gametree/nodehandlers/forms.py @ 130:d54e1328dbb1 alpha

Traipse Alpha 'OpenRPG' {091003-02} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user. Update Summary (Cleaning up for Beta) Added Bookmarks Fix to Remote Admin Commands Minor fix to text based Server Fix to Pretty Print, from Core Fix to Splitter Nodes not being created Fix to massive amounts of images loading, from Core Added 'boot' command to remote admin Added confirmation window for sent nodes Minor changes to allow for portability to an OpenSUSE linux OS Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG Zoom Mouse plugin added Images added to Plugin UI Switching to Element Tree Map efficiency, from FlexiRPG Added Status Bar to Update Manager default_manifest.xml renamed to default_upmana.xml Cleaner clode for saved repositories New TrueDebug Class in orpg_log (See documentation for usage) Mercurial's hgweb folder is ported to upmana **Pretty important update that can help remove thousands of dead children from your gametree. **Children, <forms />, <group_atts />, <horizontal />, <cols />, <rows />, <height />, etc... are all tags now. Check your gametree and look for dead children!! Dead Node Children, not that's a O O -v-v- Happy Halloween!
author sirebral
date Tue, 03 Nov 2009 21:06:03 -0600
parents 43ad912b7c17
children 90d19eb43830
rev   line source
130
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1 # Copyright (C) 2000-2001 The OpenRPG Project
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
2 #
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
3 # openrpg-dev@lists.sourceforge.net
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
4 #
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
5 # This program is free software; you can redistribute it and/or modify
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
6 # it under the terms of the GNU General Public License as published by
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
7 # the Free Software Foundation; either version 2 of the License, or
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
8 # (at your option) any later version.
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
9 #
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
10 # This program is distributed in the hope that it will be useful,
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
13 # GNU General Public License for more details.
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
14 #
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
15 # You should have received a copy of the GNU General Public License
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
16 # along with this program; if not, write to the Free Software
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
18 # --
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
19 #
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
20 # File: forms.py
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
21 # Author: Chris Davis
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
22 # Maintainer:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
23 # Version:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
24 # $Id: forms.py,v 1.53 2007/04/21 23:00:51 digitalxero Exp $
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
25 #
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
26 # Description: The file contains code for the form based nodehanlers
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
27 #
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
28
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
29 __version__ = "$Id: forms.py,v 1.53 2007/04/21 23:00:51 digitalxero Exp $"
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
30
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
31 from containers import *
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
32 import wx.lib.scrolledpanel
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
33
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
34 def bool2int(b):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
35 #in wxPython 2.5+, evt.Checked() returns True or False instead of 1.0 or 0.
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
36 #by running the results of that through this function, we convert it.
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
37 #if it was an int already, nothing changes. The difference between 1.0
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
38 #and 1, i.e. between ints and floats, is potentially dangerous when we
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
39 #use str() on it, but it seems to work fine right now.
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
40 if b:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
41 return 1
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
42 else:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
43 return 0
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
44
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
45 #################################
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
46 ## form container
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
47 #################################
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
48
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
49 class form_handler(container_handler):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
50 """
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
51 <nodehandler name='?' module='forms' class='form_handler' >
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
52 <form width='100' height='100' />
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
53 </nodehandler>
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
54 """
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
55
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
56 def __init__(self,xml,tree_node):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
57 container_handler.__init__(self,xml,tree_node)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
58
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
59 def load_children(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
60 self.atts = None
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
61 for child_xml in self.xml:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
62 if child_xml.tag == "form":
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
63 self.atts = child_xml
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
64 else:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
65 self.tree.load_xml(child_xml,self.mytree_node)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
66 if not self.atts:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
67 self.atts = ET.Element('form')
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
68 self.atts.set("width","400")
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
69 self.atts.set("height","600")
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
70 self.xml.append(self.atts)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
71
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
72 def get_design_panel(self,parent):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
73 return form_edit_panel(parent,self)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
74
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
75 def get_use_panel(self,parent):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
76 return form_panel(parent,self)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
77
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
78 def on_drop(self,evt):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
79 # make sure its a contorl node
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
80 container_handler.on_drop(self,evt)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
81
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
82
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
83 class form_panel(wx.lib.scrolledpanel.ScrolledPanel):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
84 def __init__(self, parent, handler):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
85 wx.lib.scrolledpanel.ScrolledPanel.__init__(self, parent, wx.ID_ANY, style=wx.NO_BORDER|wx.VSCROLL|wx.HSCROLL)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
86 self.height = int(handler.atts.get("height"))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
87 self.width = int(handler.atts.get("width"))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
88
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
89
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
90 self.SetSize((0,0))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
91 self.handler = handler
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
92 self.parent = parent
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
93 self.main_sizer = wx.BoxSizer(wx.VERTICAL)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
94 handler.tree.traverse(handler.mytree_node, self.create_child_wnd, None, False)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
95
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
96 self.SetSizer(self.main_sizer)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
97 self.SetAutoLayout(True)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
98
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
99 self.SetupScrolling()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
100
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
101 parent.SetSize(self.GetSize())
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
102 self.Fit()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
103
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
104
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
105 def SetSize(self, xy):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
106 (x, y) = self.GetSize()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
107 (nx, ny) = xy
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
108 if x < nx:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
109 x = nx+10
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
110 y += ny+11
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
111 wx.lib.scrolledpanel.ScrolledPanel.SetSize(self, (x, y))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
112
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
113
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
114 def create_child_wnd(self, treenode, evt):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
115 node = self.handler.tree.GetPyData(treenode)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
116 panel = node.get_use_panel(self)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
117 size = node.get_size_constraint()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
118 if panel:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
119 self.main_sizer.Add(panel, size, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
120 self.main_sizer.Add(wx.Size(10,10))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
121
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
122
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
123
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
124 F_HEIGHT = wx.NewId()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
125 F_WIDTH = wx.NewId()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
126 class form_edit_panel(wx.Panel):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
127 def __init__(self, parent, handler):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
128 wx.Panel.__init__(self, parent, -1)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
129 self.handler = handler
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
130 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Form Properties"), wx.VERTICAL)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
131 wh_sizer = wx.BoxSizer(wx.HORIZONTAL)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
132 self.text = { P_TITLE : wx.TextCtrl(self, P_TITLE, handler.xml.get('name')),
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
133 F_HEIGHT : wx.TextCtrl(self, F_HEIGHT, handler.atts.get('height')),
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
134 F_WIDTH : wx.TextCtrl(self, F_WIDTH, handler.atts.get('width'))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
135 }
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
136
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
137 wh_sizer.Add(wx.StaticText(self, -1, "Width:"), 0, wx.ALIGN_CENTER)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
138 wh_sizer.Add(wx.Size(10,10))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
139 wh_sizer.Add(self.text[F_WIDTH], 0, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
140 wh_sizer.Add(wx.Size(10,10))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
141 wh_sizer.Add(wx.StaticText(self, -1, "Height:"), 0, wx.ALIGN_CENTER)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
142 wh_sizer.Add(wx.Size(10,10))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
143 wh_sizer.Add(self.text[F_HEIGHT], 0, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
144
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
145 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
146 sizer.Add(self.text[P_TITLE], 0, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
147 sizer.Add(wx.Size(10,10))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
148 sizer.Add(wh_sizer,0,wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
149
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
150 self.SetSizer(sizer)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
151 self.SetAutoLayout(True)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
152 self.Fit()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
153 parent.SetSize(self.GetBestSize())
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
154
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
155 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
156 self.Bind(wx.EVT_TEXT, self.on_text, id=F_HEIGHT)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
157 self.Bind(wx.EVT_TEXT, self.on_text, id=F_WIDTH)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
158
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
159 def on_text(self,evt):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
160 id = evt.GetId()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
161 txt = self.text[id].GetValue()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
162 if not len(txt): return
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
163 if id == P_TITLE:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
164 self.handler.xml.set('name',txt)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
165 self.handler.rename(txt)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
166 elif id == F_HEIGHT or id == F_WIDTH:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
167 try:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
168 int(txt)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
169 except:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
170 return 0
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
171 if id == F_HEIGHT:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
172 self.handler.atts.set("height",txt)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
173 elif id == F_WIDTH:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
174 self.handler.atts.set("width",txt)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
175
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
176
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
177
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
178
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
179
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
180 ##########################
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
181 ## control handler
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
182 ##########################
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
183 class control_handler(node_handler):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
184 """ A nodehandler for form controls.
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
185 <nodehandler name='?' module='forms' class='control_handler' />
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
186 """
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
187 def __init__(self,xml,tree_node):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
188 node_handler.__init__(self,xml,tree_node)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
189
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
190 def get_size_constraint(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
191 return 0
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
192
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
193
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
194 ##########################
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
195 ## textctrl handler
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
196 ##########################
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
197 #
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
198 # Updated by Snowdog (April 2003)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
199 # Now includes Raw Send Mode (like the chat macro uses)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
200 # and an option to remove the title from text when sent
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
201 # to the chat in the normal non-chat macro mode.
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
202 #
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
203 class textctrl_handler(node_handler):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
204 """ <nodehandler class="textctrl_handler" module="form" name="">
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
205 <text multiline='0' send_button='0' raw_mode='0' hide_title='0'>Text In Node</text>
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
206 </nodehandler>
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
207 """
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
208 def __init__(self,xml,tree_node):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
209 node_handler.__init__(self,xml,tree_node)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
210 self.text_elem = self.xml.find('text')
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
211 if self.text_elem.get("send_button") == "":
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
212 self.text_elem.set("send_button","0")
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
213 if self.text_elem.get("raw_mode") == "":
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
214 self.text_elem.set("raw_mode","0")
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
215 if self.text_elem.get("hide_title") == "":
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
216 self.text_elem.set("hide_title","0")
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
217
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
218 def get_design_panel(self,parent):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
219 return textctrl_edit_panel(parent,self)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
220
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
221 def get_use_panel(self,parent):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
222 return text_panel(parent,self)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
223
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
224 def get_size_constraint(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
225 return int(self.text_elem.get("multiline",0))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
226
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
227 def is_multi_line(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
228 return int(self.text_elem.get("multiline",0))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
229
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
230 def is_raw_send(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
231 return int(self.text_elem.get("raw_mode",0))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
232
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
233 def is_hide_title(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
234 return int(self.text_elem.get("hide_title",0))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
235
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
236 def has_send_button(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
237 return int(self.text_elem.get("send_button",0))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
238
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
239 def tohtml(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
240 txt = self.get_value()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
241 txt = string.replace(txt,'\n',"<br />")
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
242 if not self.is_hide_title():
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
243 txt = "<b>"+self.xml.get("name")+":</b> "+txt
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
244 return txt
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
245
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
246 def get_value(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
247 return getText(self.text_elem)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
248
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
249 def set_value(self, new_value):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
250 self.text_elem.text = str(new_value)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
251
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
252
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
253
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
254 FORM_TEXT_CTRL = wx.NewId()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
255 FORM_SEND_BUTTON = wx.NewId()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
256
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
257 class text_panel(wx.Panel):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
258 def __init__(self, parent, handler):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
259 wx.Panel.__init__(self, parent, -1)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
260 self.chat = handler.chat
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
261 self.handler = handler
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
262 if handler.is_multi_line():
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
263 text_style = wx.TE_MULTILINE
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
264 sizer_style = wx.EXPAND
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
265 sizer = wx.BoxSizer(wx.VERTICAL)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
266 else:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
267 sizer_style = wx.ALIGN_CENTER
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
268 text_style = 0
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
269 sizer = wx.BoxSizer(wx.HORIZONTAL)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
270
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
271 txt = handler.get_value()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
272 ## if self.handler.tree.ContainsReference(txt):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
273 ## txt = self.handler.tree.ReplaceReferences(txt, False)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
274 ## text_style |= wx.TE_READONLY
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
275
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
276 self.text = wx.TextCtrl(self, FORM_TEXT_CTRL, txt, style=text_style)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
277 sizer.Add(wx.StaticText(self, -1, handler.xml.get('name')+": "), 0, sizer_style)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
278 sizer.Add(wx.Size(5,0))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
279 sizer.Add(self.text, 1, sizer_style)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
280
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
281 if handler.has_send_button():
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
282 sizer.Add(wx.Button(self, FORM_SEND_BUTTON, "Send"), 0, sizer_style)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
283
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
284 self.sizer = sizer
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
285 self.SetSizer(sizer)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
286 self.SetAutoLayout(True)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
287
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
288 parent.SetSize(self.GetBestSize())
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
289 self.Bind(wx.EVT_TEXT, self.on_text, id=FORM_TEXT_CTRL)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
290 self.Bind(wx.EVT_BUTTON, self.on_send, id=FORM_SEND_BUTTON)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
291
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
292 def on_text(self,evt):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
293 txt = self.text.GetValue()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
294 txt = strip_text(txt)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
295 self.handler.text_elem.text = txt
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
296
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
297 def on_send(self,evt):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
298 txt = self.text.GetValue()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
299 if not self.handler.is_raw_send():
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
300 #self.chat.ParsePost(self.tohtml(),True,True)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
301 self.chat.ParsePost(self.handler.tohtml(),True,True)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
302 return 1
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
303 actionlist = txt.split("\n")
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
304 for line in actionlist:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
305 if(line != ""):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
306 if line[0] != "/": ## it's not a slash command
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
307 self.chat.ParsePost(line,True,True)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
308 else:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
309 action = line
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
310 self.chat.chat_cmds.docmd(action)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
311 return 1
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
312
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
313 F_MULTI = wx.NewId()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
314 F_SEND_BUTTON = wx.NewId()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
315 F_RAW_SEND = wx.NewId()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
316 F_HIDE_TITLE = wx.NewId()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
317 F_TEXT = wx.NewId()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
318
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
319 class textctrl_edit_panel(wx.Panel):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
320 def __init__(self, parent, handler):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
321 wx.Panel.__init__(self, parent, -1)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
322 self.handler = handler
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
323 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Text Properties"), wx.VERTICAL)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
324
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
325 self.title = wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
326 self.multi = wx.CheckBox(self, F_MULTI, " Multi-Line")
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
327 self.multi.SetValue(handler.is_multi_line())
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
328 self.raw_send = wx.CheckBox(self, F_RAW_SEND, " Send as Macro")
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
329 self.raw_send.SetValue(handler.is_raw_send())
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
330 self.hide_title = wx.CheckBox(self, F_HIDE_TITLE, " Hide Title")
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
331 self.hide_title.SetValue(handler.is_hide_title())
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
332 self.send_button = wx.CheckBox(self, F_SEND_BUTTON, " Send Button")
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
333 self.send_button.SetValue(handler.has_send_button())
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
334
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
335 sizer.Add(wx.StaticText(self, P_TITLE, "Title:"), 0, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
336 sizer.Add(self.title, 0, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
337 sizer.Add(wx.Size(10,10))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
338 sizer.Add(self.multi, 0, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
339 sizer.Add(self.raw_send, 0, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
340 sizer.Add(self.hide_title, 0, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
341 sizer.Add(self.send_button, 0 , wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
342 sizer.Add(wx.Size(10,10))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
343 if handler.is_multi_line():
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
344 sizer_style = wx.EXPAND
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
345 text_style = wx.TE_MULTILINE
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
346 multi = 1
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
347 else:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
348 sizer_style=wx.EXPAND
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
349 text_style = 0
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
350 multi = 0
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
351 self.text = wx.TextCtrl(self, F_TEXT, handler.get_value(),style=text_style)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
352 sizer.Add(wx.Size(5,0))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
353 sizer.Add(self.text, multi, sizer_style)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
354 self.SetSizer(sizer)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
355 self.SetAutoLayout(True)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
356
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
357 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
358 self.Bind(wx.EVT_TEXT, self.on_text, id=F_TEXT)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
359 self.Bind(wx.EVT_CHECKBOX, self.on_button, id=F_MULTI)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
360 self.Bind(wx.EVT_CHECKBOX, self.on_raw_button, id=F_RAW_SEND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
361 self.Bind(wx.EVT_CHECKBOX, self.on_hide_button, id=F_HIDE_TITLE)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
362 self.Bind(wx.EVT_CHECKBOX, self.on_send_button, id=F_SEND_BUTTON)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
363
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
364 def on_text(self,evt):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
365 id = evt.GetId()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
366 if id == P_TITLE:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
367 txt = self.title.GetValue()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
368 if not len(txt): return
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
369 self.handler.xml.set('name',txt)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
370 self.handler.rename(txt)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
371 if id == F_TEXT:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
372 txt = self.text.GetValue()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
373 txt = strip_text(txt)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
374 self.handler.text_elem.text = txt
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
375
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
376 def on_button(self,evt):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
377 self.handler.text_elem.set("multiline",str(bool2int(evt.Checked())))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
378
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
379 def on_raw_button(self,evt):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
380 self.handler.text_elem.set("raw_mode",str(bool2int(evt.Checked())))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
381
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
382 def on_hide_button(self,evt):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
383 self.handler.text_elem.set("hide_title",str(bool2int(evt.Checked())))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
384
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
385 def on_send_button(self,evt):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
386 self.handler.text_elem.set("send_button",str(bool2int(evt.Checked())))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
387
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
388
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
389 #######################
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
390 ## listbox handler
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
391 #######################
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
392 #
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
393 # Updated by Snowdog (April 2003)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
394 # Now includesan option to remove the title from
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
395 # text when sent to the chat.
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
396 #
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
397 L_DROP = 0
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
398 L_LIST = 1
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
399 L_RADIO = 2
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
400 L_CHECK = 3
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
401 L_ROLLER = 4
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
402
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
403 class listbox_handler(node_handler):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
404 """
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
405 <nodehandler class="listbox_handler" module="forms" name="">
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
406 <list type="1" send_button='0' hide_title='0'>
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
407 <option value="" selected="" >Option Text I</option>
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
408 <option value="" selected="" >Option Text II</option>
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
409 </list>
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
410 </nodehandler>
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
411 """
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
412 def __init__(self,xml,tree_node):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
413 node_handler.__init__(self,xml,tree_node)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
414 self.list = self.xml.find('list')
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
415 self.options = self.list.findall('option')
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
416 if self.list.get("send_button") == "":
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
417 self.list.set("send_button","0")
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
418 if self.list.get("hide_title") == "":
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
419 self.list.set("hide_title","0")
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
420
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
421 def get_design_panel(self,parent):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
422 return listbox_edit_panel(parent,self)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
423
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
424 def get_use_panel(self,parent):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
425 return listbox_panel(parent,self)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
426
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
427 def get_type(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
428 return int(self.list.get("type"))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
429
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
430 def set_type(self,type):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
431 self.list.set("type",str(type))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
432
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
433 def is_hide_title(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
434 return int(self.list.get("hide_title",0))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
435
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
436 # single selection methods
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
437 def get_selected_node(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
438 for opt in self.options:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
439 if opt.get("selected") == "1": return opt
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
440 return None
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
441
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
442 def get_selected_index(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
443 i = 0
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
444 for opt in self.options:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
445 if opt.get("selected") == "1":
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
446 return i
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
447 i += 1
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
448 return 0
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
449
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
450 def get_selected_text(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
451 node = self.get_selected_node()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
452 if node:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
453 return getText(node)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
454 else:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
455 return ""
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
456
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
457
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
458 # mult selection methods
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
459
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
460 def get_selections(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
461 opts = []
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
462 for opt in self.options:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
463 if opt.get("selected") == "1":
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
464 opts.append(opt)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
465 return opts
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
466
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
467 def get_selections_text(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
468 opts = []
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
469 for opt in self.options:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
470 if opt.get("selected") == "1":
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
471 opts.append(getText(opt))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
472 return opts
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
473
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
474 def get_selections_index(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
475 opts = []
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
476 i = 0
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
477 for opt in self.options:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
478 if opt.get("selected") == "1":
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
479 opts.append(i)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
480 i += 1
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
481 return opts
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
482
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
483 # setting selection method
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
484
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
485 def set_selected_node(self,index,selected=1):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
486 if self.get_type() != L_CHECK:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
487 self.clear_selections()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
488 self.options[index].set("selected", str(bool2int(selected)))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
489
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
490 def clear_selections(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
491 for opt in self.options:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
492 opt.set("selected","0")
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
493
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
494 # misc methods
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
495
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
496 def get_options(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
497 opts = []
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
498 for opt in self.options:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
499 opts.append(getText(opt))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
500 return opts
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
501
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
502 def get_option(self,index):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
503 return getText(self.options[index])
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
504
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
505 def add_option(self,opt):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
506 elem = ET.Element('option')
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
507 elem.set("value","0")
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
508 elem.set("selected","0")
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
509 elem.text = opt
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
510 self.list.append(elem)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
511 self.options = self.list.findall('option')
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
512
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
513 def remove_option(self,index):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
514 self.list.remove(self.options[index])
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
515 self.options = self.list.findall('option')
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
516
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
517 def edit_option(self,index,value):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
518 self.options[index].text = value
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
519
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
520 def has_send_button(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
521 if self.list.get("send_button") == '0':
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
522 return False
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
523 else:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
524 return True
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
525
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
526 def get_size_constraint(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
527 if self.get_type() == L_DROP:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
528 return 0
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
529 else:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
530 return 1
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
531
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
532 def tohtml(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
533 opts = self.get_selections_text()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
534 text = ""
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
535 if not self.is_hide_title():
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
536 text = "<b>"+self.xml.get("name")+":</b> "
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
537 comma = ", "
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
538 text += comma.join(opts)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
539 return text
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
540
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
541 def get_value(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
542 return "\n".join(self.get_selections_text())
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
543
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
544 F_LIST = wx.NewId()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
545 F_SEND = wx.NewId()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
546
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
547
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
548 class listbox_panel(wx.Panel):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
549 def __init__(self, parent, handler):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
550 wx.Panel.__init__(self, parent, -1)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
551 self.handler = handler
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
552 self.chat = handler.chat
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
553 opts = handler.get_options()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
554 cur_opt = handler.get_selected_text()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
555 type = handler.get_type()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
556 label = handler.xml.get('name')
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
557
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
558 if type == L_DROP:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
559 self.list = wx.ComboBox(self, F_LIST, cur_opt, choices=opts, style=wx.CB_READONLY)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
560 if self.list.GetSize()[0] > 200:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
561 self.list.Destroy()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
562 self.list = wx.ComboBox(self, F_LIST, cur_opt, size=(200, -1), choices=opts, style=wx.CB_READONLY)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
563 elif type == L_LIST:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
564 self.list = wx.ListBox(self,F_LIST,choices=opts)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
565 elif type == L_RADIO:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
566 self.list = wx.RadioBox(self,F_LIST,label,choices=opts,majorDimension=3)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
567 elif type == L_CHECK:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
568 self.list = wx.CheckListBox(self,F_LIST,choices=opts)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
569 self.set_checks()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
570
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
571 for i in handler.get_selections_text():
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
572 if type == L_DROP:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
573 self.list.SetValue( i )
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
574 else:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
575 self.list.SetStringSelection( i )
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
576
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
577 if type == L_DROP:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
578 sizer = wx.BoxSizer(wx.HORIZONTAL)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
579
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
580 else:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
581 sizer = wx.BoxSizer(wx.VERTICAL)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
582
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
583 if type != L_RADIO:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
584 sizer.Add(wx.StaticText(self, -1, label+": "), 0, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
585 sizer.Add(wx.Size(5,0))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
586
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
587 sizer.Add(self.list, 1, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
588
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
589 if handler.has_send_button():
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
590 sizer.Add(wx.Button(self, F_SEND, "Send"), 0, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
591 self.Bind(wx.EVT_BUTTON, self.handler.on_send_to_chat, id=F_SEND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
592
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
593 self.sizer = sizer
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
594 self.SetSizer(sizer)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
595 self.SetAutoLayout(True)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
596 self.Fit()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
597
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
598 parent.SetSize(self.GetBestSize())
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
599
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
600 if type == L_DROP:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
601 self.Bind(wx.EVT_COMBOBOX, self.on_change, id=F_LIST)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
602 elif type == L_LIST:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
603 self.Bind(wx.EVT_LISTBOX, self.on_change, id=F_LIST)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
604 elif type == L_RADIO:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
605 self.Bind(wx.EVT_RADIOBOX, self.on_change, id=F_LIST)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
606 elif type == L_CHECK:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
607 self.Bind(wx.EVT_CHECKLISTBOX, self.on_check, id=F_LIST)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
608
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
609
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
610 self.type = type
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
611
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
612
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
613 def on_change(self,evt):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
614 self.handler.set_selected_node(self.list.GetSelection())
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
615
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
616 def on_check(self,evt):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
617 for i in xrange(self.list.GetCount()):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
618 self.handler.set_selected_node(i, bool2int(self.list.IsChecked(i)))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
619
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
620 def set_checks(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
621 for i in self.handler.get_selections_index():
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
622 self.list.Check(i)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
623
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
624
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
625
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
626 BUT_ADD = wx.NewId()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
627 BUT_REM = wx.NewId()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
628 BUT_EDIT = wx.NewId()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
629 F_TYPE = wx.NewId()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
630 F_NO_TITLE = wx.NewId()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
631
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
632 class listbox_edit_panel(wx.Panel):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
633 def __init__(self, parent, handler):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
634 wx.Panel.__init__(self, parent, -1)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
635 self.handler = handler
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
636 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "List Box Properties"), wx.VERTICAL)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
637
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
638 self.text = wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
639
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
640 opts = handler.get_options()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
641 self.listbox = wx.ListBox(self, F_LIST, choices=opts, style=wx.LB_HSCROLL|wx.LB_SINGLE|wx.LB_NEEDED_SB)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
642 opts = ['Drop Down', 'List Box', 'Radio Box', 'Check List']
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
643 self.type_radios = wx.RadioBox(self,F_TYPE,"List Type",choices=opts)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
644 self.type_radios.SetSelection(handler.get_type())
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
645
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
646 self.send_button = wx.CheckBox(self, F_SEND_BUTTON, " Send Button")
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
647 self.send_button.SetValue(handler.has_send_button())
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
648
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
649 self.hide_title = wx.CheckBox(self, F_NO_TITLE, " Hide Title")
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
650 self.hide_title.SetValue(handler.is_hide_title())
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
651
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
652 but_sizer = wx.BoxSizer(wx.HORIZONTAL)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
653 but_sizer.Add(wx.Button(self, BUT_ADD, "Add"), 1, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
654 but_sizer.Add(wx.Size(10,10))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
655 but_sizer.Add(wx.Button(self, BUT_EDIT, "Edit"), 1, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
656 but_sizer.Add(wx.Size(10,10))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
657 but_sizer.Add(wx.Button(self, BUT_REM, "Remove"), 1, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
658
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
659 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
660 sizer.Add(self.text, 0, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
661 sizer.Add(wx.Size(10,10))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
662 sizer.Add(self.type_radios, 0, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
663 sizer.Add(wx.Size(10,10))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
664 sizer.Add(self.send_button, 0 , wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
665 sizer.Add(self.hide_title, 0, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
666 sizer.Add(wx.Size(10,10))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
667 sizer.Add(wx.StaticText(self, -1, "Options:"), 0, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
668 sizer.Add(self.listbox,1,wx.EXPAND);
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
669 sizer.Add(but_sizer,0,wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
670
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
671 self.SetSizer(sizer)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
672 self.SetAutoLayout(True)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
673 self.Fit()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
674 parent.SetSize(self.GetBestSize())
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
675
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
676 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
677 self.Bind(wx.EVT_BUTTON, self.on_edit, id=BUT_EDIT)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
678 self.Bind(wx.EVT_BUTTON, self.on_remove, id=BUT_REM)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
679 self.Bind(wx.EVT_BUTTON, self.on_add, id=BUT_ADD)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
680 self.Bind(wx.EVT_RADIOBOX, self.on_type, id=F_TYPE)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
681 self.Bind(wx.EVT_CHECKBOX, self.on_hide_button, id=F_NO_TITLE)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
682 self.Bind(wx.EVT_CHECKBOX, self.on_send_button, id=F_SEND_BUTTON)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
683
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
684 def on_type(self,evt):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
685 self.handler.set_type(evt.GetInt())
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
686
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
687 def on_add(self,evt):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
688 dlg = wx.TextEntryDialog(self, 'Enter option?','Add Option', '')
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
689 if dlg.ShowModal() == wx.ID_OK:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
690 self.handler.add_option(dlg.GetValue())
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
691 dlg.Destroy()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
692 self.reload_options()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
693
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
694 def on_remove(self,evt):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
695 index = self.listbox.GetSelection()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
696 if index >= 0:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
697 self.handler.remove_option(index)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
698 self.reload_options()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
699
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
700 def on_edit(self,evt):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
701 index = self.listbox.GetSelection()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
702 if index >= 0:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
703 txt = self.handler.get_option(index)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
704 dlg = wx.TextEntryDialog(self, 'Enter option?','Edit Option', txt)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
705 if dlg.ShowModal() == wx.ID_OK:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
706 self.handler.edit_option(index,dlg.GetValue())
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
707 dlg.Destroy()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
708 self.reload_options()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
709
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
710 def reload_options(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
711 self.listbox.Clear()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
712 for opt in self.handler.get_options():
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
713 self.listbox.Append(opt)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
714
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
715 def on_text(self,evt):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
716 id = evt.GetId()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
717 txt = self.text.GetValue()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
718 if not len(txt): return
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
719 if id == P_TITLE:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
720 self.handler.xml.set('name',txt)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
721 self.handler.rename(txt)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
722
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
723 def on_send_button(self,evt):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
724 self.handler.list.set("send_button", str( bool2int(evt.Checked()) ))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
725
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
726 def on_hide_button(self,evt):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
727 self.handler.list.set("hide_title", str( bool2int(evt.Checked()) ))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
728
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
729
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
730 ###############################
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
731 ## link image handlers
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
732 ###############################
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
733
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
734 class link_handler(node_handler):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
735 """ A nodehandler for URLs. Will open URL in a wxHTMLFrame
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
736 <nodehandler name='?' module='forms' class='link_handler' >
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
737 <link href='http//??.??' />
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
738 </nodehandler >
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
739 """
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
740 def __init__(self,xml,tree_node):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
741 node_handler.__init__(self,xml,tree_node)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
742 self.link = self.xml[0]
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
743
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
744 def on_use(self,evt):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
745 href = self.link.get("href")
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
746 wb = webbrowser.get()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
747 wb.open(href)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
748
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
749 def get_design_panel(self,parent):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
750 return link_edit_panel(parent,self)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
751
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
752 def get_use_panel(self,parent):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
753 return link_panel(parent,self)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
754
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
755 def tohtml(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
756 href = self.link.get("href")
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
757 title = self.xml.get("name")
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
758 return "<a href=\""+href+"\" >"+title+"</a>"
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
759
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
760 class link_panel(wx.StaticText):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
761 def __init__(self,parent,handler):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
762 self.handler = handler
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
763 label = handler.xml.get('name')
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
764 wx.StaticText.__init__(self,parent,-1,label)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
765 self.SetForegroundColour(wx.BLUE)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
766 self.Bind(wx.EVT_LEFT_DOWN, self.handler.on_use)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
767
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
768
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
769 P_URL = wx.NewId()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
770
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
771 class link_edit_panel(wx.Panel):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
772 def __init__(self, parent, handler):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
773 wx.Panel.__init__(self, parent, -1)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
774 self.handler = handler
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
775 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Link Properties"), wx.VERTICAL)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
776
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
777 self.text = {}
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
778 self.text[P_TITLE] = wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
779 self.text[P_URL] = wx.TextCtrl(self, P_URL, handler.link.get('href'))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
780
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
781 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
782 sizer.Add(self.text[P_TITLE], 0, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
783 sizer.Add(wx.Size(10,10))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
784 sizer.Add(wx.StaticText(self, -1, "URL:"), 0, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
785 sizer.Add(self.text[P_URL], 0, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
786 self.SetSizer(sizer)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
787 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
788 self.Bind(wx.EVT_TEXT, self.on_text, id=P_URL)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
789
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
790 def on_text(self,evt):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
791 id = evt.GetId()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
792 txt = self.text[id].GetValue()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
793 if not len(txt): return
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
794 if id == P_TITLE:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
795 self.handler.xml.set('name',txt)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
796 self.handler.rename(txt)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
797 elif id == P_URL:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
798 self.handler.link.set('href',txt)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
799
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
800 ##########################
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
801 ## webimg node handler
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
802 ##########################
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
803 class webimg_handler(node_handler):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
804 """ A nodehandler for URLs. Will open URL in a wxHTMLFrame
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
805 <nodehandler name='?' module='forms' class='webimg_handler' >
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
806 <link href='http//??.??' />
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
807 </nodehandler >
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
808 """
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
809 def __init__(self,xml,tree_node):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
810 node_handler.__init__(self,xml,tree_node)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
811 self.link = self.xml[0]
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
812
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
813 def get_design_panel(self,parent):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
814 return link_edit_panel(parent,self)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
815
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
816 def get_use_panel(self,parent):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
817 img = img_helper().load_url(self.link.get("href"))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
818 if not img is None:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
819 return wx.StaticBitmap(parent,-1,img,size= wx.Size(img.GetWidth(),img.GetHeight()))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
820 return wx.EmptyBitmap(1, 1)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
821
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
822 def tohtml(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
823 href = self.link.get("href")
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
824 title = self.xml.get("name")
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
825 return "<img src=\""+href+"\" alt="+title+" >"
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
826
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
827
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
828
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
829 #######################
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
830 ## resource handler
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
831 #######################
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
832
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
833 class resource_handler(node_handler):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
834 """
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
835 <nodehandler class="resource_handler" module="forms" name="">
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
836 <resource base="5" current="4" checks="1">Multi-line macro</resource>
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
837 </nodehandler>
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
838 """
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
839 def __init__(self,xml,tree_node):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
840 node_handler.__init__(self,xml,tree_node)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
841 self.resource = self.xml.find('resource')
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
842 if self.resource.get("checks") == "":
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
843 self.resource.set("checks","1")
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
844 if self.resource.get("base") == "":
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
845 self.resource.set("base","1")
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
846 if self.resource.get("current") == "":
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
847 self.resource.set("current", self.resource.get("base"))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
848
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
849 def get_design_panel(self,parent):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
850 return resource_edit_panel(parent,self)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
851
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
852 def get_use_panel(self,parent):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
853 return resource_panel(parent,self)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
854
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
855 def tohtml(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
856 # decrement the current value or post a "nothing left" message
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
857 # print the multi-line macro
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
858 return "resource"
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
859
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
860 def use_checks(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
861 if self.resource.get("checks") == "1":
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
862 return True
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
863 return False
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
864
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
865 def get_base(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
866 return int(self.resource.get("base",0))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
867
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
868 def get_current(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
869 return int(self.resource.get("current",0))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
870
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
871 def get_macro(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
872 return getText(self.resource)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
873
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
874 def get_value(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
875 return self.resource.get("current")
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
876
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
877 def set_value(self, new_value):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
878 self.resource.set("current", new_value)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
879
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
880
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
881 RESOURCE_RESET = wx.NewId()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
882 RESOURCE_CHECKS = wx.NewId()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
883 RESOURCE_NUMBER = wx.NewId()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
884 RESOURCE_DONE = wx.NewId()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
885
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
886
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
887 class resource_panel(wx.Panel):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
888 def __init__(self, parent, handler):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
889 wx.Panel.__init__(self, parent, -1)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
890 self.handler = handler
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
891 self.chat = handler.chat
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
892
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
893 sizer = wx.BoxSizer(wx.HORIZONTAL)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
894 # sizer.Add(wx.Button(self, RESOURCE_RESET, "Reset"))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
895 sizer.Add(wx.StaticText(self, -1, handler.xml.get('name')+": "), 1, wx.ALIGN_RIGHT)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
896 if self.handler.use_checks():
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
897 grid = wx.GridSizer(1, 11, 0, 0)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
898 sizer.Add(grid, 0, wx.ALIGN_RIGHT)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
899 self.checks = []
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
900 used = self.handler.get_base() - self.handler.get_current()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
901 for i in range(self.handler.get_base()):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
902 self.checks.append(wx.CheckBox(self, RESOURCE_CHECKS, ""))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
903 checked = False
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
904 if i < used:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
905 checked = True
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
906 self.checks[i].SetValue(checked)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
907 grid.Add(self.checks[i])
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
908 if i-int(i/10)*10==4:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
909 grid.Add(wx.Size(1,1))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
910 else:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
911 self.number = wx.TextCtrl(self, RESOURCE_NUMBER, self.handler.resource.get("current"))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
912 sizer.Add(self.number, 0, wx.ALIGN_RIGHT)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
913 sizer.Add(wx.Size(10,10), 0, wx.ALIGN_RIGHT)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
914 sizer.Add(wx.Button(self, RESOURCE_DONE, "Apply"), 0, wx.ALIGN_RIGHT)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
915 # self.chat.InfoPost("res 10")
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
916 sizer.SetMinSize(wx.Size(380,10))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
917 self.sizer = sizer
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
918 self.SetSizer(sizer)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
919 self.SetAutoLayout(True)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
920 self.Fit()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
921 # self.chat.InfoPost("res 20")
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
922 self.Bind(wx.EVT_BUTTON, self.on_reset, id=RESOURCE_RESET)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
923 self.Bind(wx.EVT_BUTTON, self.on_done, id=RESOURCE_DONE)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
924
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
925
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
926 def on_reset(self,evt):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
927 # uncheck all the check boxes or set the text to max
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
928 if self.handler.use_checks():
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
929 for c in self.checks:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
930 c.SetValue(False)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
931 else:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
932 self.number.SetValue(self.handler.resource.get("base"))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
933 self.handler.resource.set("current", self.handler.resource.get("base"))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
934
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
935 def on_done(self,evt):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
936 # save the changes back to the handler
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
937 current = 0
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
938 if self.handler.use_checks():
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
939 for c in self.checks:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
940 if not c.GetValue():
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
941 current += 1
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
942 else:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
943 # validate text
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
944 current = int(self.number.GetValue())
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
945 change = self.handler.get_current()-current
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
946 if change > 0:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
947 macro_text = self.handler.get_macro()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
948 macro_text = macro_text.replace("_NAME_",self.handler.xml.get("name"))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
949 macro_text = macro_text.replace("_CHANGE_", str(change))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
950 macro_text = macro_text.replace("_CURRENT_", str(current))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
951 self.handler.chat.ParsePost(macro_text, True, True)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
952 self.handler.resource.set("current",str(current))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
953
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
954
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
955 RES_EDIT_TITLE = wx.NewId()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
956 RES_EDIT_BASE = wx.NewId()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
957 RES_EDIT_CURRENT = wx.NewId()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
958 RES_EDIT_CHECKS = wx.NewId()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
959 RES_EDIT_MACRO = wx.NewId()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
960
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
961
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
962 class resource_edit_panel(wx.Panel):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
963 def __init__(self, parent, handler):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
964 wx.Panel.__init__(self, parent, -1)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
965 self.handler = handler
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
966
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
967 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Resource Properties"), wx.VERTICAL)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
968 sizer.Add(wx.StaticText(self, -1, "Name of resource:"), 0, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
969 self.title = wx.TextCtrl(self, RES_EDIT_TITLE, self.handler.xml.get('name'))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
970 sizer.Add(self.title, 0, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
971 sizer.Add(wx.Size(10,10))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
972
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
973 sizer.Add(wx.StaticText(self, -1, "Base amount of resource:"), 0, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
974 self.base = wx.TextCtrl(self, RES_EDIT_BASE, self.handler.resource.get("base"))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
975 sizer.Add(self.base, 0, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
976 sizer.Add(wx.Size(10,10))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
977
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
978 sizer.Add(wx.StaticText(self, -1, "Current amount of resource:"), 0, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
979 self.current = wx.TextCtrl(self, RES_EDIT_CURRENT, self.handler.resource.get("current"))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
980 sizer.Add(self.current, 0, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
981 sizer.Add(wx.Size(10,10))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
982
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
983 opts = ['Text Number', 'Check Boxes']
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
984 self.radio = wx.RadioBox(self, RES_EDIT_CHECKS, "Amount of resource is represented by:", choices=opts)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
985 if self.handler.use_checks():
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
986 self.radio.SetSelection(1)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
987 else:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
988 self.radio.SetSelection(0)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
989 sizer.Add(self.radio, 0, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
990 sizer.Add(wx.Size(10,10))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
991
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
992 sizer.Add(wx.StaticText(self, -1, "Send the following macro:"), 0, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
993 self.macro = wx.TextCtrl(self, RES_EDIT_MACRO, self.handler.get_macro(), style=wx.TE_MULTILINE)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
994 sizer.Add(self.macro, 1, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
995
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
996 self.SetSizer(sizer)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
997 self.SetAutoLayout(True)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
998 self.Fit()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
999 parent.SetSize(self.GetBestSize())
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1000
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1001 self.Bind(wx.EVT_TEXT, self.on_title, id=RES_EDIT_TITLE)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1002 self.Bind(wx.EVT_TEXT, self.on_base, id=RES_EDIT_BASE)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1003 self.Bind(wx.EVT_TEXT, self.on_current, id=RES_EDIT_CURRENT)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1004 self.Bind(wx.EVT_RADIOBOX, self.on_type, id=RES_EDIT_CHECKS)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1005 self.Bind(wx.EVT_TEXT, self.on_macro, id=RES_EDIT_MACRO)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1006
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1007
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1008 def on_title(self, evt):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1009 if len(self.title.GetValue()):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1010 self.handler.xml.set('name', self.title.GetValue())
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1011 self.handler.rename(self.title.GetValue())
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1012
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1013 def on_base(self, evt):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1014 try:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1015 b = int(self.base.GetValue())
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1016 self.handler.resource.set("base",str(b))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1017 except:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1018 pass
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1019
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1020 def on_current(self, evt):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1021 try:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1022 c = int(self.current.GetValue())
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1023 self.handler.resource.set("current",str(c))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1024 except:
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1025 pass
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1026
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1027 def on_type(self,evt):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1028 self.handler.resource.set("checks",str(self.radio.GetSelection()))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1029
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1030 def on_macro(self,evt):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1031 self.handler.resource.text = self.macro.GetValue()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1032
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1033
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1034 #######################
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1035 ## bonus handler
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1036 #######################
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1037
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1038 class bonus_handler(node_handler):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1039 """
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1040 <nodehandler class="bonus_handler" module="forms" name="">
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1041 <bonus value="2" type="optional">Multi-line list of node references</bonus>
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1042 </nodehandler>
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1043 """
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1044 def __init__(self,xml,tree_node):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1045 node_handler.__init__(self,xml,tree_node)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1046 self.bonus_xml = self.xml.find('bonus')
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1047 self.add_to_bonus_map()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1048
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1049 def get_design_panel(self,parent):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1050 return bonus_edit_panel(parent,self)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1051
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1052 def get_use_panel(self,parent):# there is no 'use' for a bonus
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1053 return bonus_edit_panel(parent,self)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1054
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1055 def tohtml(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1056 return "bonus"# there is no 'send to chat' or 'pretty print'
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1057
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1058 def get_value(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1059 return self.bonus_xml.get('value', '')
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1060
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1061 def delete(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1062 self.remove_from_bonus_map()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1063 return node_handler.delete(self)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1064
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1065 def add_to_bonus_map(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1066 for target in getText(self.bonus_xml).split('\n'):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1067 self.tree.AddBonus(target, self)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1068
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1069 def remove_from_bonus_map(self):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1070 for target in getText(self.bonus_xml).split('\n'):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1071 self.tree.RemoveBonus(target, self)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1072
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1073
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1074
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1075 BONUS_EDIT_TITLE = wx.NewId()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1076 BONUS_EDIT_VALUE = wx.NewId()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1077 BONUS_EDIT_TYPE = wx.NewId()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1078 BONUS_EDIT_REF = wx.NewId()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1079
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1080
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1081 class bonus_edit_panel(wx.Panel):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1082 def __init__(self, parent, handler):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1083 wx.Panel.__init__(self, parent, -1)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1084 self.handler = handler
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1085
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1086 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Bonus Properties"), wx.VERTICAL)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1087 sizer.Add(wx.StaticText(self, -1, "Name of bonus:"), 0, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1088 self.title = wx.TextCtrl(self, BONUS_EDIT_TITLE, self.handler.xml.get('name'))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1089 sizer.Add(self.title, 0, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1090 sizer.Add(wx.Size(10,10))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1091
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1092 sizer.Add(wx.StaticText(self, -1, "Size of bonus:"), 0, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1093 self.value = wx.TextCtrl(self, BONUS_EDIT_VALUE, self.handler.bonus_xml.get('value', ''))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1094 sizer.Add(self.value, 0, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1095 sizer.Add(wx.Size(10,10))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1096
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1097 sizer.Add(wx.StaticText(self, -1, "Type of bonus:"), 0, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1098 self.type = wx.TextCtrl(self, BONUS_EDIT_TYPE, self.handler.bonus_xml.get("type"))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1099 sizer.Add(self.type, 0, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1100 sizer.Add(wx.Size(10,10))
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1101
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1102 sizer.Add(wx.StaticText(self, -1, "Add to the following nodes:"), 0, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1103 self.ref = wx.TextCtrl(self, BONUS_EDIT_REF, getText(self.handler.bonus_xml), style=wx.TE_MULTILINE)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1104 sizer.Add(self.ref, 1, wx.EXPAND)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1105
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1106 self.SetSizer(sizer)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1107 self.SetAutoLayout(True)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1108 self.Fit()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1109 parent.SetSize(self.GetBestSize())
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1110
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1111 self.Bind(wx.EVT_TEXT, self.on_title, id=BONUS_EDIT_TITLE)# too many calls - should call only upon close
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1112 self.Bind(wx.EVT_TEXT, self.on_value, id=BONUS_EDIT_VALUE)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1113 self.Bind(wx.EVT_TEXT, self.on_type, id=BONUS_EDIT_TYPE)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1114 self.Bind(wx.EVT_TEXT, self.on_ref, id=BONUS_EDIT_REF)
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1115
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1116
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1117 def on_title(self, evt):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1118 if len(self.title.GetValue()):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1119 self.handler.xml.set('name', self.title.GetValue())
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1120 self.handler.rename(self.title.GetValue())
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1121
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1122 def on_value(self, evt):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1123 self.handler.bonus_xml.set('value', self.value.GetValue())
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1124
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1125 def on_type(self, evt):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1126 self.handler.bonus_xml.set('type', self.type.GetValue())
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1127
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1128 def on_ref(self, evt):
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1129 self.handler.remove_from_bonus_map()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1130 self.handler.bonus_xml.text = self.ref.GetValue()
d54e1328dbb1 Traipse Alpha 'OpenRPG' {091003-02}
sirebral
parents: 129
diff changeset
1131 self.handler.add_to_bonus_map()