comparison orpg/gametree/gametree.py @ 151:06f10429eedc alpha

Traipse Alpha 'OpenRPG' {091125-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 (Cleaning up for Beta) Added Bookmarks Fix to Remote Admin Commands Minor fix to text based Server Fix to Pretty Print, from Core Fix to Splitter Nodes not being created Fix to massive amounts of images loading, from Core Added 'boot' command to remote admin Added confirmation window for sent nodes Minor changes to allow for portability to an OpenSUSE linux OS Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG Zoom Mouse plugin added Images added to Plugin UI Switching to Element Tree Map efficiency, from FlexiRPG Added Status Bar to Update Manager default_manifest.xml renamed to default_upmana.xml Cleaner clode for saved repositories New TrueDebug Class in orpg_log (See documentation for usage) Mercurial's hgweb folder is ported to upmana Pretty important update that can help remove thousands of dead children from your gametree. Children, <forms />, <group_atts />, <horizontal />, <cols />, <rows />, <height />, etc... are all tags now. Check your gametree and look for dead children!! New Gametree Recursion method, mapping, and context sensitivity. !Infinite Loops return error instead of freezing the software! New Syntax added for custom PC sheets Tip of the Day added, from Core and community Fixed Whiteboard ID to prevent random line or text deleting. Modified ID's to prevent non updated clients from ruining the fix.
author sirebral
date Wed, 25 Nov 2009 06:15:49 -0600
parents b4e02e8cd314
children 31fc0fc52a3a
comparison
equal deleted inserted replaced
149:c2caca988a11 151:06f10429eedc
33 from orpg.orpg_wx import * 33 from orpg.orpg_wx import *
34 from orpg.orpg_windows import * 34 from orpg.orpg_windows import *
35 from orpg.orpgCore import component 35 from orpg.orpgCore import component
36 from orpg.dirpath import dir_struct 36 from orpg.dirpath import dir_struct
37 from nodehandlers import core 37 from nodehandlers import core
38 import string 38 import string, urllib, time, os
39 import urllib
40 import time
41 import os
42 39
43 from orpg.orpg_xml import xml 40 from orpg.orpg_xml import xml
44 from orpg.tools.validate import validate 41 from orpg.tools.validate import validate
45 from orpg.tools.orpg_log import logger, debug 42 from orpg.tools.orpg_log import logger, debug
46 from orpg.tools.orpg_settings import settings 43 from orpg.tools.orpg_settings import settings
85 class game_tree(wx.TreeCtrl): 82 class game_tree(wx.TreeCtrl):
86 83
87 def __init__(self, parent, id): 84 def __init__(self, parent, id):
88 wx.TreeCtrl.__init__(self,parent,id, wx.DefaultPosition, 85 wx.TreeCtrl.__init__(self,parent,id, wx.DefaultPosition,
89 wx.DefaultSize,style=wx.TR_EDIT_LABELS | wx.TR_HAS_BUTTONS) 86 wx.DefaultSize,style=wx.TR_EDIT_LABELS | wx.TR_HAS_BUTTONS)
90 #self.xml = component.get('xml') #
91 self.settings = component.get('settings')
92 self.session = component.get('session')
93 self.chat = component.get('chat') 87 self.chat = component.get('chat')
94 self.mainframe = component.get('frame') 88 self.mainframe = component.get('frame')
95 self.build_img_list() 89 self.build_img_list()
96 self.build_std_menu() 90 self.build_std_menu()
97 self.nodehandlers = {} 91 self.nodehandlers = {}
125 def add_nodehandler(self, nodehandler, nodeclass): 119 def add_nodehandler(self, nodehandler, nodeclass):
126 if not self.nodehandlers.has_key(nodehandler): self.nodehandlers[nodehandler] = nodeclass 120 if not self.nodehandlers.has_key(nodehandler): self.nodehandlers[nodehandler] = nodeclass
127 else: logger.debug("Nodehandler for " + nodehandler + " already exists!") 121 else: logger.debug("Nodehandler for " + nodehandler + " already exists!")
128 122
129 def remove_nodehandler(self, nodehandler): 123 def remove_nodehandler(self, nodehandler):
130 if self.nodehandlers.has_key(nodehandler): 124 if self.nodehandlers.has_key(nodehandler): del self.nodehandlers[nodehandler]
131 del self.nodehandlers[nodehandler]
132 else: logger.debug("No nodehandler for " + nodehandler + " exists!") 125 else: logger.debug("No nodehandler for " + nodehandler + " exists!")
133 126
134 def init_nodehandlers(self): 127 def init_nodehandlers(self):
135 self.add_nodehandler('group_handler', containers.group_handler) 128 self.add_nodehandler('group_handler', containers.group_handler)
136 self.add_nodehandler('tabber_handler', containers.tabber_handler) 129 self.add_nodehandler('tabber_handler', containers.tabber_handler)
152 self.add_nodehandler('voxchat_handler', voxchat.voxchat_handler) 145 self.add_nodehandler('voxchat_handler', voxchat.voxchat_handler)
153 self.add_nodehandler('file_loader', core.file_loader) 146 self.add_nodehandler('file_loader', core.file_loader)
154 self.add_nodehandler('node_loader', core.node_loader) 147 self.add_nodehandler('node_loader', core.node_loader)
155 self.add_nodehandler('url_loader', core.url_loader) 148 self.add_nodehandler('url_loader', core.url_loader)
156 self.add_nodehandler('min_map', core.min_map) 149 self.add_nodehandler('min_map', core.min_map)
157
158 # event = wxKeyEvent
159 # set to be called by wxWindows by EVT_CHAR macro in __init__
160 150
161 def on_key_up(self, evt): 151 def on_key_up(self, evt):
162 key_code = evt.GetKeyCode() 152 key_code = evt.GetKeyCode()
163 if self.dragging and (key_code == wx.WXK_SHIFT): 153 if self.dragging and (key_code == wx.WXK_SHIFT):
164 curSelection = self.GetSelection() 154 curSelection = self.GetSelection()
187 elif key_code == wx.WXK_LEFT: self.Collapse(curSelection) 177 elif key_code == wx.WXK_LEFT: self.Collapse(curSelection)
188 elif key_code == wx.WXK_DELETE: # Handle the delete key 178 elif key_code == wx.WXK_DELETE: # Handle the delete key
189 if curSelection: 179 if curSelection:
190 nextSelect = self.GetItemParent(curSelection) 180 nextSelect = self.GetItemParent(curSelection)
191 self.on_del(evt) 181 self.on_del(evt)
192 try: 182 try:
193 if self.GetItemText(nextSelect) != "": self.SelectItem(nextSelect) 183 if self.GetItemText(nextSelect) != "": self.SelectItem(nextSelect)
194 except: pass 184 except: pass
195 elif key_code == wx.WXK_F2: 185 elif key_code == wx.WXK_F2:
196 self.rename_flag = 1 186 self.rename_flag = 1
197 self.EditLabel(curSelection) 187 self.EditLabel(curSelection)
216 self.load_tree(error=1) 206 self.load_tree(error=1)
217 return 207 return
218 208
219 209
220 def load_tree(self, filename=dir_struct["user"]+'tree.xml', error=0): 210 def load_tree(self, filename=dir_struct["user"]+'tree.xml', error=0):
221 self.settings.change("gametree", filename) 211 settings.change("gametree", filename)
222 #check file exists
223 if not os.path.exists(filename): 212 if not os.path.exists(filename):
224 emsg = "Gametree Missing!\n"+filename+" cannot be found.\n\n"\ 213 emsg = "Gametree Missing!\n"+filename+" cannot be found.\n\n"\
225 "Would you like to locate it?\n"\ 214 "Would you like to locate it?\n"\
226 "(Selecting 'No' will cause a new default gametree to be generated)" 215 "(Selecting 'No' will cause a new default gametree to be generated)"
227 self.locate_valid_tree("Gametree Error", emsg) 216 self.locate_valid_tree("Gametree Error", emsg)
228 return 217 return
229 try: 218 try:
230 f = open(filename, "rb") 219 tree = parse(filename)
231 tree = parse(f)
232 self.xml_root = tree.getroot() 220 self.xml_root = tree.getroot()
233 except: 221 except:
234 f.close()
235 self.xml_root = None 222 self.xml_root = None
236 ### Alpha ### Doing some work on Gametree to add Element Tree, slowly at first.
237 223
238 if not self.xml_root: 224 if not self.xml_root:
239 os.rename(filename,filename+".corrupt") 225 os.rename(filename,filename+".corrupt")
240 emsg = "Your gametree is being regenerated.\n\n"\ 226 emsg = "Your gametree is being regenerated.\n\n"\
241 "To salvage a recent version of your gametree\n"\ 227 "To salvage a recent version of your gametree\n"\
346 self.Bind(wx.EVT_MENU, self.on_save_tree, id=TOP_SAVE_TREE) 332 self.Bind(wx.EVT_MENU, self.on_save_tree, id=TOP_SAVE_TREE)
347 self.Bind(wx.EVT_MENU, self.on_load_new_tree, id=TOP_NEW_TREE) 333 self.Bind(wx.EVT_MENU, self.on_load_new_tree, id=TOP_NEW_TREE)
348 self.Bind(wx.EVT_MENU, self.on_tree_prop, id=TOP_TREE_PROP) 334 self.Bind(wx.EVT_MENU, self.on_tree_prop, id=TOP_TREE_PROP)
349 self.Bind(wx.EVT_MENU, self.on_insert_features, id=TOP_FEATURES) 335 self.Bind(wx.EVT_MENU, self.on_insert_features, id=TOP_FEATURES)
350 336
351
352 def do_std_menu(self, evt, obj): 337 def do_std_menu(self, evt, obj):
353 try: self.std_menu.Enable(STD_MENU_MAP, obj.checkToMapMenu()) 338 try: self.std_menu.Enable(STD_MENU_MAP, obj.checkToMapMenu())
354 except: self.std_menu.Enable(STD_MENU_MAP, obj.map_aware()) 339 except: self.std_menu.Enable(STD_MENU_MAP, obj.map_aware())
355 self.std_menu.Enable(STD_MENU_CLONE, obj.can_clone()) 340 self.std_menu.Enable(STD_MENU_CLONE, obj.can_clone())
356 self.PopupMenu(self.std_menu) 341 self.PopupMenu(self.std_menu)
357 342
358
359 def strip_html(self, player): 343 def strip_html(self, player):
360 ret_string = "" 344 ret_string = ""
361 x = 0 345 x = 0
362 in_tag = 0 346 in_tag = 0
363 for x in xrange(len(player[0])) : 347 for x in xrange(len(player[0])) :
367 else: pass 351 else: pass
368 else: ret_string = ret_string + player[0][x] 352 else: ret_string = ret_string + player[0][x]
369 logger.debug(ret_string) 353 logger.debug(ret_string)
370 return ret_string 354 return ret_string
371 355
372
373 def on_receive_data(self, data): 356 def on_receive_data(self, data):
374 self.insert_xml(data) 357 self.insert_xml(data)
375 358
376 def on_send_to_chat(self, evt): 359 def on_send_to_chat(self, evt):
377 item = self.GetSelection() 360 item = self.GetSelection()
394 obj = self.GetPyData(item) 377 obj = self.GetPyData(item)
395 selections = dlg.get_selections() 378 selections = dlg.get_selections()
396 if len(selections) == len(opts): self.chat.ParsePost(obj.tohtml(),True,True) 379 if len(selections) == len(opts): self.chat.ParsePost(obj.tohtml(),True,True)
397 else: 380 else:
398 player_ids = [] 381 player_ids = []
399 for s in selections: 382 for s in selections: player_ids.append(players[s][2])
400 player_ids.append(players[s][2])
401 self.chat.whisper_to_players(obj.tohtml(),player_ids) 383 self.chat.whisper_to_players(obj.tohtml(),player_ids)
402 384
403
404 def on_export_html(self, evt): 385 def on_export_html(self, evt):
405 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","HTML (*.html)|*.html",wx.SAVE) 386 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","HTML (*.html)|*.html",wx.SAVE)
406 if f.ShowModal() == wx.ID_OK: 387 if f.ShowModal() == wx.ID_OK:
407 item = self.GetSelection() 388 item = self.GetSelection()
408 obj = self.GetPyData(item) 389 obj = self.GetPyData(item)
409 type = f.GetFilterIndex() 390 type = f.GetFilterIndex()
410 with open(f.GetPath(),"w") as f: 391 with open(f.GetPath(),"w") as f:
411 data = "<html><head><title>"+obj.xml.get("name")+"</title></head>" 392 data = "<html><head><title>"+obj.xml.get("name")+"</title></head>"
412 data += "<body bgcolor='#FFFFFF' >"+obj.tohtml()+"</body></html>" 393 data += "<body bgcolor='#FFFFFF' >"+obj.tohtml()+"</body></html>"
413 for tag in ("</tr>","</td>","</th>","</table>","</html>","</body>"): 394 for tag in ("</tr>","</td>","</th>","</table>","</html>","</body>"): data = data.replace(tag,tag+"\n")
414 data = data.replace(tag,tag+"\n")
415 f.write(data) 395 f.write(data)
416 self.last_save_dir, throwaway = os.path.split( f.GetPath() ) 396 self.last_save_dir, throwaway = os.path.split( f.GetPath() )
417 f.Destroy() 397 f.Destroy()
418 os.chdir(dir_struct["home"]) 398 os.chdir(dir_struct["home"])
419 399
420
421 def indifferent(self, evt): 400 def indifferent(self, evt):
422 item = self.GetSelection() 401 item = self.GetSelection()
423 obj = self.GetPyData(item) 402 obj = self.GetPyData(item)
424 obj.usefulness("indifferent") 403 obj.usefulness("indifferent")
425 404
426
427 def useful(self, evt): 405 def useful(self, evt):
428 item = self.GetSelection() 406 item = self.GetSelection()
429 obj = self.GetPyData(item) 407 obj = self.GetPyData(item)
430 obj.usefulness("useful") 408 obj.usefulness("useful")
431 409
432
433 def useless(self, evt): 410 def useless(self, evt):
434 item = self.GetSelection() 411 item = self.GetSelection()
435 obj = self.GetPyData(item) 412 obj = self.GetPyData(item)
436 obj.usefulness("useless") 413 obj.usefulness("useless")
437 414
438
439 def on_email(self,evt): 415 def on_email(self,evt):
440 pass 416 pass
441 417
442
443 def on_send_to(self, evt): 418 def on_send_to(self, evt):
444 players = self.session.get_players() 419 players = self.session.get_players()
445 opts = [] 420 opts = []
446 myid = self.session.get_id() 421 myid = self.session.get_id()
447 me = None 422 me = None
459 if len(selections) == len(opts): self.session.send(xmldata) 434 if len(selections) == len(opts): self.session.send(xmldata)
460 else: 435 else:
461 for s in selections: self.session.send(xmldata,players[s][2]) 436 for s in selections: self.session.send(xmldata,players[s][2])
462 dlg.Destroy() 437 dlg.Destroy()
463 438
464
465 def on_icon(self, evt): 439 def on_icon(self, evt):
466 icons = self.icons.keys() 440 icons = self.icons.keys()
467 icons.sort() 441 icons.sort()
468 dlg = wx.SingleChoiceDialog(self,"Choose Icon?","Change Icon",icons) 442 dlg = wx.SingleChoiceDialog(self,"Choose Icon?","Change Icon",icons)
469 if dlg.ShowModal() == wx.ID_OK: 443 if dlg.ShowModal() == wx.ID_OK:
471 item = self.GetSelection() 445 item = self.GetSelection()
472 obj = self.GetPyData(item) 446 obj = self.GetPyData(item)
473 obj.change_icon(key) 447 obj.change_icon(key)
474 dlg.Destroy() 448 dlg.Destroy()
475 449
476
477 def on_wizard(self, evt): 450 def on_wizard(self, evt):
478 item = self.GetSelection() 451 item = self.GetSelection()
479 obj = self.GetPyData(item) 452 obj = self.GetPyData(item)
480 name = "New " + obj.xml_root.get("name") 453 name = "New " + obj.xml_root.get("name")
481 icon = obj.xml_root.get("icon") 454 icon = obj.xml_root.get("icon")
483 xml_data += xml.toxml(obj) 456 xml_data += xml.toxml(obj)
484 xml_data += "</nodehandler>" 457 xml_data += "</nodehandler>"
485 self.insert_xml(xml_data) 458 self.insert_xml(xml_data)
486 logger.debug(xml_data) 459 logger.debug(xml_data)
487 460
488
489 def on_clone(self, evt): 461 def on_clone(self, evt):
490 item = self.GetSelection() 462 item = self.GetSelection()
491 obj = self.GetPyData(item) 463 obj = self.GetPyData(item)
492 if obj.can_clone(): 464 if obj.can_clone():
493 parent_node = self.GetItemParent(item) 465 parent_node = self.GetItemParent(item)
496 clone_xml = XML(tostring(obj.xml)) 468 clone_xml = XML(tostring(obj.xml))
497 if parent_node == self.root: parent_xml = self.GetPyData(parent_node) 469 if parent_node == self.root: parent_xml = self.GetPyData(parent_node)
498 else: parent_xml = self.GetPyData(parent_node).xml 470 else: parent_xml = self.GetPyData(parent_node).xml
499 for i in range(len(parent_xml)): 471 for i in range(len(parent_xml)):
500 if parent_xml[i] is obj.xml: 472 if parent_xml[i] is obj.xml:
473 name = self.clone_renaming(parent_xml, parent_xml[i].get('name'))
474 clone_xml.set('name', name)
501 parent_xml.insert(i, clone_xml) 475 parent_xml.insert(i, clone_xml)
502 break 476 break
503 self.load_xml(clone_xml, parent_node, prev_sib) 477 self.load_xml(clone_xml, parent_node, prev_sib)
504 478
505 479 def clone_renaming(self, node, name):
480 node_list = node.getchildren()
481 parent = node
482 append = name.split('_')
483 try: append_d = int(append[len(append)-1]); del append[len(append)-1]
484 except: append_d = False
485 if append_d:
486 append_d += 1; name = ''
487 for a in append: name += a+'_'
488 name = name+str(append_d)
489 if not append_d:
490 append_d = 1; name = ''
491 for a in append: name += a+'_'
492 name = name+str(append_d)
493 for n in node_list:
494 if n.get('name') == name: name = self.clone_renaming(parent, name)
495 return name
496
506 def on_save(self, evt): 497 def on_save(self, evt):
507 """save node to a xml file""" 498 """save node to a xml file"""
508 item = self.GetSelection() 499 item = self.GetSelection()
509 obj = self.GetPyData(item) 500 obj = self.GetPyData(item)
510 obj.on_save(evt) 501 obj.on_save(evt)
511 os.chdir(dir_struct["home"]) 502 os.chdir(dir_struct["home"])
512 503
513
514 def on_save_tree_as(self, evt): 504 def on_save_tree_as(self, evt):
515 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","*.xml",wx.SAVE) 505 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","*.xml",wx.SAVE)
516 if f.ShowModal() == wx.ID_OK: 506 if f.ShowModal() == wx.ID_OK:
517 self.save_tree(f.GetPath()) 507 self.save_tree(f.GetPath())
518 self.last_save_dir, throwaway = os.path.split( f.GetPath() ) 508 self.last_save_dir, throwaway = os.path.split( f.GetPath() )
519 f.Destroy() 509 f.Destroy()
520 os.chdir(dir_struct["home"]) 510 os.chdir(dir_struct["home"])
521 511
522
523 def on_save_tree(self, evt=None): 512 def on_save_tree(self, evt=None):
524 filename = self.settings.get_setting("gametree") 513 filename = settings.get_setting("gametree")
525 self.save_tree(filename) 514 self.save_tree(filename)
526 515
527
528 def save_tree(self, filename=dir_struct["user"]+'tree.xml'): 516 def save_tree(self, filename=dir_struct["user"]+'tree.xml'):
529 self.xml_root.set("version", GAMETREE_VERSION) 517 self.xml_root.set("version", GAMETREE_VERSION)
530 settings.change("gametree", filename) 518 settings.change("gametree", filename)
531 ElementTree(self.xml_root).write(filename) 519 ElementTree(self.xml_root).write(filename)
532 520
533
534 def on_load_new_tree(self, evt): 521 def on_load_new_tree(self, evt):
535 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","*.xml",wx.OPEN) 522 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","*.xml",wx.OPEN)
536 if f.ShowModal() == wx.ID_OK: 523 if f.ShowModal() == wx.ID_OK:
537 self.load_tree(f.GetPath()) 524 self.load_tree(f.GetPath())
538 self.last_save_dir, throwaway = os.path.split( f.GetPath() ) 525 self.last_save_dir, throwaway = os.path.split( f.GetPath() )
539 f.Destroy() 526 f.Destroy()
540 os.chdir(dir_struct["home"]) 527 os.chdir(dir_struct["home"])
541 528
542
543 def on_insert_file(self, evt): 529 def on_insert_file(self, evt):
544 """loads xml file into the tree""" 530 """loads xml file into the tree"""
545 if self.last_save_dir == ".": 531 if self.last_save_dir == ".":
546 self.last_save_dir = dir_struct["user"] 532 self.last_save_dir = dir_struct["user"]
547 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","*.xml",wx.OPEN) 533 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","*.xml",wx.OPEN)
549 self.insert_xml(open(f.GetPath(),"r").read()) 535 self.insert_xml(open(f.GetPath(),"r").read())
550 self.last_save_dir, throwaway = os.path.split( f.GetPath() ) 536 self.last_save_dir, throwaway = os.path.split( f.GetPath() )
551 f.Destroy() 537 f.Destroy()
552 os.chdir(dir_struct["home"]) 538 os.chdir(dir_struct["home"])
553 539
554
555 def on_insert_url(self, evt): 540 def on_insert_url(self, evt):
556 """loads xml url into the tree""" 541 """loads xml url into the tree"""
557 dlg = wx.TextEntryDialog(self,"URL?","Insert URL", "http://") 542 dlg = wx.TextEntryDialog(self,"URL?","Insert URL", "http://")
558 if dlg.ShowModal() == wx.ID_OK: 543 if dlg.ShowModal() == wx.ID_OK:
559 path = dlg.GetValue() 544 path = dlg.GetValue()
560 file = urllib.urlopen(path) 545 file = urllib.urlopen(path)
561 self.insert_xml(file.read()) 546 self.insert_xml(file.read())
562 dlg.Destroy() 547 dlg.Destroy()
563 548
564
565 def on_insert_features(self, evt): 549 def on_insert_features(self, evt):
566 self.insert_xml(open(dir_struct["template"]+"feature.xml","r").read()) 550 self.insert_xml(open(dir_struct["template"]+"feature.xml","r").read())
567 551
568
569 def on_tree_prop(self, evt): 552 def on_tree_prop(self, evt):
570 dlg = gametree_prop_dlg(self, self.settings) 553 dlg = gametree_prop_dlg(self, settings)
571 if dlg.ShowModal() == wx.ID_OK: pass 554 if dlg.ShowModal() == wx.ID_OK: pass
572 dlg.Destroy() 555 dlg.Destroy()
573 556
574
575 def on_node_design(self, evt): 557 def on_node_design(self, evt):
576 item = self.GetSelection() 558 item = self.GetSelection()
577 obj = self.GetPyData(item) 559 obj = self.GetPyData(item)
578 obj.on_design(evt) 560 obj.on_design(evt)
579 561
580
581 def on_node_use(self, evt): 562 def on_node_use(self, evt):
582 item = self.GetSelection() 563 item = self.GetSelection()
583 obj = self.GetPyData(item) 564 obj = self.GetPyData(item)
584 obj.on_use(evt) 565 obj.on_use(evt)
585 566
586
587 def on_node_pp(self, evt): 567 def on_node_pp(self, evt):
588 item = self.GetSelection() 568 item = self.GetSelection()
589 obj = self.GetPyData(item) 569 obj = self.GetPyData(item)
590 obj.on_html_view(evt) 570 obj.on_html_view(evt)
591 571
592
593 def on_del(self, evt): 572 def on_del(self, evt):
594 status_value = "none" 573 status_value = "none"
595 try: 574 try:
596 item = self.GetSelection() 575 item = self.GetSelection()
597 if item: 576 if item:
602 while parent_item.IsOk() and status_value!="useful" and status_value!="useless": 581 while parent_item.IsOk() and status_value!="useful" and status_value!="useless":
603 try: 582 try:
604 parent_handler = self.GetPyData(parent_item) 583 parent_handler = self.GetPyData(parent_item)
605 status_value = parent_handler.get('status') 584 status_value = parent_handler.get('status')
606 name = parent_handler.get('name') 585 name = parent_handler.get('name')
607 if status_value == "useless": 586 if status_value == "useless": break
608 break 587 elif status_value == "useful": break
609 elif status_value == "useful": 588 except: status_value = "none"
610 break
611 except:
612 status_value = "none"
613 parent_item = self.GetItemParent(parent_item) 589 parent_item = self.GetItemParent(parent_item)
614 if status_value == "useful": 590 if status_value == "useful":
615 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) 591 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)
616 if dlg.ShowModal() == wx.ID_YES: handler.delete() 592 if dlg.ShowModal() == wx.ID_YES: handler.delete()
617 else: handler.delete() 593 else: handler.delete()
618 except: 594 except:
619 if self.GetSelection() == self.GetRootItem(): 595 if self.GetSelection() == self.GetRootItem(): msg = wx.MessageDialog(None,"You can't delete the root item.","Delete Error",wx.OK)
620 msg = wx.MessageDialog(None,"You can't delete the root item.","Delete Error",wx.OK)
621 else: msg = wx.MessageDialog(None,"Unknown error deleting node.","Delete Error",wx.OK) 596 else: msg = wx.MessageDialog(None,"Unknown error deleting node.","Delete Error",wx.OK)
622 msg.ShowModal() 597 msg.ShowModal()
623 msg.Destroy() 598 msg.Destroy()
624 599
625
626 def on_about(self, evt): 600 def on_about(self, evt):
627 item = self.GetSelection() 601 item = self.GetSelection()
628 obj = self.GetPyData(item) 602 obj = self.GetPyData(item)
629 about = MyAboutBox(self,obj.about()) 603 text = str(obj.about())
630 about.ShowModal() 604 #about = MyAboutBox(self, obj.about())
631 about.Destroy() 605 wx.MessageBox(text, 'About')#.ShowModal()
606 #about.ShowModal()
607 #about.Destroy()
632 608
633 def on_send_to_map(self, evt): 609 def on_send_to_map(self, evt):
634 item = self.GetSelection() 610 item = self.GetSelection()
635 obj = self.GetPyData(item) 611 obj = self.GetPyData(item)
636 if hasattr(obj,"on_send_to_map"): obj.on_send_to_map(evt) 612 if hasattr(obj,"on_send_to_map"): obj.on_send_to_map(evt)
646 try: new_xml = XML(txt) 622 try: new_xml = XML(txt)
647 except ExpatError: 623 except ExpatError:
648 wx.MessageBox("Error Importing Node or Tree") 624 wx.MessageBox("Error Importing Node or Tree")
649 logger.general("Error Importing Node or Tree") 625 logger.general("Error Importing Node or Tree")
650 return 626 return
651
652 if new_xml.tag == "gametree": 627 if new_xml.tag == "gametree":
653 for xml_child in new_xml: 628 for xml_child in new_xml: self.load_xml(xml_child, self.root)
654 self.load_xml(xml_child, self.root)
655 return 629 return
656
657 if new_xml.tag == "tree": 630 if new_xml.tag == "tree":
658 self.xml_root.append(new_xml.find('nodehandler')) 631 self.xml_root.append(new_xml.find('nodehandler'))
659 for xml_child in new_xml: 632 for xml_child in new_xml: self.load_xml(xml_child, self.root)
660 self.load_xml(xml_child, self.root)
661 return 633 return
662
663 self.xml_root.append(new_xml) 634 self.xml_root.append(new_xml)
664 self.load_xml(new_xml, self.root, self.root) 635 self.load_xml(new_xml, self.root, self.root)
665 636
666 def build_img_list(self): 637 def build_img_list(self):
667 """make image list""" 638 """make image list"""
693 if parent_node != self.root: 664 if parent_node != self.root:
694 ## Loading XML seems to lag on Grids and Images need a cache for load speed ## 665 ## Loading XML seems to lag on Grids and Images need a cache for load speed ##
695 family_tree = self.get_tree_map(parent_node) 666 family_tree = self.get_tree_map(parent_node)
696 family_tree.reverse() 667 family_tree.reverse()
697 map_str = '' #'!@' 668 map_str = '' #'!@'
698 for member in family_tree: 669 for member in family_tree: map_str += member +'::'
699 map_str += member +'::'
700 map_str = map_str[:len(map_str)-2] #+'@!' 670 map_str = map_str[:len(map_str)-2] #+'@!'
701 xml_element.set('map', map_str) 671 xml_element.set('map', map_str)
702 672
703 #add the first tree node 673 #add the first tree node
704 i = 0 674 i = 0
715 #create a nodehandler or continue loading xml into tree 685 #create a nodehandler or continue loading xml into tree
716 if xml_element.tag == "nodehandler": 686 if xml_element.tag == "nodehandler":
717 try: 687 try:
718 py_class = xml_element.get("class") 688 py_class = xml_element.get("class")
719 logger.debug("nodehandler class: " + py_class) 689 logger.debug("nodehandler class: " + py_class)
720 if not self.nodehandlers.has_key(py_class): 690 if not self.nodehandlers.has_key(py_class): raise Exception("Unknown Nodehandler for " + py_class)
721 raise Exception("Unknown Nodehandler for " + py_class)
722 self.nodes[self.id] = self.nodehandlers[py_class](xml_element, new_tree_node) 691 self.nodes[self.id] = self.nodehandlers[py_class](xml_element, new_tree_node)
723 self.SetPyData(new_tree_node, self.nodes[self.id]) 692 self.SetPyData(new_tree_node, self.nodes[self.id])
724 logger.debug("Node Data set") 693 logger.debug("Node Data set")
725 bmp = self.nodes[self.id].get_scaled_bitmap(16,16) 694 bmp = self.nodes[self.id].get_scaled_bitmap(16,16)
726 if bmp: self.cached_load_of_image(bmp,new_tree_node,) 695 if bmp: self.cached_load_of_image(bmp,new_tree_node,)
767 if item.IsOk(): 736 if item.IsOk():
768 obj = self.GetPyData(item) 737 obj = self.GetPyData(item)
769 self.SelectItem(item) 738 self.SelectItem(item)
770 if(isinstance(obj,core.node_handler)): 739 if(isinstance(obj,core.node_handler)):
771 if not obj.on_ldclick(evt): 740 if not obj.on_ldclick(evt):
772 action = self.settings.get_setting("treedclick") 741 action = settings.get_setting("treedclick")
773 if action == "use": obj.on_use(evt) 742 if action == "use": obj.on_use(evt)
774 elif action == "design": obj.on_design(evt) 743 elif action == "design": obj.on_design(evt)
775 elif action == "print": obj.on_html_view(evt) 744 elif action == "print": obj.on_html_view(evt)
776 elif action == "chat": self.on_send_to_chat(evt) 745 elif action == "chat": self.on_send_to_chat(evt)
777 746
804 773
805 def traverse(self, root, function, data=None, recurse=True): 774 def traverse(self, root, function, data=None, recurse=True):
806 child, cookie = self.GetFirstChild(root) 775 child, cookie = self.GetFirstChild(root)
807 while child.IsOk(): 776 while child.IsOk():
808 function(child, data) 777 function(child, data)
809 if recurse: 778 if recurse: self.traverse(child, function, data)
810 self.traverse(child, function, data)
811 child, cookie = self.GetNextChild(root, cookie) 779 child, cookie = self.GetNextChild(root, cookie)
812 780
813 def on_label_change(self, evt): 781 def on_label_change(self, evt):
814 item = evt.GetItem() 782 item = evt.GetItem()
815 txt = evt.GetLabel() 783 txt = evt.GetLabel()
823 def on_label_begin(self, evt): 791 def on_label_begin(self, evt):
824 if not self.rename_flag: evt.Veto() 792 if not self.rename_flag: evt.Veto()
825 else: 793 else:
826 self.was_labeling = 1 794 self.was_labeling = 1
827 item = evt.GetItem() 795 item = evt.GetItem()
828 if item == self.GetRootItem(): 796 if item == self.GetRootItem(): evt.Veto()
829 evt.Veto()
830 797
831 def on_drag(self, evt): 798 def on_drag(self, evt):
832 self.rename_flag = 0 799 self.rename_flag = 0
833 item = self.GetSelection() 800 item = self.GetSelection()
834 obj = self.GetPyData(item) 801 obj = self.GetPyData(item)
859 826
860 class gametree_prop_dlg(wx.Dialog): 827 class gametree_prop_dlg(wx.Dialog):
861 828
862 def __init__(self, parent, settings): 829 def __init__(self, parent, settings):
863 wx.Dialog.__init__(self, parent, wx.ID_ANY, "Game Tree Properties") 830 wx.Dialog.__init__(self, parent, wx.ID_ANY, "Game Tree Properties")
864 self.settings = settings
865 831
866 #sizers 832 #sizers
867 sizers = {} 833 sizers = {}
868 sizers['but'] = wx.BoxSizer(wx.HORIZONTAL) 834 sizers['but'] = wx.BoxSizer(wx.HORIZONTAL)
869 sizers['main'] = wx.BoxSizer(wx.VERTICAL) 835 sizers['main'] = wx.BoxSizer(wx.VERTICAL)
917 self.Fit() 883 self.Fit()
918 self.Bind(wx.EVT_BUTTON, self.on_ok, id=wx.ID_OK) 884 self.Bind(wx.EVT_BUTTON, self.on_ok, id=wx.ID_OK)
919 885
920 886
921 def on_ok(self,evt): 887 def on_ok(self,evt):
922 self.settings.change("gametree",self.ctrls[CTRL_TREE_FILE].GetValue()) 888 settings.change("gametree",self.ctrls[CTRL_TREE_FILE].GetValue())
923 self.settings.change("SaveGameTreeOnExit",str(self.ctrls[CTRL_YES].GetValue())) 889 settings.change("SaveGameTreeOnExit",str(self.ctrls[CTRL_YES].GetValue()))
924 if self.ctrls[CTRL_USE].GetValue(): self.settings.change("treedclick","use") 890 if self.ctrls[CTRL_USE].GetValue(): settings.change("treedclick","use")
925 elif self.ctrls[CTRL_DESIGN].GetValue(): self.settings.change("treedclick","design") 891 elif self.ctrls[CTRL_DESIGN].GetValue(): settings.change("treedclick","design")
926 elif self.ctrls[CTRL_PRINT].GetValue(): self.settings.change("treedclick","print") 892 elif self.ctrls[CTRL_PRINT].GetValue(): settings.change("treedclick","print")
927 elif self.ctrls[CTRL_CHAT].GetValue(): self.settings.change("treedclick","chat") 893 elif self.ctrls[CTRL_CHAT].GetValue(): settings.change("treedclick","chat")
928 self.EndModal(wx.ID_OK) 894 self.EndModal(wx.ID_OK)