annotate orpg/gametree/nodehandlers/rpg_grid.py @ 28:ff154cf3350c ornery-orc

Traipse 'OpenRPG' {100203-00} 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 (Stable) New Features: New Bookmarks Feature New 'boot' command to remote admin New confirmation window for sent nodes Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG New Zoom Mouse plugin added New Images added to Plugin UI Switching to Element Tree New Map efficiency, from FlexiRPG New Status Bar to Update Manager New TrueDebug Class in orpg_log (See documentation for usage) New Portable Mercurial New Tip of the Day, from Core and community New Reference Syntax added for custom PC sheets New Child Reference for gametree New Parent Reference for gametree New Gametree Recursion method, mapping, context sensitivity, and effeciency.. New Features node with bonus nodes and Node Referencing help added New Dieroller structure from Core New DieRoller portability for odd Dice New 7th Sea die roller; ie [7k3] = [7d10.takeHighest(3).open(10)] New 'Mythos' System die roller added New vs. die roller method for WoD; ie [3v3] = [3d10.vs(3)]. Included for Mythos roller also New Warhammer FRPG Die Roller (Special thanks to Puu-san for the support) New EZ_Tree Reference system. Push a button, Traipse the tree, get a reference (Beta!) New Grids act more like Spreadsheets in Use mode, with Auto Calc Fixes: Fix to allow for portability to an OpenSUSE linux OS Fix to mplay_client for Fedora and OpenSUSE Fix to Text based Server Fix to Remote Admin Commands Fix to Pretty Print, from Core Fix to Splitter Nodes not being created Fix to massive amounts of images loading, from Core Fix to Map from gametree not showing to all clients Fix to gametree about menus Fix to Password Manager check on startup Fix to PC Sheets from tool nodes. They now use the tabber_panel Fix to Whiteboard ID to prevent random line or text deleting. Fixes to Server, Remote Server, and Server GUI Fix to Update Manager; cleaner clode for saved repositories Fixes made to Settings Panel and now reactive settings when Ok is pressed Fixes to Alternity roller's attack roll. Uses a simple Tuple instead of a Splice Fix to Use panel of Forms and Tabbers. Now longer enters design mode Fix made Image Fetching. New fetching image and new failed image Fix to whiteboard ID's to prevent non updated clients from ruining the fix. default_manifest.xml renamed to default_upmana.xml
author sirebral
date Wed, 03 Feb 2010 22:16:49 -0600
parents 51428d30c59e
children fc48380f0c9f
rev   line source
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
1 # Copyright (C) 2000-2001 The OpenRPG Project
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
2 #
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
3 # openrpg-dev@lists.sourceforge.net
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
4 #
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
5 # This program is free software; you can redistribute it and/or modify
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
6 # it under the terms of the GNU General Public License as published by
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
7 # the Free Software Foundation; either version 2 of the License, or
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
8 # (at your option) any later version.
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
9 #
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
10 # This program is distributed in the hope that it will be useful,
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
13 # GNU General Public License for more details.
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
14 #
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
15 # You should have received a copy of the GNU General Public License
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
16 # along with this program; if not, write to the Free Software
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
18 # --
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
19 #
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
20 # File: rpg_grid.py
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
21 # Author: Chris Davis
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
22 # Maintainer:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
23 # Version:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
24 # $Id: rpg_grid.py,v Traipse 'Ornery-Orc' prof.ebral Exp $
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
25 #
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
26 # Description: The file contains code for the grid nodehanlers
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
27 #
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
29 __version__ = "$Id: rpg_grid.py,v Traipse 'Ornery-Orc' prof.ebral Exp $"
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
30
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
31 from core import *
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
32 from forms import *
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
33 from orpg.tools.orpg_log import debug
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
34 from orpg.tools.InterParse import Parse
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
35
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
36 class rpg_grid_handler(node_handler):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
37 """ Node handler for rpg grid tool
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
38 <nodehandler module='rpg_grid' class='rpg_grid_handler' name='sample'>
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
39 <grid border='' autosize='1' >
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
40 <row>
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
41 <cell size='?'></cell>
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
42 <cell></cell>
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
43 </row>
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
44 <row>
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
45 <cell></cell>
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
46 <cell></cell>
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
47 </row>
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
48 </grid>
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
49 <macros>
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
50 <macro name=''/>
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
51 </macros>
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
52 </nodehandler>
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
53 """
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
54 def __init__(self,xml,tree_node):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
55 node_handler.__init__(self,xml,tree_node)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
56 self.grid = self.xml.find('grid')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
57 if self.grid.get("border") == "": self.grid.set("border","1")
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
58 if self.grid.get("autosize") == "": self.grid.set("autosize","1")
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
59 self.macros = self.xml.find('macros')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
60 self.myeditor = None
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
61 self.refresh_rows()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
62
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
63 def refresh_die_macros(self):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
64 pass
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
65
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
66 def refresh_rows(self):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
67 self.rows = {}
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
68 tree = self.tree
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
69 icons = self.tree.icons
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
70 tree.CollapseAndReset(self.mytree_node)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
71 for row in self.grid.findall('row'):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
72 first_cell = row.find('cell')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
73 name = first_cell.text
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
74 if name == None or name == '': name = "Row"
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
75 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear'])
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
76 handler = grid_row_handler(row,new_tree_node,self)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
77 tree.SetPyData(new_tree_node,handler)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
78
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
79 def tohtml(self):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
80 border = self.grid.get("border")
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
81 name = self.xml.get('name')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
82 rows = self.grid.findall('row')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
83 colspan = str(len(rows[0].findall('cell')))
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
84 html_str = "<table border=\""+border+"\" align=center><tr bgcolor=\""+TH_BG+"\" ><th colspan="+colspan+">"+name+"</th></tr>"
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
85 for r in rows:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
86 cells = r.findall('cell')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
87 html_str += "<tr>"
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
88 for c in cells:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
89 html_str += "<td >"
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
90 text = c.text
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
91 if text == None or text == '': text = '<br />'
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
92 s = Parse.NodeMap(text, self.xml)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
93 s = Parse.Normalize(s)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
94 try: text = str(eval(s))
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
95 except: text = s
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
96 html_str += text + "</td>"
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
97 html_str += "</tr>"
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
98 html_str += "</table>"
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
99 return html_str
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
100
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
101 def get_design_panel(self,parent):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
102 return rpg_grid_edit_panel(parent, self)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
103
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
104 def get_use_panel(self,parent):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
105 return rpg_grid_panel(parent, self)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
106
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
107 def get_size_constraint(self):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
108 return 1
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
109
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
110 def is_autosized(self):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
111 return self.grid.get("autosize")
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
112
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
113 def set_autosize(self,autosize=1):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
114 self.grid.set("autosize",str(autosize))
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
115
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
116 class grid_row_handler(node_handler):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
117 """ Node Handler grid row.
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
118 """
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
119 def __init__(self,xml,tree_node,parent):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
120 node_handler.__init__(self,xml,tree_node)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
121 self.drag = False
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
122
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
123 def on_drop(self,evt):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
124 pass
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
125
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
126 def can_clone(self):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
127 return 0;
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
128
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
129 def tohtml(self):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
130 cells = self.xml.findall('cell')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
131 html_str = "<table border=1 align=center><tr >"
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
132 for c in cells: # should loop over rows first, then cells
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
133 html_str += "<td >"
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
134 text = c.text
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
135 if text == '' or text is None: text = '<br />'
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
136 html_str += text + "</td>"
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
137 html_str += "</tr>"
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
138 html_str += "</table>"
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
139 return html_str
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
140
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
141 def get_value(self):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
142 cells = self.xml.findall('cell')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
143 if len(cells) == 2: return getText(cells[1])
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
144 else: return None
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
145
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
146 def set_value(self, new_value):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
147 cells = self.xml.findall('cell')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
148 if len(cells) == 2:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
149 cells[1].text = new_value
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
150
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
151 class MyCellEditor(wx.grid.PyGridCellEditor):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
152 """
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
153 This is a sample GridCellEditor that shows you how to make your own custom
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
154 grid editors. All the methods that can be overridden are show here. The
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
155 ones that must be overridden are marked with "*Must Override*" in the
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
156 docstring.
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
157
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
158 Notice that in order to call the base class version of these special
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
159 methods we use the method name preceded by "base_". This is because these
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
160 methods are "virtual" in C++ so if we try to call wxGridCellEditor.Create
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
161 for example, then when the wxPython extension module tries to call
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
162 ptr->Create(...) then it actually calls the derived class version which
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
163 looks up the method in this class and calls it, causing a recursion loop.
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
164 If you don't understand any of this, don't worry, just call the "base_"
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
165 version instead.
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
166
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
167 ----------------------------------------------------------------------------
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
168 This class is copied from the wxPython examples directory and was written by
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
169 Robin Dunn.
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
170
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
171 I have pasted it directly in and removed all references to "log"
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
172
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
173 -- Andrew
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
174
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
175 """
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
176 def __init__(self):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
177 wx.grid.PyGridCellEditor.__init__(self)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
178
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
179 def Create(self, parent, id, evtHandler):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
180 """
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
181 Called to create the control, which must derive from wxControl.
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
182 *Must Override*
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
183 """
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
184 self._tc = wx.TextCtrl(parent, id, "", style=wx.TE_PROCESS_ENTER | wx.TE_PROCESS_TAB)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
185 self._tc.SetInsertionPoint(0)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
186 self.SetControl(self._tc)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
187 if evtHandler: self._tc.PushEventHandler(evtHandler)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
188
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
189 def SetSize(self, rect):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
190 """
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
191 Called to position/size the edit control within the cell rectangle.
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
192 If you don't fill the cell (the rect) then be sure to override
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
193 PaintBackground and do something meaningful there.
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
194 """
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
195 self._tc.SetDimensions(rect.x+1, rect.y+1, rect.width+2, rect.height+2)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
196
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
197 def BeginEdit(self, row, col, grid):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
198 """
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
199 Fetch the value from the table and prepare the edit control
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
200 to begin editing. Set the focus to the edit control.
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
201 *Must Override*
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
202 """
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
203 #self.startValue = grid.GetTable().GetValue(row, col)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
204 self.startValue = grid.get_value(row, col)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
205 self._tc.SetValue(self.startValue)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
206 self._tc.SetInsertionPointEnd()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
207 self._tc.SetFocus()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
208
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
209 # For this example, select the text
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
210 self._tc.SetSelection(0, self._tc.GetLastPosition())
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
211
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
212 def EndEdit(self, row, col, grid):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
213 """
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
214 Complete the editing of the current cell. Returns True if the value
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
215 has changed. If necessary, the control may be destroyed.
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
216 *Must Override*
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
217 """
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
218 changed = False
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
219 val = self._tc.GetValue()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
220 if val != self.startValue:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
221 changed = True
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
222 grid.GetTable().SetValue(row, col, val) # update the table
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
223 self.startValue = ''
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
224 self._tc.SetValue('')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
225 return changed
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
226
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
227 def Reset(self):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
228 """
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
229 Reset the value in the control back to its starting value.
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
230 *Must Override*
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
231 """
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
232 self._tc.SetValue(self.startValue)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
233 self._tc.SetInsertionPointEnd()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
234
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
235 def IsAcceptedKey(self, evt):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
236 """
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
237 Return True to allow the given key to start editing: the base class
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
238 version only checks that the event has no modifiers. F2 is special
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
239 and will always start the editor.
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
240 """
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
241 return (not (evt.ControlDown() or evt.AltDown()) and
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
242 evt.GetKeyCode() != wx.WXK_SHIFT)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
243
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
244 def StartingKey(self, evt):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
245 """
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
246 If the editor is enabled by pressing keys on the grid, this will be
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
247 called to let the editor do something about that first key if desired.
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
248 """
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
249 key = evt.GetKeyCode()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
250 ch = None
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
251 if key in [wx.WXK_NUMPAD0, wx.WXK_NUMPAD1, wx.WXK_NUMPAD2, wx.WXK_NUMPAD3, wx.WXK_NUMPAD4,
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
252 wx.WXK_NUMPAD5, wx.WXK_NUMPAD6, wx.WXK_NUMPAD7, wx.WXK_NUMPAD8, wx.WXK_NUMPAD9]:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
253 ch = ch = chr(ord('0') + key - wx.WXK_NUMPAD0)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
254 elif key < 256 and key >= 0 and chr(key) in string.printable:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
255 ch = chr(key)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
256 if not evt.ShiftDown(): ch = string.lower(ch)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
257 if ch is not None: self._tc.AppendText(ch)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
258 else: evt.Skip()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
259
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
260 def Destroy(self):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
261 """final cleanup"""
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
262 self.base_Destroy()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
263
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
264 def Clone(self):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
265 """
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
266 Create a new object which is the copy of this one
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
267 *Must Override*
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
268 """
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
269 return MyCellEditor()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
270
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
271
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
272 class rpg_grid(wx.grid.Grid):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
273 """grid for attacks"""
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
274 def __init__(self, parent, handler, mode):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
275 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
276 self.parent = parent
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
277 self.handler = handler
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
278 self.mode = mode
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
279 self.RegisterDataType(wx.grid.GRID_VALUE_STRING, wx.grid.GridCellStringRenderer(),MyCellEditor())
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
280
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
281 self.rows = handler.grid.findall('row')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
282 rows = len(self.rows)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
283 cols = len(self.rows[0].findall('cell'))
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
284 self.CreateGrid(rows,cols)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
285 self.SetRowLabelSize(0)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
286 self.SetColLabelSize(0)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
287 self.set_col_widths()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
288
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
289 for i in range(0,len(self.rows)): self.refresh_row(i)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
290
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
291 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
292 self.Bind(wx.grid.EVT_GRID_COL_SIZE, self.on_col_size)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
293 self.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK, self.on_leftdclick)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
294
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
295 def on_leftdclick(self,evt):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
296 if self.CanEnableCellControl(): self.EnableCellEditControl()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
297
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
298 def on_col_size(self, evt):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
299 col = evt.GetRowOrCol()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
300 cells = self.rows[0].findall('cell')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
301 size = self.GetColSize(col)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
302 cells[col].set('size',str(size))
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
303 evt.Skip()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
304
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
305 def on_cell_change(self,evt):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
306 row = evt.GetRow()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
307 col = evt.GetCol()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
308 value = self.GetCellValue(row,col)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
309 cells = self.rows[row].findall('cell')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
310 cells[col].text = value
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
311 if col == 0: self.handler.refresh_rows()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
312 for i in range(0,len(self.rows)): self.refresh_row(i)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
313
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
314 def set_col_widths(self):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
315 cells = self.rows[0].findall('cell')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
316 for i in range(0,len(cells)):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
317 try:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
318 size = int(cells[i].get('size'))
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
319 self.SetColSize(i,size)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
320 except: continue
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
321
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
322 def refresh_row(self, rowi):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
323 cells = self.rows[rowi].findall('cell')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
324 for i in range(0,len(cells)):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
325 text = cells[i].text
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
326 if text == None or text == '':
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
327 text = ''
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
328 cells[i].text = text
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
329 if self.mode == 0:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
330 s = Parse.NodeMap(text, self.handler.xml)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
331 s = Parse.NodeParent(s, self.handler.xml.get('map'))
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
332 try: text = str(eval(s))
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
333 except: text = s
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
334 self.SetCellValue(rowi,i,text)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
335
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
336 def add_row(self,evt=None):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
337 cols = self.GetNumberCols()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
338 row = Element('row')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
339 for i in range(0,cols):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
340 cell = Element('cell')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
341 cell.text = ''
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
342 row.append(cell)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
343 self.handler.grid.append(row)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
344 self.AppendRows(1)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
345 self.rows = self.handler.grid.findall('row')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
346 self.handler.refresh_rows()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
347
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
348 def add_col(self,evt=None):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
349 for r in self.rows:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
350 cell = Element('cell')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
351 cell.text = ''
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
352 r.append(cell)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
353 self.AppendCols(1)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
354 self.set_col_widths()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
355
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
356 def del_row(self,evt=None):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
357 num = self.GetNumberRows()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
358 if num == 1: return
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
359 self.handler.grid.remove(self.handler.grid[num-1])# always remove last row -- nasty
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
360 self.DeleteRows(num-1,1)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
361 self.rows = self.handler.grid.findall('row')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
362 self.handler.refresh_rows()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
363
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
364 def del_col(self,evt=None):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
365 num = self.GetNumberCols()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
366 if num == 1: return
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
367 for r in self.rows:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
368 cells = r.findall('cell')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
369 r.remove(r[num-1]) # always remove the last column -- nasty
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
370 self.DeleteCols(num-1,1)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
371 self.set_col_widths()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
372
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
373 def get_value(self, row, col):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
374 cells = self.rows[row].findall('cell')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
375 return cells[col].text
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
376
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
377
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
378 G_TITLE = wx.NewId()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
379 GRID_BOR = wx.NewId()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
380 class rpg_grid_panel(wx.Panel):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
381 def __init__(self, parent, handler):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
382 wx.Panel.__init__(self, parent, -1)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
383 self.handler = handler
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
384 self.grid = rpg_grid(self, handler, mode=0)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
385 label = handler.xml.get('name')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
386 self.main_sizer = wx.BoxSizer(wx.VERTICAL)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
387 self.main_sizer.Add(wx.StaticText(self, -1, label+": "), 0, wx.EXPAND)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
388 self.main_sizer.Add(self.grid,1,wx.EXPAND)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
389 self.SetSizer(self.main_sizer)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
390 self.SetAutoLayout(True)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
391 self.Fit()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
392 parent.SetSize(self.GetBestSize())
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
393
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
394 G_AUTO_SIZE = wx.NewId()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
395 G_ADD_ROW = wx.NewId()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
396 G_ADD_COL = wx.NewId()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
397 G_DEL_ROW = wx.NewId()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
398 G_DEL_COL = wx.NewId()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
399 G_BUT_REF = wx.NewId()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
400
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
401 class rpg_grid_edit_panel(wx.Panel):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
402 def __init__(self, parent, handler):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
403 wx.Panel.__init__(self, parent, -1)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
404 self.handler = handler
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
405 self.parent = parent
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
406 self.grid = rpg_grid(self,handler, mode=1)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
407 self.main_sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Grid"), wx.VERTICAL)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
408
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
409 self.title = wx.TextCtrl(self, G_TITLE, handler.xml.get('name'))
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
410
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
411 radio_b = wx.RadioBox(self, GRID_BOR, "Border (HTML)", choices=["no","yes"])
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
412 border = handler.grid.get("border")
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
413 radio_b.SetSelection(int(border))
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
414
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
415 self.auto_size = wx.CheckBox(self, G_AUTO_SIZE, "Auto Size")
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
416 if handler.is_autosized() == '1': self.auto_size.SetValue(True)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
417 else: self.auto_size.SetValue(False)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
418
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
419 sizer = wx.BoxSizer(wx.HORIZONTAL)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
420 sizer.Add(wx.Button(self, G_ADD_ROW, "Add Row"), 1, wx.EXPAND)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
421 sizer.Add(wx.Size(10,10))
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
422 sizer.Add(wx.Button(self, G_DEL_ROW, "Remove Row"), 1, wx.EXPAND)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
423 sizer.Add(wx.Size(10,10))
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
424 sizer.Add(wx.Button(self, G_ADD_COL, "Add Column"), 1, wx.EXPAND)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
425 sizer.Add(wx.Size(10,10))
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
426 sizer.Add(wx.Button(self, G_DEL_COL, "Remove Column"), 1, wx.EXPAND)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
427 sizer.Add(wx.Size(10,10))
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
428 sizer.Add(wx.Button(self, G_BUT_REF, "Reference"), 1)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
429
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
430 self.main_sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
431 self.main_sizer.Add(self.title, 0, wx.EXPAND)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
432 self.main_sizer.Add(radio_b, 0, 0)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
433 self.main_sizer.Add(self.auto_size, 0, 0)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
434 self.main_sizer.Add(self.grid,1,wx.EXPAND)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
435 self.main_sizer.Add(sizer,0,wx.EXPAND)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
436
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
437 self.SetSizer(self.main_sizer)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
438 self.SetAutoLayout(True)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
439 self.Fit()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
440
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
441 self.Bind(wx.EVT_TEXT, self.on_text, id=G_TITLE)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
442 self.Bind(wx.EVT_BUTTON, self.grid.add_row, id=G_ADD_ROW)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
443 self.Bind(wx.EVT_BUTTON, self.grid.del_row, id=G_DEL_ROW)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
444 self.Bind(wx.EVT_BUTTON, self.grid.add_col, id=G_ADD_COL)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
445 self.Bind(wx.EVT_BUTTON, self.grid.del_col, id=G_DEL_COL)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
446 self.Bind(wx.EVT_RADIOBOX, self.on_radio_box, id=GRID_BOR)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
447 self.Bind(wx.EVT_CHECKBOX, self.on_auto_size, id=G_AUTO_SIZE)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
448 self.Bind(wx.EVT_BUTTON, self.on_reference, id=G_BUT_REF)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
449 self.parent.Bind(wx.EVT_CLOSE, self.tree_failsafe)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
450
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
451 ## EZ_Tree Core TaS - Prof.Ebral ##
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
452 def on_reference(self, evt, car=None):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
453 self.do_tree = wx.Frame(self, -1, 'EZ Tree')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
454 self.ez_tree = orpg.gametree.gametree
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
455 self.temp_wnd = self.ez_tree.game_tree(self.do_tree, self.ez_tree.EZ_REF)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
456 self.temp_wnd.Bind(wx.EVT_LEFT_DCLICK, self.on_ldclick) ## Remove for Alpha ##
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
457 component.get('tree_fs').save_tree(settings.get("gametree"))
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
458 self.temp_wnd.load_tree(settings.get("gametree"))
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
459 self.do_tree.Show()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
460
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
461 def tree_failsafe(self, evt):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
462 self.parent.Destroy()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
463 component.add('tree', component.get('tree_fs')) ## Backup
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
464
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
465 def get_grid_ref(self, obj, complete):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
466 self.temp_wnd.Freeze()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
467 self.grid_ref = complete
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
468 self.mini_grid = wx.Frame(self, -1, 'EZ Tree Mini Grid')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
469 self.temp_grid = obj.get_use_panel(self.mini_grid)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
470 self.temp_grid.grid.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK, self.on_grid_ldclick)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
471 self.mini_grid.Show()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
472
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
473 def on_grid_ldclick(self, evt):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
474 complete = self.grid_ref
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
475 row = str(evt.GetRow()+1)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
476 col = str(evt.GetCol()+1)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
477 complete = complete[:len(complete)-2] + '::'+'('+row+','+col+')'+complete[len(complete)-2:]
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
478 col = self.grid.GetGridCursorCol()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
479 row = self.grid.GetGridCursorRow()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
480 temp_value = self.grid.GetCellValue(row, col)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
481 complete = temp_value + complete
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
482 self.grid.SetCellValue(row, col, complete)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
483 cells = self.grid.rows[row].findall('cell')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
484 cells[col].text = complete
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
485 self.mini_grid.Destroy()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
486
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
487 def on_ldclick(self, evt):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
488 self.rename_flag = 0
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
489 pt = evt.GetPosition()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
490 (item, flag) = self.temp_wnd.HitTest(pt)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
491 if item.IsOk():
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
492 obj = self.temp_wnd.GetPyData(item)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
493 self.temp_wnd.SelectItem(item)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
494 start = self.handler.xml.get('map').split('::')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
495 end = obj.xml.get('map').split('::')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
496 if obj.xml.get('class') not in ['rpg_grid_handler', 'textctrl_handler']: do = 'None'
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
497 elif end[0] == '' or start[0] != end[0]: do = 'Root'
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
498 elif start == end: do = 'Child'
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
499 elif start != end: do = 'Parent'
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
500 if do == 'Root':
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
501 complete = "!@"
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
502 for e in end:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
503 if e != '': complete += e +'::'
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
504 complete = complete + obj.xml.get('name') + '@!'
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
505 elif do == 'Parent':
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
506 while start[0] == end[0]:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
507 del end[0], start[0]
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
508 if len(start) == 0 or len(end) == 0: break
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
509 complete = "!#"
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
510 for e in end: complete += e +'::'
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
511 complete = complete + obj.xml.get('name') + '#!'
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
512 elif do == 'Child':
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
513 while start[0] == end[0]:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
514 del end[0], start[0]
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
515 if len(start) == 0 or len(end) == 0: break
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
516 complete = "!!"
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
517 for e in end: complete += e +'::'
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
518 complete = complete + obj.xml.get('name') + '!!'
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
519 if do != 'None':
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
520 if obj.xml.get('class') == 'rpg_grid_handler':
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
521 self.get_grid_ref(obj, complete)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
522 else:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
523 col = self.grid.GetGridCursorCol()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
524 row = self.grid.GetGridCursorRow()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
525 temp_value = self.grid.GetCellValue(row, col)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
526 complete = temp_value + complete
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
527 self.grid.SetCellValue(row, col, complete)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
528 cells = self.grid.rows[row].findall('cell')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
529 cells[col].text = complete
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
530 self.do_tree.Destroy()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
531 if do == 'None':
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
532 wx.MessageBox('Invalid Reference', 'Error')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
533 ##### #####
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
534
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
535 def on_auto_size(self,evt):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
536 self.handler.set_autosize(bool2int(evt.Checked()))
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
537
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
538 def on_radio_box(self,evt):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
539 id = evt.GetId()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
540 index = evt.GetInt()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
541 if id == GRID_BOR:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
542 self.handler.grid.set("border",str(index))
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
543
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
544 def on_text(self,evt):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
545 txt = self.title.GetValue()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
546 if txt != "":
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
547 self.handler.xml.set('name',txt)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
548 self.handler.rename(txt)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
549
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
550 def refresh_row(self,rowi):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
551 cells = self.rows[rowi].findall('cell')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
552 for i in range(0,len(cells)):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
553 text = cells[i].text
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
554 #s = component.get('chat').ParseMap(s, self.handler.xml)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
555 #try: text = str(eval(s))
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
556 #except: text = s
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
557 if text == None or text == '':
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
558 text = ''
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
559 cells[i].text = text
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
560 self.SetCellValue(rowi,i,text)