annotate orpg/gametree/nodehandlers/rpg_grid.py @ 131:90d19eb43830 alpha

Traipse Alpha 'OpenRPG' {091003-03} 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!! (Apparently I pasted from the OpenRPG folder. Wrong! Pro's or not, they need to eventually see the read text in their own debugger console.) Dead Node Children, now that's a O O -v-v- Happy Halloween!
author sirebral
date Tue, 03 Nov 2009 21:30:36 -0600
parents d54e1328dbb1
children 1ed2feab0db9
rev   line source
131
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
1 # Copyright (C) 2000-2001 The OpenRPG Project
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
2 #
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
3 # openrpg-dev@lists.sourceforge.net
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
4 #
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
5 # This program is free software; you can redistribute it and/or modify
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
6 # it under the terms of the GNU General Public License as published by
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
7 # the Free Software Foundation; either version 2 of the License, or
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
8 # (at your option) any later version.
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
9 #
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
10 # This program is distributed in the hope that it will be useful,
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
13 # GNU General Public License for more details.
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
14 #
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
15 # You should have received a copy of the GNU General Public License
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
16 # along with this program; if not, write to the Free Software
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
18 # --
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
19 #
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
20 # File: rpg_grid.py
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
21 # Author: Chris Davis
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
22 # Maintainer:
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
23 # Version:
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
24 # $Id: rpg_grid.py,v 1.20 2006/11/15 12:11:24 digitalxero Exp $
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
25 #
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
26 # Description: The file contains code for the grid nodehanlers
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
27 #
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
28
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
29 __version__ = "$Id: rpg_grid.py,v 1.20 2006/11/15 12:11:24 digitalxero Exp $"
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
30
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
31 from core import *
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
32 from forms import *
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
33
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
34 class rpg_grid_handler(node_handler):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
35 """ Node handler for rpg grid tool
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
36 <nodehandler module='rpg_grid' class='rpg_grid_handler' name='sample'>
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
37 <grid border='' autosize='1' >
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
38 <row>
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
39 <cell size='?'></cell>
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
40 <cell></cell>
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
41 </row>
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
42 <row>
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
43 <cell></cell>
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
44 <cell></cell>
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
45 </row>
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
46 </grid>
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
47 <macros>
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
48 <macro name=''/>
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
49 </macros>
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
50 </nodehandler>
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
51 """
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
52 def __init__(self,xml,tree_node):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
53 node_handler.__init__(self,xml,tree_node)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
54 self.grid = self.xml.find('grid')
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
55 if self.grid.get("border") == "":
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
56 self.grid.set("border","1")
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
57 if self.grid.get("autosize") == "":
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
58 self.grid.set("autosize","1")
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
59 self.macros = self.xml.find('macros')
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
60 self.myeditor = None
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
61 self.refresh_rows()
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
62
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
63 def refresh_die_macros(self):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
64 pass
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
65
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
66 def refresh_rows(self):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
67 self.rows = {}
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
68 tree = self.tree
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
69 icons = self.tree.icons
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
70 tree.CollapseAndReset(self.mytree_node)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
71 for row in self.grid.findall('row'):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
72 first_cell = row.find('cell')
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
73 name = first_cell.text
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
74 if name == None or name == '':
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
75 name = "Row"
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
76 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear'])
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
77 handler = grid_row_handler(row,new_tree_node,self)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
78 tree.SetPyData(new_tree_node,handler)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
79
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
80 def tohtml(self):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
81 border = self.grid.get("border")
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
82 name = self.xml.get('name')
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
83 rows = self.grid.findall('row')
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
84 colspan = str(len(rows[0].findall('cell')))
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
85 html_str = "<table border=\""+border+"\" align=center><tr bgcolor=\""+TH_BG+"\" ><th colspan="+colspan+">"+name+"</th></tr>"
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
86 for r in rows:
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
87 cells = r.findall('cell')
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
88 html_str += "<tr>"
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
89 for c in cells:
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
90 #html_str += "<td width='"+c.get('size')+"' >" bug here
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
91 html_str += "<td >"
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
92 text = c.text
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
93 if text == None or text == '':
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
94 text = '<br />'
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
95 html_str += text + "</td>"
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
96 html_str += "</tr>"
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
97 html_str += "</table>"
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
98 return html_str
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
99
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
100 def get_design_panel(self,parent):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
101 return rpg_grid_edit_panel(parent,self)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
102
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
103 def get_use_panel(self,parent):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
104 return rpg_grid_panel(parent,self)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
105
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
106 def get_size_constraint(self):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
107 return 1
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
108
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
109 def is_autosized(self):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
110 return self.grid.get("autosize")
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
111
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
112 def set_autosize(self,autosize=1):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
113 self.grid.set("autosize",str(autosize))
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
114
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
115 class grid_row_handler(node_handler):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
116 """ Node Handler grid row.
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
117 """
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
118 def __init__(self,xml,tree_node,parent):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
119 node_handler.__init__(self,xml,tree_node)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
120 self.drag = False
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
121
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
122 def on_drop(self,evt):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
123 pass
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
124
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
125 def can_clone(self):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
126 return 0;
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
127
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
128 def tohtml(self):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
129 cells = self.xml.findall('cell')
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
130 html_str = "<table border=1 align=center><tr >"
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
131 for c in cells: # should loop over rows first, then cells
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
132 html_str += "<td >"
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
133 text = c.text
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
134 if text == '' or text is None:
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
135 text = '<br />'
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
136 html_str += text + "</td>"
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
137 html_str += "</tr>"
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
138 html_str += "</table>"
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
139 return html_str
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
140
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
141 def get_value(self):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
142 cells = self.xml.findall('cell')
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
143 if len(cells) == 2:
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
144 return getText(cells[1])
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
145 else:
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
146 return None
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
147
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
148 def set_value(self, new_value):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
149 cells = self.xml.findall('cell')
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
150 if len(cells) == 2:
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
151 cells[1].text = new_value
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
152
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
153 class MyCellEditor(wx.grid.PyGridCellEditor):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
154 """
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
155 This is a sample GridCellEditor that shows you how to make your own custom
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
156 grid editors. All the methods that can be overridden are show here. The
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
157 ones that must be overridden are marked with "*Must Override*" in the
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
158 docstring.
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
159
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
160 Notice that in order to call the base class version of these special
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
161 methods we use the method name preceded by "base_". This is because these
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
162 methods are "virtual" in C++ so if we try to call wxGridCellEditor.Create
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
163 for example, then when the wxPython extension module tries to call
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
164 ptr->Create(...) then it actually calls the derived class version which
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
165 looks up the method in this class and calls it, causing a recursion loop.
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
166 If you don't understand any of this, don't worry, just call the "base_"
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
167 version instead.
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
168
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
169 ----------------------------------------------------------------------------
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
170 This class is copied from the wxPython examples directory and was written by
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
171 Robin Dunn.
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
172
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
173 I have pasted it directly in and removed all references to "log"
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
174
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
175 -- Andrew
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
176
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
177 """
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
178 def __init__(self):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
179 wx.grid.PyGridCellEditor.__init__(self)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
180
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
181
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
182 def Create(self, parent, id, evtHandler):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
183 """
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
184 Called to create the control, which must derive from wxControl.
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
185 *Must Override*
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
186 """
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
187 self._tc = wx.TextCtrl(parent, id, "", style=wx.TE_PROCESS_ENTER | wx.TE_PROCESS_TAB)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
188 self._tc.SetInsertionPoint(0)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
189 self.SetControl(self._tc)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
190 if evtHandler:
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
191 self._tc.PushEventHandler(evtHandler)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
192
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
193
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
194 def SetSize(self, rect):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
195 """
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
196 Called to position/size the edit control within the cell rectangle.
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
197 If you don't fill the cell (the rect) then be sure to override
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
198 PaintBackground and do something meaningful there.
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
199 """
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
200 self._tc.SetDimensions(rect.x+1, rect.y+1, rect.width+2, rect.height+2)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
201
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
202
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
203 #def Show(self, show, attr): #deprecated DeprecationWarning: Please use PyGridCellEditor.Show instead.
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
204 # """
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
205 # Show or hide the edit control. You can use the attr (if not None)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
206 # to set colours or fonts for the control.
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
207 # """
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
208 # self.base_Show(show, attr) # Removed to prevent recursive error type.
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
209
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
210
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
211 def BeginEdit(self, row, col, grid):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
212 """
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
213 Fetch the value from the table and prepare the edit control
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
214 to begin editing. Set the focus to the edit control.
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
215 *Must Override*
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
216 """
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
217 self.startValue = grid.GetTable().GetValue(row, col)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
218 self._tc.SetValue(self.startValue)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
219 self._tc.SetInsertionPointEnd()
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
220 self._tc.SetFocus()
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
221
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
222 # For this example, select the text
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
223 self._tc.SetSelection(0, self._tc.GetLastPosition())
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
224
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
225
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
226 def EndEdit(self, row, col, grid):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
227 """
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
228 Complete the editing of the current cell. Returns True if the value
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
229 has changed. If necessary, the control may be destroyed.
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
230 *Must Override*
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
231 """
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
232 changed = False
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
233
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
234 val = self._tc.GetValue()
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
235 if val != self.startValue:
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
236 changed = True
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
237 grid.GetTable().SetValue(row, col, val) # update the table
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
238
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
239 self.startValue = ''
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
240 self._tc.SetValue('')
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
241 return changed
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
242
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
243
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
244 def Reset(self):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
245 """
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
246 Reset the value in the control back to its starting value.
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
247 *Must Override*
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
248 """
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
249 self._tc.SetValue(self.startValue)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
250 self._tc.SetInsertionPointEnd()
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
251
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
252
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
253 def IsAcceptedKey(self, evt):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
254 """
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
255 Return True to allow the given key to start editing: the base class
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
256 version only checks that the event has no modifiers. F2 is special
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
257 and will always start the editor.
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
258 """
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
259
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
260 ## Oops, there's a bug here, we'll have to do it ourself..
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
261 ##return self.base_IsAcceptedKey(evt)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
262
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
263 return (not (evt.ControlDown() or evt.AltDown()) and
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
264 evt.GetKeyCode() != wx.WXK_SHIFT)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
265
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
266
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
267 def StartingKey(self, evt):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
268 """
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
269 If the editor is enabled by pressing keys on the grid, this will be
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
270 called to let the editor do something about that first key if desired.
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
271 """
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
272 key = evt.GetKeyCode()
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
273 ch = None
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
274 if key in [wx.WXK_NUMPAD0, wx.WXK_NUMPAD1, wx.WXK_NUMPAD2, wx.WXK_NUMPAD3, wx.WXK_NUMPAD4,
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
275 wx.WXK_NUMPAD5, wx.WXK_NUMPAD6, wx.WXK_NUMPAD7, wx.WXK_NUMPAD8, wx.WXK_NUMPAD9]:
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
276 ch = ch = chr(ord('0') + key - wx.WXK_NUMPAD0)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
277
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
278 elif key < 256 and key >= 0 and chr(key) in string.printable:
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
279 ch = chr(key)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
280 if not evt.ShiftDown():
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
281 ch = string.lower(ch)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
282
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
283 if ch is not None:
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
284 # For this example, replace the text. Normally we would append it.
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
285 self._tc.AppendText(ch)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
286 else:
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
287 evt.Skip()
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
288
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
289
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
290
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
291 def Destroy(self):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
292 """final cleanup"""
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
293 self.base_Destroy()
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
294
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
295
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
296 def Clone(self):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
297 """
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
298 Create a new object which is the copy of this one
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
299 *Must Override*
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
300 """
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
301 return MyCellEditor()
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
302
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
303
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
304
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
305 class rpg_grid(wx.grid.Grid):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
306 """grid for attacks"""
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
307 def __init__(self, parent, handler):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
308 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
309 self.parent = parent
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
310 self.handler = handler
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
311
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
312 # Registers a "custom" cell editor (really the example from Robin Dunn with minor mods
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
313 self.RegisterDataType(wx.grid.GRID_VALUE_STRING, wx.grid.GridCellStringRenderer(),MyCellEditor())
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
314
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
315 self.rows = handler.grid.findall('row')
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
316 rows = len(self.rows)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
317 cols = len(self.rows[0].findall('cell'))
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
318 self.CreateGrid(rows,cols)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
319 self.SetRowLabelSize(0)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
320 self.SetColLabelSize(0)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
321 self.set_col_widths()
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
322
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
323 for i in range(0,len(self.rows)):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
324 self.refresh_row(i)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
325
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
326 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
327 self.Bind(wx.grid.EVT_GRID_COL_SIZE, self.on_col_size)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
328 self.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK, self.on_leftdclick)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
329
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
330
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
331 def on_leftdclick(self,evt):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
332 if self.CanEnableCellControl():
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
333 self.EnableCellEditControl()
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
334
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
335 def on_col_size(self, evt):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
336 col = evt.GetRowOrCol()
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
337 cells = self.rows[0].findall('cell')
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
338 size = self.GetColSize(col)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
339 cells[col].set('size',str(size))
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
340 evt.Skip()
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
341
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
342 def on_cell_change(self,evt):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
343 row = evt.GetRow()
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
344 col = evt.GetCol()
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
345 value = self.GetCellValue(row,col)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
346 cells = self.rows[row].findall('cell')
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
347 cells[col].text = value
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
348 if col == 0:
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
349 self.handler.refresh_rows()
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
350
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
351 def set_col_widths(self):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
352 cells = self.rows[0].findall('cell')
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
353 for i in range(0,len(cells)):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
354 try:
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
355 size = int(cells[i].get('size'))
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
356 self.SetColSize(i,size)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
357 except:
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
358 continue
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
359
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
360 def refresh_row(self,rowi):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
361 cells = self.rows[rowi].findall('cell')
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
362 for i in range(0,len(cells)):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
363 text = cells[i].text
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
364 if text == None or text == '':
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
365 text = ''
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
366 cells[i].text = text
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
367 self.SetCellValue(rowi,i,text)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
368
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
369 def add_row(self,evt=None):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
370 cols = self.GetNumberCols()
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
371 row = Element('row')
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
372 for i in range(0,cols):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
373 cell = Element('cell')
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
374 cell.text = ''
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
375 row.append(cell)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
376 self.handler.grid.append(row)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
377 self.AppendRows(1)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
378 self.rows = self.handler.grid.findall('row')
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
379 self.handler.refresh_rows()
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
380
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
381 def add_col(self,evt=None):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
382 for r in self.rows:
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
383 cell = Element('cell')
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
384 cell.text = ''
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
385 r.append(cell)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
386 self.AppendCols(1)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
387 self.set_col_widths()
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
388
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
389 def del_row(self,evt=None):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
390 num = self.GetNumberRows()
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
391 if num == 1:
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
392 return
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
393 self.handler.grid.remove(self.handler.grid[num-1])#always remove last row -- nasty
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
394 self.DeleteRows(num-1,1)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
395 self.rows = self.handler.grid.findall('row')
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
396 self.handler.refresh_rows()
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
397
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
398 def del_col(self,evt=None):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
399 num = self.GetNumberCols()
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
400 if num == 1:
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
401 return
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
402 for r in self.rows:
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
403 cells = r.findall('cell')
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
404 r.remove(r[num-1])# always remove the last column -- nasty
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
405 self.DeleteCols(num-1,1)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
406 self.set_col_widths()
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
407
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
408
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
409 G_TITLE = wx.NewId()
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
410 GRID_BOR = wx.NewId()
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
411 class rpg_grid_panel(wx.Panel):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
412 def __init__(self, parent, handler):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
413 wx.Panel.__init__(self, parent, -1)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
414 self.handler = handler
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
415 self.grid = rpg_grid(self,handler)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
416 label = handler.xml.get('name')
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
417 self.main_sizer = wx.BoxSizer(wx.VERTICAL)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
418 self.main_sizer.Add(wx.StaticText(self, -1, label+": "), 0, wx.EXPAND)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
419 self.main_sizer.Add(self.grid,1,wx.EXPAND)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
420 self.SetSizer(self.main_sizer)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
421 self.SetAutoLayout(True)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
422 self.Fit()
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
423 parent.SetSize(self.GetBestSize())
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
424
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
425
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
426 G_AUTO_SIZE = wx.NewId()
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
427 G_ADD_ROW = wx.NewId()
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
428 G_ADD_COL = wx.NewId()
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
429 G_DEL_ROW = wx.NewId()
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
430 G_DEL_COL = wx.NewId()
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
431
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
432 class rpg_grid_edit_panel(wx.Panel):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
433 def __init__(self, parent, handler):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
434 wx.Panel.__init__(self, parent, -1)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
435 self.handler = handler
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
436 self.grid = rpg_grid(self,handler)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
437 self.title = wx.TextCtrl(self, G_TITLE, handler.xml.get('name'))
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
438
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
439 radio_b = wx.RadioBox(self, GRID_BOR, "Border (HTML)", choices=["no","yes"])
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
440 border = handler.grid.get("border")
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
441 radio_b.SetSelection(int(border))
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
442
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
443 self.auto_size = wx.CheckBox(self, G_AUTO_SIZE, " Auto Size")
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
444 if handler.is_autosized() == '1':
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
445 self.auto_size.SetValue(True)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
446 else:
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
447 self.auto_size.SetValue(False)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
448
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
449 sizer = wx.BoxSizer(wx.HORIZONTAL)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
450 sizer.Add(wx.Button(self, G_ADD_ROW, "Add Row"), 1, wx.EXPAND)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
451 sizer.Add(wx.Size(10,10))
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
452 sizer.Add(wx.Button(self, G_DEL_ROW, "Remove Row"), 1, wx.EXPAND)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
453 sizer.Add(wx.Size(10,10))
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
454 sizer.Add(wx.Button(self, G_ADD_COL, "Add Column"), 1, wx.EXPAND)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
455 sizer.Add(wx.Size(10,10))
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
456 sizer.Add(wx.Button(self, G_DEL_COL, "Remove Column"), 1, wx.EXPAND)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
457
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
458 self.main_sizer = wx.StaticBoxSizer(wx.StaticBox(self,-1,"Grid"), wx.VERTICAL)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
459 self.main_sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
460 self.main_sizer.Add(self.title, 0, wx.EXPAND)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
461 self.main_sizer.Add(radio_b, 0, 0)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
462 self.main_sizer.Add(self.auto_size, 0, 0)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
463 self.main_sizer.Add(self.grid,1,wx.EXPAND)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
464 self.main_sizer.Add(sizer,0,wx.EXPAND)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
465
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
466 self.SetSizer(self.main_sizer)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
467 self.SetAutoLayout(True)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
468 self.Fit()
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
469
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
470 self.Bind(wx.EVT_TEXT, self.on_text, id=G_TITLE)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
471 self.Bind(wx.EVT_BUTTON, self.grid.add_row, id=G_ADD_ROW)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
472 self.Bind(wx.EVT_BUTTON, self.grid.del_row, id=G_DEL_ROW)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
473 self.Bind(wx.EVT_BUTTON, self.grid.add_col, id=G_ADD_COL)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
474 self.Bind(wx.EVT_BUTTON, self.grid.del_col, id=G_DEL_COL)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
475 self.Bind(wx.EVT_RADIOBOX, self.on_radio_box, id=GRID_BOR)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
476 self.Bind(wx.EVT_CHECKBOX, self.on_auto_size, id=G_AUTO_SIZE)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
477
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
478 def on_auto_size(self,evt):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
479 self.handler.set_autosize(bool2int(evt.Checked()))
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
480
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
481 def on_radio_box(self,evt):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
482 id = evt.GetId()
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
483 index = evt.GetInt()
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
484 if id == GRID_BOR:
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
485 self.handler.grid.set("border",str(index))
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
486
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
487 def on_text(self,evt):
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
488 txt = self.title.GetValue()
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
489 if txt != "":
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
490 self.handler.xml.set('name',txt)
90d19eb43830 Traipse Alpha 'OpenRPG' {091003-03}
sirebral
parents: 130
diff changeset
491 self.handler.rename(txt)