comparison orpg/gametree/nodehandlers/containers.py @ 135:dcf4fbe09b70 beta

Traipse Beta 'OpenRPG' {091010-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 (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!! **New Gamtree Recusion method, mapping, and context sensitivity. !!Alpha - Watch out for infinite loops!!
author sirebral
date Tue, 10 Nov 2009 14:11:28 -0600
parents 449a8900f9ac
children e842a5f1b775
comparison
equal deleted inserted replaced
101:394ebb3b6a0f 135:dcf4fbe09b70
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_dom,tree_node): 42 def __init__(self, xml, tree_node):
43 node_handler.__init__(self,xml_dom,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 children = self.master_dom._get_childNodes() 47 for child_xml in self.xml:
48 for c in children: 48 self.tree.load_xml(child_xml,self.mytree_node)
49 self.tree.load_xml(c,self.mytree_node) 49
50 50 def check_map_aware(self, treenode, evt):
51 def check_map_aware(self, obj, evt): 51 node = self.tree.GetPyData(treenode)
52 if hasattr(obj,"map_aware") and obj.map_aware(): 52 if hasattr(node,"map_aware") and node.map_aware():
53 obj.on_send_to_map(evt) 53 node.on_send_to_map(evt)
54
55 54
56 def on_send_to_map(self, evt): 55 def on_send_to_map(self, evt):
57 child = self.tree.GetFirstChild(self.mytree_node) 56 self.tree.traverse(self.mytree_node, self.check_map_aware, evt)
58 if child[0].IsOk(): 57
59 self.traverse(child[0], self.check_map_aware, 0, evt) 58 def checkChildToMap(self, treenode, evt):
60 59 node = self.tree.GetPyData(treenode)
61 60 if hasattr(node,"map_aware") and node.map_aware():
62 def checkChildToMap(self, obj, evt):
63 if hasattr(obj,"map_aware") and obj.map_aware():
64 self.mapcheck = True 61 self.mapcheck = True
65 62
66 def checkToMapMenu(self): 63 def checkToMapMenu(self):
67 self.mapcheck = False 64 self.mapcheck = False
68 child = self.tree.GetFirstChild(self.mytree_node) 65 self.tree.traverse(self.mytree_node, self.checkChildToMap)
69 if child[0].IsOk():
70 self.traverse(child[0], self.checkChildToMap, 0, self.mapcheck)
71
72 return self.mapcheck 66 return self.mapcheck
73 67
74 def on_drop(self,evt): 68 def on_drop(self,evt):
75 drag_obj = self.tree.drag_obj 69 drag_obj = self.tree.drag_obj
76 if drag_obj == self or self.tree.is_parent_node(self.mytree_node,drag_obj.mytree_node): 70 if drag_obj == self or self.tree.is_parent_node(self.mytree_node,drag_obj.mytree_node):
77 return 71 return
78 opt = wx.MessageBox("Add node as child?","Container Node",wx.YES_NO|wx.CANCEL) 72 opt = wx.MessageBox("Add node as child?","Container Node",wx.YES_NO|wx.CANCEL)
79 if opt == wx.YES: 73 if opt == wx.YES:
80 xml_dom = self.tree.drag_obj.delete() 74 drop_xml = self.tree.drag_obj.delete()
81 xml_dom = self.master_dom.insertBefore(xml_dom,None) 75 self.xml.insert(0, drop_xml)
82 self.tree.load_xml(xml_dom, self.mytree_node) 76 self.tree.load_xml(drop_xml, self.mytree_node)
83 self.tree.Expand(self.mytree_node) 77 self.tree.Expand(self.mytree_node)
84 elif opt == wx.NO: 78 elif opt == wx.NO:
85 node_handler.on_drop(self,evt) 79 node_handler.on_drop(self,evt)
86 80
87 def gen_html(self, obj, evt): 81 def gen_html(self, treenode, evt):
88 self.html_str += "<p>" + obj.tohtml() 82 node = self.tree.GetPyData(treenode)
89 83 self.html_str += "<p>" + node.tohtml()
84
90 def tohtml(self): 85 def tohtml(self):
91 self.html_str = "<table border=\"1\" ><tr><td>" 86 self.html_str = "<table border=\"1\" ><tr><td>"
92 self.html_str += "<b>"+self.master_dom.getAttribute("name") + "</b>" 87 self.html_str += "<b>"+self.xml.get("name") + "</b>"
93 self.html_str += "</td></tr>\n" 88 self.html_str += "</td></tr>\n"
94 self.html_str += "<tr><td>" 89 self.html_str += "<tr><td>"
95 90
96 child = self.tree.GetFirstChild(self.mytree_node) 91 self.tree.traverse(self.mytree_node, self.gen_html, recurse=False)
97 self.traverse(child[0], self.gen_html, 0, None)
98 92
99 self.html_str += "</td></tr></table>" 93 self.html_str += "</td></tr></table>"
100 return self.html_str 94 return self.html_str
101 95
102 def get_size_constraint(self): 96 def get_size_constraint(self):
109 class group_handler(container_handler): 103 class group_handler(container_handler):
110 """ group nodehandler to be used as a placeholder for other nodehandlers. 104 """ group nodehandler to be used as a placeholder for other nodehandlers.
111 This handler will continue parsing child xml data. 105 This handler will continue parsing child xml data.
112 <nodehandler name='?' module='core' class='group_handler' /> 106 <nodehandler name='?' module='core' class='group_handler' />
113 """ 107 """
114 def __init__(self,xml_dom,tree_node): 108 def __init__(self, xml, tree_node):
115 container_handler.__init__(self,xml_dom,tree_node) 109 container_handler.__init__(self, xml, tree_node)
116 110
117 def load_children(self): 111 def load_children(self):
118 self.atts = None 112 self.atts = None
119 children = self.master_dom._get_childNodes() 113 for child_xml in self.xml:
120 for c in children: 114 if child_xml.get == "group_atts": #having the group attributes as a child is bad!
121 if c._get_tagName() == "group_atts": 115 self.xml.remove(child_xml)
122 self.atts = c 116 elif child_xml:
123 else: 117 self.tree.load_xml(child_xml, self.mytree_node)
124 self.tree.load_xml(c,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 """
125 if not self.atts: 121 if not self.atts:
126 elem = self.xml.minidom.Element('group_atts') 122 self.atts = Element('group_atts')
127 elem.setAttribute("cols","1") 123 self.atts.set("cols","1")
128 elem.setAttribute("border","1") 124 self.atts.set("border","1")
129 self.atts = self.master_dom.appendChild(elem) 125 self.xml.append(self.atts)"""
130 126
131 def get_design_panel(self,parent): 127 def get_design_panel(self,parent):
132 return group_edit_panel(parent,self) 128 return group_edit_panel(parent,self)
133 129
134 def on_use(self,evt): 130 def on_use(self,evt):
135 return 131 return
136 132
137 def gen_html(self, obj, evt): 133 def gen_html(self, treenode, evt):
134 node = self.tree.GetPyData(treenode)
138 if self.i not in self.tdatas: 135 if self.i not in self.tdatas:
139 self.tdatas[self.i] = '' 136 self.tdatas[self.i] = ''
140 self.tdatas[self.i] += "<P>" + obj.tohtml() 137 self.tdatas[self.i] += "<P>" + node.tohtml()
141 self.i += 1 138 self.i += 1
142 if self.i >= self.cols: 139 if self.i >= self.cols:
143 self.i = 0 140 self.i = 0
144 141
145 def tohtml(self): 142 def tohtml(self):
146 cols = self.atts.getAttribute("cols") 143 cols = self.xml.get("cols")
147 border = self.atts.getAttribute("border") 144 border = self.xml.get("border")
148 self.html_str = "<table border=\""+border+"\" ><tr><td colspan=\""+cols+"\">" 145 self.html_str = "<table border=\""+border+"\" ><tr><td colspan=\""+cols+"\">"
149 self.html_str += "<font size=4>"+self.master_dom.getAttribute("name") + "</font>" 146 self.html_str += "<font size=4>"+self.xml.get("name") + "</font>"
150 self.html_str += "</td></tr>\n<tr>" 147 self.html_str += "</td></tr>\n<tr>"
151
152 self.cols = int(cols) 148 self.cols = int(cols)
153 self.i = 0 149 self.i = 0
154 self.tdatas = {} 150 self.tdatas = {}
155 151 self.tree.traverse(self.mytree_node, self.gen_html, recurse=False)
156 child = self.tree.GetFirstChild(self.mytree_node)
157 if child[0].IsOk():
158 self.traverse(child[0], self.gen_html, 0, None)
159
160 for td in self.tdatas: 152 for td in self.tdatas:
161 self.html_str += "<td valign=\"top\" >" + self.tdatas[td] + "</td>\n"; 153 self.html_str += "<td valign=\"top\" >" + self.tdatas[td] + "</td>\n";
162 self.html_str += "</tr></table>" 154 self.html_str += "</tr></table>"
163 return self.html_str 155 return self.html_str
164 156
168 class group_edit_panel(wx.Panel): 160 class group_edit_panel(wx.Panel):
169 def __init__(self, parent, handler): 161 def __init__(self, parent, handler):
170 wx.Panel.__init__(self, parent, -1) 162 wx.Panel.__init__(self, parent, -1)
171 self.handler = handler 163 self.handler = handler
172 sizer = wx.BoxSizer(wx.VERTICAL) 164 sizer = wx.BoxSizer(wx.VERTICAL)
173 self.text = { P_TITLE : wx.TextCtrl(self, P_TITLE, handler.master_dom.getAttribute('name')) 165 self.text = { P_TITLE : wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
174 } 166 }
175 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND) 167 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
176 sizer.Add(self.text[P_TITLE], 0, wx.EXPAND) 168 sizer.Add(self.text[P_TITLE], 0, wx.EXPAND)
177 sizer.Add(wx.Size(10,10)) 169 sizer.Add(wx.Size(10,10))
178 170
179 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"])
180 cols = handler.atts.getAttribute("cols") 172 cols = handler.xml.get("cols")
181 if cols != "": 173 if cols != "":
182 radio_c.SetSelection(int(cols)-1) 174 radio_c.SetSelection(int(cols)-1)
183 175
184 radio_b = wx.RadioBox(self, GROUP_BOR, "Border", choices=["no","yes"]) 176 radio_b = wx.RadioBox(self, GROUP_BOR, "Border", choices=["no","yes"])
185 border = handler.atts.getAttribute("border") 177 border = handler.xml.get("border")
186 if border != "": 178 if border != "":
187 radio_b.SetSelection(int(border)) 179 radio_b.SetSelection(int(border))
188 180
189 sizer.Add(radio_c, 0, wx.EXPAND) 181 sizer.Add(radio_c, 0, wx.EXPAND)
190 sizer.Add(wx.Size(10,10)) 182 sizer.Add(wx.Size(10,10))
202 194
203 def on_radio_box(self,evt): 195 def on_radio_box(self,evt):
204 id = evt.GetId() 196 id = evt.GetId()
205 index = evt.GetInt() 197 index = evt.GetInt()
206 if id == GROUP_COLS: 198 if id == GROUP_COLS:
207 self.handler.atts.setAttribute("cols",str(index+1)) 199 self.handler.xml.set("cols",str(index+1))
208 elif id == GROUP_BOR: 200 elif id == GROUP_BOR:
209 self.handler.atts.setAttribute("border",str(index)) 201 self.handler.xml.set("border",str(index))
210 202
211 def on_text(self,evt): 203 def on_text(self,evt):
212 id = evt.GetId() 204 id = evt.GetId()
213 if id == P_TITLE: 205 if id == P_TITLE:
214 txt = self.text[id].GetValue() 206 txt = self.text[id].GetValue()
215 if txt != "": 207 if txt != "":
216 self.handler.master_dom.setAttribute('name',txt) 208 self.handler.xml.set('name',txt)
217 self.handler.rename(txt) 209 self.handler.rename(txt)
218 210
219 211
220 212
221 ########################## 213 ##########################
222 ## tabber node handler 214 ## tabber node handler
223 ########################## 215 ##########################
224 class tabber_handler(container_handler): 216 class tabber_handler(container_handler):
225 """ <nodehandler name='?' module='containers' class='tabber_handler' />""" 217 """ <nodehandler name='?' module='containers' class='tabber_handler' />"""
226 218
227 def __init__(self,xml_dom,tree_node): 219 def __init__(self, xml, tree_node):
228 container_handler.__init__(self,xml_dom,tree_node) 220 container_handler.__init__(self, xml, tree_node)
229 221
230 def get_design_panel(self,parent): 222 def get_design_panel(self,parent):
231 return tabbed_panel(parent,self,1) 223 return tabbed_panel(parent,self,1)
232 224
233 def get_use_panel(self,parent): 225 def get_use_panel(self,parent):
237 class tabbed_panel(orpgTabberWnd): 229 class tabbed_panel(orpgTabberWnd):
238 def __init__(self, parent, handler, mode): 230 def __init__(self, parent, handler, mode):
239 orpgTabberWnd.__init__(self, parent, style=FNB.FNB_NO_X_BUTTON) 231 orpgTabberWnd.__init__(self, parent, style=FNB.FNB_NO_X_BUTTON)
240 self.handler = handler 232 self.handler = handler
241 self.parent = parent 233 self.parent = parent
242 tree = self.handler.tree 234 handler.tree.traverse(handler.mytree_node, self.pick_panel, mode, False)
243 child = tree.GetFirstChild(handler.mytree_node)
244 if child[0].IsOk():
245 handler.traverse(child[0], self.pick_panel, 0, mode, False)
246 235
247 parent.SetSize(self.GetBestSize()) 236 parent.SetSize(self.GetBestSize())
248 237
249 def pick_panel(self, obj, mode): 238 def pick_panel(self, treenode, mode):
250 if mode == 1: 239 node = self.handler.tree.GetPyData(treenode)
251 panel = obj.get_design_panel(self) 240 if mode == 1: panel = node.get_design_panel(self)
252 else: 241 else: panel = node.get_use_panel(self)
253 panel = obj.get_use_panel(self) 242 name = node.xml.get("name")
254 243 if panel: self.AddPage(panel, name, False)
255 name = obj.master_dom.getAttribute("name")
256
257 if panel:
258 self.AddPage(panel, name, False)
259 244
260 ################################# 245 #################################
261 ## Splitter container 246 ## Splitter container
262 ################################# 247 #################################
263 248
264 class splitter_handler(container_handler): 249 class splitter_handler(container_handler):
265 """ <nodehandler name='?' module='containers' class='splitter_handler' />""" 250 """ <nodehandler name='?' module='containers' class='splitter_handler' />"""
266 251
267 def __init__(self,xml_dom,tree_node): 252 def __init__(self,xml,tree_node):
268 container_handler.__init__(self,xml_dom,tree_node) 253 container_handler.__init__(self,xml,tree_node)
269 254
270 def load_children(self): 255 def load_children(self):
271 self.atts = None 256 self.atts = None
272 children = self.master_dom._get_childNodes() 257 for child_xml in self.xml:
273 for c in children: 258 if child_xml.tag == "splitter_atts": self.xml.remove(child_xml) #Same here!
274 if c._get_tagName() == "splitter_atts": 259 elif child_xml: self.tree.load_xml(child_xml,self.mytree_node)
275 self.atts = c 260 if not self.xml.get('horizontal'): self.xml.set('horizontal', '0')
276 else: 261 """if not self.atts:
277 self.tree.load_xml(c,self.mytree_node) 262 self.atts = Element('splitter_atts')
278 if not self.atts: 263 self.atts.set("horizontal","0")
279 elem = self.xml.minidom.Element('splitter_atts') 264 self.xml.append(self.atts)"""
280 elem.setAttribute("horizontal","0")
281 self.atts = self.master_dom.appendChild(elem)
282 265
283 def get_design_panel(self,parent): 266 def get_design_panel(self,parent):
284 return self.build_splitter_wnd(parent, 1) 267 return self.build_splitter_wnd(parent, 1)
285 268
286 def get_use_panel(self,parent): 269 def get_use_panel(self,parent):
289 def on_drop(self,evt): 272 def on_drop(self,evt):
290 drag_obj = self.tree.drag_obj 273 drag_obj = self.tree.drag_obj
291 container_handler.on_drop(self,evt) 274 container_handler.on_drop(self,evt)
292 275
293 def build_splitter_wnd(self, parent, mode): 276 def build_splitter_wnd(self, parent, mode):
294 self.split = self.atts.getAttribute("horizontal") 277 self.split = self.xml.get("horizontal")
295 278
296 self.pane = splitter_panel(parent, self) 279 self.pane = splitter_panel(parent, self)
297 280
298 self.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)
299 282
303 self.splitter.SetOrientation(wx.HORIZONTAL) 286 self.splitter.SetOrientation(wx.HORIZONTAL)
304 287
305 self.bestSizex = -1 288 self.bestSizex = -1
306 self.bestSizey = -1 289 self.bestSizey = -1
307 290
308 cookie = 0 291 self.tree.traverse(self.mytree_node, self.doSplit, mode, False)
309 (child, cookie) = self.tree.GetFirstChild(self.mytree_node)
310 if child.IsOk():
311 self.traverse(child, self.doSplit, 0, mode, False)
312 292
313 self.pane.sizer.Add(self.splitter, 1, wx.EXPAND) 293 self.pane.sizer.Add(self.splitter, 1, wx.EXPAND)
314 294
315 295
316 if mode != 1: 296 if mode != 1:
319 self.pane.SetSize((self.bestSizex, self.bestSizey)) 299 self.pane.SetSize((self.bestSizex, self.bestSizey))
320 self.pane.Layout() 300 self.pane.Layout()
321 parent.SetSize(self.pane.GetSize()) 301 parent.SetSize(self.pane.GetSize())
322 return self.pane 302 return self.pane
323 303
324 def doSplit(self, obj, mode): 304 def doSplit(self, treenode, mode):
325 if mode == 1: 305 node = self.tree.GetPyData(treenode)
326 tmp = obj.get_design_panel(self.splitter) 306 if mode == 1: tmp = node.get_design_panel(self.splitter)
327 else: 307 else: tmp = node.get_use_panel(self.splitter)
328 tmp = obj.get_use_panel(self.splitter)
329 308
330 if self.split == '1': 309 if self.split == '1':
331 sash = tmp.GetBestSize()[1]+1 310 sash = tmp.GetBestSize()[1]+1
332 self.bestSizey += sash+11 311 self.bestSizey += sash+11
333 if self.bestSizex < tmp.GetBestSize()[0]: 312 if self.bestSizex < tmp.GetBestSize()[0]:
348 wx.Panel.__init__(self, parent, -1) 327 wx.Panel.__init__(self, parent, -1)
349 self.handler = handler 328 self.handler = handler
350 sizer = wx.BoxSizer(wx.VERTICAL) 329 sizer = wx.BoxSizer(wx.VERTICAL)
351 330
352 self.hozCheck = wx.CheckBox(self, -1, "Horizontal Split") 331 self.hozCheck = wx.CheckBox(self, -1, "Horizontal Split")
353 hoz = self.handler.atts.getAttribute("horizontal") 332 hoz = self.handler.xml.get("horizontal")
354 333
355 if hoz == '1': 334 if hoz == '1':
356 self.hozCheck.SetValue(True) 335 self.hozCheck.SetValue(True)
357 #self.splitsize = wx.BoxSizer(wx.HORIZONTAL) 336 #self.splitsize = wx.BoxSizer(wx.HORIZONTAL)
358 else: 337 else:
370 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())
371 350
372 def on_check_box(self,evt): 351 def on_check_box(self,evt):
373 state = self.hozCheck.GetValue() 352 state = self.hozCheck.GetValue()
374 if state: 353 if state:
375 self.handler.atts.setAttribute("horizontal", "1") 354 self.handler.xml.set("horizontal", "1")
376 else: 355 else:
377 self.handler.atts.setAttribute("horizontal", "0") 356 self.handler.xml.set("horizontal", "0")