comparison orpg/gametree/nodehandlers/containers.py @ 118:217fb049bd00 alpha

Traipse Alpha 'OpenRPG' {091028-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: Adds Bookmarks (Alpha) with cool Smiley Star and Plus Symbol images! Changes made to the map for increased portability. SnowDog has changes planned in Core, though. Added an initial push to the BCG. Not much to see, just shows off how it is re-writing Main code. Fix to remote admin commands Minor fix to texted based server, works in /System/ folder Some Core changes to gametree to correctly disply Pretty Print, thanks David! Fix to Splitter Nodes not being created. Added images to Plugin Control panel for Autostart feature Fix to massive amounts of images loading; from Core fix to gsclient so with_statement imports Added 'boot' command to remote admin Prep work in Pass tool for remote admin rankings and different passwords, ei, Server, Admin, Moderator, etc. Remote Admin Commands more organized, more prep work. Added Confirmation window for sent nodes. Minor changes to allow for portability to an OpenSUSE linux OS (hopefully without breaking) {091028} 00: Made changes to gametree to start working with Element Tree, mostly from Core Minor changes to Map to start working with Element Tree, from Core Preliminary changes to map efficiency, from FlexiRPG Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG Changes to main.py to start working with Element Tree
author sirebral
date Wed, 28 Oct 2009 14:24:54 -0500
parents 0c936d98f9eb
children d54e1328dbb1
comparison
equal deleted inserted replaced
117:0f18d16f3fe7 118:217fb049bd00
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 self.traverse(self.mytree_node, self.check_map_aware, evt) 56 self.tree.traverse(self.mytree_node, self.check_map_aware, evt)
58 57
59 58 def checkChildToMap(self, treenode, evt):
60 def checkChildToMap(self, obj, evt): 59 node = self.tree.GetPyData(treenode)
61 if hasattr(obj,"map_aware") and obj.map_aware(): 60 if hasattr(node,"map_aware") and node.map_aware():
62 self.mapcheck = True 61 self.mapcheck = True
63 62
64 def checkToMapMenu(self): 63 def checkToMapMenu(self):
65 self.mapcheck = False 64 self.mapcheck = False
66 self.traverse(self.mytree_node, self.checkChildToMap) 65 self.tree.traverse(self.mytree_node, self.checkChildToMap)
67
68 return self.mapcheck 66 return self.mapcheck
69 67
70 def on_drop(self,evt): 68 def on_drop(self,evt):
71 drag_obj = self.tree.drag_obj 69 drag_obj = self.tree.drag_obj
72 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):
73 return 71 return
74 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)
75 if opt == wx.YES: 73 if opt == wx.YES:
76 xml_dom = self.tree.drag_obj.delete() 74 drop_xml = self.tree.drag_obj.delete()
77 xml_dom = self.master_dom.insertBefore(xml_dom,None) 75 self.xml.insert(0, drop_xml)
78 self.tree.load_xml(xml_dom, self.mytree_node) 76 self.tree.load_xml(drop_xml, self.mytree_node)
79 self.tree.Expand(self.mytree_node) 77 self.tree.Expand(self.mytree_node)
80 elif opt == wx.NO: 78 elif opt == wx.NO:
81 node_handler.on_drop(self,evt) 79 node_handler.on_drop(self,evt)
82 80
83 def gen_html(self, obj, evt): 81 def gen_html(self, treenode, evt):
84 self.html_str += "<p>" + obj.tohtml() 82 node = self.tree.GetPyData(treenode)
85 83 self.html_str += "<p>" + node.tohtml()
84
86 def tohtml(self): 85 def tohtml(self):
87 self.html_str = "<table border=\"1\" ><tr><td>" 86 self.html_str = "<table border=\"1\" ><tr><td>"
88 self.html_str += "<b>"+self.master_dom.getAttribute("name") + "</b>" 87 self.html_str += "<b>"+self.xml.get("name") + "</b>"
89 self.html_str += "</td></tr>\n" 88 self.html_str += "</td></tr>\n"
90 self.html_str += "<tr><td>" 89 self.html_str += "<tr><td>"
91 90
92 self.traverse(self.mytree_node, self.gen_html, recurse=False) 91 self.tree.traverse(self.mytree_node, self.gen_html, recurse=False)
93 92
94 self.html_str += "</td></tr></table>" 93 self.html_str += "</td></tr></table>"
95 return self.html_str 94 return self.html_str
96 95
97 def get_size_constraint(self): 96 def get_size_constraint(self):
104 class group_handler(container_handler): 103 class group_handler(container_handler):
105 """ group nodehandler to be used as a placeholder for other nodehandlers. 104 """ group nodehandler to be used as a placeholder for other nodehandlers.
106 This handler will continue parsing child xml data. 105 This handler will continue parsing child xml data.
107 <nodehandler name='?' module='core' class='group_handler' /> 106 <nodehandler name='?' module='core' class='group_handler' />
108 """ 107 """
109 def __init__(self,xml_dom,tree_node): 108 def __init__(self, xml, tree_node):
110 container_handler.__init__(self,xml_dom,tree_node) 109 container_handler.__init__(self, xml, tree_node)
111 110
112 def load_children(self): 111 def load_children(self):
113 self.atts = None 112 self.atts = None
114 children = self.master_dom._get_childNodes() 113 for child_xml in self.xml:
115 for c in children: 114 if child_xml.tag == "group_atts":
116 if c._get_tagName() == "group_atts": 115 self.atts = child_xml
117 self.atts = c
118 else: 116 else:
119 self.tree.load_xml(c,self.mytree_node) 117 self.tree.load_xml(child_xml,self.mytree_node)
120 if not self.atts: 118 if not self.atts:
121 elem = self.xml.minidom.Element('group_atts') 119 self.atts = Element('group_atts')
122 elem.setAttribute("cols","1") 120 self.atts.set("cols","1")
123 elem.setAttribute("border","1") 121 self.atts.set("border","1")
124 self.atts = self.master_dom.appendChild(elem) 122 self.xml.append(self.atts)
125 123
126 def get_design_panel(self,parent): 124 def get_design_panel(self,parent):
127 return group_edit_panel(parent,self) 125 return group_edit_panel(parent,self)
128 126
129 def on_use(self,evt): 127 def on_use(self,evt):
130 return 128 return
131 129
132 def gen_html(self, obj, evt): 130 def gen_html(self, treenode, evt):
131 node = self.tree.GetPyData(treenode)
133 if self.i not in self.tdatas: 132 if self.i not in self.tdatas:
134 self.tdatas[self.i] = '' 133 self.tdatas[self.i] = ''
135 self.tdatas[self.i] += "<P>" + obj.tohtml() 134 self.tdatas[self.i] += "<P>" + node.tohtml()
136 self.i += 1 135 self.i += 1
137 if self.i >= self.cols: 136 if self.i >= self.cols:
138 self.i = 0 137 self.i = 0
139 138
140 def tohtml(self): 139 def tohtml(self):
141 cols = self.atts.getAttribute("cols") 140 cols = self.atts.get("cols")
142 border = self.atts.getAttribute("border") 141 border = self.atts.get("border")
143 self.html_str = "<table border=\""+border+"\" ><tr><td colspan=\""+cols+"\">" 142 self.html_str = "<table border=\""+border+"\" ><tr><td colspan=\""+cols+"\">"
144 self.html_str += "<font size=4>"+self.master_dom.getAttribute("name") + "</font>" 143 self.html_str += "<font size=4>"+self.xml.get("name") + "</font>"
145 self.html_str += "</td></tr>\n<tr>" 144 self.html_str += "</td></tr>\n<tr>"
146
147 self.cols = int(cols) 145 self.cols = int(cols)
148 self.i = 0 146 self.i = 0
149 self.tdatas = {} 147 self.tdatas = {}
150 148 self.tree.traverse(self.mytree_node, self.gen_html, recurse=False)
151 self.traverse(self.mytree_node, self.gen_html, recurse=False)
152
153 for td in self.tdatas: 149 for td in self.tdatas:
154 self.html_str += "<td valign=\"top\" >" + self.tdatas[td] + "</td>\n"; 150 self.html_str += "<td valign=\"top\" >" + self.tdatas[td] + "</td>\n";
155 self.html_str += "</tr></table>" 151 self.html_str += "</tr></table>"
156 return self.html_str 152 return self.html_str
157 153
161 class group_edit_panel(wx.Panel): 157 class group_edit_panel(wx.Panel):
162 def __init__(self, parent, handler): 158 def __init__(self, parent, handler):
163 wx.Panel.__init__(self, parent, -1) 159 wx.Panel.__init__(self, parent, -1)
164 self.handler = handler 160 self.handler = handler
165 sizer = wx.BoxSizer(wx.VERTICAL) 161 sizer = wx.BoxSizer(wx.VERTICAL)
166 self.text = { P_TITLE : wx.TextCtrl(self, P_TITLE, handler.master_dom.getAttribute('name')) 162 self.text = { P_TITLE : wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
167 } 163 }
168 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND) 164 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
169 sizer.Add(self.text[P_TITLE], 0, wx.EXPAND) 165 sizer.Add(self.text[P_TITLE], 0, wx.EXPAND)
170 sizer.Add(wx.Size(10,10)) 166 sizer.Add(wx.Size(10,10))
171 167
172 radio_c = wx.RadioBox(self, GROUP_COLS, "Columns", choices=["1","2","3","4"]) 168 radio_c = wx.RadioBox(self, GROUP_COLS, "Columns", choices=["1","2","3","4"])
173 cols = handler.atts.getAttribute("cols") 169 cols = handler.atts.get("cols")
174 if cols != "": 170 if cols != "":
175 radio_c.SetSelection(int(cols)-1) 171 radio_c.SetSelection(int(cols)-1)
176 172
177 radio_b = wx.RadioBox(self, GROUP_BOR, "Border", choices=["no","yes"]) 173 radio_b = wx.RadioBox(self, GROUP_BOR, "Border", choices=["no","yes"])
178 border = handler.atts.getAttribute("border") 174 border = handler.atts.get("border")
179 if border != "": 175 if border != "":
180 radio_b.SetSelection(int(border)) 176 radio_b.SetSelection(int(border))
181 177
182 sizer.Add(radio_c, 0, wx.EXPAND) 178 sizer.Add(radio_c, 0, wx.EXPAND)
183 sizer.Add(wx.Size(10,10)) 179 sizer.Add(wx.Size(10,10))
195 191
196 def on_radio_box(self,evt): 192 def on_radio_box(self,evt):
197 id = evt.GetId() 193 id = evt.GetId()
198 index = evt.GetInt() 194 index = evt.GetInt()
199 if id == GROUP_COLS: 195 if id == GROUP_COLS:
200 self.handler.atts.setAttribute("cols",str(index+1)) 196 self.handler.atts.set("cols",str(index+1))
201 elif id == GROUP_BOR: 197 elif id == GROUP_BOR:
202 self.handler.atts.setAttribute("border",str(index)) 198 self.handler.atts.set("border",str(index))
203 199
204 def on_text(self,evt): 200 def on_text(self,evt):
205 id = evt.GetId() 201 id = evt.GetId()
206 if id == P_TITLE: 202 if id == P_TITLE:
207 txt = self.text[id].GetValue() 203 txt = self.text[id].GetValue()
208 if txt != "": 204 if txt != "":
209 self.handler.master_dom.setAttribute('name',txt) 205 self.handler.xml.set('name',txt)
210 self.handler.rename(txt) 206 self.handler.rename(txt)
211 207
212 208
213 209
214 ########################## 210 ##########################
215 ## tabber node handler 211 ## tabber node handler
216 ########################## 212 ##########################
217 class tabber_handler(container_handler): 213 class tabber_handler(container_handler):
218 """ <nodehandler name='?' module='containers' class='tabber_handler' />""" 214 """ <nodehandler name='?' module='containers' class='tabber_handler' />"""
219 215
220 def __init__(self,xml_dom,tree_node): 216 def __init__(self, xml, tree_node):
221 container_handler.__init__(self,xml_dom,tree_node) 217 container_handler.__init__(self, xml, tree_node)
222 218
223 def get_design_panel(self,parent): 219 def get_design_panel(self,parent):
224 return tabbed_panel(parent,self,1) 220 return tabbed_panel(parent,self,1)
225 221
226 def get_use_panel(self,parent): 222 def get_use_panel(self,parent):
230 class tabbed_panel(orpgTabberWnd): 226 class tabbed_panel(orpgTabberWnd):
231 def __init__(self, parent, handler, mode): 227 def __init__(self, parent, handler, mode):
232 orpgTabberWnd.__init__(self, parent, style=FNB.FNB_NO_X_BUTTON) 228 orpgTabberWnd.__init__(self, parent, style=FNB.FNB_NO_X_BUTTON)
233 self.handler = handler 229 self.handler = handler
234 self.parent = parent 230 self.parent = parent
235 handler.traverse(handler.mytree_node, self.pick_panel, mode, False) 231 handler.tree.traverse(handler.mytree_node, self.pick_panel, mode, False)
236 232
237 parent.SetSize(self.GetBestSize()) 233 parent.SetSize(self.GetBestSize())
238 234
239 def pick_panel(self, obj, mode): 235 def pick_panel(self, treenode, mode):
240 if mode == 1: 236 node = self.handler.tree.GetPyData(treenode)
241 panel = obj.get_design_panel(self) 237 if mode == 1: panel = node.get_design_panel(self)
242 else: 238 else: panel = node.get_use_panel(self)
243 panel = obj.get_use_panel(self) 239 name = node.xml.get("name")
244 240 if panel: self.AddPage(panel, name, False)
245 name = obj.master_dom.getAttribute("name");print 'here '+name
246
247 if panel:
248 self.AddPage(panel, name, False)
249 241
250 ################################# 242 #################################
251 ## Splitter container 243 ## Splitter container
252 ################################# 244 #################################
253 245
254 class splitter_handler(container_handler): 246 class splitter_handler(container_handler):
255 """ <nodehandler name='?' module='containers' class='splitter_handler' />""" 247 """ <nodehandler name='?' module='containers' class='splitter_handler' />"""
256 248
257 def __init__(self,xml_dom,tree_node): 249 def __init__(self,xml,tree_node):
258 container_handler.__init__(self,xml_dom,tree_node) 250 container_handler.__init__(self,xml,tree_node)
259 251
260 def load_children(self): 252 def load_children(self):
261 self.atts = None 253 self.atts = None
262 children = self.master_dom._get_childNodes() 254 for child_xml in self.xml:
263 for c in children: 255 if child_xml.tag == "splitter_atts": self.atts = child_xml
264 if c._get_tagName() == "splitter_atts": 256 else: self.tree.load_xml(child_xml,self.mytree_node)
265 self.atts = c
266 else:
267 self.tree.load_xml(c,self.mytree_node)
268 if not self.atts: 257 if not self.atts:
269 elem = self.xml.minidom.Element('splitter_atts') 258 self.atts = Element('splitter_atts')
270 elem.setAttribute("horizontal","0") 259 self.atts.set("horizontal","0")
271 self.atts = self.master_dom.appendChild(elem) 260 self.xml.append(self.atts)
272 261
273 def get_design_panel(self,parent): 262 def get_design_panel(self,parent):
274 return self.build_splitter_wnd(parent, 1) 263 return self.build_splitter_wnd(parent, 1)
275 264
276 def get_use_panel(self,parent): 265 def get_use_panel(self,parent):
279 def on_drop(self,evt): 268 def on_drop(self,evt):
280 drag_obj = self.tree.drag_obj 269 drag_obj = self.tree.drag_obj
281 container_handler.on_drop(self,evt) 270 container_handler.on_drop(self,evt)
282 271
283 def build_splitter_wnd(self, parent, mode): 272 def build_splitter_wnd(self, parent, mode):
284 self.split = self.atts.getAttribute("horizontal") 273 self.split = self.atts.get("horizontal")
285 274
286 self.pane = splitter_panel(parent, self) 275 self.pane = splitter_panel(parent, self)
287 276
288 self.splitter = MultiSplitterWindow(self.pane, -1, style=wx.SP_LIVE_UPDATE|wx.SP_3DSASH|wx.SP_NO_XP_THEME) 277 self.splitter = MultiSplitterWindow(self.pane, -1, style=wx.SP_LIVE_UPDATE|wx.SP_3DSASH|wx.SP_NO_XP_THEME)
289 278
293 self.splitter.SetOrientation(wx.HORIZONTAL) 282 self.splitter.SetOrientation(wx.HORIZONTAL)
294 283
295 self.bestSizex = -1 284 self.bestSizex = -1
296 self.bestSizey = -1 285 self.bestSizey = -1
297 286
298 self.traverse(self.mytree_node, self.doSplit, mode, False) 287 self.tree.traverse(self.mytree_node, self.doSplit, mode, False)
299 288
300 self.pane.sizer.Add(self.splitter, 1, wx.EXPAND) 289 self.pane.sizer.Add(self.splitter, 1, wx.EXPAND)
301 290
302 291
303 if mode != 1: 292 if mode != 1:
306 self.pane.SetSize((self.bestSizex, self.bestSizey)) 295 self.pane.SetSize((self.bestSizex, self.bestSizey))
307 self.pane.Layout() 296 self.pane.Layout()
308 parent.SetSize(self.pane.GetSize()) 297 parent.SetSize(self.pane.GetSize())
309 return self.pane 298 return self.pane
310 299
311 def doSplit(self, obj, mode): 300 def doSplit(self, treenode, mode):
312 if mode == 1: 301 node = self.tree.GetPyData(treenode)
313 tmp = obj.get_design_panel(self.splitter) 302 if mode == 1: tmp = node.get_design_panel(self.splitter)
314 else: 303 else: tmp = node.get_use_panel(self.splitter)
315 tmp = obj.get_use_panel(self.splitter)
316 304
317 if self.split == '1': 305 if self.split == '1':
318 sash = tmp.GetBestSize()[1]+1 306 sash = tmp.GetBestSize()[1]+1
319 self.bestSizey += sash+11 307 self.bestSizey += sash+11
320 if self.bestSizex < tmp.GetBestSize()[0]: 308 if self.bestSizex < tmp.GetBestSize()[0]:
335 wx.Panel.__init__(self, parent, -1) 323 wx.Panel.__init__(self, parent, -1)
336 self.handler = handler 324 self.handler = handler
337 sizer = wx.BoxSizer(wx.VERTICAL) 325 sizer = wx.BoxSizer(wx.VERTICAL)
338 326
339 self.hozCheck = wx.CheckBox(self, -1, "Horizontal Split") 327 self.hozCheck = wx.CheckBox(self, -1, "Horizontal Split")
340 hoz = self.handler.atts.getAttribute("horizontal") 328 hoz = self.handler.atts.get("horizontal")
341 329
342 if hoz == '1': 330 if hoz == '1':
343 self.hozCheck.SetValue(True) 331 self.hozCheck.SetValue(True)
344 #self.splitsize = wx.BoxSizer(wx.HORIZONTAL) 332 #self.splitsize = wx.BoxSizer(wx.HORIZONTAL)
345 else: 333 else:
357 self.Bind(wx.EVT_CHECKBOX, self.on_check_box, id=self.hozCheck.GetId()) 345 self.Bind(wx.EVT_CHECKBOX, self.on_check_box, id=self.hozCheck.GetId())
358 346
359 def on_check_box(self,evt): 347 def on_check_box(self,evt):
360 state = self.hozCheck.GetValue() 348 state = self.hozCheck.GetValue()
361 if state: 349 if state:
362 self.handler.atts.setAttribute("horizontal", "1") 350 self.handler.atts.set("horizontal", "1")
363 else: 351 else:
364 self.handler.atts.setAttribute("horizontal", "0") 352 self.handler.atts.set("horizontal", "0")