comparison orpg/gametree/nodehandlers/containers.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
comparison
equal deleted inserted replaced
130:d54e1328dbb1 131:90d19eb43830
26 # Description: The file contains code for the container nodehandlers 26 # Description: The file contains code for the container nodehandlers
27 # 27 #
28 28
29 29
30 from core import * 30 from core import *
31 import wx.lib.splitter 31 from wx.lib.splitter import MultiSplitterWindow
32 32
33 33
34 ########################## 34 ##########################
35 ## base contiainer 35 ## base contiainer
36 ########################## 36 ##########################
37 37
38 class container_handler(node_handler): 38 class container_handler(node_handler):
39 """ should not be used! only a base class! 39 """ should not be used! only a base class!
40 <nodehandler name='?' module='core' class='container_handler' /> 40 <nodehandler name='?' module='core' class='container_handler' />
41 """ 41 """
42 def __init__(self,xml,tree_node): 42 def __init__(self, xml, tree_node):
43 node_handler.__init__(self,xml,tree_node) 43 node_handler.__init__(self, xml, tree_node)
44 self.load_children() 44 self.load_children()
45 45
46 def load_children(self): 46 def load_children(self):
47 for child_xml in self.xml: 47 for child_xml in self.xml:
48 self.tree.load_xml(child_xml,self.mytree_node) 48 self.tree.load_xml(child_xml,self.mytree_node)
51 node = self.tree.GetPyData(treenode) 51 node = self.tree.GetPyData(treenode)
52 if hasattr(node,"map_aware") and node.map_aware(): 52 if hasattr(node,"map_aware") and node.map_aware():
53 node.on_send_to_map(evt) 53 node.on_send_to_map(evt)
54 54
55 def on_send_to_map(self, evt): 55 def on_send_to_map(self, evt):
56 self.tree.traverse(self.mytree_node, self.check_map_aware, evt) 56 self.tree.traverse(self.mytree_node, self.check_map_aware, evt)
57 57
58 def checkChildToMap(self, treenode, evt): 58 def checkChildToMap(self, treenode, evt):
59 node = self.tree.GetPyData(treenode) 59 node = self.tree.GetPyData(treenode)
60 if hasattr(node,"map_aware") and node.map_aware(): 60 if hasattr(node,"map_aware") and node.map_aware():
61 self.mapcheck = True 61 self.mapcheck = True
79 node_handler.on_drop(self,evt) 79 node_handler.on_drop(self,evt)
80 80
81 def gen_html(self, treenode, evt): 81 def gen_html(self, treenode, evt):
82 node = self.tree.GetPyData(treenode) 82 node = self.tree.GetPyData(treenode)
83 self.html_str += "<p>" + node.tohtml() 83 self.html_str += "<p>" + node.tohtml()
84 84
85 def tohtml(self): 85 def tohtml(self):
86 self.html_str = "<table border=\"1\" ><tr><td>" 86 self.html_str = "<table border=\"1\" ><tr><td>"
87 self.html_str += "<b>"+self.xml.get("name") + "</b>" 87 self.html_str += "<b>"+self.xml.get("name") + "</b>"
88 self.html_str += "</td></tr>\n" 88 self.html_str += "</td></tr>\n"
89 self.html_str += "<tr><td>" 89 self.html_str += "<tr><td>"
95 95
96 def get_size_constraint(self): 96 def get_size_constraint(self):
97 return 2 97 return 2
98 98
99 99
100
101
102 ########################## 100 ##########################
103 ## group node handler 101 ## group node handler
104 ########################## 102 ##########################
105 class group_handler(container_handler): 103 class group_handler(container_handler):
106 """ group nodehandler to be used as a placeholder for other nodehandlers. 104 """ group nodehandler to be used as a placeholder for other nodehandlers.
107 This handler will continue parsing child xml data. 105 This handler will continue parsing child xml data.
108 <nodehandler name='?' module='core' class='group_handler' /> 106 <nodehandler name='?' module='core' class='group_handler' />
109 """ 107 """
110 def __init__(self,xml,tree_node): 108 def __init__(self, xml, tree_node):
111 container_handler.__init__(self,xml,tree_node) 109 container_handler.__init__(self, xml, tree_node)
112 110
113 def load_children(self): 111 def load_children(self):
114 self.atts = None 112 self.atts = None
115 for child_xml in self.xml: 113 for child_xml in self.xml:
116 if child_xml.tag == "group_atts": 114 if child_xml.get == "group_atts": #having the group attributes as a child is bad!
117 self.atts = child_xml 115 self.xml.remove(child_xml)
118 else: 116 elif child_xml:
119 self.tree.load_xml(child_xml,self.mytree_node) 117 self.tree.load_xml(child_xml, self.mytree_node)
118 if not self.xml.get('cols'): self.xml.set('cols', '1')
119 if not self.xml.get('border'): self.xml.set('border', '1')
120 """
120 if not self.atts: 121 if not self.atts:
121 self.atts = ET.Element('group_atts') 122 self.atts = Element('group_atts')
122 self.atts.set("cols","1") 123 self.atts.set("cols","1")
123 self.atts.set("border","1") 124 self.atts.set("border","1")
124 self.xml.append(self.atts) 125 self.xml.append(self.atts)"""
125 126
126 def get_design_panel(self,parent): 127 def get_design_panel(self,parent):
127 return group_edit_panel(parent,self) 128 return group_edit_panel(parent,self)
128 129
129 def on_use(self,evt): 130 def on_use(self,evt):
137 self.i += 1 138 self.i += 1
138 if self.i >= self.cols: 139 if self.i >= self.cols:
139 self.i = 0 140 self.i = 0
140 141
141 def tohtml(self): 142 def tohtml(self):
142 cols = self.atts.get("cols") 143 cols = self.xml.get("cols")
143 border = self.atts.get("border") 144 border = self.xml.get("border")
144 self.html_str = "<table border=\""+border+"\" ><tr><td colspan=\""+cols+"\">" 145 self.html_str = "<table border=\""+border+"\" ><tr><td colspan=\""+cols+"\">"
145 self.html_str += "<font size=4>"+self.xml.get("name") + "</font>" 146 self.html_str += "<font size=4>"+self.xml.get("name") + "</font>"
146 self.html_str += "</td></tr>\n<tr>" 147 self.html_str += "</td></tr>\n<tr>"
147
148 self.cols = int(cols) 148 self.cols = int(cols)
149 self.i = 0 149 self.i = 0
150 self.tdatas = {} 150 self.tdatas = {}
151
152 self.tree.traverse(self.mytree_node, self.gen_html, recurse=False) 151 self.tree.traverse(self.mytree_node, self.gen_html, recurse=False)
153
154 for td in self.tdatas: 152 for td in self.tdatas:
155 self.html_str += "<td valign=\"top\" >" + self.tdatas[td] + "</td>\n"; 153 self.html_str += "<td valign=\"top\" >" + self.tdatas[td] + "</td>\n";
156 self.html_str += "</tr></table>" 154 self.html_str += "</tr></table>"
157 return self.html_str 155 return self.html_str
158 156
169 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND) 167 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
170 sizer.Add(self.text[P_TITLE], 0, wx.EXPAND) 168 sizer.Add(self.text[P_TITLE], 0, wx.EXPAND)
171 sizer.Add(wx.Size(10,10)) 169 sizer.Add(wx.Size(10,10))
172 170
173 radio_c = wx.RadioBox(self, GROUP_COLS, "Columns", choices=["1","2","3","4"]) 171 radio_c = wx.RadioBox(self, GROUP_COLS, "Columns", choices=["1","2","3","4"])
174 cols = handler.atts.get("cols") 172 cols = handler.xml.get("cols")
175 if cols != "": 173 if cols != "":
176 radio_c.SetSelection(int(cols)-1) 174 radio_c.SetSelection(int(cols)-1)
177 175
178 radio_b = wx.RadioBox(self, GROUP_BOR, "Border", choices=["no","yes"]) 176 radio_b = wx.RadioBox(self, GROUP_BOR, "Border", choices=["no","yes"])
179 border = handler.atts.get("border") 177 border = handler.xml.get("border")
180 if border != "": 178 if border != "":
181 radio_b.SetSelection(int(border)) 179 radio_b.SetSelection(int(border))
182 180
183 sizer.Add(radio_c, 0, wx.EXPAND) 181 sizer.Add(radio_c, 0, wx.EXPAND)
184 sizer.Add(wx.Size(10,10)) 182 sizer.Add(wx.Size(10,10))
196 194
197 def on_radio_box(self,evt): 195 def on_radio_box(self,evt):
198 id = evt.GetId() 196 id = evt.GetId()
199 index = evt.GetInt() 197 index = evt.GetInt()
200 if id == GROUP_COLS: 198 if id == GROUP_COLS:
201 self.handler.atts.set("cols",str(index+1)) 199 self.handler.xml.set("cols",str(index+1))
202 elif id == GROUP_BOR: 200 elif id == GROUP_BOR:
203 self.handler.atts.set("border",str(index)) 201 self.handler.xml.set("border",str(index))
204 202
205 def on_text(self,evt): 203 def on_text(self,evt):
206 id = evt.GetId() 204 id = evt.GetId()
207 if id == P_TITLE: 205 if id == P_TITLE:
208 txt = self.text[id].GetValue() 206 txt = self.text[id].GetValue()
216 ## tabber node handler 214 ## tabber node handler
217 ########################## 215 ##########################
218 class tabber_handler(container_handler): 216 class tabber_handler(container_handler):
219 """ <nodehandler name='?' module='containers' class='tabber_handler' />""" 217 """ <nodehandler name='?' module='containers' class='tabber_handler' />"""
220 218
221 def __init__(self,xml,tree_node): 219 def __init__(self, xml, tree_node):
222 container_handler.__init__(self,xml,tree_node) 220 container_handler.__init__(self, xml, tree_node)
223 221
224 def get_design_panel(self,parent): 222 def get_design_panel(self,parent):
225 return tabbed_panel(parent,self,1) 223 return tabbed_panel(parent,self,1)
226 224
227 def get_use_panel(self,parent): 225 def get_use_panel(self,parent):
237 235
238 parent.SetSize(self.GetBestSize()) 236 parent.SetSize(self.GetBestSize())
239 237
240 def pick_panel(self, treenode, mode): 238 def pick_panel(self, treenode, mode):
241 node = self.handler.tree.GetPyData(treenode) 239 node = self.handler.tree.GetPyData(treenode)
242 if mode == 1: 240 if mode == 1: panel = node.get_design_panel(self)
243 panel = node.get_design_panel(self) 241 else: panel = node.get_use_panel(self)
244 else:
245 panel = node.get_use_panel(self)
246
247 name = node.xml.get("name") 242 name = node.xml.get("name")
248 243 if panel: self.AddPage(panel, name, False)
249 if panel:
250 self.AddPage(panel, name, False)
251 244
252 ################################# 245 #################################
253 ## Splitter container 246 ## Splitter container
254 ################################# 247 #################################
255 248
260 container_handler.__init__(self,xml,tree_node) 253 container_handler.__init__(self,xml,tree_node)
261 254
262 def load_children(self): 255 def load_children(self):
263 self.atts = None 256 self.atts = None
264 for child_xml in self.xml: 257 for child_xml in self.xml:
265 if child_xml.tag == "splitter_atts": 258 if child_xml.tag == "splitter_atts": self.xml.remove(child_xml) #Same here!
266 self.atts = child_xml 259 elif child_xml: self.tree.load_xml(child_xml,self.mytree_node)
267 else: 260 if not self.xml.get('horizontal'): self.xml.set('horizontal', '0')
268 self.tree.load_xml(child_xml,self.mytree_node) 261 """if not self.atts:
269 if not self.atts: 262 self.atts = Element('splitter_atts')
270 self.atts = ET.Element('splitter_atts')
271 self.atts.set("horizontal","0") 263 self.atts.set("horizontal","0")
272 self.xml.append(self.atts) 264 self.xml.append(self.atts)"""
273 265
274 def get_design_panel(self,parent): 266 def get_design_panel(self,parent):
275 return self.build_splitter_wnd(parent, 1) 267 return self.build_splitter_wnd(parent, 1)
276 268
277 def get_use_panel(self,parent): 269 def get_use_panel(self,parent):
280 def on_drop(self,evt): 272 def on_drop(self,evt):
281 drag_obj = self.tree.drag_obj 273 drag_obj = self.tree.drag_obj
282 container_handler.on_drop(self,evt) 274 container_handler.on_drop(self,evt)
283 275
284 def build_splitter_wnd(self, parent, mode): 276 def build_splitter_wnd(self, parent, mode):
285 self.split = self.atts.get("horizontal") 277 self.split = self.xml.get("horizontal")
286 278
287 self.pane = splitter_panel(parent, self) 279 self.pane = splitter_panel(parent, self)
288 280
289 self.splitter = wx.lib.splitter.MultiSplitterWindow(self.pane, -1, style=wx.SP_LIVE_UPDATE|wx.SP_3DSASH|wx.SP_NO_XP_THEME) 281 self.splitter = MultiSplitterWindow(self.pane, -1, style=wx.SP_LIVE_UPDATE|wx.SP_3DSASH|wx.SP_NO_XP_THEME)
290 282
291 if self.split == '1': 283 if self.split == '1':
292 self.splitter.SetOrientation(wx.VERTICAL) 284 self.splitter.SetOrientation(wx.VERTICAL)
293 else: 285 else:
294 self.splitter.SetOrientation(wx.HORIZONTAL) 286 self.splitter.SetOrientation(wx.HORIZONTAL)
295 287
296 self.bestSizex = -1 288 self.bestSizex = -1
297 self.bestSizey = -1 289 self.bestSizey = -1
298 290
299 self.tree.traverse(self.mytree_node, self.doSplit, mode, False) 291 self.tree.traverse(self.mytree_node, self.doSplit, mode, False)
300 292
301 self.pane.sizer.Add(self.splitter, 1, wx.EXPAND) 293 self.pane.sizer.Add(self.splitter, 1, wx.EXPAND)
302 294
303 295
304 if mode != 1: 296 if mode != 1:
309 parent.SetSize(self.pane.GetSize()) 301 parent.SetSize(self.pane.GetSize())
310 return self.pane 302 return self.pane
311 303
312 def doSplit(self, treenode, mode): 304 def doSplit(self, treenode, mode):
313 node = self.tree.GetPyData(treenode) 305 node = self.tree.GetPyData(treenode)
314 if mode == 1: 306 if mode == 1: tmp = node.get_design_panel(self.splitter)
315 tmp = node.get_design_panel(self.splitter) 307 else: tmp = node.get_use_panel(self.splitter)
316 else:
317 tmp = node.get_use_panel(self.splitter)
318 308
319 if self.split == '1': 309 if self.split == '1':
320 sash = tmp.GetBestSize()[1]+1 310 sash = tmp.GetBestSize()[1]+1
321 self.bestSizey += sash+11 311 self.bestSizey += sash+11
322 if self.bestSizex < tmp.GetBestSize()[0]: 312 if self.bestSizex < tmp.GetBestSize()[0]:
337 wx.Panel.__init__(self, parent, -1) 327 wx.Panel.__init__(self, parent, -1)
338 self.handler = handler 328 self.handler = handler
339 sizer = wx.BoxSizer(wx.VERTICAL) 329 sizer = wx.BoxSizer(wx.VERTICAL)
340 330
341 self.hozCheck = wx.CheckBox(self, -1, "Horizontal Split") 331 self.hozCheck = wx.CheckBox(self, -1, "Horizontal Split")
342 hoz = self.handler.atts.get("horizontal") 332 hoz = self.handler.xml.get("horizontal")
343 333
344 if hoz == '1': 334 if hoz == '1':
345 self.hozCheck.SetValue(True) 335 self.hozCheck.SetValue(True)
346 #self.splitsize = wx.BoxSizer(wx.HORIZONTAL) 336 #self.splitsize = wx.BoxSizer(wx.HORIZONTAL)
347 else: 337 else:
359 self.Bind(wx.EVT_CHECKBOX, self.on_check_box, id=self.hozCheck.GetId()) 349 self.Bind(wx.EVT_CHECKBOX, self.on_check_box, id=self.hozCheck.GetId())
360 350
361 def on_check_box(self,evt): 351 def on_check_box(self,evt):
362 state = self.hozCheck.GetValue() 352 state = self.hozCheck.GetValue()
363 if state: 353 if state:
364 self.handler.atts.set("horizontal", "1") 354 self.handler.xml.set("horizontal", "1")
365 else: 355 else:
366 self.handler.atts.set("horizontal", "0") 356 self.handler.xml.set("horizontal", "0")