comparison orpg/gametree/gametree.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 37a11fea3304
children 9314d63c0941
comparison
equal deleted inserted replaced
117:0f18d16f3fe7 118:217fb049bd00
24 # $Id: gametree.py,v 1.68 2007/12/07 20:39:48 digitalxero Exp $ 24 # $Id: gametree.py,v 1.68 2007/12/07 20:39:48 digitalxero Exp $
25 # 25 #
26 # Description: The file contains code fore the game tree shell 26 # Description: The file contains code fore the game tree shell
27 # 27 #
28 28
29 from __future__ import with_statement
30
29 __version__ = "$Id: gametree.py,v 1.68 2007/12/07 20:39:48 digitalxero Exp $" 31 __version__ = "$Id: gametree.py,v 1.68 2007/12/07 20:39:48 digitalxero Exp $"
30 32
31 from orpg.orpg_wx import * 33 from orpg.orpg_wx import *
32 from orpg.orpg_windows import * 34 from orpg.orpg_windows import *
33 from orpg.orpgCore import component 35 from orpg.orpgCore import component
40 42
41 from orpg.orpg_xml import xml 43 from orpg.orpg_xml import xml
42 from orpg.tools.validate import validate 44 from orpg.tools.validate import validate
43 from orpg.tools.orpg_log import logger 45 from orpg.tools.orpg_log import logger
44 from orpg.tools.decorators import debugging 46 from orpg.tools.decorators import debugging
47 from orpg.tools.orpg_settings import settings
45 from orpg.gametree.nodehandlers import containers, forms, dnd3e, dnd35, chatmacro 48 from orpg.gametree.nodehandlers import containers, forms, dnd3e, dnd35, chatmacro
46 from orpg.gametree.nodehandlers import map_miniature_nodehandler 49 from orpg.gametree.nodehandlers import map_miniature_nodehandler
47 from orpg.gametree.nodehandlers import minilib, rpg_grid, d20, StarWarsd20, voxchat 50 from orpg.gametree.nodehandlers import minilib, rpg_grid, d20, StarWarsd20, voxchat
48 51
49 from gametree_version import GAMETREE_VERSION 52 from gametree_version import GAMETREE_VERSION
53
54 from xml.etree.ElementTree import ElementTree, Element, parse
55 from xml.etree.ElementTree import fromstring, tostring, XML, iselement
56 from xml.parsers.expat import ExpatError
50 57
51 STD_MENU_DELETE = wx.NewId() 58 STD_MENU_DELETE = wx.NewId()
52 STD_MENU_DESIGN = wx.NewId() 59 STD_MENU_DESIGN = wx.NewId()
53 STD_MENU_USE = wx.NewId() 60 STD_MENU_USE = wx.NewId()
54 STD_MENU_PP = wx.NewId() 61 STD_MENU_PP = wx.NewId()
192 self.rename_flag = 1 199 self.rename_flag = 1
193 self.EditLabel(curSelection) 200 self.EditLabel(curSelection)
194 evt.Skip() 201 evt.Skip()
195 202
196 @debugging 203 @debugging
197 def locate_valid_tree(self, error, msg, dir, filename): ## --Snowdog 3/05 204 def locate_valid_tree(self, error, msg): ## --Snowdog 3/05
198 """prompts the user to locate a new tree file or create a new one""" 205 """prompts the user to locate a new tree file or create a new one"""
199 response = wx.MessageDialog(self, msg, error, wx.YES|wx.NO|wx.ICON_ERROR) 206 response = wx.MessageDialog(self, msg, error, wx.YES|wx.NO|wx.ICON_ERROR)
200 if response == wx.YES: 207 if response == wx.YES:
201 file = None 208 file = None
202 filetypes = "Gametree (*.xml)|*.xml|All files (*.*)|*.*" 209 dlg = wx.FileDialog(self, "Locate Gametree file", dir_struct["user"],
203 dlg = wx.FileDialog(self, "Locate Gametree file", dir, filename, filetypes,wx.OPEN | wx.CHANGE_DIR) 210 filename[ ((filename.rfind(os.sep))+len(os.sep)):],
211 "Gametree (*.xml)|*.xml|All files (*.*)|*.*",
212 wx.OPEN | wx.CHANGE_DIR)
204 if dlg.ShowModal() == wx.ID_OK: file = dlg.GetPath() 213 if dlg.ShowModal() == wx.ID_OK: file = dlg.GetPath()
205 dlg.Destroy() 214 dlg.Destroy()
206 if not file: self.load_tree(error=1) 215 if not file: self.load_tree(error=1)
207 else: self.load_tree(file) 216 else: self.load_tree(file)
208 return 217 return
212 return 221 return
213 222
214 @debugging 223 @debugging
215 def load_tree(self, filename=dir_struct["user"]+'tree.xml', error=0): 224 def load_tree(self, filename=dir_struct["user"]+'tree.xml', error=0):
216 self.settings.set_setting("gametree", filename) 225 self.settings.set_setting("gametree", filename)
217 tmp = None 226 #check file exists
218 xml_dom = None 227 if not os.path.exists(filename):
219 xml_doc = None 228 emsg = "Gametree Missing!\n"+filename+" cannot be found.\n\n"\
229 "Would you like to locate it?\n"\
230 "(Selecting 'No' will cause a new default gametree to be generated)"
231 self.locate_valid_tree("Gametree Error", emsg)
232 return
233 try:
234 f = open(filename, "rb")
235 tree = parse(f)
236 self.xml_root = tree.getroot()
237 except:
238 f.close()
239 self.xml_root = None
240 ### Alpha ### Doing some work on Gametree to add Element Tree, slowly at first.
241
220 try: 242 try:
221 logger.info("Reading Gametree file: " + filename + "...", True) 243 logger.info("Reading Gametree file: " + filename + "...", True)
222 tmp = open(filename,"r") 244 xml_doc = xml.parseXml(tostring(self.xml_root))
223 xml_doc = xml.parseXml(tmp.read())
224 tmp.close()
225 if xml_doc == None: pass 245 if xml_doc == None: pass
226 else: xml_dom = xml_doc._get_documentElement() 246 else: xml_dom = xml_doc._get_documentElement()
227 logger.info("done.", True) 247 logger.info("done.", True)
228 248 except: pass
229 except IOError: 249
230 emsg = "Gametree Missing!\n"+filename+" cannot be found.\n\n"\ 250 if not self.xml_root:
231 "Would you like to locate it?\n"\ 251 os.rename(filename,filename+".corrupt")
232 "(Selecting 'No' will cause a new default gametree to be generated)" 252 emsg = "Your gametree is being regenerated.\n\n"\
233 fn = filename[ ((filename.rfind(os.sep))+len(os.sep)):] 253 "To salvage a recent version of your gametree\n"\
234 self.locate_valid_tree("Gametree Error", emsg, dir_struct["user"], fn) 254 "exit OpenRPG and copy the lastgood.xml file in\n"\
235 logger.general(emsg) 255 "your myfiles directory to "+filename+ "\n"\
256 "in your myfiles directory.\n\n"\
257 "lastgood.xml WILL BE OVERWRITTEN NEXT TIME YOU RUN OPENRPG.\n\n"\
258 "Would you like to select a different gametree file to use?\n"\
259 "(Selecting 'No' will cause a new default gametree to be generated)"
260 self.locate_valid_tree("Corrupt Gametree!", emsg)
236 return 261 return
237 262
238 if not xml_dom: 263 if self.xml_root.tag != "gametree":
239 os.rename(filename,filename+".corrupt") 264 emsg = filename+" does not appear to be a valid gametree file.\n\n"\
240 fn = filename[ ((filename.rfind(os.sep))+len(os.sep)):] 265 "Would you like to select a different gametree file to use?\n"\
241 emsg = "Your gametree is being regenerated.\n\n"\ 266 "(Selecting 'No' will cause a new default gametree to be generated)"
242 "To salvage a recent version of your gametree\n"\ 267 self.locate_valid_tree("Invalid Gametree!", emsg)
243 "exit OpenRPG and copy the lastgood.xml file in\n"\
244 "your myfiles directory to "+fn+ "\n"\
245 "in your myfiles directory.\n\n"\
246 "lastgood.xml WILL BE OVERWRITTEN NEXT TIME YOU RUN OPENRPG.\n\n"\
247 "Would you like to select a different gametree file to use?\n"\
248 "(Selecting 'No' will cause a new default gametree to be generated)"
249 self.locate_valid_tree("Corrupt Gametree!", emsg, dir_struct["user"], fn)
250 logger.general(emsg)
251 return 268 return
252
253 if xml_dom._get_tagName() != "gametree":
254 fn = filename[ ((filename.rfind(os.sep))+len(os.sep)):]
255 emsg = fn+" does not appear to be a valid gametree file.\n\n"\
256 "Would you like to select a different gametree file to use?\n"\
257 "(Selecting 'No' will cause a new default gametree to be generated)"
258 self.locate_valid_tree("Invalid Gametree!", emsg, dir_struct["user"], fn)
259 logger.debug(emsg)
260 return
261
262 # get gametree version - we could write conversion code here!
263 self.master_dom = xml_dom
264 logger.debug("Master Dom Set")
265
266 try: 269 try:
267 version = self.master_dom.getAttribute("version") 270 # version = self.xml_root.get("version")
268 # see if we should load the gametree 271 # see if we should load the gametree
269 loadfeatures = int(self.settings.get_setting("LoadGameTreeFeatures")) 272 loadfeatures = int(settings.get_setting("LoadGameTreeFeatures"))
270 if loadfeatures: 273 if loadfeatures:
271 xml_dom = xml.parseXml(open(dir_struct["template"]+"feature.xml","r").read()) 274 features_tree = ET.parse(orpg.dirpath.dir_struct["template"]+"feature.xml")
272 xml_dom = xml_dom._get_documentElement() 275 self.xml_root.append(features_tree.getroot())
273 xml_dom = self.master_dom.appendChild(xml_dom) 276 settings.set("LoadGameTreeFeatures","0")
274 self.settings.set_setting("LoadGameTreeFeatures","0")
275 277
276 ## load tree 278 ## load tree
277 logger.debug("Features loaded (if required)") 279 logger.debug("Features loaded (if required)")
278 self.CollapseAndReset(self.root) 280 self.CollapseAndReset(self.root)
279 children = self.master_dom._get_childNodes() 281 logger.note("Parsing Gametree Nodes ", True)
280 logger.info("Parsing Gametree Nodes ", True) 282 for xml_child in self.xml_root:
281 for c in children: 283 logger.note('.', True)
282 print '.', 284 self.load_xml(xml_child,self.root)
283 self.load_xml(c,self.root) 285 logger.note("done", True)
284 logger.info("done", True) 286
285 self.Expand(self.root) 287 self.Expand(self.root)
286 self.SetPyData(self.root,self.master_dom) 288 self.SetPyData(self.root,self.xml_root)
287 if error != 1: 289 if error != 1:
288 infile = open(filename, "rb") 290 with open(filename, "rb") as infile:
289 outfile = open(dir_struct["user"]+"lastgood.xml", "wb") 291 with open(dir_struct["user"]+"lastgood.xml", "wb") as outfile:
290 outfile.write(infile.read()) 292 outfile.write(infile.read())
291 else: logger.info("Not overwriting lastgood.xml file.", True) 293 else: logger.info("Not overwriting lastgood.xml file.", True)
292 294
293 except Exception, e: 295 except Exception, e:
294 logger.general(traceback.format_exc()) 296 logger.exception(traceback.format_exc())
295 wx.MessageBox("Corrupt Tree!\nYour game tree is being regenerated. To\nsalvage a recent version of your gametree\nexit OpenRPG and copy the lastgood.xml\nfile in your myfiles directory\nto "+filename+ "\nin your myfiles directory.\nlastgood.xml WILL BE OVERWRITTEN NEXT TIME YOU RUN OPENRPG.") 297 wx.MessageBox("Corrupt Tree!\nYour game tree is being regenerated. To\nsalvage a recent version of your gametree\nexit OpenRPG and copy the lastgood.xml\nfile in your myfiles directory\nto "+filename+ "\nin your myfiles directory.\nlastgood.xml WILL BE OVERWRITTEN NEXT TIME YOU RUN OPENRPG.")
296 os.rename(filename,filename+".corrupt") 298 os.rename(filename,filename+".corrupt")
297 validate.config_file("tree.xml","default_tree.xml") 299 validate.config_file("tree.xml","default_tree.xml")
298 self.load_tree(error=1) 300 self.load_tree(error=1)
299 301
380 logger.debug(ret_string) 382 logger.debug(ret_string)
381 return ret_string 383 return ret_string
382 384
383 @debugging 385 @debugging
384 def on_receive_data(self, data, player): 386 def on_receive_data(self, data, player):
387 if iselement(data):
388 tostring(data)
385 beg = string.find(data,"<tree>") 389 beg = string.find(data,"<tree>")
386 end = string.rfind(data,"</tree>") 390 end = string.rfind(data,"</tree>")
387 data = data[6:end] 391 data = data[6:end]
388 self.insert_xml(data) 392 self.insert_xml(data)
389 393
421 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","HTML (*.html)|*.html",wx.SAVE) 425 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","HTML (*.html)|*.html",wx.SAVE)
422 if f.ShowModal() == wx.ID_OK: 426 if f.ShowModal() == wx.ID_OK:
423 item = self.GetSelection() 427 item = self.GetSelection()
424 obj = self.GetPyData(item) 428 obj = self.GetPyData(item)
425 type = f.GetFilterIndex() 429 type = f.GetFilterIndex()
426 file = open(f.GetPath(),"w") 430 with open(f.GetPath(),"w") as f:
427 data = "<html><head><title>"+obj.master_dom.getAttribute("name")+"</title></head>" 431 data = "<html><head><title>"+obj.xml.get("name")+"</title></head>"
428 data += "<body bgcolor=\"#FFFFFF\" >"+obj.tohtml()+"</body></html>" 432 data += "<body bgcolor=\"#FFFFFF\" >"+obj.tohtml()+"</body></html>"
429 for tag in ("</tr>","</td>","</th>","</table>","</html>","</body>"): 433 for tag in ("</tr>","</td>","</th>","</table>","</html>","</body>"):
430 data = data.replace(tag,tag+"\n") 434 data = data.replace(tag,tag+"\n")
431 file.write(data) 435 f.write(data)
432 file.close()
433 self.last_save_dir, throwaway = os.path.split( f.GetPath() ) 436 self.last_save_dir, throwaway = os.path.split( f.GetPath() )
434 f.Destroy() 437 f.Destroy()
435 os.chdir(dir_struct["home"]) 438 os.chdir(dir_struct["home"])
436 439
437 @debugging 440 @debugging
469 players.remove(me) 472 players.remove(me)
470 dlg = orpgMultiCheckBoxDlg( None, opts, "Select Players:", "Send To", [] ) 473 dlg = orpgMultiCheckBoxDlg( None, opts, "Select Players:", "Send To", [] )
471 if dlg.ShowModal() == wx.ID_OK: 474 if dlg.ShowModal() == wx.ID_OK:
472 item = self.GetSelection() 475 item = self.GetSelection()
473 obj = self.GetPyData(item) 476 obj = self.GetPyData(item)
474 xmldata = "<tree>" + xml.toxml(obj) + "</tree>" 477 xmldata = "<tree>" + tostring(obj.xml) + "</tree>"
475 selections = dlg.get_selections() 478 selections = dlg.get_selections()
476 if len(selections) == len(opts): self.session.send(xmldata) 479 if len(selections) == len(opts): self.session.send(xmldata)
477 else: 480 else:
478 for s in selections: self.session.send(xmldata,players[s][2]) 481 for s in selections: self.session.send(xmldata,players[s][2])
479 dlg.Destroy() 482 dlg.Destroy()
508 obj = self.GetPyData(item) 511 obj = self.GetPyData(item)
509 if obj.can_clone(): 512 if obj.can_clone():
510 parent_node = self.GetItemParent(item) 513 parent_node = self.GetItemParent(item)
511 prev_sib = self.GetPrevSibling(item) 514 prev_sib = self.GetPrevSibling(item)
512 if not prev_sib.IsOk(): prev_sib = parent_node 515 if not prev_sib.IsOk(): prev_sib = parent_node
513 xml_dom = xml.parseXml(xml.toxml(obj)) 516 clone_xml = XML(tostring(obj.xml))
514 xml_dom = xml_dom._get_firstChild() 517 if parent_node == self.root: parent_xml = self.GetPyData(parent_node)
515 parent = obj.master_dom._get_parentNode() 518 else: parent_xml = self.GetPyData(parent_node).xml
516 xml_dom = parent.insertBefore(xml_dom, obj.master_dom) 519 for i in range(len(parent_xml)):
517 self.load_xml(xml_dom, parent_node, prev_sib) 520 if parent_xml[i] is obj.xml:
521 parent_xml.insert(i, clone_xml)
522 break
523 self.load_xml(clone_xml, parent_node, prev_sib)
518 524
519 @debugging 525 @debugging
520 def on_save(self, evt): 526 def on_save(self, evt):
521 """save node to a xml file""" 527 """save node to a xml file"""
522 item = self.GetSelection() 528 item = self.GetSelection()
538 filename = self.settings.get_setting("gametree") 544 filename = self.settings.get_setting("gametree")
539 self.save_tree(filename) 545 self.save_tree(filename)
540 546
541 @debugging 547 @debugging
542 def save_tree(self, filename=dir_struct["user"]+'tree.xml'): 548 def save_tree(self, filename=dir_struct["user"]+'tree.xml'):
543 self.master_dom.setAttribute("version",GAMETREE_VERSION) 549 self.xml_root.set("version",GAMETREE_VERSION)
544 self.settings.set_setting("gametree",filename) 550 settings.set_setting("gametree",filename)
545 file = open(filename,"w") 551 ElementTree(self.xml_root).write(filename)
546 file.write(xml.toxml(self.master_dom,1))
547 file.close()
548 552
549 @debugging 553 @debugging
550 def on_load_new_tree(self, evt): 554 def on_load_new_tree(self, evt):
551 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","*.xml",wx.OPEN) 555 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","*.xml",wx.OPEN)
552 if f.ShowModal() == wx.ID_OK: 556 if f.ShowModal() == wx.ID_OK:
609 def on_del(self, evt): 613 def on_del(self, evt):
610 status_value = "none" 614 status_value = "none"
611 try: 615 try:
612 item = self.GetSelection() 616 item = self.GetSelection()
613 if item: 617 if item:
614 obj = self.GetPyData(item) 618 handler = self.GetPyData(item)
615 parent_obj = obj 619 status_value = handler.xml.get('status')
616 try: 620 name = handler.xml.get('name')
617 status_value = parent_obj.master_dom.getAttribute('status') 621 parent_item = self.GetItemParent(item)
618 name = parent_obj.master_dom.getAttribute('name') 622 while parent_item.IsOk() and status_value!="useful" and status_value!="useless":
619 except: status_value = "none"
620 parent_obj = parent_obj.master_dom._get_parentNode()
621 while status_value!="useful" and status_value!="useless":
622 try: 623 try:
623 status_value = parent_obj.getAttribute('status') 624 parent_handler = self.GetPyData(parent_item)
624 name = parent_obj.getAttribute('name') 625 status_value = parent_handler.get('status')
625 if status_value == "useless": break 626 name = parent_handler.get('name')
626 elif status_value == "useful": break 627 if status_value == "useless":
627 except: status_value = "none" 628 break
628 try: parent_obj = parent_obj._get_parentNode() 629 elif status_value == "useful":
629 except: break 630 break
631 except:
632 status_value = "none"
633 parent_item = self.GetItemParent(parent_item)
630 if status_value == "useful": 634 if status_value == "useful":
631 dlg = wx.MessageDialog(self, `name` + " And everything beneath it are considered useful. \n\nAre you sure you want to delete this item?",'Important Item',wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) 635 dlg = wx.MessageDialog(self, `name` + " And everything beneath it are considered useful. \n\nAre you sure you want to delete this item?",'Important Item',wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
632 if dlg.ShowModal() == wx.ID_YES: obj.delete() 636 if dlg.ShowModal() == wx.ID_YES: handler.delete()
633 else: obj.delete() 637 else: handler.delete()
634 except: 638 except:
635 if self.GetSelection() == self.GetRootItem(): 639 if self.GetSelection() == self.GetRootItem():
636 msg = wx.MessageDialog(None,"You can't delete the root item.","Delete Error",wx.OK) 640 msg = wx.MessageDialog(None,"You can't delete the root item.","Delete Error",wx.OK)
637 else: msg = wx.MessageDialog(None,"Unknown error deleting node.","Delete Error",wx.OK) 641 else: msg = wx.MessageDialog(None,"Unknown error deleting node.","Delete Error",wx.OK)
638 msg.ShowModal() 642 msg.ShowModal()
655 @debugging 659 @debugging
656 def insert_xml(self, txt): 660 def insert_xml(self, txt):
657 #Updated to allow safe merging of gametree files 661 #Updated to allow safe merging of gametree files
658 #without leaving an unusable and undeletable node. 662 #without leaving an unusable and undeletable node.
659 # -- Snowdog 8/03 663 # -- Snowdog 8/03
660 xml_dom = xml.parseXml(txt) 664 if not txt:
661 if xml_dom == None:
662 wx.MessageBox("Import Failed: Invalid or missing node data") 665 wx.MessageBox("Import Failed: Invalid or missing node data")
663 logger.debug("Import Failed: Invalid or missing node data") 666 logger.general("Import Failed: Invalid or missing node data")
664 logger.debug("Exit game_tree->insert_xml(self, txt)")
665 return 667 return
666 xml_temp = xml_dom._get_documentElement() 668
667 669 try:
668 if not xml_temp: 670 new_xml = XML(txt)
671 except ExpatError:
669 wx.MessageBox("Error Importing Node or Tree") 672 wx.MessageBox("Error Importing Node or Tree")
670 logger.debug("Error Importing Node or Tree") 673 logger.general("Error Importing Node or Tree")
671 logger.debug("Exit game_tree->insert_xml(self, txt)")
672 return 674 return
673 675
674 if xml_temp._get_tagName() == "gametree": 676 if new_xml.tag == "gametree":
675 children = xml_temp._get_childNodes() 677 for xml_child in new_xml:
676 for c in children: self.load_xml(c, self.root) 678 self.load_xml(xml_child, self.root)
677 logger.debug("Exit game_tree->insert_xml(self, txt)")
678 return 679 return
679 680
680 if not xml_dom: 681 self.xml_root.append(new_xml)
681 wx.MessageBox("XML Error") 682 self.load_xml(new_xml,self.root,self.root)
682 logger.debug("XML Error")
683 logger.debug("Exit game_tree->insert_xml(self, txt)")
684 return
685
686 xml_dom = xml_dom._get_firstChild()
687 child = self.master_dom._get_firstChild()
688 xml_dom = self.master_dom.insertBefore(xml_dom,child)
689 self.load_xml(xml_dom,self.root,self.root)
690 683
691 @debugging 684 @debugging
692 def build_img_list(self): 685 def build_img_list(self):
693 """make image list""" 686 """make image list"""
694 helper = img_helper() 687 helper = img_helper()
695 self.icons = { } 688 self.icons = { }
696 self._imageList= wx.ImageList(16,16,False) 689 self._imageList= wx.ImageList(16,16,False)
697 man = open(dir_struct["icon"]+"icons.xml","r") 690 icons_xml = parse(orpg.dirpath.dir_struct["icon"]+"icons.xml")
698 xml_dom = xml.parseXml(man.read()) 691 for icon in icons_xml.getroot():
699 man.close() 692 key = icon.get("name")
700 xml_dom = xml_dom._get_documentElement() 693 path = orpg.dirpath.dir_struct["icon"] + icon.get("file")
701 node_list = xml_dom._get_childNodes()
702 for n in node_list:
703 key = n.getAttribute("name")
704 path = dir_struct["icon"] + n.getAttribute("file")
705 img = helper.load_file(path) 694 img = helper.load_file(path)
706 self.icons[key] = self._imageList.Add(img) 695 self.icons[key] = self._imageList.Add(img)
707 self.SetImageList(self._imageList) 696 self.SetImageList(self._imageList)
708 697
709 @debugging 698 @debugging
710 def load_xml(self, xml_dom, parent_node, prev_node=None): 699 def load_xml(self, xml_element, parent_node, prev_node=None):
711 #add the first tree node 700 #add the first tree node
712 i = 0 701 i = 0
713 text = xml_dom.getAttribute("name") 702 name = xml_element.get("name")
714 icon = xml_dom.getAttribute("icon") 703 icon = xml_element.get("icon")
715 if self.icons.has_key(icon): i = self.icons[icon] 704 if self.icons.has_key(icon): i = self.icons[icon]
716 name = xml_dom._get_nodeName() 705
717 logger.debug("Text, icon and name set\n" + text + "\n" + icon + "\n" + name)
718 if prev_node: 706 if prev_node:
719 if prev_node == parent_node: new_tree_node = self.PrependItem(parent_node, text, i, i) 707 if prev_node == parent_node: new_tree_node = self.PrependItem(parent_node, name, i, i)
720 else: new_tree_node = self.InsertItem(parent_node,prev_node, text, i, i) 708 else: new_tree_node = self.InsertItem(parent_node,prev_node, name, i, i)
721 else: new_tree_node = self.AppendItem(parent_node, text, i, i) 709 else: new_tree_node = self.AppendItem(parent_node, name, i, i)
722 710
723 logger.debug("Node Added to tree") 711 logger.debug("Node Added to tree")
724 #create a nodehandler or continue loading xml into tree 712 #create a nodehandler or continue loading xml into tree
725 if name == "nodehandler": 713 if xml_element.tag == "nodehandler":
726 #wx.BeginBusyCursor()
727 logger.debug("We have a Nodehandler")
728 try: 714 try:
729 py_class = xml_dom.getAttribute("class") 715 py_class = xml_element.get("class")
730 logger.debug("nodehandler class: " + py_class) 716 logger.debug("nodehandler class: " + py_class)
731 if not self.nodehandlers.has_key(py_class): 717 if not self.nodehandlers.has_key(py_class):
732 raise Exception, "Unknown Nodehandler for " + py_class 718 raise Exception("Unknown Nodehandler for " + py_class)
733 self.nodes[self.id] = self.nodehandlers[py_class](xml_dom, new_tree_node) 719 self.nodes[self.id] = self.nodehandlers[py_class](xml_element, new_tree_node)
734 self.SetPyData(new_tree_node, self.nodes[self.id]) 720 self.SetPyData(new_tree_node, self.nodes[self.id])
735 logger.debug("Node Data set") 721 logger.debug("Node Data set")
736 bmp = self.nodes[self.id].get_scaled_bitmap(16,16) 722 bmp = self.nodes[self.id].get_scaled_bitmap(16,16)
737 if bmp: self.cached_load_of_image(bmp,new_tree_node,) 723 if bmp: self.cached_load_of_image(bmp,new_tree_node,)
738 logger.debug("Node Icon loaded") 724 logger.debug("Node Icon loaded")
739 self.id = self.id + 1 725 self.id = self.id + 1
740 except Exception, er: 726 except Exception, er:
741 logger.general(traceback.format_exc()) 727 logger.exception(traceback.format_exc())
742 #logger.debug("Error Info: " + xml_dom.getAttribute("class") + "\n" + str(er), True)?indent? 728
743 self.Delete(new_tree_node) 729 # was deleted -- should we delete non-nodehandler nodes then?
744 parent = xml_dom._get_parentNode() 730 #self.Delete(new_tree_node)
745 parent.removeChild(xml_dom) 731 #parent = xml_dom._get_parentNode()
732 #parent.removeChild(xml_dom)
733
746 return new_tree_node 734 return new_tree_node
747 735
748 @debugging 736 @debugging
749 def cached_load_of_image(self, bmp_in, new_tree_node): 737 def cached_load_of_image(self, bmp_in, new_tree_node):
750 image_list = self.GetImageList() 738 image_list = self.GetImageList()
816 obj = self.GetPyData(item) 804 obj = self.GetPyData(item)
817 self.SelectItem(item) 805 self.SelectItem(item)
818 if(isinstance(obj,core.node_handler)): 806 if(isinstance(obj,core.node_handler)):
819 obj.on_drop(evt) 807 obj.on_drop(evt)
820 self.drag_obj = None 808 self.drag_obj = None
809
810 def traverse(self, root, function, data=None, recurse=True):
811 child, cookie = self.GetFirstChild(root)
812 while child.IsOk():
813 function(child, data)
814 if recurse:
815 self.traverse(child, function, data)
816 child, cookie = self.GetNextChild(root, cookie)
821 817
822 @debugging 818 @debugging
823 def on_label_change(self, evt): 819 def on_label_change(self, evt):
824 item = evt.GetItem() 820 item = evt.GetItem()
825 txt = evt.GetLabel() 821 txt = evt.GetLabel()