comparison orpg/gametree/gametree.py @ 129:43ad912b7c17 alpha

Traipse Alpha 'OpenRPG' {091003-01} 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 Happy Halloween!
author sirebral
date Tue, 03 Nov 2009 08:18:46 -0600
parents ed4c3606ad1f
children d54e1328dbb1
comparison
equal deleted inserted replaced
128:fba298d65cf8 129:43ad912b7c17
40 import time 40 import time
41 import os 41 import os
42 42
43 from orpg.orpg_xml import xml 43 from orpg.orpg_xml import xml
44 from orpg.tools.validate import validate 44 from orpg.tools.validate import validate
45 from orpg.tools.orpg_log import logger 45 from orpg.tools.orpg_log import logger, debug
46 from orpg.tools.decorators import debugging
47 from orpg.tools.orpg_settings import settings 46 from orpg.tools.orpg_settings import settings
48 from orpg.gametree.nodehandlers import containers, forms, dnd3e, dnd35, chatmacro 47 from orpg.gametree.nodehandlers import containers, forms, dnd3e, dnd35, chatmacro
49 from orpg.gametree.nodehandlers import map_miniature_nodehandler 48 from orpg.gametree.nodehandlers import map_miniature_nodehandler
50 from orpg.gametree.nodehandlers import minilib, rpg_grid, d20, StarWarsd20, voxchat 49 from orpg.gametree.nodehandlers import minilib, rpg_grid, d20, StarWarsd20, voxchat
51 50
82 TOP_SAVE_TREE_AS = wx.NewId() 81 TOP_SAVE_TREE_AS = wx.NewId()
83 TOP_TREE_PROP = wx.NewId() 82 TOP_TREE_PROP = wx.NewId()
84 TOP_FEATURES = wx.NewId() 83 TOP_FEATURES = wx.NewId()
85 84
86 class game_tree(wx.TreeCtrl): 85 class game_tree(wx.TreeCtrl):
87 @debugging 86
88 def __init__(self, parent, id): 87 def __init__(self, parent, id):
89 wx.TreeCtrl.__init__(self,parent,id, wx.DefaultPosition, 88 wx.TreeCtrl.__init__(self,parent,id, wx.DefaultPosition,
90 wx.DefaultSize,style=wx.TR_EDIT_LABELS | wx.TR_HAS_BUTTONS) 89 wx.DefaultSize,style=wx.TR_EDIT_LABELS | wx.TR_HAS_BUTTONS)
91 #self.xml = component.get('xml') # 90 #self.xml = component.get('xml') #
92 self.settings = component.get('settings') 91 self.settings = component.get('settings')
119 self.was_labeling = 0 118 self.was_labeling = 0
120 self.rename_flag = 0 119 self.rename_flag = 0
121 self.image_cache = {} 120 self.image_cache = {}
122 logger.debug("Exit game_tree") 121 logger.debug("Exit game_tree")
123 122
124 @debugging 123
125 def add_nodehandler(self, nodehandler, nodeclass): 124 def add_nodehandler(self, nodehandler, nodeclass):
126 if not self.nodehandlers.has_key(nodehandler): self.nodehandlers[nodehandler] = nodeclass 125 if not self.nodehandlers.has_key(nodehandler): self.nodehandlers[nodehandler] = nodeclass
127 else: logger.debug("Nodehandler for " + nodehandler + " already exists!") 126 else: logger.debug("Nodehandler for " + nodehandler + " already exists!")
128 127
129 @debugging 128
130 def remove_nodehandler(self, nodehandler): 129 def remove_nodehandler(self, nodehandler):
131 if self.nodehandlers.has_key(nodehandler): 130 if self.nodehandlers.has_key(nodehandler):
132 del self.nodehandlers[nodehandler] 131 del self.nodehandlers[nodehandler]
133 else: logger.debug("No nodehandler for " + nodehandler + " exists!") 132 else: logger.debug("No nodehandler for " + nodehandler + " exists!")
134 133
135 @debugging 134
136 def init_nodehandlers(self): 135 def init_nodehandlers(self):
137 self.add_nodehandler('group_handler', containers.group_handler) 136 self.add_nodehandler('group_handler', containers.group_handler)
138 self.add_nodehandler('tabber_handler', containers.tabber_handler) 137 self.add_nodehandler('tabber_handler', containers.tabber_handler)
139 self.add_nodehandler('splitter_handler', containers.splitter_handler) 138 self.add_nodehandler('splitter_handler', containers.splitter_handler)
140 self.add_nodehandler('form_handler', forms.form_handler) 139 self.add_nodehandler('form_handler', forms.form_handler)
157 self.add_nodehandler('url_loader', core.url_loader) 156 self.add_nodehandler('url_loader', core.url_loader)
158 self.add_nodehandler('min_map', core.min_map) 157 self.add_nodehandler('min_map', core.min_map)
159 158
160 # event = wxKeyEvent 159 # event = wxKeyEvent
161 # set to be called by wxWindows by EVT_CHAR macro in __init__ 160 # set to be called by wxWindows by EVT_CHAR macro in __init__
162 @debugging 161
163 def on_key_up(self, evt): 162 def on_key_up(self, evt):
164 key_code = evt.GetKeyCode() 163 key_code = evt.GetKeyCode()
165 if self.dragging and (key_code == wx.WXK_SHIFT): 164 if self.dragging and (key_code == wx.WXK_SHIFT):
166 curSelection = self.GetSelection() 165 curSelection = self.GetSelection()
167 cur = wx.StockCursor(wx.CURSOR_ARROW) 166 cur = wx.StockCursor(wx.CURSOR_ARROW)
172 if(isinstance(obj,core.node_handler)): 171 if(isinstance(obj,core.node_handler)):
173 obj.on_drop(evt) 172 obj.on_drop(evt)
174 self.drag_obj = None 173 self.drag_obj = None
175 evt.Skip() 174 evt.Skip()
176 175
177 @debugging 176
178 def on_char(self, evt): 177 def on_char(self, evt):
179 key_code = evt.GetKeyCode() 178 key_code = evt.GetKeyCode()
180 curSelection = self.GetSelection() # Get the current selection 179 curSelection = self.GetSelection() # Get the current selection
181 if evt.ShiftDown() and ((key_code == wx.WXK_UP) or (key_code == wx.WXK_DOWN)) and not self.dragging: 180 if evt.ShiftDown() and ((key_code == wx.WXK_UP) or (key_code == wx.WXK_DOWN)) and not self.dragging:
182 curSelection = self.GetSelection() 181 curSelection = self.GetSelection()
198 elif key_code == wx.WXK_F2: 197 elif key_code == wx.WXK_F2:
199 self.rename_flag = 1 198 self.rename_flag = 1
200 self.EditLabel(curSelection) 199 self.EditLabel(curSelection)
201 evt.Skip() 200 evt.Skip()
202 201
203 @debugging 202
204 def locate_valid_tree(self, error, msg): ## --Snowdog 3/05 203 def locate_valid_tree(self, error, msg): ## --Snowdog 3/05
205 """prompts the user to locate a new tree file or create a new one""" 204 """prompts the user to locate a new tree file or create a new one"""
206 response = wx.MessageDialog(self, msg, error, wx.YES|wx.NO|wx.ICON_ERROR) 205 response = wx.MessageDialog(self, msg, error, wx.YES|wx.NO|wx.ICON_ERROR)
207 if response == wx.YES: 206 if response == wx.YES:
208 file = None 207 file = None
218 else: 217 else:
219 validate.config_file("tree.xml","default_tree.xml") 218 validate.config_file("tree.xml","default_tree.xml")
220 self.load_tree(error=1) 219 self.load_tree(error=1)
221 return 220 return
222 221
223 @debugging 222
224 def load_tree(self, filename=dir_struct["user"]+'tree.xml', error=0): 223 def load_tree(self, filename=dir_struct["user"]+'tree.xml', error=0):
225 self.settings.change("gametree", filename) 224 self.settings.change("gametree", filename)
226 #check file exists 225 #check file exists
227 if not os.path.exists(filename): 226 if not os.path.exists(filename):
228 emsg = "Gametree Missing!\n"+filename+" cannot be found.\n\n"\ 227 emsg = "Gametree Missing!\n"+filename+" cannot be found.\n\n"\
289 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.") 288 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.")
290 os.rename(filename,filename+".corrupt") 289 os.rename(filename,filename+".corrupt")
291 validate.config_file("tree.xml","default_tree.xml") 290 validate.config_file("tree.xml","default_tree.xml")
292 self.load_tree(error=1) 291 self.load_tree(error=1)
293 292
294 @debugging 293
295 def build_std_menu(self, obj=None): 294 def build_std_menu(self, obj=None):
296 # build useful menu 295 # build useful menu
297 useful_menu = wx.Menu() 296 useful_menu = wx.Menu()
298 useful_menu.Append(STD_MENU_NODE_USEFUL,"Use&ful") 297 useful_menu.Append(STD_MENU_NODE_USEFUL,"Use&ful")
299 useful_menu.Append(STD_MENU_NODE_USELESS,"Use&less") 298 useful_menu.Append(STD_MENU_NODE_USELESS,"Use&less")
351 self.Bind(wx.EVT_MENU, self.on_save_tree, id=TOP_SAVE_TREE) 350 self.Bind(wx.EVT_MENU, self.on_save_tree, id=TOP_SAVE_TREE)
352 self.Bind(wx.EVT_MENU, self.on_load_new_tree, id=TOP_NEW_TREE) 351 self.Bind(wx.EVT_MENU, self.on_load_new_tree, id=TOP_NEW_TREE)
353 self.Bind(wx.EVT_MENU, self.on_tree_prop, id=TOP_TREE_PROP) 352 self.Bind(wx.EVT_MENU, self.on_tree_prop, id=TOP_TREE_PROP)
354 self.Bind(wx.EVT_MENU, self.on_insert_features, id=TOP_FEATURES) 353 self.Bind(wx.EVT_MENU, self.on_insert_features, id=TOP_FEATURES)
355 354
356 @debugging 355
357 def do_std_menu(self, evt, obj): 356 def do_std_menu(self, evt, obj):
358 try: self.std_menu.Enable(STD_MENU_MAP, obj.checkToMapMenu()) 357 try: self.std_menu.Enable(STD_MENU_MAP, obj.checkToMapMenu())
359 except: self.std_menu.Enable(STD_MENU_MAP, obj.map_aware()) 358 except: self.std_menu.Enable(STD_MENU_MAP, obj.map_aware())
360 self.std_menu.Enable(STD_MENU_CLONE, obj.can_clone()) 359 self.std_menu.Enable(STD_MENU_CLONE, obj.can_clone())
361 self.PopupMenu(self.std_menu) 360 self.PopupMenu(self.std_menu)
362 361
363 @debugging 362
364 def strip_html(self, player): 363 def strip_html(self, player):
365 ret_string = "" 364 ret_string = ""
366 x = 0 365 x = 0
367 in_tag = 0 366 in_tag = 0
368 for x in xrange(len(player[0])) : 367 for x in xrange(len(player[0])) :
372 else: pass 371 else: pass
373 else: ret_string = ret_string + player[0][x] 372 else: ret_string = ret_string + player[0][x]
374 logger.debug(ret_string) 373 logger.debug(ret_string)
375 return ret_string 374 return ret_string
376 375
377 @debugging 376
378 def on_receive_data(self, data, player): 377 def on_receive_data(self, data, player):
379 if iselement(data): 378 if iselement(data):
380 tostring(data) 379 tostring(data)
381 beg = string.find(data,"<tree>") 380 beg = string.find(data,"<tree>")
382 end = string.rfind(data,"</tree>") 381 end = string.rfind(data,"</tree>")
383 data = data[6:end] 382 data = data[6:end]
384 self.insert_xml(data) 383 self.insert_xml(data)
385 384
386 @debugging 385
387 def on_send_to_chat(self, evt): 386 def on_send_to_chat(self, evt):
388 item = self.GetSelection() 387 item = self.GetSelection()
389 obj = self.GetPyData(item) 388 obj = self.GetPyData(item)
390 obj.on_send_to_chat(evt) 389 obj.on_send_to_chat(evt)
391 390
392 @debugging 391
393 def on_whisper_to(self, evt): 392 def on_whisper_to(self, evt):
394 players = self.session.get_players() 393 players = self.session.get_players()
395 opts = [] 394 opts = []
396 myid = self.session.get_id() 395 myid = self.session.get_id()
397 me = None 396 me = None
410 player_ids = [] 409 player_ids = []
411 for s in selections: 410 for s in selections:
412 player_ids.append(players[s][2]) 411 player_ids.append(players[s][2])
413 self.chat.whisper_to_players(obj.tohtml(),player_ids) 412 self.chat.whisper_to_players(obj.tohtml(),player_ids)
414 413
415 @debugging 414
416 def on_export_html(self, evt): 415 def on_export_html(self, evt):
417 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","HTML (*.html)|*.html",wx.SAVE) 416 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","HTML (*.html)|*.html",wx.SAVE)
418 if f.ShowModal() == wx.ID_OK: 417 if f.ShowModal() == wx.ID_OK:
419 item = self.GetSelection() 418 item = self.GetSelection()
420 obj = self.GetPyData(item) 419 obj = self.GetPyData(item)
427 f.write(data) 426 f.write(data)
428 self.last_save_dir, throwaway = os.path.split( f.GetPath() ) 427 self.last_save_dir, throwaway = os.path.split( f.GetPath() )
429 f.Destroy() 428 f.Destroy()
430 os.chdir(dir_struct["home"]) 429 os.chdir(dir_struct["home"])
431 430
432 @debugging 431
433 def indifferent(self, evt): 432 def indifferent(self, evt):
434 item = self.GetSelection() 433 item = self.GetSelection()
435 obj = self.GetPyData(item) 434 obj = self.GetPyData(item)
436 obj.usefulness("indifferent") 435 obj.usefulness("indifferent")
437 436
438 @debugging 437
439 def useful(self, evt): 438 def useful(self, evt):
440 item = self.GetSelection() 439 item = self.GetSelection()
441 obj = self.GetPyData(item) 440 obj = self.GetPyData(item)
442 obj.usefulness("useful") 441 obj.usefulness("useful")
443 442
444 @debugging 443
445 def useless(self, evt): 444 def useless(self, evt):
446 item = self.GetSelection() 445 item = self.GetSelection()
447 obj = self.GetPyData(item) 446 obj = self.GetPyData(item)
448 obj.usefulness("useless") 447 obj.usefulness("useless")
449 448
450 @debugging 449
451 def on_email(self,evt): 450 def on_email(self,evt):
452 pass 451 pass
453 452
454 @debugging 453
455 def on_send_to(self, evt): 454 def on_send_to(self, evt):
456 players = self.session.get_players() 455 players = self.session.get_players()
457 opts = [] 456 opts = []
458 myid = self.session.get_id() 457 myid = self.session.get_id()
459 me = None 458 me = None
471 if len(selections) == len(opts): self.session.send(xmldata) 470 if len(selections) == len(opts): self.session.send(xmldata)
472 else: 471 else:
473 for s in selections: self.session.send(xmldata,players[s][2]) 472 for s in selections: self.session.send(xmldata,players[s][2])
474 dlg.Destroy() 473 dlg.Destroy()
475 474
476 @debugging 475
477 def on_icon(self, evt): 476 def on_icon(self, evt):
478 icons = self.icons.keys() 477 icons = self.icons.keys()
479 icons.sort() 478 icons.sort()
480 dlg = wx.SingleChoiceDialog(self,"Choose Icon?","Change Icon",icons) 479 dlg = wx.SingleChoiceDialog(self,"Choose Icon?","Change Icon",icons)
481 if dlg.ShowModal() == wx.ID_OK: 480 if dlg.ShowModal() == wx.ID_OK:
483 item = self.GetSelection() 482 item = self.GetSelection()
484 obj = self.GetPyData(item) 483 obj = self.GetPyData(item)
485 obj.change_icon(key) 484 obj.change_icon(key)
486 dlg.Destroy() 485 dlg.Destroy()
487 486
488 @debugging 487
489 def on_wizard(self, evt): 488 def on_wizard(self, evt):
490 item = self.GetSelection() 489 item = self.GetSelection()
491 obj = self.GetPyData(item) 490 debug((item))
492 name = "New " + obj.master_dom.getAttribute("name") 491 obj = self.GetPyData(item)
493 icon = obj.master_dom.getAttribute("icon") 492 name = "New " + obj.xml_root.get("name")
493 icon = obj.xml_root.get("icon")
494 xml_data = "<nodehandler name=\""+name+"\" icon=\"" + icon + "\" module=\"core\" class=\"node_loader\" >" 494 xml_data = "<nodehandler name=\""+name+"\" icon=\"" + icon + "\" module=\"core\" class=\"node_loader\" >"
495 xml_data += xml.toxml(obj) 495 xml_data += xml.toxml(obj)
496 xml_data += "</nodehandler>" 496 xml_data += "</nodehandler>"
497 self.insert_xml(xml_data) 497 self.insert_xml(xml_data)
498 logger.debug(xml_data) 498 logger.debug(xml_data)
499 499
500 @debugging 500
501 def on_clone(self, evt): 501 def on_clone(self, evt):
502 item = self.GetSelection() 502 item = self.GetSelection()
503 obj = self.GetPyData(item) 503 obj = self.GetPyData(item)
504 if obj.can_clone(): 504 if obj.can_clone():
505 parent_node = self.GetItemParent(item) 505 parent_node = self.GetItemParent(item)
512 if parent_xml[i] is obj.xml: 512 if parent_xml[i] is obj.xml:
513 parent_xml.insert(i, clone_xml) 513 parent_xml.insert(i, clone_xml)
514 break 514 break
515 self.load_xml(clone_xml, parent_node, prev_sib) 515 self.load_xml(clone_xml, parent_node, prev_sib)
516 516
517 @debugging 517
518 def on_save(self, evt): 518 def on_save(self, evt):
519 """save node to a xml file""" 519 """save node to a xml file"""
520 item = self.GetSelection() 520 item = self.GetSelection()
521 obj = self.GetPyData(item) 521 obj = self.GetPyData(item)
522 obj.on_save(evt) 522 obj.on_save(evt)
523 os.chdir(dir_struct["home"]) 523 os.chdir(dir_struct["home"])
524 524
525 @debugging 525
526 def on_save_tree_as(self, evt): 526 def on_save_tree_as(self, evt):
527 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","*.xml",wx.SAVE) 527 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","*.xml",wx.SAVE)
528 if f.ShowModal() == wx.ID_OK: 528 if f.ShowModal() == wx.ID_OK:
529 self.save_tree(f.GetPath()) 529 self.save_tree(f.GetPath())
530 self.last_save_dir, throwaway = os.path.split( f.GetPath() ) 530 self.last_save_dir, throwaway = os.path.split( f.GetPath() )
531 f.Destroy() 531 f.Destroy()
532 os.chdir(dir_struct["home"]) 532 os.chdir(dir_struct["home"])
533 533
534 @debugging 534
535 def on_save_tree(self, evt=None): 535 def on_save_tree(self, evt=None):
536 filename = self.settings.get_setting("gametree") 536 filename = self.settings.get_setting("gametree")
537 self.save_tree(filename) 537 self.save_tree(filename)
538 538
539 @debugging 539
540 def save_tree(self, filename=dir_struct["user"]+'tree.xml'): 540 def save_tree(self, filename=dir_struct["user"]+'tree.xml'):
541 self.xml_root.set("version",GAMETREE_VERSION) 541 self.xml_root.set("version",GAMETREE_VERSION)
542 settings.change("gametree",filename) 542 settings.change("gametree",filename)
543 ElementTree(self.xml_root).write(filename) 543 ElementTree(self.xml_root).write(filename)
544 544
545 @debugging 545
546 def on_load_new_tree(self, evt): 546 def on_load_new_tree(self, evt):
547 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","*.xml",wx.OPEN) 547 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","*.xml",wx.OPEN)
548 if f.ShowModal() == wx.ID_OK: 548 if f.ShowModal() == wx.ID_OK:
549 self.load_tree(f.GetPath()) 549 self.load_tree(f.GetPath())
550 self.last_save_dir, throwaway = os.path.split( f.GetPath() ) 550 self.last_save_dir, throwaway = os.path.split( f.GetPath() )
551 f.Destroy() 551 f.Destroy()
552 os.chdir(dir_struct["home"]) 552 os.chdir(dir_struct["home"])
553 553
554 @debugging 554
555 def on_insert_file(self, evt): 555 def on_insert_file(self, evt):
556 """loads xml file into the tree""" 556 """loads xml file into the tree"""
557 if self.last_save_dir == ".": 557 if self.last_save_dir == ".":
558 self.last_save_dir = dir_struct["user"] 558 self.last_save_dir = dir_struct["user"]
559 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","*.xml",wx.OPEN) 559 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","*.xml",wx.OPEN)
561 self.insert_xml(open(f.GetPath(),"r").read()) 561 self.insert_xml(open(f.GetPath(),"r").read())
562 self.last_save_dir, throwaway = os.path.split( f.GetPath() ) 562 self.last_save_dir, throwaway = os.path.split( f.GetPath() )
563 f.Destroy() 563 f.Destroy()
564 os.chdir(dir_struct["home"]) 564 os.chdir(dir_struct["home"])
565 565
566 @debugging 566
567 def on_insert_url(self, evt): 567 def on_insert_url(self, evt):
568 """loads xml url into the tree""" 568 """loads xml url into the tree"""
569 dlg = wx.TextEntryDialog(self,"URL?","Insert URL", "http://") 569 dlg = wx.TextEntryDialog(self,"URL?","Insert URL", "http://")
570 if dlg.ShowModal() == wx.ID_OK: 570 if dlg.ShowModal() == wx.ID_OK:
571 path = dlg.GetValue() 571 path = dlg.GetValue()
572 file = urllib.urlopen(path) 572 file = urllib.urlopen(path)
573 self.insert_xml(file.read()) 573 self.insert_xml(file.read())
574 dlg.Destroy() 574 dlg.Destroy()
575 575
576 @debugging 576
577 def on_insert_features(self, evt): 577 def on_insert_features(self, evt):
578 self.insert_xml(open(dir_struct["template"]+"feature.xml","r").read()) 578 self.insert_xml(open(dir_struct["template"]+"feature.xml","r").read())
579 579
580 @debugging 580
581 def on_tree_prop(self, evt): 581 def on_tree_prop(self, evt):
582 dlg = gametree_prop_dlg(self, self.settings) 582 dlg = gametree_prop_dlg(self, self.settings)
583 if dlg.ShowModal() == wx.ID_OK: pass 583 if dlg.ShowModal() == wx.ID_OK: pass
584 dlg.Destroy() 584 dlg.Destroy()
585 585
586 @debugging 586
587 def on_node_design(self, evt): 587 def on_node_design(self, evt):
588 item = self.GetSelection() 588 item = self.GetSelection()
589 obj = self.GetPyData(item) 589 obj = self.GetPyData(item)
590 obj.on_design(evt) 590 obj.on_design(evt)
591 591
592 @debugging 592
593 def on_node_use(self, evt): 593 def on_node_use(self, evt):
594 item = self.GetSelection() 594 item = self.GetSelection()
595 obj = self.GetPyData(item) 595 obj = self.GetPyData(item)
596 obj.on_use(evt) 596 obj.on_use(evt)
597 597
598 @debugging 598
599 def on_node_pp(self, evt): 599 def on_node_pp(self, evt):
600 item = self.GetSelection() 600 item = self.GetSelection()
601 obj = self.GetPyData(item) 601 obj = self.GetPyData(item)
602 obj.on_html_view(evt) 602 obj.on_html_view(evt)
603 603
604 @debugging 604
605 def on_del(self, evt): 605 def on_del(self, evt):
606 status_value = "none" 606 status_value = "none"
607 try: 607 try:
608 item = self.GetSelection() 608 item = self.GetSelection()
609 if item: 609 if item:
632 msg = wx.MessageDialog(None,"You can't delete the root item.","Delete Error",wx.OK) 632 msg = wx.MessageDialog(None,"You can't delete the root item.","Delete Error",wx.OK)
633 else: msg = wx.MessageDialog(None,"Unknown error deleting node.","Delete Error",wx.OK) 633 else: msg = wx.MessageDialog(None,"Unknown error deleting node.","Delete Error",wx.OK)
634 msg.ShowModal() 634 msg.ShowModal()
635 msg.Destroy() 635 msg.Destroy()
636 636
637 @debugging 637
638 def on_about(self, evt): 638 def on_about(self, evt):
639 item = self.GetSelection() 639 item = self.GetSelection()
640 obj = self.GetPyData(item) 640 obj = self.GetPyData(item)
641 about = MyAboutBox(self,obj.about()) 641 about = MyAboutBox(self,obj.about())
642 about.ShowModal() 642 about.ShowModal()
643 about.Destroy() 643 about.Destroy()
644 644
645 @debugging 645
646 def on_send_to_map(self, evt): 646 def on_send_to_map(self, evt):
647 item = self.GetSelection() 647 item = self.GetSelection()
648 obj = self.GetPyData(item) 648 obj = self.GetPyData(item)
649 if hasattr(obj,"on_send_to_map"): obj.on_send_to_map(evt) 649 if hasattr(obj,"on_send_to_map"): obj.on_send_to_map(evt)
650 650
651 @debugging 651
652 def insert_xml(self, txt): 652 def insert_xml(self, txt):
653 #Updated to allow safe merging of gametree files 653 #Updated to allow safe merging of gametree files
654 #without leaving an unusable and undeletable node. 654 #without leaving an unusable and undeletable node.
655 # -- Snowdog 8/03 655 # -- Snowdog 8/03
656 if not txt: 656 if not txt:
671 return 671 return
672 672
673 self.xml_root.append(new_xml) 673 self.xml_root.append(new_xml)
674 self.load_xml(new_xml,self.root,self.root) 674 self.load_xml(new_xml,self.root,self.root)
675 675
676 @debugging 676
677 def build_img_list(self): 677 def build_img_list(self):
678 """make image list""" 678 """make image list"""
679 helper = img_helper() 679 helper = img_helper()
680 self.icons = { } 680 self.icons = { }
681 self._imageList= wx.ImageList(16,16,False) 681 self._imageList= wx.ImageList(16,16,False)
685 path = orpg.dirpath.dir_struct["icon"] + icon.get("file") 685 path = orpg.dirpath.dir_struct["icon"] + icon.get("file")
686 img = helper.load_file(path) 686 img = helper.load_file(path)
687 self.icons[key] = self._imageList.Add(img) 687 self.icons[key] = self._imageList.Add(img)
688 self.SetImageList(self._imageList) 688 self.SetImageList(self._imageList)
689 689
690 @debugging 690
691 def load_xml(self, xml_element, parent_node, prev_node=None): 691 def load_xml(self, xml_element, parent_node, prev_node=None):
692 #add the first tree node 692 #add the first tree node
693 i = 0 693 i = 0
694 name = xml_element.get("name") 694 name = xml_element.get("name")
695 icon = xml_element.get("icon") 695 icon = xml_element.get("icon")
723 #parent = xml_dom._get_parentNode() 723 #parent = xml_dom._get_parentNode()
724 #parent.removeChild(xml_dom) 724 #parent.removeChild(xml_dom)
725 725
726 return new_tree_node 726 return new_tree_node
727 727
728 @debugging 728
729 def cached_load_of_image(self, bmp_in, new_tree_node): 729 def cached_load_of_image(self, bmp_in, new_tree_node):
730 image_list = self.GetImageList() 730 image_list = self.GetImageList()
731 img = wx.ImageFromBitmap(bmp_in) 731 img = wx.ImageFromBitmap(bmp_in)
732 img_data = img.GetData() 732 img_data = img.GetData()
733 image_index = None 733 image_index = None
741 self.image_cache[image_index] = img_data 741 self.image_cache[image_index] = img_data
742 self.SetItemImage(new_tree_node,image_index) 742 self.SetItemImage(new_tree_node,image_index)
743 self.SetItemImage(new_tree_node,image_index, wx.TreeItemIcon_Selected) 743 self.SetItemImage(new_tree_node,image_index, wx.TreeItemIcon_Selected)
744 return image_index 744 return image_index
745 745
746 @debugging 746
747 def on_rclick(self, evt): 747 def on_rclick(self, evt):
748 pt = evt.GetPosition() 748 pt = evt.GetPosition()
749 (item, flag) = self.HitTest(pt) 749 (item, flag) = self.HitTest(pt)
750 if item.IsOk(): 750 if item.IsOk():
751 obj = self.GetPyData(item) 751 obj = self.GetPyData(item)
752 self.SelectItem(item) 752 self.SelectItem(item)
753 if(isinstance(obj,core.node_handler)): obj.on_rclick(evt) 753 if(isinstance(obj,core.node_handler)): obj.on_rclick(evt)
754 else: self.PopupMenu(self.top_menu) 754 else: self.PopupMenu(self.top_menu)
755 else: self.PopupMenu(self.top_menu,pt) 755 else: self.PopupMenu(self.top_menu,pt)
756 756
757 @debugging 757
758 def on_ldclick(self, evt): 758 def on_ldclick(self, evt):
759 self.rename_flag = 0 759 self.rename_flag = 0
760 pt = evt.GetPosition() 760 pt = evt.GetPosition()
761 (item, flag) = self.HitTest(pt) 761 (item, flag) = self.HitTest(pt)
762 if item.IsOk(): 762 if item.IsOk():
768 if action == "use": obj.on_use(evt) 768 if action == "use": obj.on_use(evt)
769 elif action == "design": obj.on_design(evt) 769 elif action == "design": obj.on_design(evt)
770 elif action == "print": obj.on_html_view(evt) 770 elif action == "print": obj.on_html_view(evt)
771 elif action == "chat": self.on_send_to_chat(evt) 771 elif action == "chat": self.on_send_to_chat(evt)
772 772
773 @debugging 773
774 def on_left_down(self, evt): 774 def on_left_down(self, evt):
775 pt = evt.GetPosition() 775 pt = evt.GetPosition()
776 (item, flag) = self.HitTest(pt) 776 (item, flag) = self.HitTest(pt)
777 if item.IsOk() and self.was_labeling: 777 if item.IsOk() and self.was_labeling:
778 self.SelectItem(item) 778 self.SelectItem(item)
782 # this next if tests to ensure that the mouse up occurred over a label, and not the icon 782 # this next if tests to ensure that the mouse up occurred over a label, and not the icon
783 self.rename_flag = 1 783 self.rename_flag = 1
784 else: self.SelectItem(item) 784 else: self.SelectItem(item)
785 evt.Skip() 785 evt.Skip()
786 786
787 @debugging 787
788 def on_left_up(self, evt): 788 def on_left_up(self, evt):
789 if self.dragging: 789 if self.dragging:
790 cur = wx.StockCursor(wx.CURSOR_ARROW) 790 cur = wx.StockCursor(wx.CURSOR_ARROW)
791 self.SetCursor(cur) 791 self.SetCursor(cur)
792 self.dragging = False 792 self.dragging = False
805 function(child, data) 805 function(child, data)
806 if recurse: 806 if recurse:
807 self.traverse(child, function, data) 807 self.traverse(child, function, data)
808 child, cookie = self.GetNextChild(root, cookie) 808 child, cookie = self.GetNextChild(root, cookie)
809 809
810 @debugging 810
811 def on_label_change(self, evt): 811 def on_label_change(self, evt):
812 item = evt.GetItem() 812 item = evt.GetItem()
813 txt = evt.GetLabel() 813 txt = evt.GetLabel()
814 self.was_labeling = 0 814 self.was_labeling = 0
815 self.rename_flag = 0 815 self.rename_flag = 0
816 if txt != "": 816 if txt != "":
817 obj = self.GetPyData(item) 817 obj = self.GetPyData(item)
818 obj.master_dom.setAttribute('name',txt) 818 obj.xml_root.setAttribute('name',txt)
819 else: evt.Veto() 819 else: evt.Veto()
820 820
821 @debugging 821
822 def on_label_begin(self, evt): 822 def on_label_begin(self, evt):
823 if not self.rename_flag: evt.Veto() 823 if not self.rename_flag: evt.Veto()
824 else: 824 else:
825 self.was_labeling = 1 825 self.was_labeling = 1
826 item = evt.GetItem() 826 item = evt.GetItem()
827 if item == self.GetRootItem(): 827 if item == self.GetRootItem():
828 evt.Veto() 828 evt.Veto()
829 829
830 @debugging 830
831 def on_drag(self, evt): 831 def on_drag(self, evt):
832 self.rename_flag = 0 832 self.rename_flag = 0
833 item = self.GetSelection() 833 item = self.GetSelection()
834 obj = self.GetPyData(item) 834 obj = self.GetPyData(item)
835 self.SelectItem(item) 835 self.SelectItem(item)
837 self.dragging = True 837 self.dragging = True
838 cur = wx.StockCursor(wx.CURSOR_HAND) 838 cur = wx.StockCursor(wx.CURSOR_HAND)
839 self.SetCursor(cur) 839 self.SetCursor(cur)
840 self.drag_obj = obj 840 self.drag_obj = obj
841 841
842 @debugging 842
843 def is_parent_node(self, node, compare_node): 843 def is_parent_node(self, node, compare_node):
844 parent_node = self.GetItemParent(node) 844 parent_node = self.GetItemParent(node)
845 if compare_node == parent_node: 845 if compare_node == parent_node:
846 logger.debug("parent node") 846 logger.debug("parent node")
847 return 1 847 return 1
857 CTRL_DESIGN = wx.NewId() 857 CTRL_DESIGN = wx.NewId()
858 CTRL_CHAT = wx.NewId() 858 CTRL_CHAT = wx.NewId()
859 CTRL_PRINT = wx.NewId() 859 CTRL_PRINT = wx.NewId()
860 860
861 class gametree_prop_dlg(wx.Dialog): 861 class gametree_prop_dlg(wx.Dialog):
862 @debugging 862
863 def __init__(self, parent, settings): 863 def __init__(self, parent, settings):
864 wx.Dialog.__init__(self, parent, wx.ID_ANY, "Game Tree Properties") 864 wx.Dialog.__init__(self, parent, wx.ID_ANY, "Game Tree Properties")
865 self.settings = settings 865 self.settings = settings
866 866
867 #sizers 867 #sizers
916 self.SetSizer(sizers['main']) 916 self.SetSizer(sizers['main'])
917 self.SetAutoLayout(True) 917 self.SetAutoLayout(True)
918 self.Fit() 918 self.Fit()
919 self.Bind(wx.EVT_BUTTON, self.on_ok, id=wx.ID_OK) 919 self.Bind(wx.EVT_BUTTON, self.on_ok, id=wx.ID_OK)
920 920
921 @debugging 921
922 def on_ok(self,evt): 922 def on_ok(self,evt):
923 self.settings.change("gametree",self.ctrls[CTRL_TREE_FILE].GetValue()) 923 self.settings.change("gametree",self.ctrls[CTRL_TREE_FILE].GetValue())
924 self.settings.change("SaveGameTreeOnExit",str(self.ctrls[CTRL_YES].GetValue())) 924 self.settings.change("SaveGameTreeOnExit",str(self.ctrls[CTRL_YES].GetValue()))
925 if self.ctrls[CTRL_USE].GetValue(): self.settings.change("treedclick","use") 925 if self.ctrls[CTRL_USE].GetValue(): self.settings.change("treedclick","use")
926 elif self.ctrls[CTRL_DESIGN].GetValue(): self.settings.change("treedclick","design") 926 elif self.ctrls[CTRL_DESIGN].GetValue(): self.settings.change("treedclick","design")