comparison orpg/gametree/nodehandlers/dnd3e.py @ 124:8827271fbe1b alpha

Traipse Alpha 'OpenRPG' {091001-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 Sun, 01 Nov 2009 11:36:14 -0600
parents 2fa8bd6785a5
children 06f10429eedc
comparison
equal deleted inserted replaced
123:174658f839c0 124:8827271fbe1b
149 from core import * 149 from core import *
150 from containers import * 150 from containers import *
151 from string import * #a 1.6003 151 from string import * #a 1.6003
152 from inspect import * #a 1.9001 152 from inspect import * #a 1.9001
153 from orpg.dirpath import dir_struct 153 from orpg.dirpath import dir_struct
154 from orpg.tools.orpg_log import debug
155 from xml.etree.ElementTree import parse
154 156
155 dnd3e_EXPORT = wx.NewId() 157 dnd3e_EXPORT = wx.NewId()
156 ############Global Stuff############## 158 ############Global Stuff##############
157 159
158 HP_CUR = wx.NewId() 160 HP_CUR = wx.NewId()
207 #d 1.6000 not used. 209 #d 1.6000 not used.
208 #def getCharacterProp(forgetIt): 210 #def getCharacterProp(forgetIt):
209 # return None 211 # return None
210 212
211 #a 1.6 convinience function added safeGetAttr 213 #a 1.6 convinience function added safeGetAttr
212 def safeGetAttr(node,lable,defRetV=None): 214 def safeGetAttr(node, label, defRetV=None):
213 cna=node.attributes 215 cna=node.attrib
214 for i2 in range(len(cna)): 216 for key in cna:
215 if cna.item(i2).name == lable: 217 if key == label:
216 return cna.item(i2).value 218 return cna[key]
217 #retV=node.getAttribute(lable) # getAttribute does not distingish between 219 #retV=node.get(lable) # get does not distingish between
218 # the attribute not being present vs it having a value of "" 220 # the attribute not being present vs it having a value of ""
219 # This is bad for this routine, thus not used. 221 # This is bad for this routine, thus not used.
220 return defRetV 222 return defRetV
221 #a 1.6... safeGetAttr end. 223 #a 1.6... safeGetAttr end.
222 224
228 """ 230 """
229 def __init__(self,xml_dom,tree_node): 231 def __init__(self,xml_dom,tree_node):
230 node_handler.__init__(self,xml_dom,tree_node) 232 node_handler.__init__(self,xml_dom,tree_node)
231 self.Version = "v1.901" #a 1.6000 general documentation, usage. 233 self.Version = "v1.901" #a 1.6000 general documentation, usage.
232 234
233 print "dnd3echar_handler - version:",self.Version #m 1.6000 235 print "dnd3echar_handler - version:", self.Version #m 1.6000
234 236
235 self.hparent = None #a 1.5002 allow ability to run up tree, this is the 237 self.hparent = None #a 1.5002 allow ability to run up tree, this is the
236 #a 1.5002 top of the handler tree, this is used to flag where to stop 238 #a 1.5002 top of the handler tree, this is used to flag where to stop
237 #a 1.5002 on the way up. Changing this will break getRoot(self) 239 #a 1.5002 on the way up. Changing this will break getRoot(self)
238 240
250 # "self.child_handlers:",self.child_handlers # a (debug) 1.5002 252 # "self.child_handlers:",self.child_handlers # a (debug) 1.5002
251 self.myeditor = None 253 self.myeditor = None
252 254
253 255
254 def new_child_handler(self,tag,text,handler_class,icon='gear'): 256 def new_child_handler(self,tag,text,handler_class,icon='gear'):
255 node_list = self.master_dom.getElementsByTagName(tag) 257 node_list = self.xml.findall(tag)
256 tree = self.tree 258 tree = self.tree
257 i = self.tree.icons[icon] 259 i = self.tree.icons[icon]
258 new_tree_node = tree.AppendItem(self.mytree_node,text,i,i) 260 new_tree_node = tree.AppendItem(self.mytree_node,text,i,i)
259 handler = handler_class(node_list[0],new_tree_node,self) 261 handler = handler_class(node_list[0],new_tree_node,self)
260 tree.SetPyData(new_tree_node,handler) 262 tree.SetPyData(new_tree_node,handler)
351 return 353 return
352 354
353 def on_html(self,evt): 355 def on_html(self,evt):
354 html_str = self.tohtml() 356 html_str = self.tohtml()
355 wnd = http_html_window(self.frame.note,-1) 357 wnd = http_html_window(self.frame.note,-1)
356 wnd.title = self.master_dom.getAttribute('name') 358 wnd.title = self.xml.get('name')
357 self.frame.add_panel(wnd) 359 self.frame.add_panel(wnd)
358 wnd.SetPage(html_str) 360 wnd.SetPage(html_str)
359 361
360 def get_design_panel(self,parent): 362 def get_design_panel(self,parent):
361 pass 363 pass
382 384
383 class howto_panel(wx.Panel): 385 class howto_panel(wx.Panel):
384 def __init__(self, parent, handler): 386 def __init__(self, parent, handler):
385 wx.Panel.__init__(self, parent, -1) 387 wx.Panel.__init__(self, parent, -1)
386 388
387 pname = handler.master_dom.setAttribute("name", 'How To') 389 pname = handler.xml.set("name", 'How To')
388 self.sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, 'How To'), wx.VERTICAL) 390 self.sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, 'How To'), wx.VERTICAL)
389 self.master_dom = handler.master_dom 391 self.xml = handler.xml
390 n_list = self.master_dom._get_childNodes() 392 n_list = self.xml.getchildren()
391 for n in n_list: 393 for n in n_list:
392 t_node = component.get('xml').safe_get_text_node(n) 394 self.sizer.Add(wx.StaticText(self, -1, n.text), 1, wx.EXPAND)
393 self.sizer.Add(wx.StaticText(self, -1, t_node._get_nodeValue()), 1, wx.EXPAND)
394 self.SetSizer(self.sizer) 395 self.SetSizer(self.sizer)
395 self.SetAutoLayout(True) 396 self.SetAutoLayout(True)
396 self.Fit() 397 self.Fit()
397 398
398 class dnd3egeneral(dnd3e_char_child): 399 class dnd3egeneral(dnd3e_char_child):
410 wnd = outline_panel(parent,self,gen_grid,"General Information") 411 wnd = outline_panel(parent,self,gen_grid,"General Information")
411 wnd.title = "General Info" 412 wnd.title = "General Info"
412 return wnd 413 return wnd
413 414
414 def tohtml(self): 415 def tohtml(self):
415 n_list = self.master_dom._get_childNodes() 416 n_list = self.xml.getchildren()
416 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>General Information</th></tr><tr><td>" 417 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>General Information</th></tr><tr><td>"
417 for n in n_list: 418 for n in n_list:
418 t_node = component.get('xml').safe_get_text_node(n) 419 debug(n)
419 html_str += "<B>"+n._get_tagName().capitalize() +":</B> " 420 html_str += "<B>"+n.tag.capitalize() +":</B> "
420 html_str += t_node._get_nodeValue() + ", " 421 html_str += n.text + ", "
421 html_str = html_str[:len(html_str)-2] + "</td></tr></table>" 422 html_str = html_str[:len(html_str)-2] + "</td></tr></table>"
422 return html_str 423 return html_str
423 424
424 def on_name_change(self,name): 425 def on_name_change(self,name):
425 self.char_hander.rename(name) 426 self.char_hander.rename(name)
426 #o 1.5002 self.char_hander = parent in this case. 427 #o 1.5002 self.char_hander = parent in this case.
427 self.charName = name #a 1.5002 make getting name easier. 428 self.charName = name #a 1.5002 make getting name easier.
428 429
429 430
430 def get_char_name( self ): 431 def get_char_name( self ):
431 node = self.master_dom.getElementsByTagName( 'name' )[0] 432 node = self.xml.findall( 'name' )[0]
432 t_node = component.get('xml').safe_get_text_node( node ) 433 return node.text
433 return t_node._get_nodeValue()
434 434
435 class gen_grid(wx.grid.Grid): 435 class gen_grid(wx.grid.Grid):
436 """grid for gen info""" 436 """grid for gen info"""
437 def __init__(self, parent, handler): 437 def __init__(self, parent, handler):
438 pname = handler.master_dom.setAttribute("name", 'General') 438 pname = handler.xml.set("name", 'General')
439 self.hparent = handler #a 1.5002 allow ability to run up tree, needed 439 self.hparent = handler #a 1.5002 allow ability to run up tree, needed
440 # a 1.5002 parent is functional parent, not invoking parent. 440 # a 1.5002 parent is functional parent, not invoking parent.
441 441
442 442
443 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 443 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
444 #self.Bind(wx.EVT_SIZE, self.on_size) 444 #self.Bind(wx.EVT_SIZE, self.on_size)
445 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change) 445 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
446 self.handler = handler 446 self.handler = handler
447 n_list = handler.master_dom._get_childNodes() 447 n_list = handler.xml.getchildren()
448 self.CreateGrid(len(n_list),2) 448 self.CreateGrid(len(n_list),2)
449 self.SetRowLabelSize(0) 449 self.SetRowLabelSize(0)
450 self.SetColLabelSize(0) 450 self.SetColLabelSize(0)
451 self.n_list = n_list 451 self.n_list = n_list
452 i = 0 452 i = 0
455 455
456 def on_cell_change(self,evt): 456 def on_cell_change(self,evt):
457 row = evt.GetRow() 457 row = evt.GetRow()
458 col = evt.GetCol() 458 col = evt.GetCol()
459 value = self.GetCellValue(row,col) 459 value = self.GetCellValue(row,col)
460 t_node = self.n_list[row]._get_firstChild() 460 self.n_list[row].text = value
461 t_node._set_nodeValue(value)
462 if row==0: 461 if row==0:
463 self.handler.on_name_change(value) 462 self.handler.on_name_change(value)
464 #self.AutoSizeColumn(1) 463 #self.AutoSizeColumn(1)
465 464
466 def refresh_row(self,rowi): 465 def refresh_row(self,rowi):
467 t_node = component.get('xml').safe_get_text_node(self.n_list[rowi]) 466 self.SetCellValue(rowi,0,self.n_list[rowi].tag)
468
469 self.SetCellValue(rowi,0,self.n_list[rowi]._get_tagName())
470 self.SetReadOnly(rowi,0) 467 self.SetReadOnly(rowi,0)
471 self.SetCellValue(rowi,1,t_node._get_nodeValue()) 468 self.SetCellValue(rowi,1,self.n_list[rowi].text)
472 self.AutoSizeColumn(1) 469 self.AutoSizeColumn(1)
473 470
474 class dnd3einventory(dnd3e_char_child): 471 class dnd3einventory(dnd3e_char_child):
475 """ Node Handler for general information. This handler will be 472 """ Node Handler for general information. This handler will be
476 created by dnd3echar_handler. 473 created by dnd3echar_handler.
485 wnd = inventory_pane(parent, self) #outline_panel(parent,self,inventory_grid,"Inventory") 482 wnd = inventory_pane(parent, self) #outline_panel(parent,self,inventory_grid,"Inventory")
486 wnd.title = "General Info" 483 wnd.title = "General Info"
487 return wnd 484 return wnd
488 485
489 def tohtml(self): 486 def tohtml(self):
490 n_list = self.master_dom._get_childNodes() 487 n_list = self.xml.getchildren()
491 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>General Information</th></tr><tr><td>" 488 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>General Information</th></tr><tr><td>"
492 for n in n_list: 489 for n in n_list:
493 t_node = component.get('xml').safe_get_text_node(n) 490 debug((n))
494 html_str += "<B>"+n._get_tagName().capitalize() +":</B> " 491 html_str += "<B>"+n.tag.capitalize() +":</B> "
495 html_str += t_node._get_nodeValue() + "<br>" 492 html_str += n.text + "<br>"
496 html_str = html_str[:len(html_str)-2] + "</td></tr></table>" 493 html_str = html_str[:len(html_str)-2] + "</td></tr></table>"
497 return html_str 494 return html_str
498 495
499 class inventory_pane(wx.Panel): 496 class inventory_pane(wx.Panel):
500 def __init__(self, parent, handler): 497 def __init__(self, parent, handler):
501 wx.Panel.__init__(self, parent, wx.ID_ANY) 498 wx.Panel.__init__(self, parent, wx.ID_ANY)
502 499 self.n_list = handler.xml.getchildren()
503 self.n_list = handler.master_dom._get_childNodes()
504 self.autosize = False 500 self.autosize = False
505
506 self.sizer = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY, "Inventroy"), wx.VERTICAL) 501 self.sizer = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY, "Inventroy"), wx.VERTICAL)
507
508 self.lang = wx.TextCtrl(self, wx.ID_ANY, "", style=wx.TE_MULTILINE | wx.TE_BESTWRAP, name="Languages") 502 self.lang = wx.TextCtrl(self, wx.ID_ANY, "", style=wx.TE_MULTILINE | wx.TE_BESTWRAP, name="Languages")
509 self.gear = wx.TextCtrl(self, wx.ID_ANY, "", style=wx.TE_MULTILINE | wx.TE_BESTWRAP, name="Gear") 503 self.gear = wx.TextCtrl(self, wx.ID_ANY, "", style=wx.TE_MULTILINE | wx.TE_BESTWRAP, name="Gear")
510 self.magic = wx.TextCtrl(self, wx.ID_ANY, "", style=wx.TE_MULTILINE | wx.TE_BESTWRAP, name="Magic") 504 self.magic = wx.TextCtrl(self, wx.ID_ANY, "", style=wx.TE_MULTILINE | wx.TE_BESTWRAP, name="Magic")
511 self.grid = wx.grid.Grid(self, wx.ID_ANY, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 505 self.grid = wx.grid.Grid(self, wx.ID_ANY, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
512
513 self.grid.CreateGrid(len(self.n_list)-3,2) 506 self.grid.CreateGrid(len(self.n_list)-3,2)
514 self.grid.SetRowLabelSize(0) 507 self.grid.SetRowLabelSize(0)
515 self.grid.SetColLabelSize(0) 508 self.grid.SetColLabelSize(0)
516
517 for i in xrange(len(self.n_list)): 509 for i in xrange(len(self.n_list)):
518 self.refresh_row(i) 510 self.refresh_row(i)
519
520 sizer1 = wx.BoxSizer(wx.HORIZONTAL) 511 sizer1 = wx.BoxSizer(wx.HORIZONTAL)
521 sizer1.Add(self.grid, 1, wx.EXPAND) 512 sizer1.Add(self.grid, 1, wx.EXPAND)
522 sizer1.Add(self.lang, 1, wx.EXPAND) 513 sizer1.Add(self.lang, 1, wx.EXPAND)
523
524 self.sizer.Add(sizer1, 0, wx.EXPAND) 514 self.sizer.Add(sizer1, 0, wx.EXPAND)
525
526 sizer2 = wx.BoxSizer(wx.HORIZONTAL) 515 sizer2 = wx.BoxSizer(wx.HORIZONTAL)
527 sizer2.Add(self.gear, 1, wx.EXPAND) 516 sizer2.Add(self.gear, 1, wx.EXPAND)
528 sizer2.Add(self.magic, 1, wx.EXPAND) 517 sizer2.Add(self.magic, 1, wx.EXPAND)
529
530 self.sizer.Add(sizer2, 1, wx.EXPAND) 518 self.sizer.Add(sizer2, 1, wx.EXPAND)
531
532 self.SetSizer(self.sizer) 519 self.SetSizer(self.sizer)
533 self.SetAutoLayout(True) 520 self.SetAutoLayout(True)
534 self.Fit() 521 self.Fit()
535
536 self.Bind(wx.EVT_TEXT, self.onTextNodeChange, self.lang) 522 self.Bind(wx.EVT_TEXT, self.onTextNodeChange, self.lang)
537 self.Bind(wx.EVT_TEXT, self.onTextNodeChange, self.gear) 523 self.Bind(wx.EVT_TEXT, self.onTextNodeChange, self.gear)
538 self.Bind(wx.EVT_TEXT, self.onTextNodeChange, self.magic) 524 self.Bind(wx.EVT_TEXT, self.onTextNodeChange, self.magic)
539 self.Bind(wx.grid.EVT_GRID_EDITOR_HIDDEN, self.on_cell_change, self.grid) 525 self.Bind(wx.grid.EVT_GRID_EDITOR_HIDDEN, self.on_cell_change, self.grid)
540 526
541
542 def fillTextNode(self, name, value): 527 def fillTextNode(self, name, value):
543 if name == 'Languages': 528 if name == 'Languages': self.lang.SetValue(value)
544 self.lang.SetValue(value) 529 elif name == 'Gear': self.gear.SetValue(value)
545 elif name == 'Gear': 530 elif name == 'Magic': self.magic.SetValue(value)
546 self.gear.SetValue(value)
547 elif name == 'Magic':
548 self.magic.SetValue(value)
549 531
550 def onTextNodeChange(self, event): 532 def onTextNodeChange(self, event):
551 id = event.GetId() 533 id = event.GetId()
552
553 if id == self.gear.GetId(): 534 if id == self.gear.GetId():
554 nodeName = 'Gear' 535 nodeName = 'Gear'
555 value = self.gear.GetValue() 536 value = self.gear.GetValue()
556 elif id == self.magic.GetId(): 537 elif id == self.magic.GetId():
557 nodeName = 'Magic' 538 nodeName = 'Magic'
558 value = self.magic.GetValue() 539 value = self.magic.GetValue()
559 elif id == self.lang.GetId(): 540 elif id == self.lang.GetId():
560 nodeName = 'Languages' 541 nodeName = 'Languages'
561 value = self.lang.GetValue() 542 value = self.lang.GetValue()
562
563 for node in self.n_list: 543 for node in self.n_list:
564 if node._get_tagName() == nodeName: 544 if node.tag == nodeName:
565 t_node = component.get('xml').safe_get_text_node(node) 545 debug(node)
566 t_node._set_nodeValue(value) 546 node.text = value
567 547
568 def saveMoney(self, row, col): 548 def saveMoney(self, row, col):
569 value = self.grid.GetCellValue(row, col) 549 value = self.grid.GetCellValue(row, col)
570 t_node = component.get('xml').safe_get_text_node(self.n_list[row]) 550 debug(self.n_list[row])
571 t_node._set_nodeValue(value) 551 self.n_list[row].text = value
572 552
573 def on_cell_change(self, evt): 553 def on_cell_change(self, evt):
574 row = evt.GetRow() 554 row = evt.GetRow()
575 col = evt.GetCol() 555 col = evt.GetCol()
576 self.grid.AutoSizeColumn(col) 556 self.grid.AutoSizeColumn(col)
577 wx.CallAfter(self.saveMoney, row, col) 557 wx.CallAfter(self.saveMoney, row, col)
578 558
579
580
581 def refresh_row(self, row): 559 def refresh_row(self, row):
582 t_node = component.get('xml').safe_get_text_node(self.n_list[row]) 560 tagname = self.n_list[row].tag
583 tagname = self.n_list[row]._get_tagName() 561 value = self.n_list[row].text
584 value = t_node._get_nodeValue() 562 if tagname == 'Gear': self.fillTextNode(tagname, value)
585 if tagname == 'Gear': 563 elif tagname == 'Magic': self.fillTextNode(tagname, value)
586 self.fillTextNode(tagname, value) 564 elif tagname == 'Languages': self.fillTextNode(tagname, value)
587 elif tagname == 'Magic':
588 self.fillTextNode(tagname, value)
589 elif tagname == 'Languages':
590 self.fillTextNode(tagname, value)
591 else: 565 else:
592 self.grid.SetCellValue(row, 0, tagname) 566 self.grid.SetCellValue(row, 0, tagname)
593 self.grid.SetReadOnly(row, 0) 567 self.grid.SetReadOnly(row, 0)
594 self.grid.SetCellValue(row, 1, value) 568 self.grid.SetCellValue(row, 1, value)
595 self.grid.AutoSize() 569 self.grid.AutoSize()
610 self.new_child_handler('saves','Saves',dnd3esaves,'skull') 584 self.new_child_handler('saves','Saves',dnd3esaves,'skull')
611 self.myeditor = None 585 self.myeditor = None
612 586
613 587
614 def new_child_handler(self,tag,text,handler_class,icon='gear'): 588 def new_child_handler(self,tag,text,handler_class,icon='gear'):
615 node_list = self.master_dom.getElementsByTagName(tag) 589 node_list = self.xml.findall(tag)
616 tree = self.tree 590 tree = self.tree
617 i = self.tree.icons[icon] 591 i = self.tree.icons[icon]
618 new_tree_node = tree.AppendItem(self.mytree_node,text,i,i) 592 new_tree_node = tree.AppendItem(self.mytree_node,text,i,i)
619 handler = handler_class(node_list[0],new_tree_node,self) 593 handler = handler_class(node_list[0],new_tree_node,self)
620 tree.SetPyData(new_tree_node,handler) 594 tree.SetPyData(new_tree_node,handler)
648 return 622 return
649 623
650 def on_html(self,evt): 624 def on_html(self,evt):
651 html_str = self.tohtml() 625 html_str = self.tohtml()
652 wnd = http_html_window(self.frame.note,-1) 626 wnd = http_html_window(self.frame.note,-1)
653 wnd.title = self.master_dom.getAttribute('name') 627 wnd.title = self.xml.get('name')
654 self.frame.add_panel(wnd) 628 self.frame.add_panel(wnd)
655 wnd.SetPage(html_str) 629 wnd.SetPage(html_str)
656 630
657 def get_design_panel(self,parent): 631 def get_design_panel(self,parent):
658 pass 632 pass
670 def __init__(self,xml_dom,tree_node,parent): 644 def __init__(self,xml_dom,tree_node,parent):
671 class_char_child.__init__(self,xml_dom,tree_node,parent) 645 class_char_child.__init__(self,xml_dom,tree_node,parent)
672 self.hparent = parent #a 1.5002 allow ability to run up tree. 646 self.hparent = parent #a 1.5002 allow ability to run up tree.
673 self.root = getRoot(self) #a 1.5002 get top of our local function tree. 647 self.root = getRoot(self) #a 1.5002 get top of our local function tree.
674 self.root.abilities = self #a 1.5002 let other classes find me. 648 self.root.abilities = self #a 1.5002 let other classes find me.
675
676 self.abilities = {} 649 self.abilities = {}
677 node_list = self.master_dom.getElementsByTagName('stat') 650 node_list = self.xml.findall('stat')
678 tree = self.tree 651 tree = self.tree
679 icons = tree.icons 652 icons = tree.icons
680
681 for n in node_list: 653 for n in node_list:
682 name = n.getAttribute('abbr') 654 name = n.get('abbr')
683 self.abilities[name] = n 655 self.abilities[name] = n
684 new_tree_node = tree.AppendItem( self.mytree_node, name, icons['gear'], icons['gear'] ) 656 new_tree_node = tree.AppendItem( self.mytree_node, name, icons['gear'], icons['gear'] )
685 tree.SetPyData( new_tree_node, self ) 657 tree.SetPyData( new_tree_node, self )
686 #print "dnd3eability - init self.abilities",self.abilities #a (debug) 1.5002 658 #print "dnd3eability - init self.abilities",self.abilities #a (debug) 1.5002
687 659
700 chat = self.chat 672 chat = self.chat
701 txt = '%s check: [1d20%s%s]' % ( name, mod1, mod ) 673 txt = '%s check: [1d20%s%s]' % ( name, mod1, mod )
702 chat.ParsePost( txt, True, True ) 674 chat.ParsePost( txt, True, True )
703 675
704 def get_mod(self,abbr): 676 def get_mod(self,abbr):
705 score = int(self.abilities[abbr].getAttribute('base')) 677 score = int(self.abilities[abbr].get('base'))
706 mod = (score - 10) / 2 678 mod = (score - 10) / 2
707 mod = int(mod) 679 mod = int(mod)
708 return mod 680 return mod
709 681
710 def set_score(self,abbr,score): 682 def set_score(self,abbr,score):
711 if score >= 0: 683 if score >= 0:
712 self.abilities[abbr].setAttribute("base",str(score)) 684 self.abilities[abbr].set("base",str(score))
713 685
714 def get_design_panel(self,parent): 686 def get_design_panel(self,parent):
715 wnd = outline_panel(parent,self,abil_grid,"Abilities") 687 wnd = outline_panel(parent,self,abil_grid,"Abilities")
716 wnd.title = "Abilities (edit)" 688 wnd.title = "Abilities (edit)"
717 return wnd 689 return wnd
718 690
719 def tohtml(self): 691 def tohtml(self):
720 html_str = """<table border='1' width=100%><tr BGCOLOR=#E9E9E9 ><th width='50%'>Ability</th> 692 html_str = """<table border='1' width=100%><tr BGCOLOR=#E9E9E9 ><th width='50%'>Ability</th>
721 <th>Base</th><th>Modifier</th></tr>""" 693 <th>Base</th><th>Modifier</th></tr>"""
722 node_list = self.master_dom.getElementsByTagName('stat') 694 node_list = self.xml.findall('stat')
723 for n in node_list: 695 for n in node_list:
724 name = n.getAttribute('name') 696 name = n.get('name')
725 abbr = n.getAttribute('abbr') 697 abbr = n.get('abbr')
726 base = n.getAttribute('base') 698 base = n.get('base')
727 mod = str(self.get_mod(abbr)) 699 mod = str(self.get_mod(abbr))
728 if int(mod) >= 0: #m 1.6013 added "int(" and ")" 700 if int(mod) >= 0: #m 1.6013 added "int(" and ")"
729 mod1 = "+" 701 mod1 = "+"
730 else: 702 else:
731 mod1 = "" 703 mod1 = ""
735 return html_str 707 return html_str
736 708
737 class abil_grid(wx.grid.Grid): 709 class abil_grid(wx.grid.Grid):
738 """grid for abilities""" 710 """grid for abilities"""
739 def __init__(self, parent, handler): 711 def __init__(self, parent, handler):
740 pname = handler.master_dom.setAttribute("name", 'Stats') 712 pname = handler.xml.set("name", 'Stats')
741 self.hparent = handler #a 1.5002 allow ability to run up tree. 713 self.hparent = handler #a 1.5002 allow ability to run up tree.
742 self.root = getRoot(self) 714 self.root = getRoot(self)
743 #a 1.5002 in this case, we need the functional parent, not the invoking parent. 715 #a 1.5002 in this case, we need the functional parent, not the invoking parent.
744 716
745 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 717 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
746 self.Bind(wx.EVT_SIZE, self.on_size) 718 self.Bind(wx.EVT_SIZE, self.on_size)
747 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change) 719 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
748 self.handler = handler 720 self.handler = handler
749 stats = handler.master_dom.getElementsByTagName('stat') 721 stats = handler.xml.findall('stat')
750 self.CreateGrid(len(stats),3) 722 self.CreateGrid(len(stats),3)
751 self.SetRowLabelSize(0) 723 self.SetRowLabelSize(0)
752 col_names = ['Ability','Score','Modifier'] 724 col_names = ['Ability','Score','Modifier']
753 for i in range(len(col_names)): 725 for i in range(len(col_names)):
754 self.SetColLabelValue(i,col_names[i]) 726 self.SetColLabelValue(i,col_names[i])
763 col = evt.GetCol() 735 col = evt.GetCol()
764 value = self.GetCellValue(row,col) 736 value = self.GetCellValue(row,col)
765 #print value 737 #print value
766 try: 738 try:
767 int(value) 739 int(value)
768 self.stats[row].setAttribute('base',value) 740 self.stats[row].set('base',value)
769 self.refresh_row(row) 741 self.refresh_row(row)
770 except: 742 except:
771 self.SetCellValue(row,col,"0") 743 self.SetCellValue(row,col,"0")
772 if self.char_wnd: 744 if self.char_wnd:
773 self.char_wnd.refresh_data() 745 self.char_wnd.refresh_data()
774 746
775 #mark5
776
777 def refresh_row(self,rowi): 747 def refresh_row(self,rowi):
778 s = self.stats[rowi] 748 s = self.stats[rowi]
779 749
780 name = s.getAttribute('name') 750 name = s.get('name')
781 abbr = s.getAttribute('abbr') 751 abbr = s.get('abbr')
782 self.SetCellValue(rowi,0,name) 752 self.SetCellValue(rowi,0,name)
783 self.SetReadOnly(rowi,0) 753 self.SetReadOnly(rowi,0)
784 self.SetCellValue(rowi,1,s.getAttribute('base')) 754 self.SetCellValue(rowi,1,s.get('base'))
785 self.SetCellValue(rowi,2,str(self.handler.get_mod(abbr))) 755 self.SetCellValue(rowi,2,str(self.handler.get_mod(abbr)))
786 self.SetReadOnly(rowi,2) 756 self.SetReadOnly(rowi,2)
787 #if self.root.saves.saveGrid: #a 1.6018 d 1.9002 whole if clause 757 #if self.root.saves.saveGrid: #a 1.6018 d 1.9002 whole if clause
788 #print getmembers(self.root.saves.saveGrid) 758 #print getmembers(self.root.saves.saveGrid)
789 #self.root.saves.saveGrid.refresh_data() #a 1.6018 759 #self.root.saves.saveGrid.refresh_data() #a 1.6018
821 wnd.title = "Classes" 791 wnd.title = "Classes"
822 return wnd 792 return wnd
823 793
824 def tohtml(self): 794 def tohtml(self):
825 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>Classes</th></tr><tr><td>" 795 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>Classes</th></tr><tr><td>"
826 n_list = self.master_dom._get_childNodes() 796 n_list = self.xml.getchildren()
827 for n in n_list: 797 for n in n_list:
828 html_str += n.getAttribute('name') + " ("+n.getAttribute('level')+"), " 798 html_str += n.get('name') + " ("+n.get('level')+"), "
829 html_str = html_str[:len(html_str)-2] + "</td></tr></table>" 799 html_str = html_str[:len(html_str)-2] + "</td></tr></table>"
830 return html_str 800 return html_str
831 801
832 def get_char_lvl( self, attr ): 802 def get_char_lvl( self, attr ):
833 node_list = self.master_dom.getElementsByTagName('class') 803 node_list = self.xml.findall('class')
834 # print "eclasses - get_char_lvl node_list",node_list 804 # print "eclasses - get_char_lvl node_list",node_list
835 tot = 0 #a 1.5009 actually, slipping in a quick enhancement ;-) 805 tot = 0 #a 1.5009 actually, slipping in a quick enhancement ;-)
836 for n in node_list: 806 for n in node_list:
837 lvl = n.getAttribute('level') #o 1.5009 not sure of the value of this 807 lvl = n.get('level') #o 1.5009 not sure of the value of this
838 tot += int(lvl) #a 1.5009 808 tot += int(lvl) #a 1.5009
839 type = n.getAttribute('name') #o 1.5009 not sure of the value of this 809 type = n.get('name') #o 1.5009 not sure of the value of this
840 #print type,lvl #a (debug) 1.5009 810 #print type,lvl #a (debug) 1.5009
841 if attr == "level": 811 if attr == "level":
842 return lvl #o 1.5009 this returns the level of someone's first class. ??? 812 return lvl #o 1.5009 this returns the level of someone's first class. ???
843 elif attr == "class": 813 elif attr == "class":
844 return type #o 1.5009 this returns one of the char's classes. ??? 814 return type #o 1.5009 this returns one of the char's classes. ???
845 if attr == "lvl": #a 1.5009 this has value, adding this. 815 if attr == "lvl": #a 1.5009 this has value, adding this.
846 return tot #a 1.5009 return character's "overall" level. 816 return tot #a 1.5009 return character's "overall" level.
847 817
848 def get_class_lvl( self, classN ): #a 1.5009 need to be able to get monk lvl 818 def get_class_lvl( self, classN ): #a 1.5009 need to be able to get monk lvl
849 #a 1.5009 this function is new. 819 #a 1.5009 this function is new.
850 node_list = self.master_dom.getElementsByTagName('class') 820 node_list = self.xml.findall('class')
851 #print "eclasses - get_class_lvl node_list",node_list 821 #print "eclasses - get_class_lvl node_list",node_list
852 for n in node_list: 822 for n in node_list:
853 lvl = n.getAttribute('level') 823 lvl = n.get('level')
854 type = n.getAttribute('name') 824 type = n.get('name')
855 if classN == type: 825 if classN == type:
856 return lvl 826 return lvl
857 827
858 class class_panel(wx.Panel): 828 class class_panel(wx.Panel):
859 def __init__(self, parent, handler): 829 def __init__(self, parent, handler):
860 pname = handler.master_dom.setAttribute("name", 'Class') 830 pname = handler.xml.set("name", 'Class')
861 831
862 wx.Panel.__init__(self, parent, -1) 832 wx.Panel.__init__(self, parent, -1)
863 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 833 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
864 sizer = wx.BoxSizer(wx.VERTICAL) 834 sizer = wx.BoxSizer(wx.VERTICAL)
865 sizer.Add(self.grid, 1, wx.EXPAND) 835 sizer.Add(self.grid, 1, wx.EXPAND)
878 #self.Bind(wx.EVT_SIZE, self.on_size) 848 #self.Bind(wx.EVT_SIZE, self.on_size)
879 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10) 849 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10)
880 self.Bind(wx.EVT_BUTTON, self.on_add, id=20) 850 self.Bind(wx.EVT_BUTTON, self.on_add, id=20)
881 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change) 851 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
882 852
883 n_list = handler.master_dom._get_childNodes() 853 n_list = handler.xml.getchildren()
884 self.n_list = n_list 854 self.n_list = n_list
885 self.master_dom = handler.master_dom 855 self.xml = handler.xml
886 self.grid.CreateGrid(len(n_list),2,1) 856 self.grid.CreateGrid(len(n_list),2,1)
887 self.grid.SetRowLabelSize(0) 857 self.grid.SetRowLabelSize(0)
888 self.grid.SetColLabelValue(0,"Class") 858 self.grid.SetColLabelValue(0,"Class")
889 self.grid.SetColLabelValue(1,"Level") 859 self.grid.SetColLabelValue(1,"Level")
890 for i in range(len(n_list)): 860 for i in range(len(n_list)):
895 row = evt.GetRow() 865 row = evt.GetRow()
896 col = evt.GetCol() 866 col = evt.GetCol()
897 value = self.grid.GetCellValue(row,col) 867 value = self.grid.GetCellValue(row,col)
898 try: 868 try:
899 int(value) 869 int(value)
900 self.n_list[row].setAttribute('level',value) 870 self.n_list[row].set('level',value)
901 except: 871 except: self.grid.SetCellValue(row,col,"1")
902 self.grid.SetCellValue(row,col,"1")
903
904 872
905 def refresh_row(self,i): 873 def refresh_row(self,i):
906 n = self.n_list[i] 874 n = self.n_list[i]
907 875 name = n.get('name')
908 name = n.getAttribute('name') 876 level = n.get('level')
909 level = n.getAttribute('level')
910 self.grid.SetCellValue(i,0,name) 877 self.grid.SetCellValue(i,0,name)
911 self.grid.SetReadOnly(i,0) 878 self.grid.SetReadOnly(i,0)
912 self.grid.SetCellValue(i,1,level) 879 self.grid.SetCellValue(i,1,level)
913 #self.grid.SetReadOnly(i,1) 880 #self.grid.SetReadOnly(i,1)
914 881
915 def on_remove(self,evt): 882 def on_remove(self,evt):
916 rows = self.grid.GetNumberRows() 883 rows = self.grid.GetNumberRows()
917 for i in range(rows): 884 for i in range(rows):
918 if self.grid.IsInSelection(i,0): 885 if self.grid.IsInSelection(i,0):
919 self.grid.DeleteRows(i) 886 self.grid.DeleteRows(i)
920 self.master_dom.removeChild(self.n_list[i]) 887 self.xml.remove(self.n_list[i])
921 888
922 def on_add(self,evt): 889 def on_add(self,evt):
923 if not self.temp_dom: 890 if not self.temp_dom:
924 tmp = open(dir_struct["dnd3e"]+"dnd3eclasses.xml","r") 891 tree = parse(dir_struct["dnd3e"]+"dnd3eclasses.xml")
925 xml_dom = parseXml_with_dlg(self,tmp.read()) 892 xml_dom = tree.getroot()
926 xml_dom = xml_dom._get_firstChild()
927 tmp.close()
928 self.temp_dom = xml_dom 893 self.temp_dom = xml_dom
929 f_list = self.temp_dom.getElementsByTagName('class') 894 f_list = self.temp_dom.findall('class')
930 opts = [] 895 opts = []
931 for f in f_list: 896 for f in f_list:
932 opts.append(f.getAttribute('name')) 897 opts.append(f.get('name'))
933 dlg = wx.SingleChoiceDialog(self,'Choose Class','Classes',opts) 898 dlg = wx.SingleChoiceDialog(self,'Choose Class','Classes',opts)
934 if dlg.ShowModal() == wx.ID_OK: 899 if dlg.ShowModal() == wx.ID_OK:
935 i = dlg.GetSelection() 900 i = dlg.GetSelection()
936 new_node = self.master_dom.appendChild(f_list[i].cloneNode(False)) 901 new_node = self.xml.append(f_list[i])
937 self.grid.AppendRows(1) 902 self.grid.AppendRows(1)
938 self.refresh_row(self.grid.GetNumberRows()-1) 903 self.refresh_row(self.grid.GetNumberRows()-1)
939 dlg.Destroy() 904 dlg.Destroy()
940
941 905
942 def on_size(self,event): 906 def on_size(self,event):
943 s = self.GetClientSizeTuple() 907 s = self.GetClientSizeTuple()
944 self.grid.SetDimensions(0,0,s[0],s[1]-25) 908 self.grid.SetDimensions(0,0,s[0],s[1]-25)
945 self.sizer.SetDimension(0,s[1]-25,s[0],25) 909 self.sizer.SetDimension(0,s[1]-25,s[0],25)
963 tree = self.tree 927 tree = self.tree
964 icons = self.tree.icons 928 icons = self.tree.icons
965 929
966 self.root = getRoot(self) #a 1.5002 930 self.root = getRoot(self) #a 1.5002
967 self.root.saves = self #a 1.6009 931 self.root.saves = self #a 1.6009
968 node_list = self.master_dom.getElementsByTagName('save') 932 node_list = self.xml.findall('save')
969 self.saves={} 933 self.saves={}
970 for n in node_list: 934 for n in node_list:
971 name = n.getAttribute('name') 935 name = n.get('name')
972 self.saves[name] = n 936 self.saves[name] = n
973 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear']) 937 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear'])
974 tree.SetPyData(new_tree_node,self) 938 tree.SetPyData(new_tree_node,self)
975 939
976 #a 1.9002 this whole method 940 #a 1.9002 this whole method
984 else: 948 else:
985 self.saveGridFrame.remove(x) 949 self.saveGridFrame.remove(x)
986 950
987 def get_mod(self,name): 951 def get_mod(self,name):
988 save = self.saves[name] 952 save = self.saves[name]
989 stat = save.getAttribute('stat') 953 stat = save.get('stat')
990 #print "dnd3esaves, get_mod: self,root",self,self.root #a (debug) 1.5002 954 #print "dnd3esaves, get_mod: self,root",self,self.root #a (debug) 1.5002
991 #print "and abilities",self.root.abilities #a (debug) 1.5002 955 #print "and abilities",self.root.abilities #a (debug) 1.5002
992 stat_mod = self.root.abilities.get_mod(stat) #a 1.5002 956 stat_mod = self.root.abilities.get_mod(stat) #a 1.5002
993 base = int(save.getAttribute('base')) 957 base = int(save.get('base'))
994 miscmod = int(save.getAttribute('miscmod')) 958 miscmod = int(save.get('miscmod'))
995 magmod = int(save.getAttribute('magmod')) 959 magmod = int(save.get('magmod'))
996 total = stat_mod + base + miscmod + magmod 960 total = stat_mod + base + miscmod + magmod
997 return total 961 return total
998 962
999 def on_rclick(self,evt): 963 def on_rclick(self,evt):
1000
1001 item = self.tree.GetSelection() 964 item = self.tree.GetSelection()
1002 name = self.tree.GetItemText(item) 965 name = self.tree.GetItemText(item)
1003 if item == self.mytree_node: 966 if item == self.mytree_node:
1004 pass #a 1.5003 syntatic place holder 967 pass #a 1.5003 syntatic place holder
1005 return #a 1.5003 968 return #a 1.5003
1008 #wnd = save_grid(self.frame.note,self) 971 #wnd = save_grid(self.frame.note,self)
1009 #wnd.title = "Saves" 972 #wnd.title = "Saves"
1010 #self.frame.add_panel(wnd) 973 #self.frame.add_panel(wnd)
1011 else: 974 else:
1012 mod = self.get_mod(name) 975 mod = self.get_mod(name)
1013 if mod >= 0: 976 if mod >= 0: mod1 = "+"
1014 mod1 = "+" 977 else: mod1 = ""
1015 else:
1016 mod1 = ""
1017 chat = self.chat 978 chat = self.chat
1018 txt = '%s save: [1d20%s%s]' % (name, mod1, mod) 979 txt = '%s save: [1d20%s%s]' % (name, mod1, mod)
1019 chat.ParsePost( txt, True, True ) 980 chat.ParsePost( txt, True, True )
1020 981
1021 def get_design_panel(self,parent): 982 def get_design_panel(self,parent):
1026 def tohtml(self): 987 def tohtml(self):
1027 html_str = """<table border='1' width=100% ><tr BGCOLOR=#E9E9E9 > 988 html_str = """<table border='1' width=100% ><tr BGCOLOR=#E9E9E9 >
1028 <th width='30%'>Save</th> 989 <th width='30%'>Save</th>
1029 <th>Key</th><th>Base</th><th>Abil</th><th>Magic</th> 990 <th>Key</th><th>Base</th><th>Abil</th><th>Magic</th>
1030 <th>Misc</th><th>Total</th></tr>""" 991 <th>Misc</th><th>Total</th></tr>"""
1031 node_list = self.master_dom.getElementsByTagName('save') 992 node_list = self.xml.findall('save')
1032 for n in node_list: 993 for n in node_list:
1033 name = n.getAttribute('name') 994 name = n.get('name')
1034 stat = n.getAttribute('stat') 995 stat = n.get('stat')
1035 base = n.getAttribute('base') 996 base = n.get('base')
1036 html_str = html_str + "<tr ALIGN='center'><td>"+name+"</td><td>"+stat+"</td><td>"+base+"</td>" 997 html_str = html_str + "<tr ALIGN='center'><td>"+name+"</td><td>"+stat+"</td><td>"+base+"</td>"
1037 #stat_mod = str(dnd_globals["stats"][stat]) #d 1.5002 998 #stat_mod = str(dnd_globals["stats"][stat]) #d 1.5002
1038 stat_mod = self.root.abilities.get_mod(stat) #a 1.5002 999 stat_mod = self.root.abilities.get_mod(stat) #a 1.5002
1039 1000
1040 mag = n.getAttribute('magmod') 1001 mag = n.get('magmod')
1041 misc = n.getAttribute('miscmod') 1002 misc = n.get('miscmod')
1042 mod = str(self.get_mod(name)) 1003 mod = str(self.get_mod(name))
1043 if mod >= 0: 1004 if mod >= 0:
1044 mod1 = "+" 1005 mod1 = "+"
1045 else: 1006 else:
1046 mod1 = "" 1007 mod1 = ""
1052 1013
1053 #mark6 1014 #mark6
1054 class save_grid(wx.grid.Grid): 1015 class save_grid(wx.grid.Grid):
1055 """grid for saves""" 1016 """grid for saves"""
1056 def __init__(self, parent, handler): 1017 def __init__(self, parent, handler):
1057 pname = handler.master_dom.setAttribute("name", 'Saves') 1018 pname = handler.xml.set("name", 'Saves')
1058 self.hparent = handler #a 1.5002 allow ability to run up tree. 1019 self.hparent = handler #a 1.5002 allow ability to run up tree.
1059 #a 1.5002 in this case, we need the functional parent, not the invoking parent. 1020 #a 1.5002 in this case, we need the functional parent, not the invoking parent.
1060 self.root = getRoot(self) 1021 self.root = getRoot(self)
1061
1062 #self.hparent.saveGrid = self #a 1.6018 d 1.9001 1022 #self.hparent.saveGrid = self #a 1.6018 d 1.9001
1063
1064
1065 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 1023 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
1066 self.Bind(wx.EVT_SIZE, self.on_size) 1024 self.Bind(wx.EVT_SIZE, self.on_size)
1067 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change) 1025 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
1068 self.handler = handler 1026 self.handler = handler
1069 saves = handler.master_dom.getElementsByTagName('save') 1027 saves = handler.xml.findall('save')
1070 self.CreateGrid(len(saves),7) 1028 self.CreateGrid(len(saves),7)
1071 self.SetRowLabelSize(0) 1029 self.SetRowLabelSize(0)
1072 col_names = ['Save','Key','base','Abil','Magic','Misc','Total'] 1030 col_names = ['Save','Key','base','Abil','Magic','Misc','Total']
1073 for i in range(len(col_names)): 1031 for i in range(len(col_names)):
1074 self.SetColLabelValue(i,col_names[i]) 1032 self.SetColLabelValue(i,col_names[i])
1075 self.saves = saves 1033 self.saves = saves
1076 i = 0 1034 i = 0
1077 for i in range(len(saves)): 1035 for i in range(len(saves)): self.refresh_row(i)
1078 self.refresh_row(i)
1079
1080
1081 #a 1.9002 remainder of code in this method. 1036 #a 1.9002 remainder of code in this method.
1082 climber = parent 1037 climber = parent
1083 nameNode = climber.GetClassName() 1038 nameNode = climber.GetClassName()
1084 while nameNode != 'wxFrame': 1039 while nameNode != 'wxFrame':
1085 climber = climber.parent 1040 climber = climber.parent
1086 nameNode = climber.GetClassName() 1041 nameNode = climber.GetClassName()
1087 masterFrame=climber 1042 masterFrame=climber
1088 masterFrame.refresh_data=self.refresh_data 1043 masterFrame.refresh_data=self.refresh_data
1089 #print getmembers(masterFrame) 1044 #print getmembers(masterFrame)
1090
1091 handler.saveGridFrame.append(masterFrame) 1045 handler.saveGridFrame.append(masterFrame)
1092 1046
1093 def on_cell_change(self,evt): 1047 def on_cell_change(self,evt):
1094 row = evt.GetRow() 1048 row = evt.GetRow()
1095 col = evt.GetCol() 1049 col = evt.GetCol()
1096 value = self.GetCellValue(row,col) 1050 value = self.GetCellValue(row,col)
1097 try: 1051 try:
1098 int(value) 1052 int(value)
1099 if col == 2: 1053 if col == 2:
1100 self.saves[row].setAttribute('base',value) 1054 self.saves[row].set('base',value)
1101 elif col ==4: 1055 elif col ==4:
1102 self.saves[row].setAttribute('magmod',value) 1056 self.saves[row].set('magmod',value)
1103 elif col ==5: # 1.5001 1057 elif col ==5: # 1.5001
1104 self.saves[row].setAttribute('miscmod',value) 1058 self.saves[row].set('miscmod',value)
1105 self.refresh_row(row) 1059 self.refresh_row(row)
1106 except: 1060 except:
1107 self.SetCellValue(row,col,"0") 1061 self.SetCellValue(row,col,"0")
1108 1062
1109 def refresh_row(self,rowi): 1063 def refresh_row(self,rowi):
1110 s = self.saves[rowi] 1064 s = self.saves[rowi]
1111 1065 name = s.get('name')
1112 name = s.getAttribute('name')
1113 self.SetCellValue(rowi,0,name) 1066 self.SetCellValue(rowi,0,name)
1114 self.SetReadOnly(rowi,0) 1067 self.SetReadOnly(rowi,0)
1115 stat = s.getAttribute('stat') 1068 stat = s.get('stat')
1116 self.SetCellValue(rowi,1,stat) 1069 self.SetCellValue(rowi,1,stat)
1117 self.SetReadOnly(rowi,1) 1070 self.SetReadOnly(rowi,1)
1118 self.SetCellValue(rowi,2,s.getAttribute('base')) 1071 self.SetCellValue(rowi,2,s.get('base'))
1119 self.SetCellValue(rowi,3,str(self.root.abilities.get_mod(stat))) 1072 self.SetCellValue(rowi,3,str(self.root.abilities.get_mod(stat)))
1120 self.SetReadOnly(rowi,3) 1073 self.SetReadOnly(rowi,3)
1121 self.SetCellValue(rowi,4,s.getAttribute('magmod')) 1074 self.SetCellValue(rowi,4,s.get('magmod'))
1122 self.SetCellValue(rowi,5,s.getAttribute('miscmod')) 1075 self.SetCellValue(rowi,5,s.get('miscmod'))
1123 mod = str(self.handler.get_mod(name)) 1076 mod = str(self.handler.get_mod(name))
1124 self.SetCellValue(rowi,6,mod) 1077 self.SetCellValue(rowi,6,mod)
1125 self.SetReadOnly(rowi,6) 1078 self.SetReadOnly(rowi,6)
1126 1079
1127 def on_size(self,evt): 1080 def on_size(self,evt):
1157 self.new_child_handler('skills','Skills',dnd3eskill,'book') 1110 self.new_child_handler('skills','Skills',dnd3eskill,'book')
1158 self.new_child_handler('feats','Feats',dnd3efeats,'book') 1111 self.new_child_handler('feats','Feats',dnd3efeats,'book')
1159 #wxMenuItem(self.tree.std_menu, dnd3e_EXPORT, "Export...", "Export") 1112 #wxMenuItem(self.tree.std_menu, dnd3e_EXPORT, "Export...", "Export")
1160 self.myeditor = None 1113 self.myeditor = None
1161 1114
1162
1163 def new_child_handler(self,tag,text,handler_class,icon='gear'): 1115 def new_child_handler(self,tag,text,handler_class,icon='gear'):
1164 node_list = self.master_dom.getElementsByTagName(tag) 1116 node_list = self.xml.findall(tag)
1165 tree = self.tree 1117 tree = self.tree
1166 i = self.tree.icons[icon] 1118 i = self.tree.icons[icon]
1167 new_tree_node = tree.AppendItem(self.mytree_node,text,i,i) 1119 new_tree_node = tree.AppendItem(self.mytree_node,text,i,i)
1168 handler = handler_class(node_list[0],new_tree_node,self) 1120 handler = handler_class(node_list[0],new_tree_node,self)
1169 tree.SetPyData(new_tree_node,handler) 1121 tree.SetPyData(new_tree_node,handler)
1170 self.child_handlers[tag] = handler 1122 self.child_handlers[tag] = handler
1171 1123
1172 def get_design_panel(self,parent): 1124 def get_design_panel(self,parent):
1173 return tabbed_panel(parent,self,1) 1125 return tabbed_panel(parent,self,1)
1174
1175 1126
1176 def get_use_panel(self,parent): 1127 def get_use_panel(self,parent):
1177 return tabbed_panel(parent,self,2) 1128 return tabbed_panel(parent,self,2)
1178 1129
1179 class skills_char_child(node_handler): 1130 class skills_char_child(node_handler):
1185 self.char_hander = parent 1136 self.char_hander = parent
1186 self.drag = False 1137 self.drag = False
1187 self.frame = component.get('frame') 1138 self.frame = component.get('frame')
1188 self.myeditor = None 1139 self.myeditor = None
1189 1140
1190
1191
1192 def on_drop(self,evt): 1141 def on_drop(self,evt):
1193 pass 1142 pass
1194 1143
1195 def on_rclick(self,evt): 1144 def on_rclick(self,evt):
1196 pass 1145 pass
1199 return 1148 return
1200 1149
1201 def on_html(self,evt): 1150 def on_html(self,evt):
1202 html_str = self.tohtml() 1151 html_str = self.tohtml()
1203 wnd = http_html_window(self.frame.note,-1) 1152 wnd = http_html_window(self.frame.note,-1)
1204 wnd.title = self.master_dom.getAttribute('name') 1153 wnd.title = self.xml.get('name')
1205 self.frame.add_panel(wnd) 1154 self.frame.add_panel(wnd)
1206 wnd.SetPage(html_str) 1155 wnd.SetPage(html_str)
1207 1156
1208 def get_design_panel(self,parent): 1157 def get_design_panel(self,parent):
1209 pass 1158 pass
1225 self.root.skills = self #a 1.6009 1174 self.root.skills = self #a 1.6009
1226 1175
1227 skills_char_child.__init__(self,xml_dom,tree_node,parent) 1176 skills_char_child.__init__(self,xml_dom,tree_node,parent)
1228 tree = self.tree 1177 tree = self.tree
1229 icons = self.tree.icons 1178 icons = self.tree.icons
1230 node_list = self.master_dom.getElementsByTagName('skill') 1179 node_list = self.xml.findall('skill')
1231 1180
1232 self.skills={} 1181 self.skills={}
1233 #Adding code to not display skills you can not use -mgt 1182 #Adding code to not display skills you can not use -mgt
1234 for n in node_list: 1183 for n in node_list:
1235 name = n.getAttribute('name') 1184 name = n.get('name')
1236 self.skills[name] = n 1185 self.skills[name] = n
1237 skill_check = self.skills[name] 1186 skill_check = self.skills[name]
1238 ranks = int(skill_check.getAttribute('rank')) 1187 ranks = int(skill_check.get('rank'))
1239 trained = int(skill_check.getAttribute('untrained')) 1188 trained = int(skill_check.get('untrained'))
1240 1189
1241 if ranks > 0 or trained == 1: 1190 if ranks > 0 or trained == 1:
1242 new_tree_node = tree.AppendItem(self.mytree_node,name, 1191 new_tree_node = tree.AppendItem(self.mytree_node,name,
1243 icons['gear'],icons['gear']) 1192 icons['gear'],icons['gear'])
1244 else: 1193 else: continue
1245 continue
1246
1247 tree.SetPyData(new_tree_node,self) 1194 tree.SetPyData(new_tree_node,self)
1248 1195
1249 1196
1250
1251 def refresh_skills(self): 1197 def refresh_skills(self):
1252 #Adding this so when you update the grid the tree will reflect 1198 #Adding this so when you update the grid the tree will reflect
1253 #The change. -mgt 1199 #The change. -mgt
1254 tree = self.tree 1200 tree = self.tree
1255 icons = self.tree.icons 1201 icons = self.tree.icons
1256 tree.CollapseAndReset(self.mytree_node) 1202 tree.CollapseAndReset(self.mytree_node)
1257 node_list = self.master_dom.getElementsByTagName('skill') 1203 node_list = self.xml.findall('skill')
1258 1204
1259 self.skills={} 1205 self.skills={}
1260 for n in node_list: 1206 for n in node_list:
1261 name = n.getAttribute('name') 1207 name = n.get('name')
1262 self.skills[name] = n 1208 self.skills[name] = n
1263 skill_check = self.skills[name] 1209 skill_check = self.skills[name]
1264 ranks = int(skill_check.getAttribute('rank')) 1210 ranks = int(skill_check.get('rank'))
1265 trained = int(skill_check.getAttribute('untrained')) 1211 trained = int(skill_check.get('untrained'))
1266 1212
1267 if ranks > 0 or trained == 1: 1213 if ranks > 0 or trained == 1:
1268 new_tree_node = tree.AppendItem(self.mytree_node,name, 1214 new_tree_node = tree.AppendItem(self.mytree_node,name,
1269 icons['gear'],icons['gear']) 1215 icons['gear'],icons['gear'])
1270 else: 1216 else: continue
1271 continue
1272
1273 tree.SetPyData(new_tree_node,self) 1217 tree.SetPyData(new_tree_node,self)
1274 1218
1275 def get_mod(self,name): 1219 def get_mod(self,name):
1276 skill = self.skills[name] 1220 skill = self.skills[name]
1277 stat = skill.getAttribute('stat') 1221 stat = skill.get('stat')
1278 #stat_mod = int(dnd_globals["stats"][stat]) #d 1.5002 1222 #stat_mod = int(dnd_globals["stats"][stat]) #d 1.5002
1279 stat_mod = self.root.abilities.get_mod(stat) #a 1.5002 1223 stat_mod = self.root.abilities.get_mod(stat) #a 1.5002
1280 rank = int(skill.getAttribute('rank')) 1224 rank = int(skill.get('rank'))
1281 misc = int(skill.getAttribute('misc')) 1225 misc = int(skill.get('misc'))
1282 total = stat_mod + rank + misc 1226 total = stat_mod + rank + misc
1283 return total 1227 return total
1284 1228
1285 def on_rclick(self,evt): 1229 def on_rclick(self,evt):
1286 item = self.tree.GetSelection() 1230 item = self.tree.GetSelection()
1292 return 1236 return
1293 # following line fails, 1237 # following line fails,
1294 #dnd3e_char_child.on_ldclick(self,evt) #d 1.6014 1238 #dnd3e_char_child.on_ldclick(self,evt) #d 1.6014
1295 # it's what it used to try to do. 1239 # it's what it used to try to do.
1296 ac = self.root.ac.get_check_pen() #a 1.5002 for 1.5004 verify fix. 1240 ac = self.root.ac.get_check_pen() #a 1.5002 for 1.5004 verify fix.
1297
1298 skill = self.skills[name] 1241 skill = self.skills[name]
1299 1242 untr = skill.get('untrained') #a 1.6004
1300 untr = skill.getAttribute('untrained') #a 1.6004 1243 rank = skill.get('rank') #a 1.6004
1301 rank = skill.getAttribute('rank') #a 1.6004
1302 if eval('%s == 0' % (untr)): #a 1.6004 1244 if eval('%s == 0' % (untr)): #a 1.6004
1303 if eval('%s == 0' % (rank)): #a 1.6004 1245 if eval('%s == 0' % (rank)): #a 1.6004
1304 res = 'You fumble around, accomplishing nothing' #a 1.6004 1246 res = 'You fumble around, accomplishing nothing' #a 1.6004
1305 txt = '%s Skill Check: %s' % (name, res) #a 1.6004 1247 txt = '%s Skill Check: %s' % (name, res) #a 1.6004
1306 chat = self.chat #a 1.6004 1248 chat = self.chat #a 1.6004
1308 return #a 1.6004 1250 return #a 1.6004
1309 1251
1310 armor = '' 1252 armor = ''
1311 acCp = '' 1253 acCp = ''
1312 if ac < 0: #acCp >= 1 #m 1.5004 this is stored as negatives. 1254 if ac < 0: #acCp >= 1 #m 1.5004 this is stored as negatives.
1313 armorCheck = int(skill.getAttribute('armorcheck')) 1255 armorCheck = int(skill.get('armorcheck'))
1314 #print "ac,armorCheck",ac,armorCheck 1256 #print "ac,armorCheck",ac,armorCheck
1315 if armorCheck == 1: 1257 if armorCheck == 1:
1316 acCp=ac 1258 acCp=ac
1317 armor = '(includes Armor Penalty of %s)' % (acCp) 1259 armor = '(includes Armor Penalty of %s)' % (acCp)
1318 if item == self.mytree_node: 1260 if item == self.mytree_node:
1320 #wnd = skill_grid(self.frame.note,self) 1262 #wnd = skill_grid(self.frame.note,self)
1321 #wnd.title = "Skills" 1263 #wnd.title = "Skills"
1322 #self.frame.add_panel(wnd) 1264 #self.frame.add_panel(wnd)
1323 else: 1265 else:
1324 mod = self.get_mod(name) 1266 mod = self.get_mod(name)
1325 if mod >= 0: 1267 if mod >= 0: mod1 = "+"
1326 mod1 = "+" 1268 else: mod1 = ""
1327 else:
1328 mod1 = ""
1329 chat = self.chat 1269 chat = self.chat
1330 txt = '%s Skill Check: [1d20%s%s%s] %s' % ( 1270 txt = '%s Skill Check: [1d20%s%s%s] %s' % (
1331 name, mod1, mod, acCp, armor) 1271 name, mod1, mod, acCp, armor)
1332 chat.ParsePost(txt,True,True) 1272 chat.ParsePost(txt,True,True)
1333 1273
1338 1278
1339 def tohtml(self): 1279 def tohtml(self):
1340 html_str = """<table border='1' width=100% ><tr BGCOLOR=#E9E9E9 > 1280 html_str = """<table border='1' width=100% ><tr BGCOLOR=#E9E9E9 >
1341 <th width='30%'>Skill</th><th>Key</th> 1281 <th width='30%'>Skill</th><th>Key</th>
1342 <th>Rank</th><th>Abil</th><th>Misc</th><th>Total</th></tr>""" 1282 <th>Rank</th><th>Abil</th><th>Misc</th><th>Total</th></tr>"""
1343 node_list = self.master_dom.getElementsByTagName('skill') 1283 node_list = self.xml.findall('skill')
1344 1284
1345 for n in node_list: 1285 for n in node_list:
1346 name = n.getAttribute('name') 1286 name = n.get('name')
1347 stat = n.getAttribute('stat') 1287 stat = n.get('stat')
1348 rank = n.getAttribute('rank') 1288 rank = n.get('rank')
1349 untr = n.getAttribute('untrained') #a 1.6004 1289 untr = n.get('untrained') #a 1.6004
1350 #Filter unsuable skills out of pretty print -mgt 1290 #Filter unsuable skills out of pretty print -mgt
1351 if eval('%s > 0' % (rank)) or eval('%s == 1' % (untr)): 1291 if eval('%s > 0' % (rank)) or eval('%s == 1' % (untr)):
1352 if eval('%s >=1' % (rank)): 1292 if eval('%s >=1' % (rank)):
1353 html_str += "<tr ALIGN='center' bgcolor='#CCCCFF'><td>" #a 1.6004 1293 html_str += "<tr ALIGN='center' bgcolor='#CCCCFF'><td>" #a 1.6004
1354 #html_str += "<tr ALIGN='center' bgcolor='green'><td>" #d 1.6004 1294 #html_str += "<tr ALIGN='center' bgcolor='green'><td>" #d 1.6004
1361 html_str += stat+"</td><td>"+rank+"</td>" 1301 html_str += stat+"</td><td>"+rank+"</td>"
1362 else: 1302 else:
1363 continue 1303 continue
1364 stat_mod = self.root.abilities.get_mod(stat) #a 1.5002 1304 stat_mod = self.root.abilities.get_mod(stat) #a 1.5002
1365 #stat_mod = str(dnd_globals["stats"][stat]) #d 1.5002 1305 #stat_mod = str(dnd_globals["stats"][stat]) #d 1.5002
1366 misc = n.getAttribute('misc') 1306 misc = n.get('misc')
1367 mod = str(self.get_mod(name)) 1307 mod = str(self.get_mod(name))
1368 if mod >= 0: 1308 if mod >= 0:
1369 mod1 = "+" 1309 mod1 = "+"
1370 else: 1310 else:
1371 mod1 = "" 1311 mod1 = ""
1378 class skill_grid(wx.grid.Grid): 1318 class skill_grid(wx.grid.Grid):
1379 """ panel for skills """ 1319 """ panel for skills """
1380 def __init__(self, parent, handler): 1320 def __init__(self, parent, handler):
1381 self.hparent = handler #a 1.5002 need function parent, not invoker 1321 self.hparent = handler #a 1.5002 need function parent, not invoker
1382 self.root = getRoot(self) #a 1.5002 1322 self.root = getRoot(self) #a 1.5002
1383 pname = handler.master_dom.setAttribute("name", 'Skills') 1323 pname = handler.xml.set("name", 'Skills')
1384 1324
1385 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 1325 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
1386 self.Bind(wx.EVT_SIZE, self.on_size) 1326 self.Bind(wx.EVT_SIZE, self.on_size)
1387 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change) 1327 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
1388 self.handler = handler 1328 self.handler = handler
1389 skills = handler.master_dom.getElementsByTagName('skill') 1329 skills = handler.xml.findall('skill')
1390 #xelf.stats = dnd_globals["stats"] #d 1.5002 1330 #xelf.stats = dnd_globals["stats"] #d 1.5002
1391 1331
1392 self.CreateGrid(len(skills),6) 1332 self.CreateGrid(len(skills),6)
1393 self.SetRowLabelSize(0) 1333 self.SetRowLabelSize(0)
1394 col_names = ['Skill','Key','Rank','Abil','Misc','Total'] 1334 col_names = ['Skill','Key','Rank','Abil','Misc','Total']
1405 value = self.GetCellValue(row,col) 1345 value = self.GetCellValue(row,col)
1406 #print value 1346 #print value
1407 try: 1347 try:
1408 int(value) 1348 int(value)
1409 if col == 2: 1349 if col == 2:
1410 self.skills[row].setAttribute('rank',value) 1350 self.skills[row].set('rank',value)
1411 elif col ==4: 1351 elif col ==4:
1412 self.skills[row].setAttribute('misc',value) 1352 self.skills[row].set('misc',value)
1413 self.refresh_row(row) 1353 self.refresh_row(row)
1414 except: 1354 except:
1415 self.SetCellValue(row,col,"0") 1355 self.SetCellValue(row,col,"0")
1416 1356
1417 #call refresh_skills 1357 #call refresh_skills
1418 self.handler.refresh_skills() 1358 self.handler.refresh_skills()
1419 1359
1420 def refresh_row(self,rowi): 1360 def refresh_row(self,rowi):
1421 s = self.skills[rowi] 1361 s = self.skills[rowi]
1422 name = s.getAttribute('name') 1362 name = s.get('name')
1423 self.SetCellValue(rowi,0,name) 1363 self.SetCellValue(rowi,0,name)
1424 self.SetReadOnly(rowi,0) 1364 self.SetReadOnly(rowi,0)
1425 stat = s.getAttribute('stat') 1365 stat = s.get('stat')
1426 self.SetCellValue(rowi,1,stat) 1366 self.SetCellValue(rowi,1,stat)
1427 self.SetReadOnly(rowi,1) 1367 self.SetReadOnly(rowi,1)
1428 self.SetCellValue(rowi,2,s.getAttribute('rank')) 1368 self.SetCellValue(rowi,2,s.get('rank'))
1429 #self.SetCellValue(rowi,3,str(dnd_globals["stats"][stat])) #d 1.5002 1369 #self.SetCellValue(rowi,3,str(dnd_globals["stats"][stat])) #d 1.5002
1430 if self.root.abilities: #a 1.5002 sanity check. 1370 if self.root.abilities: #a 1.5002 sanity check.
1431 stat_mod=self.root.abilities.get_mod(stat) #a 1.5002 1371 stat_mod=self.root.abilities.get_mod(stat) #a 1.5002
1432 else: #a 1.5002 1372 else: #a 1.5002
1433 stat_mod = -6 #a 1.5002 this can happen if code is changed so 1373 stat_mod = -6 #a 1.5002 this can happen if code is changed so
1434 #a 1.5002 that abilities are not defined prior invokation of init. 1374 #a 1.5002 that abilities are not defined prior invokation of init.
1435 print "Please advise dnd3e maintainer alert 1.5002 raised" 1375 print "Please advise dnd3e maintainer alert 1.5002 raised"
1436 1376
1437 self.SetCellValue(rowi,3,str(stat_mod)) #a 1.5002 1377 self.SetCellValue(rowi,3,str(stat_mod)) #a 1.5002
1438 self.SetReadOnly(rowi,3) 1378 self.SetReadOnly(rowi,3)
1439 self.SetCellValue(rowi,4,s.getAttribute('misc')) 1379 self.SetCellValue(rowi,4,s.get('misc'))
1440 mod = str(self.handler.get_mod(name)) 1380 mod = str(self.handler.get_mod(name))
1441 self.SetCellValue(rowi,5,mod) 1381 self.SetCellValue(rowi,5,mod)
1442 self.SetReadOnly(rowi,5) 1382 self.SetReadOnly(rowi,5)
1443 1383
1444 def on_size(self,evt): 1384 def on_size(self,evt):
1478 #wnd.title = "Feats - " + self.charName 1418 #wnd.title = "Feats - " + self.charName
1479 return wnd 1419 return wnd
1480 1420
1481 def tohtml(self): 1421 def tohtml(self):
1482 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>Feats</th></tr><tr><td>" 1422 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>Feats</th></tr><tr><td>"
1483 n_list = self.master_dom._get_childNodes() 1423 n_list = self.xml.getchildren()
1484 for n in n_list: 1424 for n in n_list:
1485 html_str += n.getAttribute('name')+ ", " 1425 html_str += n.get('name')+ ", "
1486 html_str = html_str[:len(html_str)-2] + "</td></tr></table>" 1426 html_str = html_str[:len(html_str)-2] + "</td></tr></table>"
1487 return html_str 1427 return html_str
1488 1428
1489 class feat_panel(wx.Panel): 1429 class feat_panel(wx.Panel):
1490 def __init__(self, parent, handler): 1430 def __init__(self, parent, handler):
1491 1431
1492 self.hparent = handler #a 1.5002 allow ability to run up tree. 1432 self.hparent = handler #a 1.5002 allow ability to run up tree.
1493 #a 1.5002 in this case, we need the functional parent, not the invoking parent. 1433 #a 1.5002 in this case, we need the functional parent, not the invoking parent.
1494 self.root = getRoot(self) #a 1.5002 1434 self.root = getRoot(self) #a 1.5002
1495 #tempTitle= 'Feats - ' + self.root.general.charName #a 1.5010 1435 #tempTitle= 'Feats - ' + self.root.general.charName #a 1.5010
1496 #pname = handler.master_dom.setAttribute("name", tempTitle) #a 1.5010 1436 #pname = handler.xml.set("name", tempTitle) #a 1.5010
1497 pname = handler.master_dom.setAttribute("name", 'Feats') #d 1.5010 1437 pname = handler.xml.set("name", 'Feats') #d 1.5010
1498 1438
1499 wx.Panel.__init__(self, parent, -1) 1439 wx.Panel.__init__(self, parent, -1)
1500 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 1440 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
1501 sizer = wx.BoxSizer(wx.VERTICAL) 1441 sizer = wx.BoxSizer(wx.VERTICAL)
1502 sizer.Add(self.grid, 1, wx.EXPAND) 1442 sizer.Add(self.grid, 1, wx.EXPAND)
1515 1455
1516 #self.Bind(wx.EVT_SIZE, self.on_size) 1456 #self.Bind(wx.EVT_SIZE, self.on_size)
1517 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10) 1457 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10)
1518 self.Bind(wx.EVT_BUTTON, self.on_add, id=20) 1458 self.Bind(wx.EVT_BUTTON, self.on_add, id=20)
1519 1459
1520 n_list = handler.master_dom._get_childNodes() 1460 n_list = handler.xml.getchildren()
1521 self.n_list = n_list 1461 self.n_list = n_list
1522 self.master_dom = handler.master_dom 1462 self.xml = handler.xml
1523 self.grid.CreateGrid(len(n_list),3,1) 1463 self.grid.CreateGrid(len(n_list),3,1)
1524 self.grid.SetRowLabelSize(0) 1464 self.grid.SetRowLabelSize(0)
1525 self.grid.SetColLabelValue(0,"Feat") 1465 self.grid.SetColLabelValue(0,"Feat")
1526 self.grid.SetColLabelValue(1,"Type") 1466 self.grid.SetColLabelValue(1,"Type")
1527 self.grid.SetColLabelValue(2,"Reference") #m 1.6 typo correction. 1467 self.grid.SetColLabelValue(2,"Reference") #m 1.6 typo correction.
1530 self.temp_dom = None 1470 self.temp_dom = None
1531 1471
1532 def refresh_row(self,i): 1472 def refresh_row(self,i):
1533 feat = self.n_list[i] 1473 feat = self.n_list[i]
1534 1474
1535 name = feat.getAttribute('name') 1475 name = feat.get('name')
1536 type = feat.getAttribute('type') 1476 type = feat.get('type')
1537 desc = feat.getAttribute('desc') #m 1.6 correct typo 1477 desc = feat.get('desc') #m 1.6 correct typo
1538 self.grid.SetCellValue(i,0,name) 1478 self.grid.SetCellValue(i,0,name)
1539 self.grid.SetReadOnly(i,0) 1479 self.grid.SetReadOnly(i,0)
1540 self.grid.SetCellValue(i,1,type) 1480 self.grid.SetCellValue(i,1,type)
1541 self.grid.SetReadOnly(i,1) 1481 self.grid.SetReadOnly(i,1)
1542 self.grid.SetCellValue(i,2,desc) #m 1.6 correct typo 1482 self.grid.SetCellValue(i,2,desc) #m 1.6 correct typo
1545 def on_remove(self,evt): 1485 def on_remove(self,evt):
1546 rows = self.grid.GetNumberRows() 1486 rows = self.grid.GetNumberRows()
1547 for i in range(rows): 1487 for i in range(rows):
1548 if self.grid.IsInSelection(i,0): 1488 if self.grid.IsInSelection(i,0):
1549 self.grid.DeleteRows(i) 1489 self.grid.DeleteRows(i)
1550 self.master_dom.removeChild(self.n_list[i]) 1490 self.xml.remove(self.n_list[i])
1551 1491
1552 def on_add(self,evt): 1492 def on_add(self,evt):
1553 1493
1554 if not self.temp_dom: 1494 if not self.temp_dom:
1555 tmp = open(dir_struct["dnd3e"]+"dnd3efeats.xml","r") 1495 tree = parse(dir_struct["dnd3e"]+"dnd3efeats.xml")
1556 xml_dom = parseXml_with_dlg(self,tmp.read()) 1496 temp_dom = tree.getroot()
1557 xml_dom = xml_dom._get_firstChild() 1497 f_list = temp_dom.findall('feat')
1558 tmp.close()
1559 temp_dom = xml_dom
1560 f_list = temp_dom.getElementsByTagName('feat')
1561 opts = [] 1498 opts = []
1562 for f in f_list: 1499 for f in f_list:
1563 opts.append(f.getAttribute('name') + " - [" + 1500 opts.append(f.get('name') + " - [" +
1564 f.getAttribute('type') + "] - " + f.getAttribute('desc')) 1501 f.get('type') + "] - " + f.get('desc'))
1565 dlg = wx.SingleChoiceDialog(self,'Choose Feat','Feats',opts) 1502 dlg = wx.SingleChoiceDialog(self,'Choose Feat','Feats',opts)
1566 if dlg.ShowModal() == wx.ID_OK: 1503 if dlg.ShowModal() == wx.ID_OK:
1567 i = dlg.GetSelection() 1504 i = dlg.GetSelection()
1568 new_node = self.master_dom.appendChild(f_list[i].cloneNode(False)) 1505 new_node = self.xml.append(f_list[i])
1569 self.grid.AppendRows(1) 1506 self.grid.AppendRows(1)
1570 self.refresh_row(self.grid.GetNumberRows()-1) 1507 self.refresh_row(self.grid.GetNumberRows()-1)
1571 dlg.Destroy() 1508 dlg.Destroy()
1572 1509
1573 1510
1605 #wxMenuItem(self.tree.std_menu, dnd3e_EXPORT, "Export...", "Export") 1542 #wxMenuItem(self.tree.std_menu, dnd3e_EXPORT, "Export...", "Export")
1606 self.myeditor = None 1543 self.myeditor = None
1607 1544
1608 1545
1609 def new_child_handler(self,tag,text,handler_class,icon='gear'): 1546 def new_child_handler(self,tag,text,handler_class,icon='gear'):
1610 node_list = self.master_dom.getElementsByTagName(tag) 1547 node_list = self.xml.findall(tag)
1611 tree = self.tree 1548 tree = self.tree
1612 i = self.tree.icons[icon] 1549 i = self.tree.icons[icon]
1613 new_tree_node = tree.AppendItem(self.mytree_node,text,i,i) 1550 new_tree_node = tree.AppendItem(self.mytree_node,text,i,i)
1614 handler = handler_class(node_list[0],new_tree_node,self) 1551 handler = handler_class(node_list[0],new_tree_node,self)
1615 tree.SetPyData(new_tree_node,handler) 1552 tree.SetPyData(new_tree_node,handler)
1644 return 1581 return
1645 1582
1646 def on_html(self,evt): 1583 def on_html(self,evt):
1647 html_str = self.tohtml() 1584 html_str = self.tohtml()
1648 wnd = http_html_window(self.frame.note,-1) 1585 wnd = http_html_window(self.frame.note,-1)
1649 wnd.title = self.master_dom.getAttribute('name') 1586 wnd.title = self.xml.get('name')
1650 self.frame.add_panel(wnd) 1587 self.frame.add_panel(wnd)
1651 wnd.SetPage(html_str) 1588 wnd.SetPage(html_str)
1652 1589
1653 def get_design_panel(self,parent): 1590 def get_design_panel(self,parent):
1654 pass 1591 pass
1673 wnd = outline_panel(parent,self,hp_panel,"Hit Points") 1610 wnd = outline_panel(parent,self,hp_panel,"Hit Points")
1674 wnd.title = "Hit Points" 1611 wnd.title = "Hit Points"
1675 return wnd 1612 return wnd
1676 1613
1677 def on_rclick( self, evt ): 1614 def on_rclick( self, evt ):
1678 chp = self.master_dom.getAttribute('current') 1615 chp = self.xml.get('current')
1679 mhp = self.master_dom.getAttribute('max') 1616 mhp = self.xml.get('max')
1680 txt = '((HP: %s / %s))' % ( chp, mhp ) 1617 txt = '((HP: %s / %s))' % ( chp, mhp )
1681 self.chat.ParsePost( txt, True, True ) 1618 self.chat.ParsePost( txt, True, True )
1682 1619
1683 def tohtml(self): 1620 def tohtml(self):
1684 html_str = "<table width=100% border=1 >" 1621 html_str = "<table width=100% border=1 >"
1685 html_str += "<tr BGCOLOR=#E9E9E9 ><th colspan=4>Hit Points</th></tr>" 1622 html_str += "<tr BGCOLOR=#E9E9E9 ><th colspan=4>Hit Points</th></tr>"
1686 html_str += "<tr><th>Max:</th>" 1623 html_str += "<tr><th>Max:</th>"
1687 html_str += "<td>"+self.master_dom.getAttribute('max')+"</td>" 1624 html_str += "<td>"+self.xml.get('max')+"</td>"
1688 html_str += "<th>Current:</th>" 1625 html_str += "<th>Current:</th>"
1689 html_str += "<td>"+self.master_dom.getAttribute('current')+"</td>" 1626 html_str += "<td>"+self.xml.get('current')+"</td>"
1690 html_str += "</tr></table>" 1627 html_str += "</tr></table>"
1691 return html_str 1628 return html_str
1692 1629
1693 class hp_panel(wx.Panel): 1630 class hp_panel(wx.Panel):
1694 def __init__(self, parent, handler): 1631 def __init__(self, parent, handler):
1695 wx.Panel.__init__(self, parent, -1) 1632 wx.Panel.__init__(self, parent, -1)
1696 self.hparent = handler #a 1.5002 allow ability to run up tree. In this 1633 self.hparent = handler #a 1.5002 allow ability to run up tree. In this
1697 #a 1.5002 case, we need the functional parent, not the invoking parent. 1634 #a 1.5002 case, we need the functional parent, not the invoking parent.
1698 1635
1699 pname = handler.master_dom.setAttribute("name", 'HitPoints') 1636 pname = handler.xml.set("name", 'HitPoints')
1700 self.sizer = wx.FlexGridSizer(2, 4, 2, 2) # rows, cols, hgap, vgap 1637 self.sizer = wx.FlexGridSizer(2, 4, 2, 2) # rows, cols, hgap, vgap
1701 self.master_dom = handler.master_dom 1638 self.xml = handler.xml
1702 self.sizer.AddMany([ (wx.StaticText(self, -1, "HP Current:"), 0, 1639 self.sizer.AddMany([ (wx.StaticText(self, -1, "HP Current:"), 0,
1703 wx.ALIGN_CENTER_VERTICAL), 1640 wx.ALIGN_CENTER_VERTICAL),
1704 (wx.TextCtrl(self, HP_CUR, 1641 (wx.TextCtrl(self, HP_CUR,
1705 self.master_dom.getAttribute('current')), 0, wx.EXPAND), 1642 self.xml.get('current')), 0, wx.EXPAND),
1706 (wx.StaticText(self, -1, "HP Max:"), 0, wx.ALIGN_CENTER_VERTICAL), 1643 (wx.StaticText(self, -1, "HP Max:"), 0, wx.ALIGN_CENTER_VERTICAL),
1707 (wx.TextCtrl(self, HP_MAX, self.master_dom.getAttribute('max')), 1644 (wx.TextCtrl(self, HP_MAX, self.xml.get('max')),
1708 0, wx.EXPAND), 1645 0, wx.EXPAND),
1709 ]) 1646 ])
1710 self.sizer.AddGrowableCol(1) 1647 self.sizer.AddGrowableCol(1)
1711 self.SetSizer(self.sizer) 1648 self.SetSizer(self.sizer)
1712 self.SetAutoLayout(True) 1649 self.SetAutoLayout(True)
1717 self.Bind(wx.EVT_TEXT, self.on_text, id=HP_CUR) 1654 self.Bind(wx.EVT_TEXT, self.on_text, id=HP_CUR)
1718 1655
1719 def on_text(self,evt): 1656 def on_text(self,evt):
1720 id = evt.GetId() 1657 id = evt.GetId()
1721 if id == HP_CUR: 1658 if id == HP_CUR:
1722 self.master_dom.setAttribute('current',evt.GetString()) 1659 self.xml.set('current',evt.GetString())
1723 elif id == HP_MAX: 1660 elif id == HP_MAX:
1724 self.master_dom.setAttribute('max',evt.GetString()) 1661 self.xml.set('max',evt.GetString())
1725 1662
1726 def on_size(self,evt): 1663 def on_size(self,evt):
1727 s = self.GetClientSizeTuple() 1664 s = self.GetClientSizeTuple()
1728 self.sizer.SetDimension(0,0,s[0],s[1]) 1665 self.sizer.SetDimension(0,0,s[0],s[1])
1729 1666
1759 """<table border='1' width=100% ><tr BGCOLOR=#E9E9E9 > 1696 """<table border='1' width=100% ><tr BGCOLOR=#E9E9E9 >
1760 <th width='80%'>Weapon Name</th><th>Added Footnote</th></tr>\n""") 1697 <th width='80%'>Weapon Name</th><th>Added Footnote</th></tr>\n""")
1761 self.temp_dom={} 1698 self.temp_dom={}
1762 #a 1.5012 end a1b 1699 #a 1.5012 end a1b
1763 1700
1764 node_list = self.master_dom.getElementsByTagName('melee') 1701 node_list = self.xml.findall('melee')
1765 self.melee = node_list[0] 1702 self.melee = node_list[0]
1766 node_list = self.master_dom.getElementsByTagName('ranged') 1703 node_list = self.xml.findall('ranged')
1767 self.ranged = node_list[0] 1704 self.ranged = node_list[0]
1768 self.refresh_weapons() # this causes self.weapons to be loaded. 1705 self.refresh_weapons() # this causes self.weapons to be loaded.
1769 1706
1770 #a 1.5012 this whole if clause. 1707 #a 1.5012 this whole if clause.
1771 if self.updateFootNotes == True: 1708 if self.updateFootNotes == True:
1779 fnFrame = wx.Frame(masterFrame, -1, title) 1716 fnFrame = wx.Frame(masterFrame, -1, title)
1780 fnFrame.panel = wx.html.HtmlWindow(fnFrame,-1) 1717 fnFrame.panel = wx.html.HtmlWindow(fnFrame,-1)
1781 fnFrame.panel.SetPage(self.html_str) 1718 fnFrame.panel.SetPage(self.html_str)
1782 fnFrame.Show() 1719 fnFrame.Show()
1783 1720
1784 #weaponsH = self.master_dom.getElementsByTagName('attacks') 1721 #weaponsH = self.xml.findall('attacks')
1785 #mark7 1722 #mark7
1786 1723
1787 #a 1.9001 this whole method 1724 #a 1.9001 this whole method
1788 def refreshMRdata(self): # refresh the data in the melee/ranged section 1725 def refreshMRdata(self): # refresh the data in the melee/ranged section
1789 # of the attack chart. 1726 # of the attack chart.
1799 self.weapons = {} 1736 self.weapons = {}
1800 1737
1801 tree = self.tree 1738 tree = self.tree
1802 icons = self.tree.icons 1739 icons = self.tree.icons
1803 tree.CollapseAndReset(self.mytree_node) 1740 tree.CollapseAndReset(self.mytree_node)
1804 node_list = self.master_dom.getElementsByTagName('weapon') 1741 node_list = self.xml.findall('weapon')
1805 for n in node_list: 1742 for n in node_list:
1806 name = n.getAttribute('name') 1743 name = n.get('name')
1807 fn = safeGetAttr(n,'fn') #a 1.5012 can be removed when 1744 fn = safeGetAttr(n,'fn') #a 1.5012 can be removed when
1808 #a 1.5012 confident all characters in the world have footnotes. 1745 #a 1.5012 confident all characters in the world have footnotes.
1809 #if self.updateFootNotes: 1746 #if self.updateFootNotes:
1810 if fn == None:#a 1.5012 1747 if fn == None:#a 1.5012
1811 self.updateFootNotes=True 1748 self.updateFootNotes=True
1815 tree.SetPyData(new_tree_node,self) 1752 tree.SetPyData(new_tree_node,self)
1816 self.weapons[name]=n 1753 self.weapons[name]=n
1817 1754
1818 def updateFootN(self,n):#a 1.5012 this whole function 1755 def updateFootN(self,n):#a 1.5012 this whole function
1819 if not self.temp_dom: 1756 if not self.temp_dom:
1820 tmp = open(dir_struct["dnd3e"]+"dnd3eweapons.xml","r") 1757 tree = parse(dir_struct["dnd3e"]+"dnd3eweapons.xml")
1821 #tmp = open("c:\clh\codeSamples\sample1.xml","r") #a (debug) 1.5012 1758 self.temp_dom = tree.getroot()
1822 self.temp_dom = xml.dom.minidom.parse(tmp) 1759 nameF = n.get('name')
1823 1760 w_list = self.temp_dom.findall('weapon')
1824 #self.temp_dom = parseXml_with_dlg(self,tmp.read())
1825 self.temp_dom = self.temp_dom._get_firstChild()
1826 tmp.close()
1827 nameF = n.getAttribute('name')
1828 w_list = self.temp_dom.getElementsByTagName('weapon')
1829 found = False 1761 found = False
1830 for w in w_list: 1762 for w in w_list:
1831 if nameF == w.getAttribute('name'): 1763 if nameF == w.get('name'):
1832 found = True 1764 found = True
1833 fnN = safeGetAttr(n,'fn') 1765 fnN = safeGetAttr(n,'fn')
1834 if fnN == None or fnN == 'None': 1766 if fnN == None or fnN == 'None':
1835 fnW = w.getAttribute('fn') 1767 fnW = w.get('fn')
1836 #print "weapon",nameF,"footnotes are updated to",fnW 1768 #print "weapon",nameF,"footnotes are updated to",fnW
1837 self.html_str += ("<tr ALIGN='center'><td>"+nameF+"</td>"+ 1769 self.html_str += ("<tr ALIGN='center'><td>"+nameF+"</td>"+
1838 "<td>"+fnW+"</td></tr>\n") 1770 "<td>"+fnW+"</td></tr>\n")
1839 n.setAttribute('fn',fnW) 1771 n.set('fn',fnW)
1840 break 1772 break
1841 if not found: 1773 if not found:
1842 self.html_str += ("<tr ALIGN='center'><td>"+nameF+" - Custom "+ 1774 self.html_str += ("<tr ALIGN='center'><td>"+nameF+" - Custom "+
1843 "Weapon, research "+ 1775 "Weapon, research "+
1844 "and update manually; setting footnote to indicate custom</td>"+ 1776 "and update manually; setting footnote to indicate custom</td>"+
1845 "<td>"+'X'+"</td></tr>\n") 1777 "<td>"+'X'+"</td></tr>\n")
1846 n.setAttribute('fn','X') 1778 n.set('fn','X')
1847 1779
1848 1780
1849 def get_mod(self,type='m'): 1781 def get_mod(self,type='m'):
1850 (base, base2, base3, base4, base5, base6, stat_mod, misc) \ 1782 (base, base2, base3, base4, base5, base6, stat_mod, misc) \
1851 = self.get_attack_data(type) 1783 = self.get_attack_data(type)
1859 stat = 'Dex' #m was dnd_globals["stats"]['Dex'] 1.5002 1791 stat = 'Dex' #m was dnd_globals["stats"]['Dex'] 1.5002
1860 temp = self.ranged 1792 temp = self.ranged
1861 stat_mod = -7 1793 stat_mod = -7
1862 stat_mod = self.root.abilities.get_mod(stat) #a 1.5002 1794 stat_mod = self.root.abilities.get_mod(stat) #a 1.5002
1863 #print "Big test - stat_mod",stat_mod #a (debug) 1.6000 1795 #print "Big test - stat_mod",stat_mod #a (debug) 1.6000
1864 base = int(temp.getAttribute('base')) 1796 base = int(temp.get('base'))
1865 base2 = int(temp.getAttribute('second')) 1797 base2 = int(temp.get('second'))
1866 base3 = int(temp.getAttribute('third')) 1798 base3 = int(temp.get('third'))
1867 base4 = int(temp.getAttribute('forth')) 1799 base4 = int(temp.get('forth'))
1868 base5 = int(temp.getAttribute('fifth')) 1800 base5 = int(temp.get('fifth'))
1869 base6 = int(temp.getAttribute('sixth')) 1801 base6 = int(temp.get('sixth'))
1870 misc = int(temp.getAttribute('misc')) 1802 misc = int(temp.get('misc'))
1871 return (base, base2, base3, base4, base5, base6, stat_mod ,misc) 1803 return (base, base2, base3, base4, base5, base6, stat_mod ,misc)
1872 1804
1873 def on_rclick(self,evt): 1805 def on_rclick(self,evt):
1874 item = self.tree.GetSelection() 1806 item = self.tree.GetSelection()
1875 1807
1879 return #a 1.6015 1811 return #a 1.6015
1880 #dnd3e_char_child.on_ldclick(self,evt)#d 1.6015 1812 #dnd3e_char_child.on_ldclick(self,evt)#d 1.6015
1881 #self.frame.add_panel(self.get_design_panel(self.frame.note)) 1813 #self.frame.add_panel(self.get_design_panel(self.frame.note))
1882 else: 1814 else:
1883 #print "entering attack phase" 1815 #print "entering attack phase"
1884 mod = int(self.weapons[name].getAttribute('mod')) 1816 mod = int(self.weapons[name].get('mod'))
1885 wepMod = mod #a 1.5008 1817 wepMod = mod #a 1.5008
1886 footNotes = safeGetAttr(self.weapons[name],'fn','') 1818 footNotes = safeGetAttr(self.weapons[name],'fn','')
1887 cat = self.weapons[name].getAttribute('category') #a1.6001 1819 cat = self.weapons[name].get('category') #a1.6001
1888 result = split(cat,"-",2) #a 1.6001 1820 result = split(cat,"-",2) #a 1.6001
1889 if len(result) < 2: #a 1.6021 this if & else 1821 if len(result) < 2: #a 1.6021 this if & else
1890 print "warning: 1.6002 unable to interpret weapon category" 1822 print "warning: 1.6002 unable to interpret weapon category"
1891 print "format 'type weapon-[Range|Melee]', probably missing" 1823 print "format 'type weapon-[Range|Melee]', probably missing"
1892 print "the hyphen. Assuming Melee" 1824 print "the hyphen. Assuming Melee"
1894 tres="Melee" 1826 tres="Melee"
1895 else: 1827 else:
1896 tres=result[1] 1828 tres=result[1]
1897 #print "print FootNotes,tres",footNotes,tres 1829 #print "print FootNotes,tres",footNotes,tres
1898 if tres == 'Melee': #a 1.6001 #m 1.6022 use of tres here and... 1830 if tres == 'Melee': #a 1.6001 #m 1.6022 use of tres here and...
1899 #if self.weapons[name].getAttribute('range') == '0':#d 1.6001 1831 #if self.weapons[name].get('range') == '0':#d 1.6001
1900 rangeOrMelee = 'm' #a 1.5008 code demote for next comment block 1832 rangeOrMelee = 'm' #a 1.5008 code demote for next comment block
1901 elif tres == 'Ranged': #m 1.6001 (was just else) #m 1.6022 here 1833 elif tres == 'Ranged': #m 1.6001 (was just else) #m 1.6022 here
1902 rangeOrMelee = 'r' #a 1.5008 1834 rangeOrMelee = 'r' #a 1.5008
1903 else:#a 1.6001 add this whole else clause. 1835 else:#a 1.6001 add this whole else clause.
1904 print "warning: 1.6001 unable to interpret weapon category" 1836 print "warning: 1.6001 unable to interpret weapon category"
1905 print "treating weapon as Melee, please correct xml" 1837 print "treating weapon as Melee, please correct xml"
1906 print "weapon name:",name 1838 print "weapon name:",name
1907 rangeOrMelee ='m' 1839 rangeOrMelee ='m'
1908 mod = mod + self.get_mod(rangeOrMelee) #a 1.5008 1840 mod = mod + self.get_mod(rangeOrMelee) #a 1.5008
1909 chat = self.chat 1841 chat = self.chat
1910 dmg = self.weapons[name].getAttribute('damage') 1842 dmg = self.weapons[name].get('damage')
1911 1843
1912 #a 1.6003 start code fix instance a 1844 #a 1.6003 start code fix instance a
1913 result = split(dmg,"/",2) 1845 result = split(dmg,"/",2)
1914 dmg = result[0] 1846 dmg = result[0]
1915 #print "1.6003 check:dmg",dmg,";result",result 1847 #print "1.6003 check:dmg",dmg,";result",result
2035 html_str += "<td>"+str(ranged[0]+ranged[1]+ranged[2])+"</td>" 1967 html_str += "<td>"+str(ranged[0]+ranged[1]+ranged[2])+"</td>"
2036 html_str += "<td>"+str(ranged[0])+"</td>" 1968 html_str += "<td>"+str(ranged[0])+"</td>"
2037 html_str += "<td>"+str(ranged[1])+"</td>" 1969 html_str += "<td>"+str(ranged[1])+"</td>"
2038 html_str += "<td>"+str(ranged[2])+"</td></tr></table>" 1970 html_str += "<td>"+str(ranged[2])+"</td></tr></table>"
2039 1971
2040 n_list = self.master_dom.getElementsByTagName('weapon') 1972 n_list = self.xml.findall('weapon')
2041 for n in n_list: 1973 for n in n_list:
2042 mod = n.getAttribute('mod') 1974 mod = n.get('mod')
2043 if mod >= 0: 1975 if mod >= 0:
2044 mod1 = "+" 1976 mod1 = "+"
2045 else: 1977 else:
2046 mod1 = "" 1978 mod1 = ""
2047 ran = n.getAttribute('range') 1979 ran = n.get('range')
2048 total = str(int(mod) + self.get_mod(ran)) 1980 total = str(int(mod) + self.get_mod(ran))
2049 html_str += """<P><table width=100% border=1 ><tr BGCOLOR=#E9E9E9 > 1981 html_str += """<P><table width=100% border=1 ><tr BGCOLOR=#E9E9E9 >
2050 <th colspan=2>Weapon</th> 1982 <th colspan=2>Weapon</th>
2051 <th>Attack</th><th >Damage</th><th>Critical</th></tr>""" 1983 <th>Attack</th><th >Damage</th><th>Critical</th></tr>"""
2052 html_str += "<tr ALIGN='center' ><td colspan=2>" 1984 html_str += "<tr ALIGN='center' ><td colspan=2>"
2053 html_str += n.getAttribute('name')+"</td><td>"+total+"</td>" 1985 html_str += n.get('name')+"</td><td>"+total+"</td>"
2054 html_str += "<td>"+n.getAttribute('damage')+"</td><td>" 1986 html_str += "<td>"+n.get('damage')+"</td><td>"
2055 html_str += n.getAttribute('critical')+"</td></tr>" 1987 html_str += n.get('critical')+"</td></tr>"
2056 html_str += """<tr BGCOLOR=#E9E9E9 ><th>Range</th><th>Weight</th> 1988 html_str += """<tr BGCOLOR=#E9E9E9 ><th>Range</th><th>Weight</th>
2057 <th>Type</th><th>Size</th><th>Misc Mod</th></tr>""" 1989 <th>Type</th><th>Size</th><th>Misc Mod</th></tr>"""
2058 html_str += "<tr ALIGN='center'><td>"+ran+"</td><td>" 1990 html_str += "<tr ALIGN='center'><td>"+ran+"</td><td>"
2059 html_str += n.getAttribute('weight')+"</td>" 1991 html_str += n.get('weight')+"</td>"
2060 html_str += "<td>"+n.getAttribute('type')+"</td><td>" 1992 html_str += "<td>"+n.get('type')+"</td><td>"
2061 html_str += n.getAttribute('size')+"</td>" 1993 html_str += n.get('size')+"</td>"
2062 html_str += '<td>%s%s</td></tr>' % (mod1, mod) 1994 html_str += '<td>%s%s</td></tr>' % (mod1, mod)
2063 #a 1.5012 add next two lines to pretty print footnotes. 1995 #a 1.5012 add next two lines to pretty print footnotes.
2064 html_str += """<tr><th BGCOLOR=#E9E9E9 colspan=2>Footnotes:</th>""" 1996 html_str += """<tr><th BGCOLOR=#E9E9E9 colspan=2>Footnotes:</th>"""
2065 html_str += "<th colspan=3>"+safeGetAttr(n,'fn','')+"</th></tr>" 1997 html_str += "<th colspan=3>"+safeGetAttr(n,'fn','')+"</th></tr>"
2066 html_str += '</table>' 1998 html_str += '</table>'
2067 return html_str 1999 return html_str
2068 2000
2069 class attack_grid(wx.grid.Grid): 2001 class attack_grid(wx.grid.Grid):
2070 """grid for attacks""" 2002 """grid for attacks"""
2071 def __init__(self, parent, handler): 2003 def __init__(self, parent, handler):
2072 pname = handler.master_dom.setAttribute("name", 'Melee') 2004 pname = handler.xml.set("name", 'Melee')
2073 self.hparent = handler #a 1.5002 allow ability to run up tree. 2005 self.hparent = handler #a 1.5002 allow ability to run up tree.
2074 #a 1.5002 we need the functional parent, not the invoking parent. 2006 #a 1.5002 we need the functional parent, not the invoking parent.
2075 2007
2076 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 2008 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
2077 2009
2126 col = evt.GetCol() 2058 col = evt.GetCol()
2127 value = self.GetCellValue(row,col) 2059 value = self.GetCellValue(row,col)
2128 try: 2060 try:
2129 int(value) 2061 int(value)
2130 if col==1: 2062 if col==1:
2131 self.rows[row].setAttribute('base',value) 2063 self.rows[row].set('base',value)
2132 elif col==2: 2064 elif col==2:
2133 self.rows[row].setAttribute('second',value) 2065 self.rows[row].set('second',value)
2134 elif col==3: 2066 elif col==3:
2135 self.rows[row].setAttribute('third',value) 2067 self.rows[row].set('third',value)
2136 elif col==4: 2068 elif col==4:
2137 self.rows[row].setAttribute('forth',value) 2069 self.rows[row].set('forth',value)
2138 elif col==5: 2070 elif col==5:
2139 self.rows[row].setAttribute('fifth',value) 2071 self.rows[row].set('fifth',value)
2140 elif col==6: 2072 elif col==6:
2141 self.rows[row].setAttribute('sixth',value) 2073 self.rows[row].set('sixth',value)
2142 elif col==8: 2074 elif col==8:
2143 self.rows[row].setAttribute('misc',value) 2075 self.rows[row].set('misc',value)
2144 #print "row:",row,"value",value,self.rows[row] 2076 #print "row:",row,"value",value,self.rows[row]
2145 self.parent.refresh_data() 2077 self.parent.refresh_data()
2146 except: 2078 except:
2147 self.SetCellValue(row,col,"0") 2079 self.SetCellValue(row,col,"0")
2148 2080
2179 class weapon_panel(wx.Panel): 2111 class weapon_panel(wx.Panel):
2180 def __init__(self, parent, handler): 2112 def __init__(self, parent, handler):
2181 self.hparent = handler #a 1.5012 2113 self.hparent = handler #a 1.5012
2182 self.root = getRoot(self) 2114 self.root = getRoot(self)
2183 2115
2184 pname = handler.master_dom.setAttribute("name", 'Weapons') 2116 pname = handler.xml.set("name", 'Weapons')
2185 2117
2186 wx.Panel.__init__(self, parent, -1) 2118 wx.Panel.__init__(self, parent, -1)
2187 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 2119 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
2188 sizer = wx.BoxSizer(wx.VERTICAL) 2120 sizer = wx.BoxSizer(wx.VERTICAL)
2189 sizer.Add(self.grid, 1, wx.EXPAND) 2121 sizer.Add(self.grid, 1, wx.EXPAND)
2205 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10) 2137 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10)
2206 self.Bind(wx.EVT_BUTTON, self.on_add, id=20) 2138 self.Bind(wx.EVT_BUTTON, self.on_add, id=20)
2207 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change) 2139 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
2208 self.grid.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK, self.on_gridRclick)#a 1.5012 2140 self.grid.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK, self.on_gridRclick)#a 1.5012
2209 2141
2210 n_list = handler.master_dom.getElementsByTagName('weapon') 2142 n_list = handler.xml.findall('weapon')
2211 self.n_list = n_list 2143 self.n_list = n_list
2212 self.master_dom = handler.master_dom 2144 self.xml = handler.xml
2213 self.handler = handler 2145 self.handler = handler
2214 #trash=input("weapon panel init colnames") 2146 #trash=input("weapon panel init colnames")
2215 self.colAttr = ['name','damage','mod','critical','type','weight', 2147 self.colAttr = ['name','damage','mod','critical','type','weight',
2216 'range','size','Total','fn', 'comment'] #a 1.5012 2148 'range','size','Total','fn', 'comment'] #a 1.5012
2217 col_names = ['Name','Damage','To hit\nmod','Critical','Type','Weight', 2149 col_names = ['Name','Damage','To hit\nmod','Critical','Type','Weight',
2236 col = evt.GetCol() 2168 col = evt.GetCol()
2237 value = self.grid.GetCellValue(row,col) 2169 value = self.grid.GetCellValue(row,col)
2238 #print "wp, on rclick,grid row,col,value",row,col,value 2170 #print "wp, on rclick,grid row,col,value",row,col,value
2239 if col == 9 and value != 'None': 2171 if col == 9 and value != 'None':
2240 n = self.n_list[row] 2172 n = self.n_list[row]
2241 name = n.getAttribute('name') 2173 name = n.get('name')
2242 #print "we want a panel!" 2174 #print "we want a panel!"
2243 handler = self.hparent 2175 handler = self.hparent
2244 #print "handler:",handler 2176 #print "handler:",handler
2245 # A handler is a node, and nodes have a reference to 2177 # A handler is a node, and nodes have a reference to
2246 # the master frame 2178 # the master frame
2248 #print "masterFrame:",masterFrame 2180 #print "masterFrame:",masterFrame
2249 title = name+"'s Special Weapon Characteristics" 2181 title = name+"'s Special Weapon Characteristics"
2250 fnFrame = wx.Frame(masterFrame, -1, title) 2182 fnFrame = wx.Frame(masterFrame, -1, title)
2251 fnFrame.panel = wx.html.HtmlWindow(fnFrame,-1) 2183 fnFrame.panel = wx.html.HtmlWindow(fnFrame,-1)
2252 if not self.temp_dom: 2184 if not self.temp_dom:
2253 tmp = open(dir_struct["dnd3e"]+ 2185 tree = parse(dir_struct["dnd3e"]+"dnd3eweapons.xml")
2254 "dnd3eweapons.xml","r") 2186 xml_dom = tree.getroot()
2255 #tmp = open("c:\clh\codeSamples\sample1.xml","r")
2256 xml_dom = parseXml_with_dlg(self,tmp.read())
2257 xml_dom = xml_dom._get_firstChild()
2258 tmp.close()
2259 self.temp_dom = xml_dom 2187 self.temp_dom = xml_dom
2260 f_list = self.temp_dom.getElementsByTagName('f') # the footnotes 2188 f_list = self.temp_dom.findall('f') # the footnotes
2261 #print "weapon_panel - on_rclick f_list",f_list#a 1.6 2189 #print "weapon_panel - on_rclick f_list",f_list#a 1.6
2262 n = self.n_list[row] 2190 n = self.n_list[row]
2263 name = n.getAttribute('name') 2191 name = n.get('name')
2264 footnotes = n.getAttribute('fn') 2192 footnotes = n.get('fn')
2265 html_str = "<html><body>" 2193 html_str = "<html><body>"
2266 html_str += """<table border='1' width=100% ><tr BGCOLOR=#E9E9E9 > 2194 html_str += """<table border='1' width=100% ><tr BGCOLOR=#E9E9E9 >
2267 <th width='10%'>Note</th><th>Description</th></tr>\n""" 2195 <th width='10%'>Note</th><th>Description</th></tr>\n"""
2268 #print "rclick,name,fn",name,footnotes 2196 #print "rclick,name,fn",name,footnotes
2269 if footnotes == "": 2197 if footnotes == "":
2271 html_str += " <td>This weapon has no footnotes</td></tr>" 2199 html_str += " <td>This weapon has no footnotes</td></tr>"
2272 for i in range(len(footnotes)): 2200 for i in range(len(footnotes)):
2273 aNote=footnotes[i] 2201 aNote=footnotes[i]
2274 found=False 2202 found=False
2275 for f in f_list: 2203 for f in f_list:
2276 if f.getAttribute('mark') == aNote: 2204 if f.get('mark') == aNote:
2277 found=True 2205 found=True
2278 text=f.getAttribute('txt') 2206 text=f.get('txt')
2279 html_str += ("<tr ALIGN='center'><td>"+aNote+"</td>"+ 2207 html_str += ("<tr ALIGN='center'><td>"+aNote+"</td>"+
2280 "<td>"+text+"</td></tr>\n") 2208 "<td>"+text+"</td></tr>\n")
2281 if not found: 2209 if not found:
2282 html_str += ("<tr ALIGN='center'><td>"+aNote+"</td>"+ 2210 html_str += ("<tr ALIGN='center'><td>"+aNote+"</td>"+
2283 "<td>is not a recognized footnote</td></tr>\n") 2211 "<td>is not a recognized footnote</td></tr>\n")
2297 row = evt.GetRow() 2225 row = evt.GetRow()
2298 col = evt.GetCol() 2226 col = evt.GetCol()
2299 value = self.grid.GetCellValue(row,col) 2227 value = self.grid.GetCellValue(row,col)
2300 if col == 2 and not int(value): # special case for mod, demoted 2228 if col == 2 and not int(value): # special case for mod, demoted
2301 value = "0" #a 5.012 demoted 2229 value = "0" #a 5.012 demoted
2302 self.n_list[row].setAttribute('mod',value) # a 5.012 demoted 2230 self.n_list[row].set('mod',value) # a 5.012 demoted
2303 if not (col == 9 and value == "None" and 2231 if not (col == 9 and value == "None" and
2304 self.n_list[row].getAttribute('fn') == "None" 2232 self.n_list[row].get('fn') == "None"
2305 ): #a 5.012 special case for footnotes 2233 ): #a 5.012 special case for footnotes
2306 self.n_list[row].setAttribute(self.colAttr[col],value)#a 5.012 2234 self.n_list[row].set(self.colAttr[col],value)#a 5.012
2307 #print "cell change",row,col,value 2235 #print "cell change",row,col,value
2308 #if col == 0:#d 5.012 use of colAttr removed need for this. 2236 #if col == 0:#d 5.012 use of colAttr removed need for this.
2309 # self.n_list[row].setAttribute('name',value) #d 5.012 2237 # self.n_list[row].set('name',value) #d 5.012
2310 #elif col == 2: #d 5.012 2238 #elif col == 2: #d 5.012
2311 # try:#d 5.012 simplifying... remove this block. 2239 # try:#d 5.012 simplifying... remove this block.
2312 # int(value) 2240 # int(value)
2313 # self.n_list[row].setAttribute('mod',value) 2241 # self.n_list[row].set('mod',value)
2314 # #self.refresh_row(row) #d 5.012 did nothing. 2242 # #self.refresh_row(row) #d 5.012 did nothing.
2315 # except: 2243 # except:
2316 # value = "0" 2244 # value = "0"
2317 # self.n_list[row].setAttribute('mod',value) 2245 # self.n_list[row].set('mod',value)
2318 #else: #d 5.012 demoted self.n set. 2246 #else: #d 5.012 demoted self.n set.
2319 # self.n_list[row].setAttribute(self.grid.GetColLabelValue(col),value) 2247 # self.n_list[row].set(self.grid.GetColLabelValue(col),value)
2320 2248
2321 2249
2322 def refresh_row(self,i): 2250 def refresh_row(self,i):
2323 n = self.n_list[i] 2251 n = self.n_list[i]
2324 fn = n.getAttribute('fn') 2252 fn = n.get('fn')
2325 #print "fn=",fn 2253 #print "fn=",fn
2326 name = n.getAttribute('name') 2254 name = n.get('name')
2327 mod = n.getAttribute('mod') 2255 mod = n.get('mod')
2328 ran = n.getAttribute('range') 2256 ran = n.get('range')
2329 total = str(int(mod) + self.handler.get_mod(ran)) 2257 total = str(int(mod) + self.handler.get_mod(ran))
2330 self.grid.SetCellValue(i,0,name) 2258 self.grid.SetCellValue(i,0,name)
2331 self.grid.SetCellValue(i,1,n.getAttribute('damage')) 2259 self.grid.SetCellValue(i,1,n.get('damage'))
2332 self.grid.SetCellValue(i,2,mod) 2260 self.grid.SetCellValue(i,2,mod)
2333 self.grid.SetCellValue(i,3,n.getAttribute('critical')) 2261 self.grid.SetCellValue(i,3,n.get('critical'))
2334 self.grid.SetCellValue(i,4,n.getAttribute('type')) 2262 self.grid.SetCellValue(i,4,n.get('type'))
2335 self.grid.SetCellValue(i,5,n.getAttribute('weight')) 2263 self.grid.SetCellValue(i,5,n.get('weight'))
2336 self.grid.SetCellValue(i,6,ran) 2264 self.grid.SetCellValue(i,6,ran)
2337 self.grid.SetCellValue(i,7,n.getAttribute('size') ) 2265 self.grid.SetCellValue(i,7,n.get('size') )
2338 self.grid.SetCellValue(i,8,total) 2266 self.grid.SetCellValue(i,8,total)
2339 self.grid.SetCellValue(i,9,safeGetAttr(n,'fn','None')) #a 1.5012 2267 self.grid.SetCellValue(i,9,safeGetAttr(n,'fn','None')) #a 1.5012
2340 self.grid.SetCellValue(i,10,safeGetAttr(n,'comment','')) #a 1.5012 2268 self.grid.SetCellValue(i,10,safeGetAttr(n,'comment','')) #a 1.5012
2341 #fn=safeGetAttr(n,'fn','None') #a (debug) 1.5012 2269 #fn=safeGetAttr(n,'fn','None') #a (debug) 1.5012
2342 #print "fn ",fn,"<" #a (debug) 1.5012 2270 #print "fn ",fn,"<" #a (debug) 1.5012
2348 rows = self.grid.GetNumberRows() 2276 rows = self.grid.GetNumberRows()
2349 #for i in range(rows): #d 1.6011 do it backwards, 2277 #for i in range(rows): #d 1.6011 do it backwards,
2350 for i in range(rows-1,-1,-1): #a 1.6011 or you lose context 2278 for i in range(rows-1,-1,-1): #a 1.6011 or you lose context
2351 if self.grid.IsInSelection(i,0): 2279 if self.grid.IsInSelection(i,0):
2352 self.grid.DeleteRows(i) 2280 self.grid.DeleteRows(i)
2353 self.master_dom.removeChild(self.n_list[i]) 2281 self.xml.remove(self.n_list[i])
2354 self.n_list = self.master_dom.getElementsByTagName('weapon') 2282 self.n_list = self.xml.findall('weapon')
2355 self.handler.refresh_weapons() 2283 self.handler.refresh_weapons()
2356 2284
2357 def on_add(self,evt): 2285 def on_add(self,evt):
2358 if not self.temp_dom: 2286 if not self.temp_dom:
2359 tmp = open(dir_struct["dnd3e"]+"dnd3eweapons.xml","r") 2287 tree = parse(dir_struct["dnd3e"]+"dnd3eweapons.xml")
2360 #tmp = open("c:\clh\codeSamples\sample1.xml","r") #a (debug) 1.5012 2288 xml_dom = tree.getroot()
2361 xml_dom = parseXml_with_dlg(self,tmp.read())
2362 xml_dom = xml_dom._get_firstChild()
2363 tmp.close()
2364 self.temp_dom = xml_dom 2289 self.temp_dom = xml_dom
2365 f_list = self.temp_dom.getElementsByTagName('weapon') 2290 f_list = self.temp_dom.findall('weapon')
2366 opts = [] 2291 opts = []
2367 #print "weapon_panel - on_add f_list",f_list#a 1.6 2292 #print "weapon_panel - on_add f_list",f_list#a 1.6
2368 for f in f_list: 2293 for f in f_list:
2369 opts.append(f.getAttribute('name')) 2294 opts.append(f.get('name'))
2370 dlg = wx.SingleChoiceDialog(self,'Choose Weapon','Weapon List',opts) 2295 dlg = wx.SingleChoiceDialog(self,'Choose Weapon','Weapon List',opts)
2371 if dlg.ShowModal() == wx.ID_OK: 2296 if dlg.ShowModal() == wx.ID_OK:
2372 i = dlg.GetSelection() 2297 i = dlg.GetSelection()
2373 #print f_list[i] # DOM Element: weapon. 2298 #print f_list[i] # DOM Element: weapon.
2374 new_node = self.master_dom.appendChild(f_list[i].cloneNode(False)) 2299 new_node = self.xml.append(f_list[i])
2375 #print self.grid.AppendRows # a bound method of wxGrid 2300 #print self.grid.AppendRows # a bound method of wxGrid
2376 self.grid.AppendRows(1) 2301 self.grid.AppendRows(1)
2377 self.n_list = self.master_dom.getElementsByTagName('weapon') 2302 self.n_list = self.xml.findall('weapon')
2378 #print "self.n_list",self.n_list # list of DOM weapons 2303 #print "self.n_list",self.n_list # list of DOM weapons
2379 self.refresh_row(self.grid.GetNumberRows()-1) 2304 self.refresh_row(self.grid.GetNumberRows()-1)
2380 self.handler.refresh_weapons() 2305 self.handler.refresh_weapons()
2381 dlg.Destroy() 2306 dlg.Destroy()
2382 2307
2398 self.refresh_row(i) 2323 self.refresh_row(i)
2399 2324
2400 2325
2401 class attack_panel(wx.Panel): 2326 class attack_panel(wx.Panel):
2402 def __init__(self, parent, handler): 2327 def __init__(self, parent, handler):
2403 pname = handler.master_dom.setAttribute("name", 'Melee') 2328 pname = handler.xml.set("name", 'Melee')
2404 self.parent = parent #a 1.9001 2329 self.parent = parent #a 1.9001
2405 2330
2406 wx.Panel.__init__(self, parent, -1) 2331 wx.Panel.__init__(self, parent, -1)
2407 2332
2408 self.a_grid = attack_grid(self, handler) 2333 self.a_grid = attack_grid(self, handler)
2454 else: 2379 else:
2455 ac_total += max_dex 2380 ac_total += max_dex
2456 return ac_total 2381 return ac_total
2457 2382
2458 def get_max_dex(self): 2383 def get_max_dex(self):
2459 armor_list = self.master_dom.getElementsByTagName('armor') 2384 armor_list = self.xml.findall('armor')
2460 dex = 10 2385 dex = 10
2461 for a in armor_list: 2386 for a in armor_list:
2462 temp = int(a.getAttribute("maxdex")) 2387 temp = int(a.get("maxdex"))
2463 if temp < dex: 2388 if temp < dex:
2464 dex = temp 2389 dex = temp
2465 return dex 2390 return dex
2466 2391
2467 def get_total(self,attr): 2392 def get_total(self,attr):
2468 armor_list = self.master_dom.getElementsByTagName('armor') 2393 armor_list = self.xml.findall('armor')
2469 total = 0 2394 total = 0
2470 for a in armor_list: 2395 for a in armor_list:
2471 total += int(a.getAttribute(attr)) 2396 total += int(a.get(attr))
2472 return total 2397 return total
2473 2398
2474 def get_design_panel(self,parent): 2399 def get_design_panel(self,parent):
2475 wnd = outline_panel(parent,self,ac_panel,"Armor") 2400 wnd = outline_panel(parent,self,ac_panel,"Armor")
2476 wnd.title = "Armor" 2401 wnd.title = "Armor"
2491 html_str += "<td>"+str(self.get_armor_class())+"</td>" 2416 html_str += "<td>"+str(self.get_armor_class())+"</td>"
2492 html_str += "<td>"+str(self.get_check_pen())+"</td>" 2417 html_str += "<td>"+str(self.get_check_pen())+"</td>"
2493 html_str += "<td>"+str(self.get_spell_failure())+"</td>" 2418 html_str += "<td>"+str(self.get_spell_failure())+"</td>"
2494 html_str += "<td>"+str(self.get_max_dex())+"</td>" 2419 html_str += "<td>"+str(self.get_max_dex())+"</td>"
2495 html_str += "<td>"+str(self.get_total_weight())+"</td></tr></table>" 2420 html_str += "<td>"+str(self.get_total_weight())+"</td></tr></table>"
2496 n_list = self.master_dom._get_childNodes() 2421 n_list = self.xml.getchildren()
2497 for n in n_list: 2422 for n in n_list:
2498 html_str += """<P><table width=100% border=1 ><tr BGCOLOR=#E9E9E9 > 2423 html_str += """<P><table width=100% border=1 ><tr BGCOLOR=#E9E9E9 >
2499 <th colspan=3>Armor</th><th>Type</th><th >Bonus</th></tr>""" 2424 <th colspan=3>Armor</th><th>Type</th><th >Bonus</th></tr>"""
2500 html_str += "<tr ALIGN='center' >" 2425 html_str += "<tr ALIGN='center' >"
2501 html_str += "<td colspan=3>"+n.getAttribute('name')+"</td>" 2426 html_str += "<td colspan=3>"+n.get('name')+"</td>"
2502 html_str += "<td>"+n.getAttribute('type')+"</td>" 2427 html_str += "<td>"+n.get('type')+"</td>"
2503 html_str += "<td>"+n.getAttribute('bonus')+"</td></tr>" 2428 html_str += "<td>"+n.get('bonus')+"</td></tr>"
2504 html_str += """<tr BGCOLOR=#E9E9E9 >""" 2429 html_str += """<tr BGCOLOR=#E9E9E9 >"""
2505 html_str += "<th>Check Penalty</th><th>Spell Failure</th>" 2430 html_str += "<th>Check Penalty</th><th>Spell Failure</th>"
2506 html_str += "<th>Max Dex</th><th>Speed</th><th>Weight</th></tr>" 2431 html_str += "<th>Max Dex</th><th>Speed</th><th>Weight</th></tr>"
2507 html_str += "<tr ALIGN='center'>" 2432 html_str += "<tr ALIGN='center'>"
2508 html_str += "<td>"+n.getAttribute('checkpenalty')+"</td>" 2433 html_str += "<td>"+n.get('checkpenalty')+"</td>"
2509 html_str += "<td>"+n.getAttribute('spellfailure')+"</td>" 2434 html_str += "<td>"+n.get('spellfailure')+"</td>"
2510 html_str += "<td>"+n.getAttribute('maxdex')+"</td>" 2435 html_str += "<td>"+n.get('maxdex')+"</td>"
2511 html_str += "<td>"+n.getAttribute('speed')+"</td>" 2436 html_str += "<td>"+n.get('speed')+"</td>"
2512 html_str += "<td>"+n.getAttribute('weight')+"</td></tr></table>" 2437 html_str += "<td>"+n.get('weight')+"</td></tr></table>"
2513 return html_str 2438 return html_str
2514 2439
2515 2440
2516 class ac_panel(wx.Panel): 2441 class ac_panel(wx.Panel):
2517 def __init__(self, parent, handler): 2442 def __init__(self, parent, handler):
2518 pname = handler.master_dom.setAttribute("name", 'Armor') 2443 pname = handler.xml.set("name", 'Armor')
2519 self.hparent = handler #a 1.5002 allow ability to run up tree. 2444 self.hparent = handler #a 1.5002 allow ability to run up tree.
2520 #a 1.5002 we need the functional parent, not the invoking parent. 2445 #a 1.5002 we need the functional parent, not the invoking parent.
2521 2446
2522 wx.Panel.__init__(self, parent, -1) 2447 wx.Panel.__init__(self, parent, -1)
2523 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 2448 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
2538 2463
2539 #self.Bind(wx.EVT_SIZE, self.on_size) 2464 #self.Bind(wx.EVT_SIZE, self.on_size)
2540 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10) 2465 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10)
2541 self.Bind(wx.EVT_BUTTON, self.on_add, id=20) 2466 self.Bind(wx.EVT_BUTTON, self.on_add, id=20)
2542 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change) 2467 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
2543 self.master_dom = handler.master_dom 2468 self.xml = handler.xml
2544 n_list = handler.master_dom._get_childNodes() 2469 n_list = handler.xml.getchildren()
2545 self.n_list = n_list 2470 self.n_list = n_list
2546 col_names = ['Armor','bonus','maxdex','cp','sf','weight','speed','type'] 2471 col_names = ['Armor','bonus','maxdex','cp','sf','weight','speed','type']
2547 self.grid.CreateGrid(len(n_list),len(col_names),1) 2472 self.grid.CreateGrid(len(n_list),len(col_names),1)
2548 self.grid.SetRowLabelSize(0) 2473 self.grid.SetRowLabelSize(0)
2549 for i in range(len(col_names)): 2474 for i in range(len(col_names)):
2560 col = evt.GetCol() 2485 col = evt.GetCol()
2561 value = self.grid.GetCellValue(row,col) 2486 value = self.grid.GetCellValue(row,col)
2562 if col >= 1 and col <= 5: 2487 if col >= 1 and col <= 5:
2563 try: 2488 try:
2564 int(value) 2489 int(value)
2565 self.n_list[row].setAttribute(self.atts[col],value) 2490 self.n_list[row].set(self.atts[col],value)
2566 except: 2491 except:
2567 self.grid.SetCellValue(row,col,"0") 2492 self.grid.SetCellValue(row,col,"0")
2568 else: 2493 else:
2569 self.n_list[row].setAttribute(self.atts[col],value) 2494 self.n_list[row].set(self.atts[col],value)
2570 2495
2571 def refresh_row(self,i): 2496 def refresh_row(self,i):
2572 n = self.n_list[i] 2497 n = self.n_list[i]
2573 2498
2574 for y in range(len(self.atts)): 2499 for y in range(len(self.atts)):
2575 self.grid.SetCellValue(i,y,n.getAttribute(self.atts[y])) 2500 self.grid.SetCellValue(i,y,n.get(self.atts[y]))
2576 2501
2577 def on_remove(self,evt): 2502 def on_remove(self,evt):
2578 rows = self.grid.GetNumberRows() 2503 rows = self.grid.GetNumberRows()
2579 for i in range(rows): 2504 for i in range(rows):
2580 if self.grid.IsInSelection(i,0): 2505 if self.grid.IsInSelection(i,0):
2581 self.grid.DeleteRows(i) 2506 self.grid.DeleteRows(i)
2582 self.master_dom.removeChild(self.n_list[i]) 2507 self.xml.remove(self.n_list[i])
2583 2508
2584 def on_add(self,evt): 2509 def on_add(self,evt):
2585 if not self.temp_dom: 2510 if not self.temp_dom:
2586 tmp = open(dir_struct["dnd3e"]+"dnd3earmor.xml","r") 2511 tree = parse(dir_struct["dnd3e"]+"dnd3earmor.xml")
2587 xml_dom = parseXml_with_dlg(self,tmp.read()) 2512 xml_dom = tree.getroot()
2588 xml_dom = xml_dom._get_firstChild()
2589 tmp.close()
2590 self.temp_dom = xml_dom 2513 self.temp_dom = xml_dom
2591 f_list = self.temp_dom.getElementsByTagName('armor') 2514 f_list = self.temp_dom.findall('armor')
2592 opts = [] 2515 opts = []
2593 for f in f_list: 2516 for f in f_list:
2594 opts.append(f.getAttribute('name')) 2517 opts.append(f.get('name'))
2595 dlg = wx.SingleChoiceDialog(self,'Choose Armor:','Armor List',opts) 2518 dlg = wx.SingleChoiceDialog(self,'Choose Armor:','Armor List',opts)
2596 if dlg.ShowModal() == wx.ID_OK: 2519 if dlg.ShowModal() == wx.ID_OK:
2597 i = dlg.GetSelection() 2520 i = dlg.GetSelection()
2598 new_node = self.master_dom.appendChild(f_list[i].cloneNode(False)) 2521 new_node = self.xml.append(f_list[i])
2599 self.grid.AppendRows(1) 2522 self.grid.AppendRows(1)
2600 self.refresh_row(self.grid.GetNumberRows()-1) 2523 self.refresh_row(self.grid.GetNumberRows()-1)
2601 dlg.Destroy() 2524 dlg.Destroy()
2602 2525
2603 def on_size(self,event): 2526 def on_size(self,event):
2629 self.new_child_handler('powers','Powers',dnd3epowers,'book') 2552 self.new_child_handler('powers','Powers',dnd3epowers,'book')
2630 self.new_child_handler('pp','Power Points',dnd3epp,'gear') 2553 self.new_child_handler('pp','Power Points',dnd3epp,'gear')
2631 self.myeditor = None 2554 self.myeditor = None
2632 2555
2633 def new_child_handler(self,tag,text,handler_class,icon='gear'): 2556 def new_child_handler(self,tag,text,handler_class,icon='gear'):
2634 node_list = self.master_dom.getElementsByTagName(tag) 2557 node_list = self.xml.findall(tag)
2635 tree = self.tree 2558 tree = self.tree
2636 i = self.tree.icons[icon] 2559 i = self.tree.icons[icon]
2637 new_tree_node = tree.AppendItem(self.mytree_node,text,i,i) 2560 new_tree_node = tree.AppendItem(self.mytree_node,text,i,i)
2638 handler = handler_class(node_list[0],new_tree_node,self) 2561 handler = handler_class(node_list[0],new_tree_node,self)
2639 tree.SetPyData(new_tree_node,handler) 2562 tree.SetPyData(new_tree_node,handler)
2675 return 2598 return
2676 2599
2677 def on_html(self,evt): 2600 def on_html(self,evt):
2678 html_str = self.tohtml() 2601 html_str = self.tohtml()
2679 wnd = http_html_window(self.frame.note,-1) 2602 wnd = http_html_window(self.frame.note,-1)
2680 wnd.title = self.master_dom.getAttribute('name') 2603 wnd.title = self.xml.get('name')
2681 self.frame.add_panel(wnd) 2604 self.frame.add_panel(wnd)
2682 wnd.SetPage(html_str) 2605 wnd.SetPage(html_str)
2683 2606
2684 def get_design_panel(self,parent): 2607 def get_design_panel(self,parent):
2685 pass 2608 pass
2700 self.hparent = parent #a 1.5002 allow ability to run up tree. 2623 self.hparent = parent #a 1.5002 allow ability to run up tree.
2701 self.root = getRoot(self) #a 1.5002 2624 self.root = getRoot(self) #a 1.5002
2702 self.root.spells = self #a 1.6009 2625 self.root.spells = self #a 1.6009
2703 2626
2704 2627
2705 node_list = self.master_dom.getElementsByTagName( 'spell' ) 2628 node_list = self.xml.findall( 'spell' )
2706 self.spells = {} 2629 self.spells = {}
2707 tree = self.tree 2630 tree = self.tree
2708 icons = self.tree.icons 2631 icons = self.tree.icons
2709 for n in node_list: 2632 for n in node_list:
2710 name = n.getAttribute('name') 2633 name = n.get('name')
2711 self.spells[ name ] = n 2634 self.spells[ name ] = n
2712 new_tree_node = tree.AppendItem( self.mytree_node, name, icons['gear'], icons['gear'] ) 2635 new_tree_node = tree.AppendItem( self.mytree_node, name, icons['gear'], icons['gear'] )
2713 tree.SetPyData( new_tree_node, self ) 2636 tree.SetPyData( new_tree_node, self )
2714 2637
2715 def on_rclick( self, evt ): 2638 def on_rclick( self, evt ):
2716 item = self.tree.GetSelection() 2639 item = self.tree.GetSelection()
2717 name = self.tree.GetItemText( item ) 2640 name = self.tree.GetItemText( item )
2718 if item == self.mytree_node: 2641 if item == self.mytree_node:
2719 dnd3e_char_child.on_ldclick( self, evt ) 2642 dnd3e_char_child.on_ldclick( self, evt )
2720 else: 2643 else:
2721 level = self.spells[ name ].getAttribute( 'level' ) 2644 level = self.spells[ name ].get( 'level' )
2722 descr = self.spells[ name ].getAttribute( 'desc' ) 2645 descr = self.spells[ name ].get( 'desc' )
2723 use = self.spells[ name ].getAttribute( 'used' ) 2646 use = self.spells[ name ].get( 'used' )
2724 memrz = self.spells[ name ].getAttribute( 'memrz' ) 2647 memrz = self.spells[ name ].get( 'memrz' )
2725 use += '+1' 2648 use += '+1'
2726 charNameL=self.root.general.charName #a 1.5002 2649 charNameL=self.root.general.charName #a 1.5002
2727 left = eval( '%s - ( %s )' % ( memrz, use ) ) 2650 left = eval( '%s - ( %s )' % ( memrz, use ) )
2728 if left < 0: 2651 if left < 0:
2729 txt = '%s Tried to cast %s but has used all of them for today,' 2652 txt = '%s Tried to cast %s but has used all of them for today,'
2738 if left != 1: 2661 if left != 1:
2739 s = 's' 2662 s = 's'
2740 #txt = '%s can cast %s %d more time%s' % ( dnd_globals["gen"]["Name"], name, left, s )#d 1.5002 2663 #txt = '%s can cast %s %d more time%s' % ( dnd_globals["gen"]["Name"], name, left, s )#d 1.5002
2741 txt = '%s can cast %s %d more time%s' % ( charNameL, name, left, s ) #a 1.5002 2664 txt = '%s can cast %s %d more time%s' % ( charNameL, name, left, s ) #a 1.5002
2742 self.chat.ParsePost( txt, False, False ) 2665 self.chat.ParsePost( txt, False, False )
2743 self.spells[ name ].setAttribute( 'used', `eval( use )` ) 2666 self.spells[ name ].set( 'used', `eval( use )` )
2744 2667
2745 def refresh_spells(self): 2668 def refresh_spells(self):
2746 self.spells = {} 2669 self.spells = {}
2747 tree = self.tree 2670 tree = self.tree
2748 icons = self.tree.icons 2671 icons = self.tree.icons
2749 tree.CollapseAndReset(self.mytree_node) 2672 tree.CollapseAndReset(self.mytree_node)
2750 node_list = self.master_dom.getElementsByTagName('spell') 2673 node_list = self.xml.findall('spell')
2751 for n in node_list: 2674 for n in node_list:
2752 name = n.getAttribute('name') 2675 name = n.get('name')
2753 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear']) 2676 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear'])
2754 tree.SetPyData(new_tree_node,self) 2677 tree.SetPyData(new_tree_node,self)
2755 self.spells[name]=n 2678 self.spells[name]=n
2756 2679
2757 def get_design_panel(self,parent): 2680 def get_design_panel(self,parent):
2759 wnd.title = "Spells" 2682 wnd.title = "Spells"
2760 return wnd 2683 return wnd
2761 2684
2762 def tohtml(self): 2685 def tohtml(self):
2763 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>Arcane Spells</th></tr><tr><td><br>" 2686 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>Arcane Spells</th></tr><tr><td><br>"
2764 n_list = self.master_dom._get_childNodes() 2687 n_list = self.xml.getchildren()
2765 for n in n_list: 2688 for n in n_list:
2766 html_str += "(" + n.getAttribute('level') + ") " + n.getAttribute('name')+ ", " 2689 html_str += "(" + n.get('level') + ") " + n.get('name')+ ", "
2767 html_str = html_str[:len(html_str)-2] + "</td></tr></table>" 2690 html_str = html_str[:len(html_str)-2] + "</td></tr></table>"
2768 return html_str 2691 return html_str
2769 2692
2770 def get_char_lvl( self, attr ): 2693 def get_char_lvl( self, attr ):
2771 return self.char_hander.get_char_lvl(attr) 2694 return self.char_hander.get_char_lvl(attr)
2772 2695
2773 class spells_panel(wx.Panel): 2696 class spells_panel(wx.Panel):
2774 def __init__(self, parent, handler): 2697 def __init__(self, parent, handler):
2775 pname = handler.master_dom.setAttribute("name", 'Arcane Spells') 2698 pname = handler.xml.set("name", 'Arcane Spells')
2776 self.hparent = handler #a 1.5002 allow ability to run up tree. 2699 self.hparent = handler #a 1.5002 allow ability to run up tree.
2777 #a 1.5002 in this case, we need the functional parent, not the invoking parent. 2700 #a 1.5002 in this case, we need the functional parent, not the invoking parent.
2778 2701
2779 wx.Panel.__init__(self, parent, -1) 2702 wx.Panel.__init__(self, parent, -1)
2780 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 2703 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
2798 #self.Bind(wx.EVT_SIZE, self.on_size) 2721 #self.Bind(wx.EVT_SIZE, self.on_size)
2799 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10) 2722 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10)
2800 self.Bind(wx.EVT_BUTTON, self.on_add, id=20) 2723 self.Bind(wx.EVT_BUTTON, self.on_add, id=20)
2801 self.Bind(wx.EVT_BUTTON, self.on_refresh_spells, id=30) 2724 self.Bind(wx.EVT_BUTTON, self.on_refresh_spells, id=30)
2802 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change) 2725 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
2803 n_list = handler.master_dom._get_childNodes() 2726 n_list = handler.xml.getchildren()
2804 self.n_list = n_list 2727 self.n_list = n_list
2805 self.master_dom = handler.master_dom 2728 self.xml = handler.xml
2806 self.grid.CreateGrid(len(n_list),4,1) 2729 self.grid.CreateGrid(len(n_list),4,1)
2807 self.grid.SetRowLabelSize(0) 2730 self.grid.SetRowLabelSize(0)
2808 self.grid.SetColLabelValue(0,"No.") 2731 self.grid.SetColLabelValue(0,"No.")
2809 self.grid.SetColLabelValue(1,"Lvl") 2732 self.grid.SetColLabelValue(1,"Lvl")
2810 self.grid.SetColLabelValue(2,"Spell") 2733 self.grid.SetColLabelValue(2,"Spell")
2816 def on_cell_change(self,evt): 2739 def on_cell_change(self,evt):
2817 row = evt.GetRow() 2740 row = evt.GetRow()
2818 col = evt.GetCol() 2741 col = evt.GetCol()
2819 value = self.grid.GetCellValue(row,col) 2742 value = self.grid.GetCellValue(row,col)
2820 if col == 0: 2743 if col == 0:
2821 self.n_list[row].setAttribute('memrz',value) 2744 self.n_list[row].set('memrz',value)
2822 2745
2823 2746
2824 def refresh_row(self,i): 2747 def refresh_row(self,i):
2825 spell = self.n_list[i] 2748 spell = self.n_list[i]
2826 2749
2827 memrz = spell.getAttribute('memrz') 2750 memrz = spell.get('memrz')
2828 name = spell.getAttribute('name') 2751 name = spell.get('name')
2829 type = spell.getAttribute('desc') 2752 type = spell.get('desc')
2830 level = spell.getAttribute('level') 2753 level = spell.get('level')
2831 self.grid.SetCellValue(i,0,memrz) 2754 self.grid.SetCellValue(i,0,memrz)
2832 self.grid.SetCellValue(i,2,name) 2755 self.grid.SetCellValue(i,2,name)
2833 self.grid.SetReadOnly(i,2) 2756 self.grid.SetReadOnly(i,2)
2834 self.grid.SetCellValue(i,3,type) 2757 self.grid.SetCellValue(i,3,type)
2835 self.grid.SetReadOnly(i,3) 2758 self.grid.SetReadOnly(i,3)
2839 def on_remove(self,evt): 2762 def on_remove(self,evt):
2840 rows = self.grid.GetNumberRows() 2763 rows = self.grid.GetNumberRows()
2841 for i in range(rows): 2764 for i in range(rows):
2842 if self.grid.IsInSelection(i,0): 2765 if self.grid.IsInSelection(i,0):
2843 self.grid.DeleteRows(i) 2766 self.grid.DeleteRows(i)
2844 self.master_dom.removeChild(self.n_list[i]) 2767 self.xml.remove(self.n_list[i])
2845 2768
2846 def on_add(self,evt): 2769 def on_add(self,evt):
2847 2770 debug()
2848 if not self.temp_dom: 2771 if not self.temp_dom:
2849 tmp = open(dir_struct["dnd3e"]+"dnd3espells.xml","r") 2772 tree = parse(dir_struct["dnd3e"]+"dnd3espells.xml")
2850 xml_dom = parseXml_with_dlg(self,tmp.read()) 2773 xml_dom = tree.getroot()
2851 xml_dom = xml_dom._get_firstChild()
2852 tmp.close()
2853 self.temp_dom = xml_dom 2774 self.temp_dom = xml_dom
2854 f_list = self.temp_dom.getElementsByTagName('spell') 2775 debug(self.temp_dom)
2776 f_list = self.temp_dom.findall('spell')
2855 opts = [] 2777 opts = []
2856 #lvl = int(dnd3e_char_child.get_char_lvl('level')) 2778 #lvl = int(dnd3e_char_child.get_char_lvl('level'))
2857 #castlvl = eval('%s/2' % (lvl)) 2779 #castlvl = eval('%s/2' % (lvl))
2858 for f in f_list: 2780 for f in f_list:
2859 spelllvl = f.getAttribute('level') 2781 spelllvl = f.get('level')
2860 #if spelllvl <= "1": 2782 #if spelllvl <= "1":
2861 # opts.append("(" + f.getAttribute('level') + ")" + f.getAttribute('name')) 2783 # opts.append("(" + f.get('level') + ")" + f.get('name'))
2862 #else: 2784 #else:
2863 # if eval('%d >= %s' %(castlvl, spelllvl)): 2785 # if eval('%d >= %s' %(castlvl, spelllvl)):
2864 opts.append("(" + f.getAttribute('level') + ")" + f.getAttribute('name')) 2786 opts.append("(" + f.get('level') + ")" + f.get('name'))
2865 dlg = wx.SingleChoiceDialog(self,'Choose Spell','Spells',opts) 2787 dlg = wx.SingleChoiceDialog(self,'Choose Spell','Spells',opts)
2866 if dlg.ShowModal() == wx.ID_OK: 2788 if dlg.ShowModal() == wx.ID_OK:
2867 i = dlg.GetSelection() 2789 i = dlg.GetSelection()
2868 new_node = self.master_dom.appendChild(f_list[i].cloneNode(False)) 2790 new_node = self.xml.append(f_list[i])
2869 self.grid.AppendRows(1) 2791 self.grid.AppendRows(1)
2870 self.n_list = self.master_dom.getElementsByTagName('spell') 2792 self.n_list = self.xml.findall('spell')
2871 self.refresh_row(self.grid.GetNumberRows()-1) 2793 self.refresh_row(self.grid.GetNumberRows()-1)
2872 self.handler.refresh_spells() 2794 self.handler.refresh_spells()
2873 dlg.Destroy() 2795 dlg.Destroy()
2874 2796
2875 def on_refresh_spells( self, evt ): 2797 def on_refresh_spells( self, evt ):
2876 f_list = self.master_dom.getElementsByTagName('spell') 2798 f_list = self.xml.findall('spell')
2877 2799
2878 for spell in f_list: 2800 for spell in f_list:
2879 spell.setAttribute( 'used', '0' ) 2801 spell.set( 'used', '0' )
2880 2802
2881 def on_size(self,event): 2803 def on_size(self,event):
2882 s = self.GetClientSizeTuple() 2804 s = self.GetClientSizeTuple()
2883 self.grid.SetDimensions(0,0,s[0],s[1]-25) 2805 self.grid.SetDimensions(0,0,s[0],s[1]-25)
2884 self.sizer.SetDimension(0,s[1]-25,s[0],25) 2806 self.sizer.SetDimension(0,s[1]-25,s[0],25)
2905 self.hparent = parent #a 1.5002 allow ability to run up tree. 2827 self.hparent = parent #a 1.5002 allow ability to run up tree.
2906 self.root = getRoot(self) #a 1.5002 2828 self.root = getRoot(self) #a 1.5002
2907 self.root.divine = self #a 1.6009 2829 self.root.divine = self #a 1.6009
2908 2830
2909 2831
2910 node_list = self.master_dom.getElementsByTagName( 'gift' ) 2832 node_list = self.xml.findall( 'gift' )
2911 self.spells = {} 2833 self.spells = {}
2912 tree = self.tree 2834 tree = self.tree
2913 icons = self.tree.icons 2835 icons = self.tree.icons
2914 for n in node_list: 2836 for n in node_list:
2915 name = n.getAttribute('name') 2837 name = n.get('name')
2916 self.spells[ name ] = n 2838 self.spells[ name ] = n
2917 new_tree_node = tree.AppendItem( self.mytree_node, name, icons['flask'], icons['flask'] ) 2839 new_tree_node = tree.AppendItem( self.mytree_node, name, icons['flask'], icons['flask'] )
2918 tree.SetPyData( new_tree_node, self ) 2840 tree.SetPyData( new_tree_node, self )
2919 2841
2920 def on_rclick( self, evt ): 2842 def on_rclick( self, evt ):
2922 item = self.tree.GetSelection() 2844 item = self.tree.GetSelection()
2923 name = self.tree.GetItemText( item ) 2845 name = self.tree.GetItemText( item )
2924 if item == self.mytree_node: 2846 if item == self.mytree_node:
2925 dnd3e_char_child.on_ldclick( self, evt ) 2847 dnd3e_char_child.on_ldclick( self, evt )
2926 else: 2848 else:
2927 level = self.spells[ name ].getAttribute( 'level' ) 2849 level = self.spells[ name ].get( 'level' )
2928 descr = self.spells[ name ].getAttribute( 'desc' ) 2850 descr = self.spells[ name ].get( 'desc' )
2929 use = self.spells[ name ].getAttribute( 'used' ) 2851 use = self.spells[ name ].get( 'used' )
2930 memrz = self.spells[ name ].getAttribute( 'memrz' ) 2852 memrz = self.spells[ name ].get( 'memrz' )
2931 use += '+1' 2853 use += '+1'
2932 left = eval( '%s - ( %s )' % ( memrz, use ) ) 2854 left = eval( '%s - ( %s )' % ( memrz, use ) )
2933 if left < 0: 2855 if left < 0:
2934 txt = '%s Tried to cast %s but has used all of them for today,' #m 1.5002 break in 2. 2856 txt = '%s Tried to cast %s but has used all of them for today,' #m 1.5002 break in 2.
2935 txt += "Please rest so I can cast more."' % ( charNameL, name )' #a 1.5002 2857 txt += "Please rest so I can cast more."' % ( charNameL, name )' #a 1.5002
2943 if left != 1: 2865 if left != 1:
2944 s = 's' 2866 s = 's'
2945 #txt = '%s can cast %s %d more time%s' % ( dnd_globals["gen"]["Name"], name, left, s ) #d 1.5002 2867 #txt = '%s can cast %s %d more time%s' % ( dnd_globals["gen"]["Name"], name, left, s ) #d 1.5002
2946 txt = '%s can cast %s %d more time%s' % ( charNameL, name, left, s ) #a 1.5002 2868 txt = '%s can cast %s %d more time%s' % ( charNameL, name, left, s ) #a 1.5002
2947 self.chat.ParsePost( txt, False, False ) 2869 self.chat.ParsePost( txt, False, False )
2948 self.spells[ name ].setAttribute( 'used', `eval( use )` ) 2870 self.spells[ name ].set( 'used', `eval( use )` )
2949 2871
2950 def refresh_spells(self): 2872 def refresh_spells(self):
2951 self.spells = {} 2873 self.spells = {}
2952 tree = self.tree 2874 tree = self.tree
2953 icons = self.tree.icons 2875 icons = self.tree.icons
2954 tree.CollapseAndReset(self.mytree_node) 2876 tree.CollapseAndReset(self.mytree_node)
2955 2877
2956 node_list = self.master_dom.getElementsByTagName('gift') 2878 node_list = self.xml.findall('gift')
2957 for n in node_list: 2879 for n in node_list:
2958 name = n.getAttribute('name') 2880 name = n.get('name')
2959 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['flask'],icons['flask']) 2881 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['flask'],icons['flask'])
2960 tree.SetPyData(new_tree_node,self) 2882 tree.SetPyData(new_tree_node,self)
2961 self.spells[name]=n 2883 self.spells[name]=n
2962 2884
2963 def get_design_panel(self,parent): 2885 def get_design_panel(self,parent):
2965 wnd.title = "Spells" 2887 wnd.title = "Spells"
2966 return wnd 2888 return wnd
2967 2889
2968 def tohtml(self): 2890 def tohtml(self):
2969 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>Divine Spells</th></tr><tr><td><br>" 2891 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>Divine Spells</th></tr><tr><td><br>"
2970 n_list = self.master_dom._get_childNodes() 2892 n_list = self.xml.getchildren()
2971 for n in n_list: 2893 for n in n_list:
2972 html_str += "(" + n.getAttribute('level') + ") " + n.getAttribute('name')+ ", " 2894 html_str += "(" + n.get('level') + ") " + n.get('name')+ ", "
2973 html_str = html_str[:len(html_str)-2] + "</td></tr></table>" 2895 html_str = html_str[:len(html_str)-2] + "</td></tr></table>"
2974 return html_str 2896 return html_str
2975 2897
2976 def get_char_lvl( self, attr ): 2898 def get_char_lvl( self, attr ):
2977 return self.char_hander.get_char_lvl(attr) 2899 return self.char_hander.get_char_lvl(attr)
2978 2900
2979 class divine_panel(wx.Panel): 2901 class divine_panel(wx.Panel):
2980 def __init__(self, parent, handler): 2902 def __init__(self, parent, handler):
2981 pname = handler.master_dom.setAttribute("name", 'Divine Spells') 2903 pname = handler.xml.set("name", 'Divine Spells')
2982 self.hparent = handler #a 1.5002 allow ability to run up tree. 2904 self.hparent = handler #a 1.5002 allow ability to run up tree.
2983 #a 1.5002 in this case, we need the functional parent, not the invoking parent. 2905 #a 1.5002 in this case, we need the functional parent, not the invoking parent.
2984 2906
2985 wx.Panel.__init__(self, parent, -1) 2907 wx.Panel.__init__(self, parent, -1)
2986 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 2908 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
3005 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10) 2927 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10)
3006 self.Bind(wx.EVT_BUTTON, self.on_add, id=20) 2928 self.Bind(wx.EVT_BUTTON, self.on_add, id=20)
3007 self.Bind(wx.EVT_BUTTON, self.on_refresh_spells, id=30) 2929 self.Bind(wx.EVT_BUTTON, self.on_refresh_spells, id=30)
3008 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change) 2930 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
3009 2931
3010 n_list = handler.master_dom._get_childNodes() 2932 n_list = handler.xml.getchildren()
3011 self.n_list = n_list 2933 self.n_list = n_list
3012 self.master_dom = handler.master_dom 2934 self.xml = handler.xml
3013 self.grid.CreateGrid(len(n_list),4,1) 2935 self.grid.CreateGrid(len(n_list),4,1)
3014 self.grid.SetRowLabelSize(0) 2936 self.grid.SetRowLabelSize(0)
3015 self.grid.SetColLabelValue(0,"No.") 2937 self.grid.SetColLabelValue(0,"No.")
3016 self.grid.SetColLabelValue(1,"Lvl") 2938 self.grid.SetColLabelValue(1,"Lvl")
3017 self.grid.SetColLabelValue(2,"Spell") 2939 self.grid.SetColLabelValue(2,"Spell")
3024 row = evt.GetRow() 2946 row = evt.GetRow()
3025 2947
3026 col = evt.GetCol() 2948 col = evt.GetCol()
3027 value = self.grid.GetCellValue(row,col) 2949 value = self.grid.GetCellValue(row,col)
3028 if col == 0: 2950 if col == 0:
3029 self.n_list[row].setAttribute('memrz',value) 2951 self.n_list[row].set('memrz',value)
3030 2952
3031 2953
3032 def refresh_row(self,i): 2954 def refresh_row(self,i):
3033 spell = self.n_list[i] 2955 spell = self.n_list[i]
3034 2956
3035 memrz = spell.getAttribute('memrz') 2957 memrz = spell.get('memrz')
3036 name = spell.getAttribute('name') 2958 name = spell.get('name')
3037 type = spell.getAttribute('desc') 2959 type = spell.get('desc')
3038 level = spell.getAttribute('level') 2960 level = spell.get('level')
3039 self.grid.SetCellValue(i,0,memrz) 2961 self.grid.SetCellValue(i,0,memrz)
3040 self.grid.SetCellValue(i,2,name) 2962 self.grid.SetCellValue(i,2,name)
3041 self.grid.SetReadOnly(i,2) 2963 self.grid.SetReadOnly(i,2)
3042 self.grid.SetCellValue(i,3,type) 2964 self.grid.SetCellValue(i,3,type)
3043 self.grid.SetReadOnly(i,3) 2965 self.grid.SetReadOnly(i,3)
3047 def on_remove(self,evt): 2969 def on_remove(self,evt):
3048 rows = self.grid.GetNumberRows() 2970 rows = self.grid.GetNumberRows()
3049 for i in range(rows): 2971 for i in range(rows):
3050 if self.grid.IsInSelection(i,0): 2972 if self.grid.IsInSelection(i,0):
3051 self.grid.DeleteRows(i) 2973 self.grid.DeleteRows(i)
3052 self.master_dom.removeChild(self.n_list[i]) 2974 self.xml.remove(self.n_list[i])
3053 2975
3054 def on_add(self,evt): 2976 def on_add(self,evt):
3055 if not self.temp_dom: 2977 if not self.temp_dom:
3056 tmp = open(dir_struct["dnd3e"]+"dnd3edivine.xml","r") 2978 tree = parse(dir_struct["dnd3e"]+"dnd3edivine.xml")
3057 2979 xml_dom = tree.getroot()
3058 xml_dom = parseXml_with_dlg(self,tmp.read())
3059 xml_dom = xml_dom._get_firstChild()
3060 tmp.close()
3061 self.temp_dom = xml_dom 2980 self.temp_dom = xml_dom
3062 f_list = self.temp_dom.getElementsByTagName('gift') 2981 f_list = self.temp_dom.findall('gift')
3063 opts = [] 2982 opts = []
3064 #lvl = int(dnd3e_char_child.get_char_lvl('level')) 2983 #lvl = int(dnd3e_char_child.get_char_lvl('level'))
3065 #castlvl = lvl / 2 2984 #castlvl = lvl / 2
3066 for f in f_list: 2985 for f in f_list:
3067 spelllvl = f.getAttribute('level') 2986 spelllvl = f.get('level')
3068 #if spelllvl <= "1": 2987 #if spelllvl <= "1":
3069 # opts.append("(" + f.getAttribute('level') + ")" + f.getAttribute('name')) 2988 # opts.append("(" + f.get('level') + ")" + f.get('name'))
3070 #else: 2989 #else:
3071 # if eval('%d >= %s' %(castlvl, spelllvl)): 2990 # if eval('%d >= %s' %(castlvl, spelllvl)):
3072 opts.append("(" + f.getAttribute('level') + ")" + f.getAttribute('name')) 2991 opts.append("(" + f.get('level') + ")" + f.get('name'))
3073 dlg = wx.SingleChoiceDialog(self,'Choose Spell','Spells',opts) 2992 dlg = wx.SingleChoiceDialog(self,'Choose Spell','Spells',opts)
3074 if dlg.ShowModal() == wx.ID_OK: 2993 if dlg.ShowModal() == wx.ID_OK:
3075 i = dlg.GetSelection() 2994 i = dlg.GetSelection()
3076 new_node = self.master_dom.appendChild(f_list[i].cloneNode(False)) 2995 new_node = self.xml.append(f_list[i])
3077 self.grid.AppendRows(1) 2996 self.grid.AppendRows(1)
3078 self.n_list = self.master_dom.getElementsByTagName('gift') 2997 self.n_list = self.xml.findall('gift')
3079 self.refresh_row(self.grid.GetNumberRows()-1) 2998 self.refresh_row(self.grid.GetNumberRows()-1)
3080 self.handler.refresh_spells() 2999 self.handler.refresh_spells()
3081 dlg.Destroy() 3000 dlg.Destroy()
3082 3001
3083 def on_refresh_spells( self, evt ): 3002 def on_refresh_spells( self, evt ):
3084 f_list = self.master_dom.getElementsByTagName('gift') 3003 f_list = self.xml.findall('gift')
3085 for spell in f_list: 3004 for spell in f_list:
3086 spell.setAttribute( 'used', '0' ) 3005 spell.set( 'used', '0' )
3087 3006
3088 def on_size(self,event): 3007 def on_size(self,event):
3089 s = self.GetClientSizeTuple() 3008 s = self.GetClientSizeTuple()
3090 self.grid.SetDimensions(0,0,s[0],s[1]-25) 3009 self.grid.SetDimensions(0,0,s[0],s[1]-25)
3091 self.sizer.SetDimension(0,s[1]-25,s[0],25) 3010 self.sizer.SetDimension(0,s[1]-25,s[0],25)
3113 snp_char_child.__init__(self,xml_dom,tree_node,parent) 3032 snp_char_child.__init__(self,xml_dom,tree_node,parent)
3114 self.hparent = parent #a 1.5002 allow ability to run up tree. 3033 self.hparent = parent #a 1.5002 allow ability to run up tree.
3115 self.root = getRoot(self) #a 1.5002 3034 self.root = getRoot(self) #a 1.5002
3116 self.root.powers = self #a 1.6009 3035 self.root.powers = self #a 1.6009
3117 3036
3118 node_list = self.master_dom.getElementsByTagName( 'power' ) 3037 node_list = self.xml.findall( 'power' )
3119 self.powers = {} 3038 self.powers = {}
3120 tree = self.tree 3039 tree = self.tree
3121 icons = self.tree.icons 3040 icons = self.tree.icons
3122 for n in node_list: 3041 for n in node_list:
3123 name = n.getAttribute('name') 3042 name = n.get('name')
3124 self.powers[ name ] = n 3043 self.powers[ name ] = n
3125 new_tree_node = tree.AppendItem( self.mytree_node, name, 3044 new_tree_node = tree.AppendItem( self.mytree_node, name,
3126 icons['gear'], icons['gear'] ) 3045 icons['gear'], icons['gear'] )
3127 tree.SetPyData( new_tree_node, self ) 3046 tree.SetPyData( new_tree_node, self )
3128 3047
3133 name = self.tree.GetItemText( item ) 3052 name = self.tree.GetItemText( item )
3134 charNameL = self.root.general.charName #a 1.5002 3053 charNameL = self.root.general.charName #a 1.5002
3135 if item == self.mytree_node: 3054 if item == self.mytree_node:
3136 dnd3e_char_child.on_ldclick( self, evt ) 3055 dnd3e_char_child.on_ldclick( self, evt )
3137 else: 3056 else:
3138 level = int(self.powers[ name ].getAttribute( 'level' )) 3057 level = int(self.powers[ name ].get( 'level' ))
3139 descr = self.powers[ name ].getAttribute( 'desc' ) 3058 descr = self.powers[ name ].get( 'desc' )
3140 #use can be removed -mgt 3059 #use can be removed -mgt
3141 #use = self.powers[ name ].getAttribute( 'used' ) 3060 #use = self.powers[ name ].get( 'used' )
3142 points = self.powers[ name ].getAttribute( 'point' ) 3061 points = self.powers[ name ].get( 'point' )
3143 #cpp and fre are strings without the eval -mgt 3062 #cpp and fre are strings without the eval -mgt
3144 cpp = eval(self.root.pp.get_char_pp('current1')) #a 1.5002 3063 cpp = eval(self.root.pp.get_char_pp('current1')) #a 1.5002
3145 fre = eval(self.root.pp.get_char_pp('free')) #a 1.5002 3064 fre = eval(self.root.pp.get_char_pp('free')) #a 1.5002
3146 if level == 0 and fre > 0: 3065 if level == 0 and fre > 0:
3147 left = eval('%s - ( %s )' % ( fre, points )) 3066 left = eval('%s - ( %s )' % ( fre, points ))
3184 self.powers = {} 3103 self.powers = {}
3185 3104
3186 tree = self.tree 3105 tree = self.tree
3187 icons = self.tree.icons 3106 icons = self.tree.icons
3188 tree.CollapseAndReset(self.mytree_node) 3107 tree.CollapseAndReset(self.mytree_node)
3189 node_list = self.master_dom.getElementsByTagName('power') 3108 node_list = self.xml.findall('power')
3190 for n in node_list: 3109 for n in node_list:
3191 name = n.getAttribute('name') 3110 name = n.get('name')
3192 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear']) 3111 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear'])
3193 tree.SetPyData(new_tree_node,self) 3112 tree.SetPyData(new_tree_node,self)
3194 self.powers[name]=n 3113 self.powers[name]=n
3195 3114
3196 def get_design_panel(self,parent): 3115 def get_design_panel(self,parent):
3198 wnd.title = "Powers" 3117 wnd.title = "Powers"
3199 return wnd 3118 return wnd
3200 3119
3201 def tohtml(self): 3120 def tohtml(self):
3202 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>Powers</th></tr><tr><td><br>" 3121 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>Powers</th></tr><tr><td><br>"
3203 n_list = self.master_dom._get_childNodes() 3122 n_list = self.xml.getchildren()
3204 for n in n_list: 3123 for n in n_list:
3205 html_str += "(" + n.getAttribute('level') + ") " + n.getAttribute('name')+ ", " 3124 html_str += "(" + n.get('level') + ") " + n.get('name')+ ", "
3206 html_str = html_str[:len(html_str)-2] + "</td></tr></table>" 3125 html_str = html_str[:len(html_str)-2] + "</td></tr></table>"
3207 return html_str 3126 return html_str
3208 3127
3209 3128
3210 class power_panel(wx.Panel): 3129 class power_panel(wx.Panel):
3211 def __init__(self, parent, handler): 3130 def __init__(self, parent, handler):
3212 #m 1.5015 corrected typo, was Pionic. 3131 #m 1.5015 corrected typo, was Pionic.
3213 pname = handler.master_dom.setAttribute("name", 'Psionic Powers') 3132 pname = handler.xml.set("name", 'Psionic Powers')
3214 self.hparent = handler #a 1.5002 allow ability to run up tree. In this 3133 self.hparent = handler #a 1.5002 allow ability to run up tree. In this
3215 #a 1.5002 case, we need the functional parent, not the invoking parent. 3134 #a 1.5002 case, we need the functional parent, not the invoking parent.
3216 self.root = getRoot(self) #a (debug) 1.5002,1.5014 3135 self.root = getRoot(self) #a (debug) 1.5002,1.5014
3217 3136
3218 wx.Panel.__init__(self, parent, -1) 3137 wx.Panel.__init__(self, parent, -1)
3237 3156
3238 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10) 3157 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10)
3239 self.Bind(wx.EVT_BUTTON, self.on_add, id=20) 3158 self.Bind(wx.EVT_BUTTON, self.on_add, id=20)
3240 self.Bind(wx.EVT_BUTTON, self.on_refresh_powers, id=30) 3159 self.Bind(wx.EVT_BUTTON, self.on_refresh_powers, id=30)
3241 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change) 3160 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
3242 n_list = handler.master_dom._get_childNodes() 3161 n_list = handler.xml.getchildren()
3243 self.n_list = n_list 3162 self.n_list = n_list
3244 self.master_dom = handler.master_dom 3163 self.xml = handler.xml
3245 self.grid.CreateGrid(len(n_list),5,1) 3164 self.grid.CreateGrid(len(n_list),5,1)
3246 self.grid.SetRowLabelSize(0) 3165 self.grid.SetRowLabelSize(0)
3247 self.grid.SetColLabelValue(0,"PP") 3166 self.grid.SetColLabelValue(0,"PP")
3248 self.grid.SetColLabelValue(1,"Lvl") 3167 self.grid.SetColLabelValue(1,"Lvl")
3249 self.grid.SetColLabelValue(2,"Power") 3168 self.grid.SetColLabelValue(2,"Power")
3257 def on_cell_change(self,evt): 3176 def on_cell_change(self,evt):
3258 row = evt.GetRow() 3177 row = evt.GetRow()
3259 col = evt.GetCol() 3178 col = evt.GetCol()
3260 value = self.grid.GetCellValue(row,col) 3179 value = self.grid.GetCellValue(row,col)
3261 """if col == 0: 3180 """if col == 0:
3262 self.n_list[row].setAttribute('memrz',value)""" 3181 self.n_list[row].set('memrz',value)"""
3263 3182
3264 3183
3265 def refresh_row(self,i): 3184 def refresh_row(self,i):
3266 power = self.n_list[i] 3185 power = self.n_list[i]
3267 3186
3268 point = power.getAttribute('point') 3187 point = power.get('point')
3269 name = power.getAttribute('name') 3188 name = power.get('name')
3270 type = power.getAttribute('desc') 3189 type = power.get('desc')
3271 test = power.getAttribute('test') 3190 test = power.get('test')
3272 level = power.getAttribute('level') 3191 level = power.get('level')
3273 self.grid.SetCellValue(i,0,point) 3192 self.grid.SetCellValue(i,0,point)
3274 self.grid.SetReadOnly(i,0) 3193 self.grid.SetReadOnly(i,0)
3275 self.grid.SetCellValue(i,1,level) 3194 self.grid.SetCellValue(i,1,level)
3276 self.grid.SetReadOnly(i,1) 3195 self.grid.SetReadOnly(i,1)
3277 self.grid.SetCellValue(i,2,name) 3196 self.grid.SetCellValue(i,2,name)
3284 def on_remove(self,evt): 3203 def on_remove(self,evt):
3285 rows = self.grid.GetNumberRows() 3204 rows = self.grid.GetNumberRows()
3286 for i in range(rows): 3205 for i in range(rows):
3287 if self.grid.IsInSelection(i,0): 3206 if self.grid.IsInSelection(i,0):
3288 self.grid.DeleteRows(i) 3207 self.grid.DeleteRows(i)
3289 self.master_dom.removeChild(self.n_list[i]) 3208 self.xml.remove(self.n_list[i])
3290 3209
3291 def on_add(self,evt): 3210 def on_add(self,evt):
3211 debug()
3292 if not self.temp_dom: 3212 if not self.temp_dom:
3293 tmp = open(dir_struct["dnd3e"]+"dnd3epowers.xml","r") 3213 tree = parse(dir_struct["dnd3e"]+"dnd3epowers.xml")
3294 3214 xml_dom = tree.getroot()
3295 xml_dom = parseXml_with_dlg(self,tmp.read())
3296 xml_dom = xml_dom._get_firstChild()
3297 tmp.close()
3298 self.temp_dom = xml_dom 3215 self.temp_dom = xml_dom
3299 f_list = self.temp_dom.getElementsByTagName('power') 3216 debug(self.temp)
3217 f_list = self.temp_dom.findall('power')
3300 opts = [] 3218 opts = []
3301 #lvl = int(dnd3e_char_child.get_char_lvl('level')) 3219 #lvl = int(dnd3e_char_child.get_char_lvl('level'))
3302 #castlvl = lvl / 2 3220 #castlvl = lvl / 2
3303 for f in f_list: 3221 for f in f_list:
3304 spelllvl = f.getAttribute('level') 3222 spelllvl = f.get('level')
3305 #if spelllvl <= "1": 3223 #if spelllvl <= "1":
3306 # opts.append("(" + f.getAttribute('level') + ") - " + f.getAttribute('name') + " - " + f.getAttribute('test')) 3224 # opts.append("(" + f.get('level') + ") - " + f.get('name') + " - " + f.get('test'))
3307 #else: 3225 #else:
3308 # if eval('%d >= %s' %(castlvl, spelllvl)): 3226 # if eval('%d >= %s' %(castlvl, spelllvl)):
3309 opts.append("(" + f.getAttribute('level') + ") - " + 3227 opts.append("(" + f.get('level') + ") - " +
3310 f.getAttribute('name') + " - " + f.getAttribute('test')) 3228 f.get('name') + " - " + f.get('test'))
3311 dlg = wx.SingleChoiceDialog(self,'Choose Power','Powers',opts) 3229 dlg = wx.SingleChoiceDialog(self,'Choose Power','Powers',opts)
3312 if dlg.ShowModal() == wx.ID_OK: 3230 if dlg.ShowModal() == wx.ID_OK:
3313 i = dlg.GetSelection() 3231 i = dlg.GetSelection()
3314 new_node = self.master_dom.appendChild(f_list[i].cloneNode(False)) 3232 new_node = self.xml.append(f_list[i])
3315 self.grid.AppendRows(1) 3233 self.grid.AppendRows(1)
3316 self.n_list = self.master_dom.getElementsByTagName('power') 3234 self.n_list = self.xml.findall('power')
3317 self.refresh_row(self.grid.GetNumberRows()-1) 3235 self.refresh_row(self.grid.GetNumberRows()-1)
3318 self.handler.refresh_powers() 3236 self.handler.refresh_powers()
3319 dlg.Destroy() 3237 dlg.Destroy()
3320 3238
3321 def on_remove(self,evt): 3239 def on_remove(self,evt):
3322 rows = self.grid.GetNumberRows() 3240 rows = self.grid.GetNumberRows()
3323 for i in range(rows): 3241 for i in range(rows):
3324 if self.grid.IsInSelection(i,0): 3242 if self.grid.IsInSelection(i,0):
3325 self.grid.DeleteRows(i) 3243 self.grid.DeleteRows(i)
3326 self.master_dom.removeChild(self.n_list[i]) 3244 self.xml.remove(self.n_list[i])
3327 self.n_list = self.master_dom.getElementsByTagName('weapon') 3245 self.n_list = self.xml.findall('weapon')
3328 self.handler.refresh_powers() 3246 self.handler.refresh_powers()
3329 3247
3330 def on_refresh_powers( self, evt ): 3248 def on_refresh_powers( self, evt ):
3331 #a 1.5002,1.5014 s 3249 #a 1.5002,1.5014 s
3332 self.root.pp.set_char_pp('current1',self.root.pp.get_char_pp('max1')) 3250 self.root.pp.set_char_pp('current1',self.root.pp.get_char_pp('max1'))
3378 #html_str += "<th colspan=8>Power Points</th></tr>" #d 1.6010 3296 #html_str += "<th colspan=8>Power Points</th></tr>" #d 1.6010
3379 html_str += "<th colspan=7>Power Points</th>" #a 1.6010 3297 html_str += "<th colspan=7>Power Points</th>" #a 1.6010
3380 #m 1.6010 rearanged everything below to "return html_str" 3298 #m 1.6010 rearanged everything below to "return html_str"
3381 html_str += "</tr><tr>" 3299 html_str += "</tr><tr>"
3382 html_str += "<th colspan=2>Max:</th>" 3300 html_str += "<th colspan=2>Max:</th>"
3383 html_str += "<td>"+self.master_dom.getAttribute('max1')+"</td>" 3301 html_str += "<td>"+self.xml.get('max1')+"</td>"
3384 html_str += "<th colspan=3>Max Talents/day:</th>" 3302 html_str += "<th colspan=3>Max Talents/day:</th>"
3385 html_str += "<td>"+self.master_dom.getAttribute('maxfree')+"</td>" 3303 html_str += "<td>"+self.xml.get('maxfree')+"</td>"
3386 html_str += "</tr><tr>" 3304 html_str += "</tr><tr>"
3387 html_str += "<th colspan=2>Current:</th>" 3305 html_str += "<th colspan=2>Current:</th>"
3388 html_str += "<td>"+self.master_dom.getAttribute('current1')+"</td>" 3306 html_str += "<td>"+self.xml.get('current1')+"</td>"
3389 html_str += "<th colspan=3>Current Talents/day:</th>" 3307 html_str += "<th colspan=3>Current Talents/day:</th>"
3390 html_str += "<td>"+self.master_dom.getAttribute('free')+"</td>" 3308 html_str += "<td>"+self.xml.get('free')+"</td>"
3391 html_str += "</tr></table>" 3309 html_str += "</tr></table>"
3392 return html_str 3310 return html_str
3393 3311
3394 def get_char_pp( self, attr ): 3312 def get_char_pp( self, attr ):
3395 pp = self.master_dom.getAttribute(attr) 3313 pp = self.xml.get(attr)
3396 #print "dnd3epp -get_char_pp: attr,pp",attr,pp 3314 #print "dnd3epp -get_char_pp: attr,pp",attr,pp
3397 return pp 3315 return pp
3398 3316
3399 def set_char_pp( self, attr, evl ): 3317 def set_char_pp( self, attr, evl ):
3400 qSub = str(evl) #a 1.5014 must force it to be a string for next call. 3318 qSub = str(evl) #a 1.5014 must force it to be a string for next call.
3401 self.master_dom.setAttribute(attr, qSub) 3319 self.xml.set(attr, qSub)
3402 #This function needs to be looked at the idea is to refresh the power panel 3320 #This function needs to be looked at the idea is to refresh the power panel
3403 #But it causes a seg fault when you refresh from powers -mgt 3321 #But it causes a seg fault when you refresh from powers -mgt
3404 #if self.ppPanel: #a 1.5015 3322 #if self.ppPanel: #a 1.5015
3405 # self.ppPanel.on_refresh(attr,qSub) #a 1.5015 3323 # self.ppPanel.on_refresh(attr,qSub) #a 1.5015
3406 3324
3410 wx.Panel.__init__(self, parent, -1) 3328 wx.Panel.__init__(self, parent, -1)
3411 self.hparent = handler #a 1.5002 allow ability to run up tree. 3329 self.hparent = handler #a 1.5002 allow ability to run up tree.
3412 #a 1.5002 we need the functional parent, not the invoking parent. 3330 #a 1.5002 we need the functional parent, not the invoking parent.
3413 self.hparent.ppPanel=self #a 1.5xx 3331 self.hparent.ppPanel=self #a 1.5xx
3414 3332
3415 pname = handler.master_dom.setAttribute("name", 'PowerPoints') 3333 pname = handler.xml.set("name", 'PowerPoints')
3416 self.sizer = wx.FlexGridSizer(2, 4, 2, 2) # rows, cols, hgap, vgap 3334 self.sizer = wx.FlexGridSizer(2, 4, 2, 2) # rows, cols, hgap, vgap
3417 self.master_dom = handler.master_dom 3335 self.xml = handler.xml
3418 3336
3419 self.static1= wx.StaticText(self, -1, "PP Current:") #a 1.5015 3337 self.static1= wx.StaticText(self, -1, "PP Current:") #a 1.5015
3420 self.dyn1= wx.TextCtrl(self, PP_CUR, 3338 self.dyn1= wx.TextCtrl(self, PP_CUR,
3421 self.master_dom.getAttribute('current1')) #a 1.5015 3339 self.xml.get('current1')) #a 1.5015
3422 self.dyn3= wx.TextCtrl(self, PP_FRE, 3340 self.dyn3= wx.TextCtrl(self, PP_FRE,
3423 self.master_dom.getAttribute('free')) #a 1.5015 3341 self.xml.get('free')) #a 1.5015
3424 # self.sizer.AddMany([ (wx.StaticText(self, -1, "PP Current:"), #d 1.5015 3342 # self.sizer.AddMany([ (wx.StaticText(self, -1, "PP Current:"), #d 1.5015
3425 # 0, wx.ALIGN_CENTER_VERTICAL), 3343 # 0, wx.ALIGN_CENTER_VERTICAL),
3426 # (wx.TextCtrl(self, PP_CUR, #d 1.5015 3344 # (wx.TextCtrl(self, PP_CUR, #d 1.5015
3427 # self.master_dom.getAttribute('current1')), 0, wx.EXPAND), 3345 # self.xml.get('current1')), 0, wx.EXPAND),
3428 self.sizer.AddMany([ (self.static1, 0, wx.ALIGN_CENTER_VERTICAL), 3346 self.sizer.AddMany([ (self.static1, 0, wx.ALIGN_CENTER_VERTICAL),
3429 (self.dyn1, 0, wx.EXPAND), 3347 (self.dyn1, 0, wx.EXPAND),
3430 (wx.StaticText(self, -1, "PP Max:"), 0, wx.ALIGN_CENTER_VERTICAL), 3348 (wx.StaticText(self, -1, "PP Max:"), 0, wx.ALIGN_CENTER_VERTICAL),
3431 (wx.TextCtrl(self, PP_MAX, 3349 (wx.TextCtrl(self, PP_MAX,
3432 self.master_dom.getAttribute('max1')), 0, wx.EXPAND), 3350 self.xml.get('max1')), 0, wx.EXPAND),
3433 (wx.StaticText(self, -1, "Current Free Talants per day:"), 3351 (wx.StaticText(self, -1, "Current Free Talants per day:"),
3434 0, wx.ALIGN_CENTER_VERTICAL), 3352 0, wx.ALIGN_CENTER_VERTICAL),
3435 (self.dyn3, 0, wx.EXPAND), #a 1.5015 3353 (self.dyn3, 0, wx.EXPAND), #a 1.5015
3436 # (wx.TextCtrl(self, PP_FRE, 3354 # (wx.TextCtrl(self, PP_FRE,
3437 # self.master_dom.getAttribute('free')), 0, wx.EXPAND),#d 1.5015 3355 # self.xml.get('free')), 0, wx.EXPAND),#d 1.5015
3438 (wx.StaticText(self, -1, "Max Free Talants per day:"), 3356 (wx.StaticText(self, -1, "Max Free Talants per day:"),
3439 0, wx.ALIGN_CENTER_VERTICAL), 3357 0, wx.ALIGN_CENTER_VERTICAL),
3440 (wx.TextCtrl(self, PP_MFRE, 3358 (wx.TextCtrl(self, PP_MFRE,
3441 self.master_dom.getAttribute('maxfree')), 0, wx.EXPAND), 3359 self.xml.get('maxfree')), 0, wx.EXPAND),
3442 ]) 3360 ])
3443 3361
3444 self.sizer.AddGrowableCol(1) 3362 self.sizer.AddGrowableCol(1)
3445 self.SetSizer(self.sizer) 3363 self.SetSizer(self.sizer)
3446 self.SetAutoLayout(True) 3364 self.SetAutoLayout(True)
3453 self.Bind(wx.EVT_TEXT, self.on_text, id=PP_MFRE) 3371 self.Bind(wx.EVT_TEXT, self.on_text, id=PP_MFRE)
3454 3372
3455 def on_text(self,evt): 3373 def on_text(self,evt):
3456 id = evt.GetId() 3374 id = evt.GetId()
3457 if id == PP_CUR: 3375 if id == PP_CUR:
3458 self.master_dom.setAttribute('current1',evt.GetString()) 3376 self.xml.set('current1',evt.GetString())
3459 elif id == PP_MAX: 3377 elif id == PP_MAX:
3460 self.master_dom.setAttribute('max1',evt.GetString()) 3378 self.xml.set('max1',evt.GetString())
3461 elif id == PP_FRE: 3379 elif id == PP_FRE:
3462 self.master_dom.setAttribute('free',evt.GetString()) 3380 self.xml.set('free',evt.GetString())
3463 elif id == PP_MFRE: 3381 elif id == PP_MFRE:
3464 self.master_dom.setAttribute('maxfree',evt.GetString()) 3382 self.xml.set('maxfree',evt.GetString())
3465 3383
3466 def on_size(self,evt): 3384 def on_size(self,evt):
3467 s = self.GetClientSizeTuple() 3385 s = self.GetClientSizeTuple()
3468 self.sizer.SetDimension(0,0,s[0],s[1]) 3386 self.sizer.SetDimension(0,0,s[0],s[1])
3469 3387