comparison orpg/gametree/gametree.py @ 76:37a11fea3304 ornery-dev

More clean up. Images now posts a Chat Info post if image doesn't load.
author sirebral
date Sat, 22 Aug 2009 04:02:14 -0500
parents 449a8900f9ac
children 217fb049bd00 dcf4fbe09b70
comparison
equal deleted inserted replaced
75:f518bc709fd1 76:37a11fea3304
36 import string 36 import string
37 import urllib 37 import urllib
38 import time 38 import time
39 import os 39 import os
40 40
41 from orpg.orpg_xml import xml
42 from orpg.tools.validate import validate
41 from orpg.tools.orpg_log import logger 43 from orpg.tools.orpg_log import logger
42 from orpg.tools.decorators import debugging 44 from orpg.tools.decorators import debugging
43 from orpg.gametree.nodehandlers import containers, forms, dnd3e, dnd35, chatmacro 45 from orpg.gametree.nodehandlers import containers, forms, dnd3e, dnd35, chatmacro
44 from orpg.gametree.nodehandlers import map_miniature_nodehandler 46 from orpg.gametree.nodehandlers import map_miniature_nodehandler
45 from orpg.gametree.nodehandlers import minilib, rpg_grid, d20, StarWarsd20, voxchat 47 from orpg.gametree.nodehandlers import minilib, rpg_grid, d20, StarWarsd20, voxchat
77 class game_tree(wx.TreeCtrl): 79 class game_tree(wx.TreeCtrl):
78 @debugging 80 @debugging
79 def __init__(self, parent, id): 81 def __init__(self, parent, id):
80 wx.TreeCtrl.__init__(self,parent,id, wx.DefaultPosition, 82 wx.TreeCtrl.__init__(self,parent,id, wx.DefaultPosition,
81 wx.DefaultSize,style=wx.TR_EDIT_LABELS | wx.TR_HAS_BUTTONS) 83 wx.DefaultSize,style=wx.TR_EDIT_LABELS | wx.TR_HAS_BUTTONS)
82 self.orpgLog = component.get('log') 84 #self.xml = component.get('xml') #
83 self.validate = component.get('validate')
84 self.xml = component.get('xml')
85 self.settings = component.get('settings') 85 self.settings = component.get('settings')
86 self.session = component.get('session') 86 self.session = component.get('session')
87 self.chat = component.get('chat') 87 self.chat = component.get('chat')
88 self.mainframe = component.get('frame') 88 self.mainframe = component.get('frame')
89 self.build_img_list() 89 self.build_img_list()
103 self.id = 1 103 self.id = 1
104 self.dragging = False 104 self.dragging = False
105 self.last_save_dir = dir_struct["user"] 105 self.last_save_dir = dir_struct["user"]
106 106
107 #Create tree from default if it does not exist 107 #Create tree from default if it does not exist
108 self.validate.config_file("tree.xml","default_tree.xml") 108 validate.config_file("tree.xml","default_tree.xml")
109 component.add("tree", self) 109 component.add("tree", self)
110 #build tree 110 #build tree
111 self.root = self.AddRoot("Game Tree",self.icons['gear']) 111 self.root = self.AddRoot("Game Tree",self.icons['gear'])
112 self.was_labeling = 0 112 self.was_labeling = 0
113 self.rename_flag = 0 113 self.rename_flag = 0
114 self.image_cache = {} 114 self.image_cache = {}
115 self.orpgLog.log("Exit game_tree", ORPG_DEBUG) 115 logger.debug("Exit game_tree")
116 116
117 @debugging 117 @debugging
118 def add_nodehandler(self, nodehandler, nodeclass): 118 def add_nodehandler(self, nodehandler, nodeclass):
119 if not self.nodehandlers.has_key(nodehandler): 119 if not self.nodehandlers.has_key(nodehandler): self.nodehandlers[nodehandler] = nodeclass
120 self.nodehandlers[nodehandler] = nodeclass 120 else: logger.debug("Nodehandler for " + nodehandler + " already exists!")
121 else:
122 self.orpgLog.log("Nodehandler for " + nodehandler + " already exists!", ORPG_DEBUG, True)
123 121
124 @debugging 122 @debugging
125 def remove_nodehandler(self, nodehandler): 123 def remove_nodehandler(self, nodehandler):
126 if self.nodehandlers.has_key(nodehandler): 124 if self.nodehandlers.has_key(nodehandler):
127 del self.nodehandlers[nodehandler] 125 del self.nodehandlers[nodehandler]
128 else: 126 else: logger.debug("No nodehandler for " + nodehandler + " exists!")
129 self.orpgLog.log("No nodehandler for " + nodehandler + " exists!", ORPG_DEBUG, True)
130 127
131 @debugging 128 @debugging
132 def init_nodehandlers(self): 129 def init_nodehandlers(self):
133 self.add_nodehandler('group_handler', containers.group_handler) 130 self.add_nodehandler('group_handler', containers.group_handler)
134 self.add_nodehandler('tabber_handler', containers.tabber_handler) 131 self.add_nodehandler('tabber_handler', containers.tabber_handler)
181 if(isinstance(obj,core.node_handler)): 178 if(isinstance(obj,core.node_handler)):
182 self.dragging = True 179 self.dragging = True
183 cur = wx.StockCursor(wx.CURSOR_HAND) 180 cur = wx.StockCursor(wx.CURSOR_HAND)
184 self.SetCursor(cur) 181 self.SetCursor(cur)
185 self.drag_obj = obj 182 self.drag_obj = obj
186 elif key_code == wx.WXK_LEFT: 183 elif key_code == wx.WXK_LEFT: self.Collapse(curSelection)
187 self.Collapse(curSelection)
188 elif key_code == wx.WXK_DELETE: # Handle the delete key 184 elif key_code == wx.WXK_DELETE: # Handle the delete key
189 if curSelection: 185 if curSelection:
190 nextSelect = self.GetItemParent(curSelection) 186 nextSelect = self.GetItemParent(curSelection)
191 self.on_del(evt) 187 self.on_del(evt)
192 try: 188 try:
193 if self.GetItemText(nextSelect) != "": 189 if self.GetItemText(nextSelect) != "": self.SelectItem(nextSelect)
194 self.SelectItem(nextSelect) 190 except: pass
195 except:
196 pass
197 elif key_code == wx.WXK_F2: 191 elif key_code == wx.WXK_F2:
198 self.rename_flag = 1 192 self.rename_flag = 1
199 self.EditLabel(curSelection) 193 self.EditLabel(curSelection)
200 evt.Skip() 194 evt.Skip()
201 195
211 dlg.Destroy() 205 dlg.Destroy()
212 if not file: self.load_tree(error=1) 206 if not file: self.load_tree(error=1)
213 else: self.load_tree(file) 207 else: self.load_tree(file)
214 return 208 return
215 else: 209 else:
216 self.validate.config_file("tree.xml","default_tree.xml") 210 validate.config_file("tree.xml","default_tree.xml")
217 self.load_tree(error=1) 211 self.load_tree(error=1)
218 return 212 return
219 213
220 @debugging 214 @debugging
221 def load_tree(self, filename=dir_struct["user"]+'tree.xml', error=0): 215 def load_tree(self, filename=dir_struct["user"]+'tree.xml', error=0):
222 self.settings.set_setting("gametree", filename) 216 self.settings.set_setting("gametree", filename)
223 tmp = None 217 tmp = None
224 xml_dom = None 218 xml_dom = None
225 xml_doc = None 219 xml_doc = None
226 try: 220 try:
227 self.orpgLog.log("Reading Gametree file: " + filename + "...", ORPG_INFO, True) 221 logger.info("Reading Gametree file: " + filename + "...", True)
228 tmp = open(filename,"r") 222 tmp = open(filename,"r")
229 xml_doc = self.xml.parseXml(tmp.read()) 223 xml_doc = xml.parseXml(tmp.read())
230 tmp.close() 224 tmp.close()
231 if xml_doc == None: 225 if xml_doc == None: pass
232 pass 226 else: xml_dom = xml_doc._get_documentElement()
233 else: 227 logger.info("done.", True)
234 xml_dom = xml_doc._get_documentElement()
235 self.orpgLog.log("done.", ORPG_INFO, True)
236 228
237 except IOError: 229 except IOError:
238 emsg = "Gametree Missing!\n"+filename+" cannot be found.\n\n"\ 230 emsg = "Gametree Missing!\n"+filename+" cannot be found.\n\n"\
239 "Would you like to locate it?\n"\ 231 "Would you like to locate it?\n"\
240 "(Selecting 'No' will cause a new default gametree to be generated)" 232 "(Selecting 'No' will cause a new default gametree to be generated)"
241 fn = filename[ ((filename.rfind(os.sep))+len(os.sep)):] 233 fn = filename[ ((filename.rfind(os.sep))+len(os.sep)):]
242 self.locate_valid_tree("Gametree Error", emsg, dir_struct["user"], fn) 234 self.locate_valid_tree("Gametree Error", emsg, dir_struct["user"], fn)
243 self.orpgLog.log(emsg, ORPG_GENERAL) 235 logger.general(emsg)
244 return 236 return
245 237
246 if not xml_dom: 238 if not xml_dom:
247 os.rename(filename,filename+".corrupt") 239 os.rename(filename,filename+".corrupt")
248 fn = filename[ ((filename.rfind(os.sep))+len(os.sep)):] 240 fn = filename[ ((filename.rfind(os.sep))+len(os.sep)):]
253 "in your myfiles directory.\n\n"\ 245 "in your myfiles directory.\n\n"\
254 "lastgood.xml WILL BE OVERWRITTEN NEXT TIME YOU RUN OPENRPG.\n\n"\ 246 "lastgood.xml WILL BE OVERWRITTEN NEXT TIME YOU RUN OPENRPG.\n\n"\
255 "Would you like to select a different gametree file to use?\n"\ 247 "Would you like to select a different gametree file to use?\n"\
256 "(Selecting 'No' will cause a new default gametree to be generated)" 248 "(Selecting 'No' will cause a new default gametree to be generated)"
257 self.locate_valid_tree("Corrupt Gametree!", emsg, dir_struct["user"], fn) 249 self.locate_valid_tree("Corrupt Gametree!", emsg, dir_struct["user"], fn)
258 self.orpgLog.log(emsg, ORPG_GENERAL) 250 logger.general(emsg)
259 return 251 return
260 252
261 if xml_dom._get_tagName() != "gametree": 253 if xml_dom._get_tagName() != "gametree":
262 fn = filename[ ((filename.rfind(os.sep))+len(os.sep)):] 254 fn = filename[ ((filename.rfind(os.sep))+len(os.sep)):]
263 emsg = fn+" does not appear to be a valid gametree file.\n\n"\ 255 emsg = fn+" does not appear to be a valid gametree file.\n\n"\
264 "Would you like to select a different gametree file to use?\n"\ 256 "Would you like to select a different gametree file to use?\n"\
265 "(Selecting 'No' will cause a new default gametree to be generated)" 257 "(Selecting 'No' will cause a new default gametree to be generated)"
266 self.locate_valid_tree("Invalid Gametree!", emsg, dir_struct["user"], fn) 258 self.locate_valid_tree("Invalid Gametree!", emsg, dir_struct["user"], fn)
267 self.orpgLog.log(emsg, ORPG_DEBUG) 259 logger.debug(emsg)
268 self.orpgLog.log("Exit game_tree->load_tree(self, filename, error)", ORPG_DEBUG)
269 return 260 return
270 261
271 # get gametree version - we could write conversion code here! 262 # get gametree version - we could write conversion code here!
272 self.master_dom = xml_dom 263 self.master_dom = xml_dom
273 self.orpgLog.log("Master Dom Set", ORPG_DEBUG) 264 logger.debug("Master Dom Set")
274 265
275 try: 266 try:
276 version = self.master_dom.getAttribute("version") 267 version = self.master_dom.getAttribute("version")
277 # see if we should load the gametree 268 # see if we should load the gametree
278 loadfeatures = int(self.settings.get_setting("LoadGameTreeFeatures")) 269 loadfeatures = int(self.settings.get_setting("LoadGameTreeFeatures"))
279 if loadfeatures: 270 if loadfeatures:
280 xml_dom = self.xml.parseXml(open(dir_struct["template"]+"feature.xml","r").read()) 271 xml_dom = xml.parseXml(open(dir_struct["template"]+"feature.xml","r").read())
281 xml_dom = xml_dom._get_documentElement() 272 xml_dom = xml_dom._get_documentElement()
282 xml_dom = self.master_dom.appendChild(xml_dom) 273 xml_dom = self.master_dom.appendChild(xml_dom)
283 self.settings.set_setting("LoadGameTreeFeatures","0") 274 self.settings.set_setting("LoadGameTreeFeatures","0")
284 275
285 ## load tree 276 ## load tree
286 self.orpgLog.log("Features loaded (if required)", ORPG_DEBUG) 277 logger.debug("Features loaded (if required)")
287 self.CollapseAndReset(self.root) 278 self.CollapseAndReset(self.root)
288 children = self.master_dom._get_childNodes() 279 children = self.master_dom._get_childNodes()
289 self.orpgLog.log("Parsing Gametree Nodes ", ORPG_INFO, True) 280 logger.info("Parsing Gametree Nodes ", True)
290 for c in children: 281 for c in children:
291 print '.', 282 print '.',
292 self.load_xml(c,self.root) 283 self.load_xml(c,self.root)
293 self.orpgLog.log("done", ORPG_INFO, True) 284 logger.info("done", True)
294 self.Expand(self.root) 285 self.Expand(self.root)
295 self.SetPyData(self.root,self.master_dom) 286 self.SetPyData(self.root,self.master_dom)
296 if error != 1: 287 if error != 1:
297 infile = open(filename, "rb") 288 infile = open(filename, "rb")
298 outfile = open(dir_struct["user"]+"lastgood.xml", "wb") 289 outfile = open(dir_struct["user"]+"lastgood.xml", "wb")
299 outfile.write(infile.read()) 290 outfile.write(infile.read())
300 else: 291 else: logger.info("Not overwriting lastgood.xml file.", True)
301 self.orpgLog.log("Not overwriting lastgood.xml file.", ORPG_INFO, True)
302 292
303 except Exception, e: 293 except Exception, e:
304 self.orpgLog.log(traceback.format_exc(), ORPG_GENERAL) 294 logger.general(traceback.format_exc())
305 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.") 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.")
306 os.rename(filename,filename+".corrupt") 296 os.rename(filename,filename+".corrupt")
307 self.validate.config_file("tree.xml","default_tree.xml") 297 validate.config_file("tree.xml","default_tree.xml")
308 self.load_tree(error=1) 298 self.load_tree(error=1)
309 299
310 @debugging 300 @debugging
311 def build_std_menu(self, obj=None): 301 def build_std_menu(self, obj=None):
312 # build useful menu 302 # build useful menu
381 ret_string = "" 371 ret_string = ""
382 x = 0 372 x = 0
383 in_tag = 0 373 in_tag = 0
384 for x in xrange(len(player[0])) : 374 for x in xrange(len(player[0])) :
385 if player[0][x] == "<" or player[0][x] == ">" or in_tag == 1 : 375 if player[0][x] == "<" or player[0][x] == ">" or in_tag == 1 :
386 if player[0][x] == "<" : 376 if player[0][x] == "<" : in_tag = 1
387 in_tag = 1 377 elif player[0][x] == ">" : in_tag = 0
388 elif player[0][x] == ">" : 378 else: pass
389 in_tag = 0 379 else: ret_string = ret_string + player[0][x]
390 else : 380 logger.debug(ret_string)
391 pass
392 else :
393 ret_string = ret_string + player[0][x]
394 self.orpgLog.log(ret_string, ORPG_DEBUG)
395 return ret_string 381 return ret_string
396 382
397 @debugging 383 @debugging
398 def on_receive_data(self, data, player): 384 def on_receive_data(self, data, player):
399 beg = string.find(data,"<tree>") 385 beg = string.find(data,"<tree>")
412 players = self.session.get_players() 398 players = self.session.get_players()
413 opts = [] 399 opts = []
414 myid = self.session.get_id() 400 myid = self.session.get_id()
415 me = None 401 me = None
416 for p in players: 402 for p in players:
417 if p[2] != myid: 403 if p[2] != myid: opts.append("("+p[2]+") " + self.strip_html(p))
418 opts.append("("+p[2]+") " + self.strip_html(p)) 404 else: me = p
419 else: 405 if len(opts): players.remove(me)
420 me = p
421 if len(opts):
422 players.remove(me)
423 if len(opts): 406 if len(opts):
424 dlg = orpgMultiCheckBoxDlg( self.GetParent(),opts,"Select Players:","Whisper To",[] ) 407 dlg = orpgMultiCheckBoxDlg( self.GetParent(),opts,"Select Players:","Whisper To",[] )
425 if dlg.ShowModal() == wx.ID_OK: 408 if dlg.ShowModal() == wx.ID_OK:
426 item = self.GetSelection() 409 item = self.GetSelection()
427 obj = self.GetPyData(item) 410 obj = self.GetPyData(item)
428 selections = dlg.get_selections() 411 selections = dlg.get_selections()
429 if len(selections) == len(opts): 412 if len(selections) == len(opts): self.chat.ParsePost(obj.tohtml(),True,True)
430 self.chat.ParsePost(obj.tohtml(),True,True)
431 else: 413 else:
432 player_ids = [] 414 player_ids = []
433 for s in selections: 415 for s in selections:
434 player_ids.append(players[s][2]) 416 player_ids.append(players[s][2])
435 self.chat.whisper_to_players(obj.tohtml(),player_ids) 417 self.chat.whisper_to_players(obj.tohtml(),player_ids)
479 players = self.session.get_players() 461 players = self.session.get_players()
480 opts = [] 462 opts = []
481 myid = self.session.get_id() 463 myid = self.session.get_id()
482 me = None 464 me = None
483 for p in players: 465 for p in players:
484 if p[2] != myid: 466 if p[2] != myid: opts.append("("+p[2]+") " + self.strip_html(p))
485 opts.append("("+p[2]+") " + self.strip_html(p)) 467 else: me = p
486 else:
487 me = p
488 if len(opts): 468 if len(opts):
489 players.remove(me) 469 players.remove(me)
490 dlg = orpgMultiCheckBoxDlg( None, opts, "Select Players:", "Send To", [] ) 470 dlg = orpgMultiCheckBoxDlg( None, opts, "Select Players:", "Send To", [] )
491 if dlg.ShowModal() == wx.ID_OK: 471 if dlg.ShowModal() == wx.ID_OK:
492 item = self.GetSelection() 472 item = self.GetSelection()
493 obj = self.GetPyData(item) 473 obj = self.GetPyData(item)
494 xmldata = "<tree>" + self.xml.toxml(obj) + "</tree>" 474 xmldata = "<tree>" + xml.toxml(obj) + "</tree>"
495 selections = dlg.get_selections() 475 selections = dlg.get_selections()
496 if len(selections) == len(opts): 476 if len(selections) == len(opts): self.session.send(xmldata)
497 self.session.send(xmldata)
498 else: 477 else:
499 for s in selections: 478 for s in selections: self.session.send(xmldata,players[s][2])
500 self.session.send(xmldata,players[s][2])
501 dlg.Destroy() 479 dlg.Destroy()
502 480
503 @debugging 481 @debugging
504 def on_icon(self, evt): 482 def on_icon(self, evt):
505 icons = self.icons.keys() 483 icons = self.icons.keys()
517 item = self.GetSelection() 495 item = self.GetSelection()
518 obj = self.GetPyData(item) 496 obj = self.GetPyData(item)
519 name = "New " + obj.master_dom.getAttribute("name") 497 name = "New " + obj.master_dom.getAttribute("name")
520 icon = obj.master_dom.getAttribute("icon") 498 icon = obj.master_dom.getAttribute("icon")
521 xml_data = "<nodehandler name=\""+name+"\" icon=\"" + icon + "\" module=\"core\" class=\"node_loader\" >" 499 xml_data = "<nodehandler name=\""+name+"\" icon=\"" + icon + "\" module=\"core\" class=\"node_loader\" >"
522 xml_data += self.xml.toxml(obj) 500 xml_data += xml.toxml(obj)
523 xml_data += "</nodehandler>" 501 xml_data += "</nodehandler>"
524 self.insert_xml(xml_data) 502 self.insert_xml(xml_data)
525 self.orpgLog.log(xml_data, ORPG_DEBUG) 503 logger.debug(xml_data)
526 504
527 @debugging 505 @debugging
528 def on_clone(self, evt): 506 def on_clone(self, evt):
529 item = self.GetSelection() 507 item = self.GetSelection()
530 obj = self.GetPyData(item) 508 obj = self.GetPyData(item)
531 if obj.can_clone(): 509 if obj.can_clone():
532 parent_node = self.GetItemParent(item) 510 parent_node = self.GetItemParent(item)
533 prev_sib = self.GetPrevSibling(item) 511 prev_sib = self.GetPrevSibling(item)
534 if not prev_sib.IsOk(): 512 if not prev_sib.IsOk(): prev_sib = parent_node
535 prev_sib = parent_node 513 xml_dom = xml.parseXml(xml.toxml(obj))
536 xml_dom = self.xml.parseXml(self.xml.toxml(obj))
537 xml_dom = xml_dom._get_firstChild() 514 xml_dom = xml_dom._get_firstChild()
538 parent = obj.master_dom._get_parentNode() 515 parent = obj.master_dom._get_parentNode()
539 xml_dom = parent.insertBefore(xml_dom, obj.master_dom) 516 xml_dom = parent.insertBefore(xml_dom, obj.master_dom)
540 self.load_xml(xml_dom, parent_node, prev_sib) 517 self.load_xml(xml_dom, parent_node, prev_sib)
541 518
564 @debugging 541 @debugging
565 def save_tree(self, filename=dir_struct["user"]+'tree.xml'): 542 def save_tree(self, filename=dir_struct["user"]+'tree.xml'):
566 self.master_dom.setAttribute("version",GAMETREE_VERSION) 543 self.master_dom.setAttribute("version",GAMETREE_VERSION)
567 self.settings.set_setting("gametree",filename) 544 self.settings.set_setting("gametree",filename)
568 file = open(filename,"w") 545 file = open(filename,"w")
569 file.write(self.xml.toxml(self.master_dom,1)) 546 file.write(xml.toxml(self.master_dom,1))
570 file.close() 547 file.close()
571 548
572 @debugging 549 @debugging
573 def on_load_new_tree(self, evt): 550 def on_load_new_tree(self, evt):
574 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","*.xml",wx.OPEN) 551 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","*.xml",wx.OPEN)
605 self.insert_xml(open(dir_struct["template"]+"feature.xml","r").read()) 582 self.insert_xml(open(dir_struct["template"]+"feature.xml","r").read())
606 583
607 @debugging 584 @debugging
608 def on_tree_prop(self, evt): 585 def on_tree_prop(self, evt):
609 dlg = gametree_prop_dlg(self, self.settings) 586 dlg = gametree_prop_dlg(self, self.settings)
610 if dlg.ShowModal() == wx.ID_OK: 587 if dlg.ShowModal() == wx.ID_OK: pass
611 pass
612 dlg.Destroy() 588 dlg.Destroy()
613 589
614 @debugging 590 @debugging
615 def on_node_design(self, evt): 591 def on_node_design(self, evt):
616 item = self.GetSelection() 592 item = self.GetSelection()
638 obj = self.GetPyData(item) 614 obj = self.GetPyData(item)
639 parent_obj = obj 615 parent_obj = obj
640 try: 616 try:
641 status_value = parent_obj.master_dom.getAttribute('status') 617 status_value = parent_obj.master_dom.getAttribute('status')
642 name = parent_obj.master_dom.getAttribute('name') 618 name = parent_obj.master_dom.getAttribute('name')
643 except: 619 except: status_value = "none"
644 status_value = "none"
645 parent_obj = parent_obj.master_dom._get_parentNode() 620 parent_obj = parent_obj.master_dom._get_parentNode()
646 while status_value!="useful" and status_value!="useless": 621 while status_value!="useful" and status_value!="useless":
647 try: 622 try:
648 status_value = parent_obj.getAttribute('status') 623 status_value = parent_obj.getAttribute('status')
649 name = parent_obj.getAttribute('name') 624 name = parent_obj.getAttribute('name')
650 if status_value == "useless": 625 if status_value == "useless": break
651 break 626 elif status_value == "useful": break
652 elif status_value == "useful": 627 except: status_value = "none"
653 break 628 try: parent_obj = parent_obj._get_parentNode()
654 except: 629 except: break
655 status_value = "none"
656 try:
657 parent_obj = parent_obj._get_parentNode()
658 except:
659 break
660 if status_value == "useful": 630 if status_value == "useful":
661 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) 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)
662 if dlg.ShowModal() == wx.ID_YES: 632 if dlg.ShowModal() == wx.ID_YES: obj.delete()
663 obj.delete() 633 else: obj.delete()
664 else:
665 obj.delete()
666 except: 634 except:
667 if self.GetSelection() == self.GetRootItem(): 635 if self.GetSelection() == self.GetRootItem():
668 msg = wx.MessageDialog(None,"You can't delete the root item.","Delete Error",wx.OK) 636 msg = wx.MessageDialog(None,"You can't delete the root item.","Delete Error",wx.OK)
669 else: 637 else: msg = wx.MessageDialog(None,"Unknown error deleting node.","Delete Error",wx.OK)
670 msg = wx.MessageDialog(None,"Unknown error deleting node.","Delete Error",wx.OK)
671 msg.ShowModal() 638 msg.ShowModal()
672 msg.Destroy() 639 msg.Destroy()
673 640
674 @debugging 641 @debugging
675 def on_about(self, evt): 642 def on_about(self, evt):
681 648
682 @debugging 649 @debugging
683 def on_send_to_map(self, evt): 650 def on_send_to_map(self, evt):
684 item = self.GetSelection() 651 item = self.GetSelection()
685 obj = self.GetPyData(item) 652 obj = self.GetPyData(item)
686 if hasattr(obj,"on_send_to_map"): 653 if hasattr(obj,"on_send_to_map"): obj.on_send_to_map(evt)
687 obj.on_send_to_map(evt)
688 654
689 @debugging 655 @debugging
690 def insert_xml(self, txt): 656 def insert_xml(self, txt):
691 self.orpgLog.log("Enter game_tree->insert_xml(self, txt)", ORPG_DEBUG)
692 #Updated to allow safe merging of gametree files 657 #Updated to allow safe merging of gametree files
693 #without leaving an unusable and undeletable node. 658 #without leaving an unusable and undeletable node.
694 # -- Snowdog 8/03 659 # -- Snowdog 8/03
695 xml_dom = self.xml.parseXml(txt) 660 xml_dom = xml.parseXml(txt)
696 if xml_dom == None: 661 if xml_dom == None:
697 wx.MessageBox("Import Failed: Invalid or missing node data") 662 wx.MessageBox("Import Failed: Invalid or missing node data")
698 self.orpgLog.log("Import Failed: Invalid or missing node data", ORPG_DEBUG) 663 logger.debug("Import Failed: Invalid or missing node data")
699 self.orpgLog.log("Exit game_tree->insert_xml(self, txt)", ORPG_DEBUG) 664 logger.debug("Exit game_tree->insert_xml(self, txt)")
700 return 665 return
701 xml_temp = xml_dom._get_documentElement() 666 xml_temp = xml_dom._get_documentElement()
702 667
703 if not xml_temp: 668 if not xml_temp:
704 wx.MessageBox("Error Importing Node or Tree") 669 wx.MessageBox("Error Importing Node or Tree")
705 self.orpgLog.log("Error Importing Node or Tree", ORPG_DEBUG) 670 logger.debug("Error Importing Node or Tree")
706 self.orpgLog.log("Exit game_tree->insert_xml(self, txt)", ORPG_DEBUG) 671 logger.debug("Exit game_tree->insert_xml(self, txt)")
707 return 672 return
708 673
709 if xml_temp._get_tagName() == "gametree": 674 if xml_temp._get_tagName() == "gametree":
710 children = xml_temp._get_childNodes() 675 children = xml_temp._get_childNodes()
711 for c in children: 676 for c in children: self.load_xml(c, self.root)
712 self.load_xml(c, self.root) 677 logger.debug("Exit game_tree->insert_xml(self, txt)")
713 self.orpgLog.log("Exit game_tree->insert_xml(self, txt)", ORPG_DEBUG)
714 return 678 return
715 679
716 if not xml_dom: 680 if not xml_dom:
717 wx.MessageBox("XML Error") 681 wx.MessageBox("XML Error")
718 self.orpgLog.log("XML Error", ORPG_DEBUG) 682 logger.debug("XML Error")
719 self.orpgLog.log("Exit game_tree->insert_xml(self, txt)", ORPG_DEBUG) 683 logger.debug("Exit game_tree->insert_xml(self, txt)")
720 return 684 return
721 685
722 xml_dom = xml_dom._get_firstChild() 686 xml_dom = xml_dom._get_firstChild()
723 child = self.master_dom._get_firstChild() 687 child = self.master_dom._get_firstChild()
724 xml_dom = self.master_dom.insertBefore(xml_dom,child) 688 xml_dom = self.master_dom.insertBefore(xml_dom,child)
729 """make image list""" 693 """make image list"""
730 helper = img_helper() 694 helper = img_helper()
731 self.icons = { } 695 self.icons = { }
732 self._imageList= wx.ImageList(16,16,False) 696 self._imageList= wx.ImageList(16,16,False)
733 man = open(dir_struct["icon"]+"icons.xml","r") 697 man = open(dir_struct["icon"]+"icons.xml","r")
734 xml_dom = self.xml.parseXml(man.read()) 698 xml_dom = xml.parseXml(man.read())
735 man.close() 699 man.close()
736 xml_dom = xml_dom._get_documentElement() 700 xml_dom = xml_dom._get_documentElement()
737 node_list = xml_dom._get_childNodes() 701 node_list = xml_dom._get_childNodes()
738 for n in node_list: 702 for n in node_list:
739 key = n.getAttribute("name") 703 key = n.getAttribute("name")
746 def load_xml(self, xml_dom, parent_node, prev_node=None): 710 def load_xml(self, xml_dom, parent_node, prev_node=None):
747 #add the first tree node 711 #add the first tree node
748 i = 0 712 i = 0
749 text = xml_dom.getAttribute("name") 713 text = xml_dom.getAttribute("name")
750 icon = xml_dom.getAttribute("icon") 714 icon = xml_dom.getAttribute("icon")
751 if self.icons.has_key(icon): 715 if self.icons.has_key(icon): i = self.icons[icon]
752 i = self.icons[icon]
753 name = xml_dom._get_nodeName() 716 name = xml_dom._get_nodeName()
754 self.orpgLog.log("Text, icon and name set\n" + text + "\n" + icon + "\n" + name, ORPG_DEBUG) 717 logger.debug("Text, icon and name set\n" + text + "\n" + icon + "\n" + name)
755 if prev_node: 718 if prev_node:
756 if prev_node == parent_node: 719 if prev_node == parent_node: new_tree_node = self.PrependItem(parent_node, text, i, i)
757 new_tree_node = self.PrependItem(parent_node, text, i, i) 720 else: new_tree_node = self.InsertItem(parent_node,prev_node, text, i, i)
758 else: 721 else: new_tree_node = self.AppendItem(parent_node, text, i, i)
759 new_tree_node = self.InsertItem(parent_node,prev_node, text, i, i) 722
760 else: 723 logger.debug("Node Added to tree")
761 new_tree_node = self.AppendItem(parent_node, text, i, i)
762
763 self.orpgLog.log("Node Added to tree", ORPG_DEBUG)
764 #create a nodehandler or continue loading xml into tree 724 #create a nodehandler or continue loading xml into tree
765 if name == "nodehandler": 725 if name == "nodehandler":
766 #wx.BeginBusyCursor() 726 #wx.BeginBusyCursor()
767 self.orpgLog.log("We have a Nodehandler", ORPG_DEBUG) 727 logger.debug("We have a Nodehandler")
768 try: 728 try:
769 py_class = xml_dom.getAttribute("class") 729 py_class = xml_dom.getAttribute("class")
770 self.orpgLog.log("nodehandler class: " + py_class, ORPG_DEBUG) 730 logger.debug("nodehandler class: " + py_class)
771 if not self.nodehandlers.has_key(py_class): 731 if not self.nodehandlers.has_key(py_class):
772 raise Exception, "Unknown Nodehandler for " + py_class 732 raise Exception, "Unknown Nodehandler for " + py_class
773 self.nodes[self.id] = self.nodehandlers[py_class](xml_dom, new_tree_node) 733 self.nodes[self.id] = self.nodehandlers[py_class](xml_dom, new_tree_node)
774 self.SetPyData(new_tree_node, self.nodes[self.id]) 734 self.SetPyData(new_tree_node, self.nodes[self.id])
775 self.orpgLog.log("Node Data set", ORPG_DEBUG) 735 logger.debug("Node Data set")
776 bmp = self.nodes[self.id].get_scaled_bitmap(16,16) 736 bmp = self.nodes[self.id].get_scaled_bitmap(16,16)
777 if bmp: 737 if bmp: self.cached_load_of_image(bmp,new_tree_node,)
778 self.cached_load_of_image(bmp,new_tree_node,) 738 logger.debug("Node Icon loaded")
779 self.orpgLog.log("Node Icon loaded", ORPG_DEBUG)
780 self.id = self.id + 1 739 self.id = self.id + 1
781 except Exception, er: 740 except Exception, er:
782 self.orpgLog.log(traceback.format_exc(), ORPG_GENERAL) 741 logger.general(traceback.format_exc())
783 #self.orpgLog.log("Error Info: " + xml_dom.getAttribute("class") + "\n" + str(er), ORPG_GENERAL, True)?indent? 742 #logger.debug("Error Info: " + xml_dom.getAttribute("class") + "\n" + str(er), True)?indent?
784 self.Delete(new_tree_node) 743 self.Delete(new_tree_node)
785 parent = xml_dom._get_parentNode() 744 parent = xml_dom._get_parentNode()
786 parent.removeChild(xml_dom) 745 parent.removeChild(xml_dom)
787 return new_tree_node 746 return new_tree_node
788 747
809 pt = evt.GetPosition() 768 pt = evt.GetPosition()
810 (item, flag) = self.HitTest(pt) 769 (item, flag) = self.HitTest(pt)
811 if item.IsOk(): 770 if item.IsOk():
812 obj = self.GetPyData(item) 771 obj = self.GetPyData(item)
813 self.SelectItem(item) 772 self.SelectItem(item)
814 if(isinstance(obj,core.node_handler)): 773 if(isinstance(obj,core.node_handler)): obj.on_rclick(evt)
815 obj.on_rclick(evt) 774 else: self.PopupMenu(self.top_menu)
816 else: 775 else: self.PopupMenu(self.top_menu,pt)
817 self.PopupMenu(self.top_menu)
818 else:
819 self.PopupMenu(self.top_menu,pt)
820 776
821 @debugging 777 @debugging
822 def on_ldclick(self, evt): 778 def on_ldclick(self, evt):
823 self.rename_flag = 0 779 self.rename_flag = 0
824 pt = evt.GetPosition() 780 pt = evt.GetPosition()
827 obj = self.GetPyData(item) 783 obj = self.GetPyData(item)
828 self.SelectItem(item) 784 self.SelectItem(item)
829 if(isinstance(obj,core.node_handler)): 785 if(isinstance(obj,core.node_handler)):
830 if not obj.on_ldclick(evt): 786 if not obj.on_ldclick(evt):
831 action = self.settings.get_setting("treedclick") 787 action = self.settings.get_setting("treedclick")
832 if action == "use": 788 if action == "use": obj.on_use(evt)
833 obj.on_use(evt) 789 elif action == "design": obj.on_design(evt)
834 elif action == "design": 790 elif action == "print": obj.on_html_view(evt)
835 obj.on_design(evt) 791 elif action == "chat": self.on_send_to_chat(evt)
836 elif action == "print":
837 obj.on_html_view(evt)
838 elif action == "chat":
839 self.on_send_to_chat(evt)
840 792
841 @debugging 793 @debugging
842 def on_left_down(self, evt): 794 def on_left_down(self, evt):
843 pt = evt.GetPosition() 795 pt = evt.GetPosition()
844 (item, flag) = self.HitTest(pt) 796 (item, flag) = self.HitTest(pt)
847 self.rename_flag = 0 799 self.rename_flag = 0
848 self.was_labeling = 0 800 self.was_labeling = 0
849 elif (flag & wx.TREE_HITTEST_ONITEMLABEL) == wx.TREE_HITTEST_ONITEMLABEL and self.IsSelected(item): 801 elif (flag & wx.TREE_HITTEST_ONITEMLABEL) == wx.TREE_HITTEST_ONITEMLABEL and self.IsSelected(item):
850 # this next if tests to ensure that the mouse up occurred over a label, and not the icon 802 # this next if tests to ensure that the mouse up occurred over a label, and not the icon
851 self.rename_flag = 1 803 self.rename_flag = 1
852 else: 804 else: self.SelectItem(item)
853 self.SelectItem(item)
854 evt.Skip() 805 evt.Skip()
855 806
856 @debugging 807 @debugging
857 def on_left_up(self, evt): 808 def on_left_up(self, evt):
858 if self.dragging: 809 if self.dragging:
875 self.was_labeling = 0 826 self.was_labeling = 0
876 self.rename_flag = 0 827 self.rename_flag = 0
877 if txt != "": 828 if txt != "":
878 obj = self.GetPyData(item) 829 obj = self.GetPyData(item)
879 obj.master_dom.setAttribute('name',txt) 830 obj.master_dom.setAttribute('name',txt)
880 else: 831 else: evt.Veto()
881 evt.Veto()
882 832
883 @debugging 833 @debugging
884 def on_label_begin(self, evt): 834 def on_label_begin(self, evt):
885 if not self.rename_flag: 835 if not self.rename_flag: evt.Veto()
886 evt.Veto()
887 else: 836 else:
888 self.was_labeling = 1 837 self.was_labeling = 1
889 item = evt.GetItem() 838 item = evt.GetItem()
890 if item == self.GetRootItem(): 839 if item == self.GetRootItem():
891 evt.Veto() 840 evt.Veto()
904 853
905 @debugging 854 @debugging
906 def is_parent_node(self, node, compare_node): 855 def is_parent_node(self, node, compare_node):
907 parent_node = self.GetItemParent(node) 856 parent_node = self.GetItemParent(node)
908 if compare_node == parent_node: 857 if compare_node == parent_node:
909 self.orpgLog.log("parent node", ORPG_DEBUG) 858 logger.debug("parent node")
910 return 1 859 return 1
911 elif parent_node == self.root: 860 elif parent_node == self.root:
912 self.orpgLog.log("not parent", ORPG_DEBUG) 861 logger.debug("not parent")
913 return 0 862 return 0
914 else: 863 else: return self.is_parent_node(parent_node, compare_node)
915 return self.is_parent_node(parent_node, compare_node)
916 864
917 CTRL_TREE_FILE = wx.NewId() 865 CTRL_TREE_FILE = wx.NewId()
918 CTRL_YES = wx.NewId() 866 CTRL_YES = wx.NewId()
919 CTRL_NO = wx.NewId() 867 CTRL_NO = wx.NewId()
920 CTRL_USE = wx.NewId() 868 CTRL_USE = wx.NewId()
984 932
985 @debugging 933 @debugging
986 def on_ok(self,evt): 934 def on_ok(self,evt):
987 self.settings.set_setting("gametree",self.ctrls[CTRL_TREE_FILE].GetValue()) 935 self.settings.set_setting("gametree",self.ctrls[CTRL_TREE_FILE].GetValue())
988 self.settings.set_setting("SaveGameTreeOnExit",str(self.ctrls[CTRL_YES].GetValue())) 936 self.settings.set_setting("SaveGameTreeOnExit",str(self.ctrls[CTRL_YES].GetValue()))
989 if self.ctrls[CTRL_USE].GetValue(): 937 if self.ctrls[CTRL_USE].GetValue(): self.settings.set_setting("treedclick","use")
990 self.settings.set_setting("treedclick","use") 938 elif self.ctrls[CTRL_DESIGN].GetValue(): self.settings.set_setting("treedclick","design")
991 elif self.ctrls[CTRL_DESIGN].GetValue(): 939 elif self.ctrls[CTRL_PRINT].GetValue(): self.settings.set_setting("treedclick","print")
992 self.settings.set_setting("treedclick","design") 940 elif self.ctrls[CTRL_CHAT].GetValue(): self.settings.set_setting("treedclick","chat")
993 elif self.ctrls[CTRL_PRINT].GetValue():
994 self.settings.set_setting("treedclick","print")
995 elif self.ctrls[CTRL_CHAT].GetValue():
996 self.settings.set_setting("treedclick","chat")
997 self.EndModal(wx.ID_OK) 941 self.EndModal(wx.ID_OK)