comparison orpg/gametree/nodehandlers/d20.py @ 118:217fb049bd00 alpha

Traipse Alpha 'OpenRPG' {091028-00} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user. Update Summary: Adds Bookmarks (Alpha) with cool Smiley Star and Plus Symbol images! Changes made to the map for increased portability. SnowDog has changes planned in Core, though. Added an initial push to the BCG. Not much to see, just shows off how it is re-writing Main code. Fix to remote admin commands Minor fix to texted based server, works in /System/ folder Some Core changes to gametree to correctly disply Pretty Print, thanks David! Fix to Splitter Nodes not being created. Added images to Plugin Control panel for Autostart feature Fix to massive amounts of images loading; from Core fix to gsclient so with_statement imports Added 'boot' command to remote admin Prep work in Pass tool for remote admin rankings and different passwords, ei, Server, Admin, Moderator, etc. Remote Admin Commands more organized, more prep work. Added Confirmation window for sent nodes. Minor changes to allow for portability to an OpenSUSE linux OS (hopefully without breaking) {091028} 00: Made changes to gametree to start working with Element Tree, mostly from Core Minor changes to Map to start working with Element Tree, from Core Preliminary changes to map efficiency, from FlexiRPG Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG Changes to main.py to start working with Element Tree
author sirebral
date Wed, 28 Oct 2009 14:24:54 -0500
parents c5bc2abaf7f8
children 8827271fbe1b
comparison
equal deleted inserted replaced
117:0f18d16f3fe7 118:217fb049bd00
28 28
29 __version__ = "$Id: d20.py,v 1.30 2007/05/22 00:50:57 digitalxero Exp $" 29 __version__ = "$Id: d20.py,v 1.30 2007/05/22 00:50:57 digitalxero Exp $"
30 30
31 from core import * 31 from core import *
32 import re 32 import re
33 from xml.etree.ElementTree import ElementTree, Element, iselement
34 from xml.etree.ElementTree import fromstring, tostring, parse, XML
33 35
34 D20_EXPORT = wx.NewId() 36 D20_EXPORT = wx.NewId()
35 ############################ 37 ############################
36 ## d20 character node handler 38 ## d20 character node handler
37 ############################ 39 ############################
40 ##The whole look and easy of use redone by Digitalxero 42 ##The whole look and easy of use redone by Digitalxero
41 class container_handler(node_handler): 43 class container_handler(node_handler):
42 """ should not be used! only a base class! 44 """ should not be used! only a base class!
43 <nodehandler name='?' module='core' class='container_handler' /> 45 <nodehandler name='?' module='core' class='container_handler' />
44 """ 46 """
45 def __init__(self,xml_dom,tree_node): 47 def __init__(self,xml,tree_node):
46 node_handler.__init__(self,xml_dom,tree_node) 48 node_handler.__init__(self,xml,tree_node)
47 self.load_children() 49 self.load_children()
48 50
49 def load_children(self): 51 def load_children(self):
50 children = self.master_dom._get_childNodes() 52 children = self.xml._get_childNodes()
51 for c in children: 53 for c in children:
52 self.tree.load_xml(c,self.mytree_node) 54 self.tree.load_xml(c,self.mytree_node)
53 55
54 56
55 def on_drop(self,evt): 57 def on_drop(self,evt):
58 # return 60 # return
59 if drag_obj == self: 61 if drag_obj == self:
60 return 62 return
61 opt = wx.MessageBox("Add node as child?","Container Node",wx.YES_NO|wx.CANCEL) 63 opt = wx.MessageBox("Add node as child?","Container Node",wx.YES_NO|wx.CANCEL)
62 if opt == wx.YES: 64 if opt == wx.YES:
63 xml_dom = self.tree.drag_obj.delete() 65 xml = self.tree.drag_obj.delete()
64 xml_dom = self.master_dom.insertBefore(xml_dom,None) 66 xml = self.xml.insertBefore(xml,None)
65 self.tree.load_xml(xml_dom, self.mytree_node) 67 self.tree.load_xml(xml, self.mytree_node)
66 self.tree.Expand(self.mytree_node) 68 self.tree.Expand(self.mytree_node)
67 elif opt == wx.NO: 69 elif opt == wx.NO:
68 node_handler.on_drop(self,evt) 70 node_handler.on_drop(self,evt)
69 71
70 def tohtml(self): 72 def tohtml(self):
71 cookie = 0 73 cookie = 0
72 html_str = "<table border=\"1\" ><tr><td>" 74 html_str = "<table border=\"1\" ><tr><td>"
73 html_str += "<b>"+self.master_dom.getAttribute("name") + "</b>" 75 html_str += "<b>"+self.xml.get("name") + "</b>"
74 html_str += "</td></tr>\n" 76 html_str += "</td></tr>\n"
75 html_str += "<tr><td>" 77 html_str += "<tr><td>"
76 78
77 max = tree.GetChildrenCount(handler.mytree_node,0) 79 max = tree.GetChildrenCount(handler.mytree_node,0)
78 try: 80 try:
108 110
109 class d20char_handler(node_handler): 111 class d20char_handler(node_handler):
110 """ Node handler for a d20 charactor 112 """ Node handler for a d20 charactor
111 <nodehandler name='?' module='d20' class='d20char_handler2' /> 113 <nodehandler name='?' module='d20' class='d20char_handler2' />
112 """ 114 """
113 def __init__(self,xml_dom,tree_node): 115 def __init__(self,xml,tree_node):
114 node_handler.__init__(self,xml_dom,tree_node) 116 node_handler.__init__(self,xml,tree_node)
115 self.frame = component.get('frame') 117 self.frame = component.get('frame')
116 self.child_handlers = {} 118 self.child_handlers = {}
117 self.new_child_handler('howtouse','HowTO use this tool',d20howto,'note') 119 self.new_child_handler('howtouse','HowTO use this tool',d20howto,'note')
118 self.new_child_handler('general','General Information',d20general,'gear') 120 self.new_child_handler('general','General Information',d20general,'gear')
119 self.new_child_handler('inventory','Money and Inventory',d20inventory,'money') 121 self.new_child_handler('inventory','Money and Inventory',d20inventory,'money')
134 136
135 137
136 def on_version(self,old_version): 138 def on_version(self,old_version):
137 node_handler.on_version(self,old_version) 139 node_handler.on_version(self,old_version)
138 if old_version == "": 140 if old_version == "":
139 tmp = open(orpg.dirpath.dir_struct["nodes"]+"d20character.xml","r") 141 data = parse(orpg.dirpath.dir_struct["nodes"]+"d20character.xml").getroot()
140 xml_dom = parseXml_with_dlg(self.tree,tmp.read())
141 xml_dom = xml_dom._get_firstChild()
142 tmp.close()
143 ## add new nodes
144 for tag in ("howtouse","inventory","powers","divine","pp"): 142 for tag in ("howtouse","inventory","powers","divine","pp"):
145 node_list = xml_dom.getElementsByTagName(tag) 143 self.xml.append(data.find(tag))
146 self.master_dom.appendChild(node_list[0])
147 144
148 ## add new atts 145 ## add new atts
149 melee_attack = self.master_dom.getElementsByTagName('melee')[0] 146 melee_attack = self.xml.find('melee')
150 melee_attack.setAttribute("second","0") 147 melee_attack.set("second","0")
151 melee_attack.setAttribute("third","0") 148 melee_attack.set("third","0")
152 melee_attack.setAttribute("forth","0") 149 melee_attack.set("forth","0")
153 melee_attack.setAttribute("fifth","0") 150 melee_attack.set("fifth","0")
154 melee_attack.setAttribute("sixth","0") 151 melee_attack.set("sixth","0")
155 range_attack = self.master_dom.getElementsByTagName('ranged')[0] 152 range_attack = self.xml.find('ranged')
156 range_attack.setAttribute("second","0") 153 range_attack.set("second","0")
157 range_attack.setAttribute("third","0") 154 range_attack.set("third","0")
158 range_attack.setAttribute("forth","0") 155 range_attack.set("forth","0")
159 range_attack.setAttribute("fifth","0") 156 range_attack.set("fifth","0")
160 range_attack.setAttribute("sixth","0") 157 range_attack.set("sixth","0")
161 158
162 gen_list = self.master_dom.getElementsByTagName('general')[0] 159 gen_list = self.xml.find('general')
163 160
164 for tag in ("currentxp","xptolevel"): 161 for tag in ("currentxp","xptolevel"):
165 node_list = xml_dom.getElementsByTagName(tag) 162 gen_list.append(data.find(tag))
166 gen_list.appendChild(node_list[0])
167 ## temp fix 163 ## temp fix
168 #parent = self.master_dom._get_parentNode() 164 #parent = self.xml._get_parentNode()
169 #old_dom = parent.replaceChild(xml_dom,self.master_dom) 165 #old_dom = parent.replaceChild(xml,self.xml)
170 #self.master_dom = xml_dom 166 #self.xml = xml
171 print old_version 167 print old_version
172 168
173 169
174 def get_char_name( self ): 170 def get_char_name( self ):
175 return self.child_handlers['general'].get_char_name() 171 return self.child_handlers['general'].get_char_name()
183 def get_char_lvl( self, attr ): 179 def get_char_lvl( self, attr ):
184 return self.child_handlers['classes'].get_char_lvl(attr) 180 return self.child_handlers['classes'].get_char_lvl(attr)
185 181
186 182
187 def new_child_handler(self,tag,text,handler_class,icon='gear'): 183 def new_child_handler(self,tag,text,handler_class,icon='gear'):
188 node_list = self.master_dom.getElementsByTagName(tag)
189 tree = self.tree 184 tree = self.tree
190 i = self.tree.icons[icon] 185 i = self.tree.icons[icon]
191 new_tree_node = tree.AppendItem(self.mytree_node,text,i,i) 186 new_tree_node = tree.AppendItem(self.mytree_node,text,i,i)
192 handler = handler_class(node_list[0],new_tree_node,self) 187 handler = handler_class(self.xml.find(tag),new_tree_node,self)
193 tree.SetPyData(new_tree_node,handler) 188 tree.SetPyData(new_tree_node,handler)
194 self.child_handlers[tag] = handler 189 self.child_handlers[tag] = handler
195 190
196 def get_design_panel(self,parent): 191 def get_design_panel(self,parent):
197 return tabbed_panel(parent,self,1) 192 return tabbed_panel(parent,self,1)
262 for m in range(max): 257 for m in range(max):
263 if mode == 1: 258 if mode == 1:
264 panel = obj.get_design_panel(self) 259 panel = obj.get_design_panel(self)
265 else: 260 else:
266 panel = obj.get_use_panel(self) 261 panel = obj.get_use_panel(self)
267 name = obj.master_dom.getAttribute("name") 262 name = obj.xml.get("name")
268 263
269 if panel: 264 if panel:
270 self.AddPage(panel,name) 265 self.AddPage(panel,name)
271 if m < max-1: 266 if m < max-1:
272 child = tree.GetNextSibling(child) 267 child = tree.GetNextSibling(child)
295 290
296 class d20_char_child(node_handler): 291 class d20_char_child(node_handler):
297 """ Node Handler for skill. This handler will be 292 """ Node Handler for skill. This handler will be
298 created by d20char_handler. 293 created by d20char_handler.
299 """ 294 """
300 def __init__(self,xml_dom,tree_node,parent): 295 def __init__(self,xml,tree_node,parent):
301 node_handler.__init__(self,xml_dom,tree_node) 296 node_handler.__init__(self,xml,tree_node)
302 self.char_hander = parent 297 self.char_hander = parent
303 self.drag = False 298 self.drag = False
304 self.frame = component.get('frame') 299 self.frame = component.get('frame')
305 self.myeditor = None 300 self.myeditor = None
306 301
307
308 def on_drop(self,evt): 302 def on_drop(self,evt):
309 pass 303 pass
310 304
311 def on_rclick(self,evt): 305 def on_rclick(self,evt):
312 pass 306 pass
313 307
314 def on_ldclick(self,evt): 308 def on_ldclick(self,evt):
315 return 309 return
316 if self.myeditor == None or self.myeditor.destroyed: 310 if self.myeditor == None or self.myeditor.destroyed:
317 title = self.master_dom.getAttribute('name') + " Editor" 311 title = self.xml.get('name') + " Editor"
318 self.myeditor = wx.Frame(self.frame, -1, title) 312 self.myeditor = wx.Frame(self.frame, -1, title)
319 if wx.Platform == '__WXMSW__': 313 if wx.Platform == '__WXMSW__':
320 icon = wx.Icon(orpg.dirpath.dir_struct["icon"]+'grid.ico', wx.BITMAP_TYPE_ICO) 314 icon = wx.Icon(orpg.dirpath.dir_struct["icon"]+'grid.ico', wx.BITMAP_TYPE_ICO)
321 self.myeditor.SetIcon(icon) 315 self.myeditor.SetIcon(icon)
322 del icon 316 del icon
328 self.myeditor.Raise() 322 self.myeditor.Raise()
329 323
330 def on_html(self,evt): 324 def on_html(self,evt):
331 html_str = self.tohtml() 325 html_str = self.tohtml()
332 wnd = http_html_window(self.frame.note,-1) 326 wnd = http_html_window(self.frame.note,-1)
333 wnd.title = self.master_dom.getAttribute('name') 327 wnd.title = self.xml.get('name')
334 self.frame.add_panel(wnd) 328 self.frame.add_panel(wnd)
335 wnd.SetPage(html_str) 329 wnd.SetPage(html_str)
336 330
337 def get_design_panel(self,parent): 331 def get_design_panel(self,parent):
338 pass 332 pass
346 340
347 class d20skill(d20_char_child): 341 class d20skill(d20_char_child):
348 """ Node Handler for skill. This handler will be 342 """ Node Handler for skill. This handler will be
349 created by d20char_handler. 343 created by d20char_handler.
350 """ 344 """
351 def __init__(self,xml_dom,tree_node,parent): 345 def __init__(self,xml,tree_node,parent):
352 d20_char_child.__init__(self,xml_dom,tree_node,parent) 346 d20_char_child.__init__(self,xml,tree_node,parent)
353 tree = self.tree 347 tree = self.tree
354 icons = self.tree.icons 348 icons = self.tree.icons
355 node_list = self.master_dom.getElementsByTagName('skill')
356 self.skills={} 349 self.skills={}
357 for n in node_list: 350 for n in self.xml.findall('skill'):
358 name = n.getAttribute('name') 351 name = n.get('name')
359 self.skills[name] = n 352 self.skills[name] = n
360 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear']) 353 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear'])
361 tree.SetPyData(new_tree_node,self) 354 tree.SetPyData(new_tree_node,self)
362 355
363 def get_mod(self,name): 356 def get_mod(self,name):
364 skill = self.skills[name] 357 skill = self.skills[name]
365 stat = skill.getAttribute('stat') 358 stat = skill.get('stat')
366 ac = int(skill.getAttribute('armorcheck')) 359 ac = int(skill.get('armorcheck'))
367 if ac: 360 if ac:
368 ac = self.char_hander.child_handlers['ac'].get_check_pen() 361 ac = self.char_hander.child_handlers['ac'].get_check_pen()
369 stat_mod = self.char_hander.child_handlers['abilities'].get_mod(stat) 362 stat_mod = self.char_hander.child_handlers['abilities'].get_mod(stat)
370 rank = int(skill.getAttribute('rank')) 363 rank = int(skill.get('rank'))
371 misc = int(skill.getAttribute('misc')) 364 misc = int(skill.get('misc'))
372 total = stat_mod + rank + misc + ac 365 total = stat_mod + rank + misc + ac
373 return total 366 return total
374 367
375 def on_rclick(self,evt): 368 def on_rclick(self,evt):
376 item = self.tree.GetSelection() 369 item = self.tree.GetSelection()
380 #wnd = skill_grid(self.frame.note,self) 373 #wnd = skill_grid(self.frame.note,self)
381 #wnd.title = "Skills 374 #wnd.title = "Skills
382 #self.frame.add_panel(wnd) 375 #self.frame.add_panel(wnd)
383 else: 376 else:
384 skill = self.skills[name]; 377 skill = self.skills[name];
385 untrained = skill.getAttribute('untrained'); 378 untrained = skill.get('untrained');
386 rank = skill.getAttribute('rank'); 379 rank = skill.get('rank');
387 if untrained == "0" and rank == "0": 380 if untrained == "0" and rank == "0":
388 txt = '%s Skill Check: Untrained' % (name) 381 txt = '%s Skill Check: Untrained' % (name)
389 else: 382 else:
390 mod = self.get_mod(name) 383 mod = self.get_mod(name)
391 if mod >= 0: 384 if mod >= 0:
402 return wnd 395 return wnd
403 396
404 def tohtml(self): 397 def tohtml(self):
405 html_str = """<table border='1' width=100% ><tr BGCOLOR=#E9E9E9 ><th width='30%'>Skill</th><th>Key</th> 398 html_str = """<table border='1' width=100% ><tr BGCOLOR=#E9E9E9 ><th width='30%'>Skill</th><th>Key</th>
406 <th>Rank</th><th>Abil</th><th>Misc</th><th>Total</th></tr>""" 399 <th>Rank</th><th>Abil</th><th>Misc</th><th>Total</th></tr>"""
407 node_list = self.master_dom.getElementsByTagName('skill') 400 for n in self.xml.findall('skill'):
408 for n in node_list: 401 name = n.get('name')
409 name = n.getAttribute('name') 402 stat = n.get('stat')
410 stat = n.getAttribute('stat') 403 rank = n.get('rank')
411 rank = n.getAttribute('rank')
412 html_str = html_str + "<tr ALIGN='center'><td>"+name+"</td><td>"+stat+"</td><td>"+rank+"</td>" 404 html_str = html_str + "<tr ALIGN='center'><td>"+name+"</td><td>"+stat+"</td><td>"+rank+"</td>"
413 stat_mod = str(self.char_hander.child_handlers['abilities'].get_mod(stat)) 405 stat_mod = str(self.char_hander.child_handlers['abilities'].get_mod(stat))
414 misc = n.getAttribute('misc') 406 misc = n.get('misc')
415 mod = str(self.get_mod(name)) 407 mod = str(self.get_mod(name))
416 if mod >= 0: 408 if mod >= 0:
417 mod1 = "+" 409 mod1 = "+"
418 else: 410 else:
419 mod1 = "" 411 mod1 = ""
424 416
425 class d20ability(d20_char_child): 417 class d20ability(d20_char_child):
426 """ Node Handler for ability. This handler will be 418 """ Node Handler for ability. This handler will be
427 created by d20char_handler. 419 created by d20char_handler.
428 """ 420 """
429 def __init__(self,xml_dom,tree_node,parent): 421 def __init__(self,xml,tree_node,parent):
430 d20_char_child.__init__(self,xml_dom,tree_node,parent) 422 d20_char_child.__init__(self,xml,tree_node,parent)
431 self.abilities = {} 423 self.abilities = {}
432 node_list = self.master_dom.getElementsByTagName('stat')
433 tree = self.tree 424 tree = self.tree
434 icons = tree.icons 425 icons = tree.icons
435 for n in node_list: 426 for n in self.xml.findall('stat'):
436 name = n.getAttribute('abbr') 427 name = n.get('abbr')
437 self.abilities[name] = n 428 self.abilities[name] = n
438 new_tree_node = tree.AppendItem( self.mytree_node, name, icons['gear'], icons['gear'] ) 429 new_tree_node = tree.AppendItem( self.mytree_node, name, icons['gear'], icons['gear'] )
439 tree.SetPyData( new_tree_node, self ) 430 tree.SetPyData( new_tree_node, self )
440 431
441 def on_rclick( self, evt ): 432 def on_rclick( self, evt ):
452 chat = self.chat 443 chat = self.chat
453 txt = '%s check: [1d20%s%s]' % ( name, mod1, mod ) 444 txt = '%s check: [1d20%s%s]' % ( name, mod1, mod )
454 chat.ParsePost( txt, True, True ) 445 chat.ParsePost( txt, True, True )
455 446
456 def get_mod(self,abbr): 447 def get_mod(self,abbr):
457 score = int(self.abilities[abbr].getAttribute('base')) 448 score = int(self.abilities[abbr].get('base'))
458 mod = (score - 10) / 2 449 mod = (score - 10) / 2
459 return mod 450 return mod
460 451
461 def set_score(self,abbr,score): 452 def set_score(self,abbr,score):
462 if score >= 0: 453 if score >= 0:
463 self.abilities[abbr].setAttribute("base",str(score)) 454 self.abilities[abbr].set("base",str(score))
464 455
465 def get_design_panel(self,parent): 456 def get_design_panel(self,parent):
466 wnd = outline_panel(parent,self,abil_grid,"Abilities") 457 wnd = outline_panel(parent,self,abil_grid,"Abilities")
467 wnd.title = "Abilities (edit)" 458 wnd.title = "Abilities (edit)"
468 return wnd 459 return wnd
469 460
470 def tohtml(self): 461 def tohtml(self):
471 html_str = """<table border='1' width=100%><tr BGCOLOR=#E9E9E9 ><th width='50%'>Ability</th> 462 html_str = """<table border='1' width=100%><tr BGCOLOR=#E9E9E9 ><th width='50%'>Ability</th>
472 <th>Base</th><th>Modifier</th></tr>""" 463 <th>Base</th><th>Modifier</th></tr>"""
473 node_list = self.master_dom.getElementsByTagName('stat') 464 for n in self.xml.findall('stat'):
474 for n in node_list: 465 name = n.get('name')
475 name = n.getAttribute('name') 466 abbr = n.get('abbr')
476 abbr = n.getAttribute('abbr') 467 base = n.get('base')
477 base = n.getAttribute('base')
478 mod = str(self.get_mod(abbr)) 468 mod = str(self.get_mod(abbr))
479 if mod >= 0: 469 if mod >= 0:
480 mod1 = "+" 470 mod1 = "+"
481 else: 471 else:
482 mod1 = "" 472 mod1 = ""
483 html_str = html_str + "<tr ALIGN='center'><td>"+name+"</td><td>"+base+'</td><td>%s%s</td></tr>' % (mod1, mod) 473 html_str = html_str + "<tr ALIGN='center'><td>"+name+"</td><td>"+base+'</td><td>%s%s</td></tr>' % (mod1, mod)
484 html_str = html_str + "</table>" 474 html_str = html_str + "</table>"
485 return html_str 475 return html_str
486 476
477
487 class d20saves(d20_char_child): 478 class d20saves(d20_char_child):
488 """ Node Handler for saves. This handler will be 479 """ Node Handler for saves. This handler will be
489 created by d20char_handler. 480 created by d20char_handler.
490 """ 481 """
491 def __init__(self,xml_dom,tree_node,parent): 482 def __init__(self,xml,tree_node,parent):
492 d20_char_child.__init__(self,xml_dom,tree_node,parent) 483 d20_char_child.__init__(self,xml,tree_node,parent)
493 tree = self.tree 484 tree = self.tree
494 icons = self.tree.icons 485 icons = self.tree.icons
495 node_list = self.master_dom.getElementsByTagName('save')
496 self.saves={} 486 self.saves={}
497 for n in node_list: 487 for n in self.xml.findall('save'):
498 name = n.getAttribute('name') 488 name = n.get('name')
499 self.saves[name] = n 489 self.saves[name] = n
500 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear']) 490 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear'])
501 tree.SetPyData(new_tree_node,self) 491 tree.SetPyData(new_tree_node,self)
502 492
503 def get_mod(self,name): 493 def get_mod(self,name):
504 save = self.saves[name] 494 save = self.saves[name]
505 stat = save.getAttribute('stat') 495 stat = save.get('stat')
506 stat_mod = self.char_hander.child_handlers['abilities'].get_mod(stat) 496 stat_mod = self.char_hander.child_handlers['abilities'].get_mod(stat)
507 base = int(save.getAttribute('base')) 497 base = int(save.get('base'))
508 miscmod = int(save.getAttribute('miscmod')) 498 miscmod = int(save.get('miscmod'))
509 magmod = int(save.getAttribute('magmod')) 499 magmod = int(save.get('magmod'))
510 total = stat_mod + base + miscmod + magmod 500 total = stat_mod + base + miscmod + magmod
511 return total 501 return total
512 502
513 def on_rclick(self,evt): 503 def on_rclick(self,evt):
514 item = self.tree.GetSelection() 504 item = self.tree.GetSelection()
535 525
536 def tohtml(self): 526 def tohtml(self):
537 html_str = """<table border='1' width=100% ><tr BGCOLOR=#E9E9E9 ><th width='30%'>Save</th> 527 html_str = """<table border='1' width=100% ><tr BGCOLOR=#E9E9E9 ><th width='30%'>Save</th>
538 <th>Key</th><th>Base</th><th>Abil</th><th>Magic</th> 528 <th>Key</th><th>Base</th><th>Abil</th><th>Magic</th>
539 <th>Misc</th><th>Total</th></tr>""" 529 <th>Misc</th><th>Total</th></tr>"""
540 node_list = self.master_dom.getElementsByTagName('save') 530 for n in self.xml.findall('save'):
541 for n in node_list: 531 name = n.get('name')
542 name = n.getAttribute('name') 532 stat = n.get('stat')
543 stat = n.getAttribute('stat') 533 base = n.get('base')
544 base = n.getAttribute('base')
545 html_str = html_str + "<tr ALIGN='center'><td>"+name+"</td><td>"+stat+"</td><td>"+base+"</td>" 534 html_str = html_str + "<tr ALIGN='center'><td>"+name+"</td><td>"+stat+"</td><td>"+base+"</td>"
546 stat_mod = str(self.char_hander.child_handlers['abilities'].get_mod(stat)) 535 stat_mod = str(self.char_hander.child_handlers['abilities'].get_mod(stat))
547 mag = n.getAttribute('magmod') 536 mag = n.get('magmod')
548 misc = n.getAttribute('miscmod') 537 misc = n.get('miscmod')
549 mod = str(self.get_mod(name)) 538 mod = str(self.get_mod(name))
550 if mod >= 0: 539 if mod >= 0:
551 mod1 = "+" 540 mod1 = "+"
552 else: 541 else:
553 mod1 = "" 542 mod1 = ""
559 548
560 class d20general(d20_char_child): 549 class d20general(d20_char_child):
561 """ Node Handler for general information. This handler will be 550 """ Node Handler for general information. This handler will be
562 created by d20char_handler. 551 created by d20char_handler.
563 """ 552 """
564 def __init__(self,xml_dom,tree_node,parent): 553 def __init__(self,xml,tree_node,parent):
565 d20_char_child.__init__(self,xml_dom,tree_node,parent) 554 d20_char_child.__init__(self,xml,tree_node,parent)
566 555
567 def get_design_panel(self,parent): 556 def get_design_panel(self,parent):
568 wnd = outline_panel(parent,self,gen_grid,"General Information") 557 wnd = outline_panel(parent,self,gen_grid,"General Information")
569 wnd.title = "General Info" 558 wnd.title = "General Info"
570 return wnd 559 return wnd
571 560
572 def tohtml(self): 561 def tohtml(self):
573 n_list = self.master_dom._get_childNodes()
574 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>General Information</th></tr><tr><td>" 562 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>General Information</th></tr><tr><td>"
575 for n in n_list: 563 for n in self.xml:
576 t_node = component.get('xml').safe_get_text_node(n) 564 html_str += "<B>"+n.tag.capitalize() +":</B> "
577 html_str += "<B>"+n._get_tagName().capitalize() +":</B> " 565 html_str += n.text + ", "
578 html_str += t_node._get_nodeValue() + ", "
579 html_str = html_str[:len(html_str)-2] + "</td></tr></table>" 566 html_str = html_str[:len(html_str)-2] + "</td></tr></table>"
580 return html_str 567 return html_str
581 568
582 def on_name_change(self,name): 569 def on_name_change(self,name):
583 self.char_hander.rename(name) 570 self.char_hander.rename(name)
584 571
585 def get_char_name( self ): 572 def get_char_name( self ):
586 node = self.master_dom.getElementsByTagName( 'name' )[0] 573 return self.xml.find( 'name' ).text
587 t_node = component.get('xml').safe_get_text_node( node )
588 return t_node._get_nodeValue()
589 574
590 575
591 class d20classes(d20_char_child): 576 class d20classes(d20_char_child):
592 """ Node Handler for classes. This handler will be 577 """ Node Handler for classes. This handler will be
593 created by d20char_handler. 578 created by d20char_handler.
594 """ 579 """
595 def __init__(self,xml_dom,tree_node,parent): 580 def __init__(self,xml,tree_node,parent):
596 d20_char_child.__init__(self,xml_dom,tree_node,parent) 581 d20_char_child.__init__(self,xml,tree_node,parent)
597 582
598 def get_design_panel(self,parent): 583 def get_design_panel(self,parent):
599 wnd = outline_panel(parent,self,class_panel,"Classes") 584 wnd = outline_panel(parent,self,class_panel,"Classes")
600 wnd.title = "Classes" 585 wnd.title = "Classes"
601 return wnd 586 return wnd
602 587
603 def tohtml(self): 588 def tohtml(self):
604 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>Classes</th></tr><tr><td>" 589 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>Classes</th></tr><tr><td>"
605 n_list = self.master_dom._get_childNodes() 590 for n in self.xml:
606 for n in n_list: 591 html_str += n.get('name') + " ("+n.get('level')+"), "
607 html_str += n.getAttribute('name') + " ("+n.getAttribute('level')+"), "
608 html_str = html_str[:len(html_str)-2] + "</td></tr></table>" 592 html_str = html_str[:len(html_str)-2] + "</td></tr></table>"
609 return html_str 593 return html_str
610 594
611 def get_char_lvl( self, attr ): 595 def get_char_lvl( self, attr ):
612 node_list = self.master_dom.getElementsByTagName('class') 596 for n in self.xml.findall('class'):
613 for n in node_list: 597 lvl = n.get('level')
614 lvl = n.getAttribute('level') 598 type = n.get('name')
615 type = n.getAttribute('name')
616 if attr == "level": 599 if attr == "level":
617 return lvl 600 return lvl
618 elif attr == "class": 601 elif attr == "class":
619 return type 602 return type
620 603
621 604
622 class d20feats(d20_char_child): 605 class d20feats(d20_char_child):
623 """ Node Handler for classes. This handler will be 606 """ Node Handler for classes. This handler will be
624 created by d20char_handler. 607 created by d20char_handler.
625 """ 608 """
626 def __init__(self,xml_dom,tree_node,parent): 609 def __init__(self,xml,tree_node,parent):
627 d20_char_child.__init__(self,xml_dom,tree_node,parent) 610 d20_char_child.__init__(self,xml,tree_node,parent)
628 611
629 def get_design_panel(self,parent): 612 def get_design_panel(self,parent):
630 wnd = outline_panel(parent,self,feat_panel,"Feats") 613 wnd = outline_panel(parent,self,feat_panel,"Feats")
631 wnd.title = "Feats" 614 wnd.title = "Feats"
632 return wnd 615 return wnd
633 616
634 def tohtml(self): 617 def tohtml(self):
635 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>Feats</th></tr><tr><td>" 618 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>Feats</th></tr><tr><td>"
636 n_list = self.master_dom._get_childNodes() 619 for n in self.xml:
637 for n in n_list: 620 html_str += n.get('name')+ ", "
638 html_str += n.getAttribute('name')+ ", "
639 html_str = html_str[:len(html_str)-2] + "</td></tr></table>" 621 html_str = html_str[:len(html_str)-2] + "</td></tr></table>"
640 return html_str 622 return html_str
623
641 624
642 class d20spells(d20_char_child): 625 class d20spells(d20_char_child):
643 """ Node Handler for classes. This handler will be 626 """ Node Handler for classes. This handler will be
644 created by d20char_handler. 627 created by d20char_handler.
645 """ 628 """
646 def __init__(self,xml_dom,tree_node,parent): 629 def __init__(self,xml,tree_node,parent):
647 d20_char_child.__init__(self,xml_dom,tree_node,parent) 630 d20_char_child.__init__(self,xml,tree_node,parent)
648 node_list = self.master_dom.getElementsByTagName( 'spell' )
649 self.spells = {} 631 self.spells = {}
650 tree = self.tree 632 tree = self.tree
651 icons = self.tree.icons 633 icons = self.tree.icons
652 for n in node_list: 634 for n in self.xml.findall( 'spell' ):
653 name = n.getAttribute('name') 635 name = n.get('name')
654 self.spells[ name ] = n 636 self.spells[ name ] = n
655 new_tree_node = tree.AppendItem( self.mytree_node, name, icons['gear'], icons['gear'] ) 637 new_tree_node = tree.AppendItem( self.mytree_node, name, icons['gear'], icons['gear'] )
656 tree.SetPyData( new_tree_node, self ) 638 tree.SetPyData( new_tree_node, self )
657 639
658 def on_rclick( self, evt ): 640 def on_rclick( self, evt ):
659 item = self.tree.GetSelection() 641 item = self.tree.GetSelection()
660 name = self.tree.GetItemText( item ) 642 name = self.tree.GetItemText( item )
661 if item == self.mytree_node: 643 if item == self.mytree_node:
662 d20_char_child.on_ldclick( self, evt ) 644 d20_char_child.on_ldclick( self, evt )
663 else: 645 else:
664 level = self.spells[ name ].getAttribute( 'level' ) 646 level = self.spells[ name ].get( 'level' )
665 descr = self.spells[ name ].getAttribute( 'desc' ) 647 descr = self.spells[ name ].get( 'desc' )
666 use = self.spells[ name ].getAttribute( 'used' ) 648 use = self.spells[ name ].get( 'used' )
667 memrz = self.spells[ name ].getAttribute( 'memrz' ) 649 memrz = self.spells[ name ].get( 'memrz' )
668 cname = self.char_hander.get_char_name() 650 cname = self.char_hander.get_char_name()
669 use += '+1' 651 use += '+1'
670 left = eval( '%s - ( %s )' % ( memrz, use ) ) 652 left = eval( '%s - ( %s )' % ( memrz, use ) )
671 if left < 0: 653 if left < 0:
672 txt = '%s Tried to cast %s but has used all of them for today, "Please rest so I can cast more."' % ( cname, name ) 654 txt = '%s Tried to cast %s but has used all of them for today, "Please rest so I can cast more."' % ( cname, name )
677 s = '' 659 s = ''
678 if left != 1: 660 if left != 1:
679 s = 's' 661 s = 's'
680 txt = '%s can cast %s %d more time%s' % ( cname, name, left, s ) 662 txt = '%s can cast %s %d more time%s' % ( cname, name, left, s )
681 self.chat.ParsePost( txt, False, False ) 663 self.chat.ParsePost( txt, False, False )
682 self.spells[ name ].setAttribute( 'used', `eval( use )` ) 664 self.spells[ name ].set( 'used', `eval( use )` )
683 665
684 def refresh_spells(self): 666 def refresh_spells(self):
685 self.spells = {} 667 self.spells = {}
686 tree = self.tree 668 tree = self.tree
687 icons = self.tree.icons 669 icons = self.tree.icons
688 tree.CollapseAndReset(self.mytree_node) 670 tree.CollapseAndReset(self.mytree_node)
689 node_list = self.master_dom.getElementsByTagName('spell') 671 for n in self.xml.findall('spell'):
690 for n in node_list: 672 name = n.get('name')
691 name = n.getAttribute('name')
692 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear']) 673 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear'])
693 tree.SetPyData(new_tree_node,self) 674 tree.SetPyData(new_tree_node,self)
694 self.spells[name]=n 675 self.spells[name]=n
695 676
696 def get_design_panel(self,parent): 677 def get_design_panel(self,parent):
698 wnd.title = "Spells" 679 wnd.title = "Spells"
699 return wnd 680 return wnd
700 681
701 def tohtml(self): 682 def tohtml(self):
702 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>Arcane Spells</th></tr><tr><td><br />" 683 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>Arcane Spells</th></tr><tr><td><br />"
703 n_list = self.master_dom._get_childNodes() 684 for n in self.xml:
704 for n in n_list: 685 html_str += "(" + n.get('level') + ") " + n.get('name')+ ", "
705 html_str += "(" + n.getAttribute('level') + ") " + n.getAttribute('name')+ ", "
706 html_str = html_str[:len(html_str)-2] + "</td></tr></table>" 686 html_str = html_str[:len(html_str)-2] + "</td></tr></table>"
707 return html_str 687 return html_str
708 688
709 def get_char_lvl( self, attr ): 689 def get_char_lvl( self, attr ):
710 return self.char_hander.get_char_lvl(attr) 690 return self.char_hander.get_char_lvl(attr)
711 691
712 class d20divine(d20_char_child): 692 class d20divine(d20_char_child):
713 """ Node Handler for classes. This handler will be 693 """ Node Handler for classes. This handler will be
714 created by d20char_handler. 694 created by d20char_handler.
715 """ 695 """
716 def __init__(self,xml_dom,tree_node,parent): 696 def __init__(self,xml,tree_node,parent):
717 d20_char_child.__init__(self,xml_dom,tree_node,component,parent) 697 d20_char_child.__init__(self,xml,tree_node,parent)
718 node_list = self.master_dom.getElementsByTagName( 'gift' )
719 self.spells = {} 698 self.spells = {}
720 tree = self.tree 699 tree = self.tree
721 icons = self.tree.icons 700 icons = self.tree.icons
722 for n in node_list: 701 for n in self.xml.findall( 'gift' ):
723 name = n.getAttribute('name') 702 name = n.get('name')
724 self.spells[ name ] = n 703 self.spells[ name ] = n
725 new_tree_node = tree.AppendItem( self.mytree_node, name, icons['flask'], icons['flask'] ) 704 new_tree_node = tree.AppendItem( self.mytree_node, name, icons['flask'], icons['flask'] )
726 tree.SetPyData( new_tree_node, self ) 705 tree.SetPyData( new_tree_node, self )
727 706
728 def on_rclick( self, evt ): 707 def on_rclick( self, evt ):
729 item = self.tree.GetSelection() 708 item = self.tree.GetSelection()
730 name = self.tree.GetItemText( item ) 709 name = self.tree.GetItemText( item )
731 if item == self.mytree_node: 710 if item == self.mytree_node:
732 d20_char_child.on_ldclick( self, evt ) 711 d20_char_child.on_ldclick( self, evt )
733 else: 712 else:
734 level = self.spells[ name ].getAttribute( 'level' ) 713 level = self.spells[ name ].get( 'level' )
735 descr = self.spells[ name ].getAttribute( 'desc' ) 714 descr = self.spells[ name ].get( 'desc' )
736 use = self.spells[ name ].getAttribute( 'used' ) 715 use = self.spells[ name ].get( 'used' )
737 memrz = self.spells[ name ].getAttribute( 'memrz' ) 716 memrz = self.spells[ name ].get( 'memrz' )
738 cname = self.char_hander.get_char_name() 717 cname = self.char_hander.get_char_name()
739 use += '+1' 718 use += '+1'
740 left = eval( '%s - ( %s )' % ( memrz, use ) ) 719 left = eval( '%s - ( %s )' % ( memrz, use ) )
741 if left < 0: 720 if left < 0:
742 txt = '%s Tried to cast %s but has used all of them for today, "Please rest so I can cast more."' % ( cname, name ) 721 txt = '%s Tried to cast %s but has used all of them for today, "Please rest so I can cast more."' % ( cname, name )
747 s = '' 726 s = ''
748 if left != 1: 727 if left != 1:
749 s = 's' 728 s = 's'
750 txt = '%s can cast %s %d more time%s' % ( cname, name, left, s ) 729 txt = '%s can cast %s %d more time%s' % ( cname, name, left, s )
751 self.chat.ParsePost( txt, False, False ) 730 self.chat.ParsePost( txt, False, False )
752 self.spells[ name ].setAttribute( 'used', `eval( use )` ) 731 self.spells[ name ].set( 'used', `eval( use )` )
753 732
754 def refresh_spells(self): 733 def refresh_spells(self):
755 self.spells = {} 734 self.spells = {}
756 tree = self.tree 735 tree = self.tree
757 icons = self.tree.icons 736 icons = self.tree.icons
758 tree.CollapseAndReset(self.mytree_node) 737 tree.CollapseAndReset(self.mytree_node)
759 node_list = self.master_dom.getElementsByTagName('gift') 738 for n in self.xml.findall('gift'):
760 for n in node_list: 739 name = n.get('name')
761 name = n.getAttribute('name')
762 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['flask'],icons['flask']) 740 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['flask'],icons['flask'])
763 tree.SetPyData(new_tree_node,self) 741 tree.SetPyData(new_tree_node,self)
764 self.spells[name]=n 742 self.spells[name]=n
765 743
766 def get_design_panel(self,parent): 744 def get_design_panel(self,parent):
767 wnd = outline_panel(parent,self,divine_panel,"Spells") 745 wnd = outline_panel(parent,self,divine_panel,"Spells")
768 wnd.title = "Spells" 746 wnd.title = "Spells"
769 return wnd 747 return wnd
770 748
771 def tohtml(self): 749 def tohtml(self):
772 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>Divine Spells</th></tr><tr><td><br />" 750 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>Divine Spells</th></tr><tr><td><br />"
773 n_list = self.master_dom._get_childNodes() 751 for n in self.xml:
774 for n in n_list: 752 html_str += "(" + n.get('level') + ") " + n.get('name')+ ", "
775 html_str += "(" + n.getAttribute('level') + ") " + n.getAttribute('name')+ ", "
776 html_str = html_str[:len(html_str)-2] + "</td></tr></table>" 753 html_str = html_str[:len(html_str)-2] + "</td></tr></table>"
777 return html_str 754 return html_str
778 755
779 def get_char_lvl( self, attr ): 756 def get_char_lvl( self, attr ):
780 return self.char_hander.get_char_lvl(attr) 757 return self.char_hander.get_char_lvl(attr)
781 758
782 class d20powers(d20_char_child): 759 class d20powers(d20_char_child):
783 """ Node Handler for classes. This handler will be 760 """ Node Handler for classes. This handler will be
784 created by d20char_handler. 761 created by d20char_handler.
785 """ 762 """
786 def __init__(self,xml_dom,tree_node,parent): 763 def __init__(self,xml,tree_node,parent):
787 d20_char_child.__init__(self,xml_dom,tree_node,parent) 764 d20_char_child.__init__(self,xml,tree_node,parent)
788 node_list = self.master_dom.getElementsByTagName( 'power' ) 765 #cpp = self.xml.findall( 'pp' ).get('current1')
789 #cpp = self.master_dom.getElementsByTagName( 'pp' ).getAttribute('current1')
790 self.powers = {} 766 self.powers = {}
791 tree = self.tree 767 tree = self.tree
792 icons = self.tree.icons 768 icons = self.tree.icons
793 for n in node_list: 769 for n in self.xml.findall( 'power' ):
794 name = n.getAttribute('name') 770 name = n.get('name')
795 self.powers[ name ] = n 771 self.powers[ name ] = n
796 new_tree_node = tree.AppendItem( self.mytree_node, name, icons['gear'], icons['gear'] ) 772 new_tree_node = tree.AppendItem( self.mytree_node, name, icons['gear'], icons['gear'] )
797 tree.SetPyData( new_tree_node, self ) 773 tree.SetPyData( new_tree_node, self )
798 774
799 def on_rclick( self, evt ): 775 def on_rclick( self, evt ):
800 item = self.tree.GetSelection() 776 item = self.tree.GetSelection()
801 name = self.tree.GetItemText( item ) 777 name = self.tree.GetItemText( item )
802 if item == self.mytree_node: 778 if item == self.mytree_node:
803 d20_char_child.on_ldclick( self, evt ) 779 d20_char_child.on_ldclick( self, evt )
804 else: 780 else:
805 level = self.powers[ name ].getAttribute( 'level' ) 781 level = self.powers[ name ].get( 'level' )
806 descr = self.powers[ name ].getAttribute( 'desc' ) 782 descr = self.powers[ name ].get( 'desc' )
807 use = self.powers[ name ].getAttribute( 'used' ) 783 use = self.powers[ name ].get( 'used' )
808 points = self.powers[ name ].getAttribute( 'point' ) 784 points = self.powers[ name ].get( 'point' )
809 cpp = self.char_hander.get_char_pp('current1') 785 cpp = self.char_hander.get_char_pp('current1')
810 fre = self.char_hander.get_char_pp('free') 786 fre = self.char_hander.get_char_pp('free')
811 cname = self.char_hander.get_char_name() 787 cname = self.char_hander.get_char_name()
812 if level == "0" and fre != "0": 788 if level == "0" and fre != "0":
813 left = eval('%s - ( %s )' % ( fre, points )) 789 left = eval('%s - ( %s )' % ( fre, points ))
835 self.chat.ParsePost( txt, True, False ) 811 self.chat.ParsePost( txt, True, False )
836 s = '' 812 s = ''
837 if left != 1: 813 if left != 1:
838 s = 's' 814 s = 's'
839 txt = '%s can use %s %d more time%s' % ( cname, name, numcast, s ) 815 txt = '%s can use %s %d more time%s' % ( cname, name, numcast, s )
840 txt += ' - And has %d more PowerpointsP left' % (left) 816 txt += ' - And has %d more Powerpoints left' % (left)
841 self.chat.ParsePost( txt, False, False ) 817 self.chat.ParsePost( txt, False, False )
842 self.char_hander.set_char_pp('current1', left) 818 self.char_hander.set_char_pp('current1', left)
843 819
844 def refresh_powers(self): 820 def refresh_powers(self):
845 self.powers = {} 821 self.powers = {}
846 tree = self.tree 822 tree = self.tree
847 icons = self.tree.icons 823 icons = self.tree.icons
848 tree.CollapseAndReset(self.mytree_node) 824 tree.CollapseAndReset(self.mytree_node)
849 node_list = self.master_dom.getElementsByTagName('power') 825 for n in self.xml.findall('power'):
850 for n in node_list: 826 name = n.get('name')
851 name = n.getAttribute('name')
852 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['questionhead'],icons['questionhead']) 827 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['questionhead'],icons['questionhead'])
853 tree.SetPyData(new_tree_node,self) 828 tree.SetPyData(new_tree_node,self)
854 self.powers[name]=n 829 self.powers[name]=n
855 830
856 def get_design_panel(self,parent): 831 def get_design_panel(self,parent):
858 wnd.title = "Powers" 833 wnd.title = "Powers"
859 return wnd 834 return wnd
860 835
861 def tohtml(self): 836 def tohtml(self):
862 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>Powers</th></tr><tr><td><br />" 837 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>Powers</th></tr><tr><td><br />"
863 n_list = self.master_dom._get_childNodes() 838 for n in self.xml:
864 for n in n_list: 839 html_str += "(" + n.get('level') + ") " + n.get('name')+ ", "
865 html_str += "(" + n.getAttribute('level') + ") " + n.getAttribute('name')+ ", "
866 html_str = html_str[:len(html_str)-2] + "</td></tr></table>" 840 html_str = html_str[:len(html_str)-2] + "</td></tr></table>"
867 return html_str 841 return html_str
868 842
869 def get_char_lvl( self, attr ): 843 def get_char_lvl( self, attr ):
870 return self.char_hander.get_char_lvl(attr) 844 return self.char_hander.get_char_lvl(attr)
877 851
878 class d20howto(d20_char_child): 852 class d20howto(d20_char_child):
879 """ Node Handler for hit points. This handler will be 853 """ Node Handler for hit points. This handler will be
880 created by d20char_handler. 854 created by d20char_handler.
881 """ 855 """
882 def __init__(self,xml_dom,tree_node,parent): 856 def __init__(self,xml,tree_node,parent):
883 d20_char_child.__init__(self,xml_dom,tree_node,parent) 857 d20_char_child.__init__(self,xml,tree_node,parent)
884 858
885 def get_design_panel(self,parent): 859 def get_design_panel(self,parent):
886 wnd = outline_panel(parent,self,howto_panel,"How To") 860 wnd = outline_panel(parent,self,howto_panel,"How To")
887 wnd.title = "How To" 861 wnd.title = "How To"
888 return wnd 862 return wnd
889 863
890 class d20inventory(d20_char_child): 864 class d20inventory(d20_char_child):
891 """ Node Handler for general information. This handler will be 865 """ Node Handler for general information. This handler will be
892 created by d20char_handler. 866 created by d20char_handler.
893 """ 867 """
894 def __init__(self,xml_dom,tree_node,parent): 868 def __init__(self,xml,tree_node,parent):
895 d20_char_child.__init__(self,xml_dom,tree_node,parent) 869 d20_char_child.__init__(self,xml,tree_node,parent)
896 870
897 def get_design_panel(self,parent): 871 def get_design_panel(self,parent):
898 wnd = outline_panel(parent,self,inventory_grid,"Inventory") 872 wnd = outline_panel(parent,self,inventory_grid,"Inventory")
899 wnd.title = "General Info" 873 wnd.title = "General Info"
900 return wnd 874 return wnd
901 875
902 def tohtml(self): 876 def tohtml(self):
903 n_list = self.master_dom._get_childNodes()
904 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>General Information</th></tr><tr><td>" 877 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>General Information</th></tr><tr><td>"
905 for n in n_list: 878 for n in self.xml:
906 t_node = component.get('xml').safe_get_text_node(n) 879 html_str += "<B>"+n.tag.capitalize() +":</B> "
907 html_str += "<B>"+n._get_tagName().capitalize() +":</B> " 880 html_str += n.text + "<br />"
908 html_str += t_node._get_nodeValue() + "<br />"
909 html_str = html_str[:len(html_str)-2] + "</td></tr></table>" 881 html_str = html_str[:len(html_str)-2] + "</td></tr></table>"
910 return html_str 882 return html_str
911 883
912 def on_name_change(self,name): 884 def on_name_change(self,name):
913 self.char_hander.rename(name) 885 self.char_hander.rename(name)
914 886
915 def get_char_name( self ): 887 def get_char_name( self ):
916 node = self.master_dom.getElementsByTagName( 'name' )[0] 888 return self.xml.find( 'name' ).text
917 t_node = component.get('xml').safe_get_text_node( node ) 889
918 return t_node._get_nodeValue()
919 890
920 class d20hp(d20_char_child): 891 class d20hp(d20_char_child):
921 """ Node Handler for hit points. This handler will be 892 """ Node Handler for hit points. This handler will be
922 created by d20char_handler. 893 created by d20char_handler.
923 """ 894 """
924 def __init__(self,xml_dom,tree_node,parent): 895 def __init__(self,xml,tree_node,parent):
925 d20_char_child.__init__(self,xml_dom,tree_node,parent) 896 d20_char_child.__init__(self,xml,tree_node,parent)
926 897
927 def get_design_panel(self,parent): 898 def get_design_panel(self,parent):
928 wnd = outline_panel(parent,self,hp_panel,"Hit Points") 899 wnd = outline_panel(parent,self,hp_panel,"Hit Points")
929 wnd.title = "Hit Points" 900 wnd.title = "Hit Points"
930 return wnd 901 return wnd
931 902
932 def tohtml(self): 903 def tohtml(self):
933 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th colspan=4>Hit Points</th></tr>" 904 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th colspan=4>Hit Points</th></tr>"
934 html_str += "<tr><th>Max:</th><td>"+self.master_dom.getAttribute('max')+"</td>" 905 html_str += "<tr><th>Max:</th><td>"+self.xml.get('max')+"</td>"
935 html_str += "<th>Current:</th><td>"+self.master_dom.getAttribute('current')+"</td>" 906 html_str += "<th>Current:</th><td>"+self.xml.get('current')+"</td>"
936 html_str += "</tr></table>" 907 html_str += "</tr></table>"
937 return html_str 908 return html_str
938 909
939 def get_max_hp( self ): 910 def get_max_hp( self ):
940 try: 911 try:
941 return eval( self.master_dom.getAttribute( 'max' ) ) 912 return eval( self.xml.get( 'max' ) )
942 except: 913 except:
943 return 0 914 return 0
944 def get_current_hp( self ): 915 def get_current_hp( self ):
945 try: 916 try:
946 return eval( self.master_dom.getAttribute( 'current' ) ) 917 return eval( self.xml.get( 'current' ) )
947 except: 918 except:
948 return 0 919 return 0
949 920
950 class d20pp(d20_char_child): 921 class d20pp(d20_char_child):
951 """ Node Handler for power points. This handler will be 922 """ Node Handler for power points. This handler will be
952 created by d20char_handler. 923 created by d20char_handler.
953 """ 924 """
954 def __init__(self,xml_dom,tree_node,parent): 925 def __init__(self,xml,tree_node,parent):
955 d20_char_child.__init__(self,xml_dom,tree_node,parent) 926 d20_char_child.__init__(self,xml,tree_node,parent)
956 927
957 def get_design_panel(self,parent): 928 def get_design_panel(self,parent):
958 wnd = outline_panel(parent,self,pp_panel,"Power Points") 929 wnd = outline_panel(parent,self,pp_panel,"Power Points")
959 wnd.title = "Power Points" 930 wnd.title = "Power Points"
960 return wnd 931 return wnd
961 932
962 def tohtml(self): 933 def tohtml(self):
963 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th colspan=8>Power Points</th></tr>" 934 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th colspan=8>Power Points</th></tr>"
964 html_str += "<tr><th>Max:</th><td>"+self.master_dom.getAttribute('max1')+"</td>" 935 html_str += "<tr><th>Max:</th><td>"+self.xml.get('max1')+"</td>"
965 html_str += "<th>Current:</th><td>"+self.master_dom.getAttribute('current1')+"</td>" 936 html_str += "<th>Current:</th><td>"+self.xml.get('current1')+"</td>"
966 html_str += "<th>Current Talents/day:</th><td>"+self.master_dom.getAttribute('free')+"</td>" 937 html_str += "<th>Current Talents/day:</th><td>"+self.xml.get('free')+"</td>"
967 html_str += "<th>Max Talents/day:</th><td>"+self.master_dom.getAttribute('maxfree')+"</td>" 938 html_str += "<th>Max Talents/day:</th><td>"+self.xml.get('maxfree')+"</td>"
968 html_str += "</tr></table>" 939 html_str += "</tr></table>"
969 return html_str 940 return html_str
970 941
971 def get_char_pp( self, attr ): 942 def get_char_pp( self, attr ):
972 pp = self.master_dom.getAttribute(attr) 943 pp = self.xml.get(attr)
973 return pp 944 return pp
974 945
975 def set_char_pp( self, attr, evl ): 946 def set_char_pp( self, attr, evl ):
976 pp = self.master_dom.setAttribute(attr, evl) 947 pp = self.xml.set(attr, evl)
977 return pp 948 return pp
978 949
979 class d20attacks(d20_char_child): 950 class d20attacks(d20_char_child):
980 """ Node Handler for attacks. This handler will be 951 """ Node Handler for attacks. This handler will be
981 created by d20char_handler. 952 created by d20char_handler.
982 """ 953 """
983 def __init__(self,xml_dom,tree_node,parent): 954 def __init__(self,xml,tree_node,parent):
984 d20_char_child.__init__(self,xml_dom,tree_node,parent) 955 d20_char_child.__init__(self,xml,tree_node,parent)
985 node_list = self.master_dom.getElementsByTagName('melee') 956 node_list = self.xml.findall('melee')
986 self.melee = node_list[0] 957 self.melee = node_list[0]
987 node_list = self.master_dom.getElementsByTagName('ranged') 958 node_list = self.xml.findall('ranged')
988 self.ranged = node_list[0] 959 self.ranged = node_list[0]
989 self.refresh_weapons() 960 self.refresh_weapons()
990 961
991 def refresh_weapons(self): 962 def refresh_weapons(self):
992 self.weapons = {} 963 self.weapons = {}
993 tree = self.tree 964 tree = self.tree
994 icons = self.tree.icons 965 icons = self.tree.icons
995 tree.CollapseAndReset(self.mytree_node) 966 tree.CollapseAndReset(self.mytree_node)
996 node_list = self.master_dom.getElementsByTagName('weapon') 967 node_list = self.xml.findall('weapon')
997 for n in node_list: 968 for n in node_list:
998 name = n.getAttribute('name') 969 name = n.get('name')
999 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['sword'],icons['sword']) 970 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['sword'],icons['sword'])
1000 tree.SetPyData(new_tree_node,self) 971 tree.SetPyData(new_tree_node,self)
1001 self.weapons[name]=n 972 self.weapons[name]=n
1002 973
1003 def get_attack_data(self): 974 def get_attack_data(self):
1004 temp = self.melee 975 temp = self.melee
1005 base = int(temp.getAttribute('base')) 976 base = int(temp.get('base'))
1006 base2 = int(temp.getAttribute('second')) 977 base2 = int(temp.get('second'))
1007 base3 = int(temp.getAttribute('third')) 978 base3 = int(temp.get('third'))
1008 base4 = int(temp.getAttribute('forth')) 979 base4 = int(temp.get('forth'))
1009 base5 = int(temp.getAttribute('fifth')) 980 base5 = int(temp.get('fifth'))
1010 base6 = int(temp.getAttribute('sixth')) 981 base6 = int(temp.get('sixth'))
1011 misc = int(temp.getAttribute('misc')) 982 misc = int(temp.get('misc'))
1012 return (base, base2, base3, base4, base5, base6, misc) 983 return (base, base2, base3, base4, base5, base6, misc)
1013 984
1014 # Replace any 'S' and 'D' in an attack modifier and damage modifier with the 985 # Replace any 'S' and 'D' in an attack modifier and damage modifier with the
1015 # strength bonus or dexterity bonus respectively. 986 # strength bonus or dexterity bonus respectively.
1016 def process_mod_codes( self, attack, damage ): 987 def process_mod_codes( self, attack, damage ):
1036 if item == self.mytree_node: 1007 if item == self.mytree_node:
1037 d20_char_child.on_ldclick(self,evt) 1008 d20_char_child.on_ldclick(self,evt)
1038 #self.frame.add_panel(self.get_design_panel(self.frame.note)) 1009 #self.frame.add_panel(self.get_design_panel(self.frame.note))
1039 else: 1010 else:
1040 # Weapon/attack specific attack modifier (e.g. "S+1" for a longsword+1). 1011 # Weapon/attack specific attack modifier (e.g. "S+1" for a longsword+1).
1041 attack_mod_str = self.weapons[name].getAttribute('mod') 1012 attack_mod_str = self.weapons[name].get('mod')
1042 1013
1043 # Weapon/attack specific damage (e.g. "1d8+S+1" for a longsword+1). 1014 # Weapon/attack specific damage (e.g. "1d8+S+1" for a longsword+1).
1044 damage_str = self.weapons[name].getAttribute('damage') 1015 damage_str = self.weapons[name].get('damage')
1045 (num_damage_dice, damage_die, damage_mods, extra_damage) = self.decompose_damage( damage_str ) 1016 (num_damage_dice, damage_die, damage_mods, extra_damage) = self.decompose_damage( damage_str )
1046 1017
1047 # Replace any 'S' and 'D' in attack_mod_str and damage_str with the 1018 # Replace any 'S' and 'D' in attack_mod_str and damage_str with the
1048 # strength bonus or dexterity bonus respectively. 1019 # strength bonus or dexterity bonus respectively.
1049 (attack_mod_str, damage_mods) = self.process_mod_codes( attack_mod_str, damage_mods ) 1020 (attack_mod_str, damage_mods) = self.process_mod_codes( attack_mod_str, damage_mods )
1050 1021
1051 # Base attack bonuses for up to six attacks. 1022 # Base attack bonuses for up to six attacks.
1052 bab_attributes = ['base', 'second', 'third', 'forth', 'fifth', 'sixth'] 1023 bab_attributes = ['base', 'second', 'third', 'forth', 'fifth', 'sixth']
1053 bab = [] 1024 bab = []
1054 for b in bab_attributes: 1025 for b in bab_attributes:
1055 bab.append( int(self.melee.getAttribute( b )) ) 1026 bab.append( int(self.melee.get( b )) )
1056 1027
1057 # Misc. attack modifier to be applied to *all* attacks. 1028 # Misc. attack modifier to be applied to *all* attacks.
1058 misc_mod = int(self.melee.getAttribute( 'misc' )); 1029 misc_mod = int(self.melee.get( 'misc' ));
1059 1030
1060 # Attack modifier (except BAB) 1031 # Attack modifier (except BAB)
1061 attack_mod = misc_mod + eval( attack_mod_str ) 1032 attack_mod = misc_mod + eval( attack_mod_str )
1062 1033
1063 # Total damage mod (except extra dice) 1034 # Total damage mod (except extra dice)
1065 damage_mod = eval( damage_mods ) 1036 damage_mod = eval( damage_mods )
1066 else: 1037 else:
1067 damage_mod = 0 1038 damage_mod = 0
1068 1039
1069 # Determine critical hit range and multiplier. 1040 # Determine critical hit range and multiplier.
1070 critical_str = self.weapons[name].getAttribute( 'critical' ) 1041 critical_str = self.weapons[name].get( 'critical' )
1071 m = re.match( r"(((?P<min>\d+)-)?\d+/)?x(?P<mult>\d+)", critical_str ) 1042 m = re.match( r"(((?P<min>\d+)-)?\d+/)?x(?P<mult>\d+)", critical_str )
1072 crit_min = m.group( 'min' ) 1043 crit_min = m.group( 'min' )
1073 crit_mult = m.group( 'mult' ) 1044 crit_mult = m.group( 'mult' )
1074 if crit_min == None: 1045 if crit_min == None:
1075 crit_min = 20 1046 crit_min = 20
1118 if babs[i] > 0: 1089 if babs[i] > 0:
1119 html_str += '/%+d' % babs[i] 1090 html_str += '/%+d' % babs[i]
1120 html_str += "</td></tr><tr ALIGN='center' ><th BGCOLOR=#E9E9E9>Misc. Attack Bonus</th>" 1091 html_str += "</td></tr><tr ALIGN='center' ><th BGCOLOR=#E9E9E9>Misc. Attack Bonus</th>"
1121 html_str += '<td>%+d</td></tr></table>' % babs[6] 1092 html_str += '<td>%+d</td></tr></table>' % babs[6]
1122 1093
1123 n_list = self.master_dom.getElementsByTagName('weapon') 1094 n_list = self.xml.findall('weapon')
1124 for n in n_list: 1095 for n in n_list:
1125 (attack_mod, damage_mod) = self.process_mod_codes( n.getAttribute( 'mod' ), \ 1096 (attack_mod, damage_mod) = self.process_mod_codes( n.get( 'mod' ), \
1126 n.getAttribute( 'damage' ) ) 1097 n.get( 'damage' ) )
1127 attack_mod = eval( attack_mod ) 1098 attack_mod = eval( attack_mod )
1128 html_str += """<P><table width=100% border=1><tr BGCOLOR=#E9E9E9><th colspan=3>Weapon</th> 1099 html_str += """<P><table width=100% border=1><tr BGCOLOR=#E9E9E9><th colspan=3>Weapon</th>
1129 <th>Attack</th><th >Damage</th></tr>""" \ 1100 <th>Attack</th><th >Damage</th></tr>""" \
1130 + "<tr ALIGN='center'><td colspan=3>" \ 1101 + "<tr ALIGN='center'><td colspan=3>" \
1131 + n.getAttribute('name') + "</td><td>" 1102 + n.get('name') + "</td><td>"
1132 html_str += '%+d</td><td>%s</td></tr>' % (attack_mod, damage_mod) 1103 html_str += '%+d</td><td>%s</td></tr>' % (attack_mod, damage_mod)
1133 html_str += """<tr BGCOLOR=#E9E9E9 ><th>Critical</th><th>Range</th><th>Weight</th> 1104 html_str += """<tr BGCOLOR=#E9E9E9 ><th>Critical</th><th>Range</th><th>Weight</th>
1134 <th>Type</th><th>Size</th></tr>""" \ 1105 <th>Type</th><th>Size</th></tr>""" \
1135 + "<tr ALIGN='center'><td>" \ 1106 + "<tr ALIGN='center'><td>" \
1136 + n.getAttribute( 'critical' ) + "</td><td>" \ 1107 + n.get( 'critical' ) + "</td><td>" \
1137 + n.getAttribute( 'range' ) + "</td><td>" \ 1108 + n.get( 'range' ) + "</td><td>" \
1138 + n.getAttribute( 'weight' )+"</td><td>" \ 1109 + n.get( 'weight' )+"</td><td>" \
1139 + n.getAttribute( 'type' ) + "</td><td>" \ 1110 + n.get( 'type' ) + "</td><td>" \
1140 + n.getAttribute( 'size' ) + "</td></tr></table>" 1111 + n.get( 'size' ) + "</td></tr></table>"
1141 return html_str 1112 return html_str
1142 1113
1143 class d20armor(d20_char_child): 1114 class d20armor(d20_char_child):
1144 """ Node Handler for ac. This handler will be 1115 """ Node Handler for ac. This handler will be
1145 created by d20char_handler. 1116 created by d20char_handler.
1146 """ 1117 """
1147 def __init__(self,xml_dom,tree_node,parent): 1118 def __init__(self,xml,tree_node,parent):
1148 d20_char_child.__init__(self,xml_dom,tree_node,parent) 1119 d20_char_child.__init__(self,xml,tree_node,parent)
1149 1120
1150 def get_spell_failure(self): 1121 def get_spell_failure(self):
1151 return self.get_total('spellfailure') 1122 return self.get_total('spellfailure')
1152 1123
1153 def get_total_weight(self): 1124 def get_total_weight(self):
1166 else: 1137 else:
1167 ac_total += max_dex 1138 ac_total += max_dex
1168 return ac_total 1139 return ac_total
1169 1140
1170 def get_max_dex(self): 1141 def get_max_dex(self):
1171 armor_list = self.master_dom.getElementsByTagName('armor') 1142 armor_list = self.xml.findall('armor')
1172 dex = 10 1143 dex = 10
1173 for a in armor_list: 1144 for a in armor_list:
1174 temp = int(a.getAttribute("maxdex")) 1145 temp = int(a.get("maxdex"))
1175 if temp < dex: 1146 if temp < dex:
1176 dex = temp 1147 dex = temp
1177 return dex 1148 return dex
1178 1149
1179 def get_total(self,attr): 1150 def get_total(self,attr):
1180 armor_list = self.master_dom.getElementsByTagName('armor') 1151 armor_list = self.xml.findall('armor')
1181 total = 0 1152 total = 0
1182 for a in armor_list: 1153 for a in armor_list:
1183 total += int(a.getAttribute(attr)) 1154 total += int(a.get(attr))
1184 return total 1155 return total
1185 1156
1186 def get_design_panel(self,parent): 1157 def get_design_panel(self,parent):
1187 wnd = outline_panel(parent,self,ac_panel,"Armor") 1158 wnd = outline_panel(parent,self,ac_panel,"Armor")
1188 wnd.title = "Armor" 1159 wnd.title = "Armor"
1194 html_str += "<tr ALIGN='center' ><td>"+str(self.get_armor_class())+"</td>" 1165 html_str += "<tr ALIGN='center' ><td>"+str(self.get_armor_class())+"</td>"
1195 html_str += "<td>"+str(self.get_check_pen())+"</td>" 1166 html_str += "<td>"+str(self.get_check_pen())+"</td>"
1196 html_str += "<td>"+str(self.get_spell_failure())+"</td>" 1167 html_str += "<td>"+str(self.get_spell_failure())+"</td>"
1197 html_str += "<td>"+str(self.get_max_dex())+"</td>" 1168 html_str += "<td>"+str(self.get_max_dex())+"</td>"
1198 html_str += "<td>"+str(self.get_total_weight())+"</td></tr></table>" 1169 html_str += "<td>"+str(self.get_total_weight())+"</td></tr></table>"
1199 n_list = self.master_dom._get_childNodes() 1170 for n in self.xml:
1200 for n in n_list:
1201 html_str += """<P><table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th colspan=3>Armor</th> 1171 html_str += """<P><table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th colspan=3>Armor</th>
1202 <th>Type</th><th >Bonus</th></tr>""" 1172 <th>Type</th><th >Bonus</th></tr>"""
1203 html_str += "<tr ALIGN='center' ><td colspan=3>"+n.getAttribute('name')+"</td>" 1173 html_str += "<tr ALIGN='center' ><td colspan=3>"+n.get('name')+"</td>"
1204 html_str += "<td>"+n.getAttribute('type')+"</td>" 1174 html_str += "<td>"+n.get('type')+"</td>"
1205 html_str += "<td>"+n.getAttribute('bonus')+"</td></tr>" 1175 html_str += "<td>"+n.get('bonus')+"</td></tr>"
1206 html_str += """<tr BGCOLOR=#E9E9E9 ><th>Check Penalty</th><th>Spell Failure</th> 1176 html_str += """<tr BGCOLOR=#E9E9E9 ><th>Check Penalty</th><th>Spell Failure</th>
1207 <th>Max Dex</th><th>Speed</th><th>Weight</th></tr>""" 1177 <th>Max Dex</th><th>Speed</th><th>Weight</th></tr>"""
1208 html_str += "<tr ALIGN='center'><td>"+n.getAttribute('checkpenalty')+"</td>" 1178 html_str += "<tr ALIGN='center'><td>"+n.get('checkpenalty')+"</td>"
1209 html_str += "<td>"+n.getAttribute('spellfailure')+"</td>" 1179 html_str += "<td>"+n.get('spellfailure')+"</td>"
1210 html_str += "<td>"+n.getAttribute('maxdex')+"</td>" 1180 html_str += "<td>"+n.get('maxdex')+"</td>"
1211 html_str += "<td>"+n.getAttribute('speed')+"</td>" 1181 html_str += "<td>"+n.get('speed')+"</td>"
1212 html_str += "<td>"+n.getAttribute('weight')+"</td></tr></table>" 1182 html_str += "<td>"+n.get('weight')+"</td></tr></table>"
1213 return html_str 1183 return html_str
1214 1184
1215 1185
1216 ######################## 1186 ########################
1217 ## d20 char windows 1187 ## d20 char windows
1240 self.panel.SetDimensions(20,20,s[0]-40,s[1]-40) 1210 self.panel.SetDimensions(20,20,s[0]-40,s[1]-40)
1241 self.outline.SetDimensions(5,5,s[0]-10,s[1]-10) 1211 self.outline.SetDimensions(5,5,s[0]-10,s[1]-10)
1242 1212
1243 class char_panel(wx.ScrolledWindow): 1213 class char_panel(wx.ScrolledWindow):
1244 def __init__(self, parent, handler): 1214 def __init__(self, parent, handler):
1245 pname = handler.master_dom.setAttribute("name", 'TWO') 1215 pname = handler.xml.set("name", 'TWO')
1246 wx.ScrolledWindow.__init__(self, parent, -1,style=wx.VSCROLL | wx.SUNKEN_BORDER ) 1216 wx.ScrolledWindow.__init__(self, parent, -1,style=wx.VSCROLL | wx.SUNKEN_BORDER )
1247 self.height = 1200 1217 self.height = 1200
1248 self.SetScrollbars(10, 10,80, self.height/10) 1218 self.SetScrollbars(10, 10,80, self.height/10)
1249 self.main_sizer = wx.BoxSizer(wx.HORIZONTAL) 1219 self.main_sizer = wx.BoxSizer(wx.HORIZONTAL)
1250 self.panels = {} 1220 self.panels = {}
1295 HOWTO_MAX = wx.NewId() 1265 HOWTO_MAX = wx.NewId()
1296 1266
1297 class howto_panel(wx.Panel): 1267 class howto_panel(wx.Panel):
1298 def __init__(self, parent, handler): 1268 def __init__(self, parent, handler):
1299 wx.Panel.__init__(self, parent, -1) 1269 wx.Panel.__init__(self, parent, -1)
1300 pname = handler.master_dom.setAttribute("name", 'How To') 1270 pname = handler.xml.set("name", 'How To')
1301 self.sizer = wx.FlexGridSizer(2, 4, 2, 2) # rows, cols, hgap, vgap 1271 self.sizer = wx.FlexGridSizer(2, 4, 2, 2) # rows, cols, hgap, vgap
1302 self.master_dom = handler.master_dom 1272 self.sizer.AddMany([ (wx.StaticText(self, -1,
1303 n_list = self.master_dom._get_childNodes() 1273 handler.xml.find('howto').text),
1304 for n in n_list: 1274 0, wx.ALIGN_CENTER_VERTICAL),
1305 t_node = component.get('xml').safe_get_text_node(n) 1275 ])
1306 self.sizer.AddMany([ (wx.StaticText(self, -1, t_node._get_nodeValue()), 0, wx.ALIGN_CENTER_VERTICAL),
1307 ])
1308 self.sizer.AddGrowableCol(1) 1276 self.sizer.AddGrowableCol(1)
1309 self.SetSizer(self.sizer) 1277 self.SetSizer(self.sizer)
1310 1278
1311 1279
1312 HP_CUR = wx.NewId() 1280 HP_CUR = wx.NewId()
1313 HP_MAX = wx.NewId() 1281 HP_MAX = wx.NewId()
1314 1282
1315 class hp_panel(wx.Panel): 1283 class hp_panel(wx.Panel):
1316 def __init__(self, parent, handler): 1284 def __init__(self, parent, handler):
1317 wx.Panel.__init__(self, parent, -1) 1285 wx.Panel.__init__(self, parent, -1)
1318 pname = handler.master_dom.setAttribute("name", 'HitPoints') 1286 pname = handler.xml.set("name", 'HitPoints')
1319 self.sizer = wx.FlexGridSizer(2, 4, 2, 2) # rows, cols, hgap, vgap 1287 self.sizer = wx.FlexGridSizer(2, 4, 2, 2) # rows, cols, hgap, vgap
1320 self.master_dom = handler.master_dom 1288 self.xml = handler.xml
1321 self.sizer.AddMany([ (wx.StaticText(self, -1, "HP Current:"), 0, wx.ALIGN_CENTER_VERTICAL), 1289 self.sizer.AddMany([ (wx.StaticText(self, -1, "HP Current:"), 0, wx.ALIGN_CENTER_VERTICAL),
1322 (wx.TextCtrl(self, HP_CUR, self.master_dom.getAttribute('current')), 0, wx.EXPAND), 1290 (wx.TextCtrl(self, HP_CUR, self.xml.get('current')), 0, wx.EXPAND),
1323 (wx.StaticText(self, -1, "HP Max:"), 0, wx.ALIGN_CENTER_VERTICAL), 1291 (wx.StaticText(self, -1, "HP Max:"), 0, wx.ALIGN_CENTER_VERTICAL),
1324 (wx.TextCtrl(self, HP_MAX, self.master_dom.getAttribute('max')), 0, wx.EXPAND), 1292 (wx.TextCtrl(self, HP_MAX, self.xml.get('max')), 0, wx.EXPAND),
1325 ]) 1293 ])
1326 self.sizer.AddGrowableCol(1) 1294 self.sizer.AddGrowableCol(1)
1327 self.SetSizer(self.sizer) 1295 self.SetSizer(self.sizer)
1328 self.Bind(wx.EVT_SIZE, self.on_size) 1296 self.Bind(wx.EVT_SIZE, self.on_size)
1329 self.Bind(wx.EVT_TEXT, self.on_text, id=HP_MAX) 1297 self.Bind(wx.EVT_TEXT, self.on_text, id=HP_MAX)
1330 self.Bind(wx.EVT_TEXT, self.on_text, id=HP_CUR) 1298 self.Bind(wx.EVT_TEXT, self.on_text, id=HP_CUR)
1331 1299
1332 def on_text(self,evt): 1300 def on_text(self,evt):
1333 id = evt.GetId() 1301 id = evt.GetId()
1334 if id == HP_CUR: 1302 if id == HP_CUR:
1335 self.master_dom.setAttribute('current',evt.GetString()) 1303 self.xml.set('current',evt.GetString())
1336 elif id == HP_MAX: 1304 elif id == HP_MAX:
1337 self.master_dom.setAttribute('max',evt.GetString()) 1305 self.xml.set('max',evt.GetString())
1338 1306
1339 def on_size(self,evt): 1307 def on_size(self,evt):
1340 s = self.GetClientSizeTuple() 1308 s = self.GetClientSizeTuple()
1341 self.sizer.SetDimension(0,0,s[0],s[1]) 1309 self.sizer.SetDimension(0,0,s[0],s[1])
1342 1310
1346 PP_MFRE = wx.NewId() 1314 PP_MFRE = wx.NewId()
1347 1315
1348 class pp_panel(wx.Panel): 1316 class pp_panel(wx.Panel):
1349 def __init__(self, parent, handler): 1317 def __init__(self, parent, handler):
1350 wx.Panel.__init__(self, parent, -1) 1318 wx.Panel.__init__(self, parent, -1)
1351 pname = handler.master_dom.setAttribute("name", 'PowerPoints') 1319 pname = handler.xml.set("name", 'PowerPoints')
1352 self.sizer = wx.FlexGridSizer(2, 4, 2, 2) # rows, cols, hgap, vgap 1320 self.sizer = wx.FlexGridSizer(2, 4, 2, 2) # rows, cols, hgap, vgap
1353 self.master_dom = handler.master_dom 1321 self.xml = handler.xml
1354 1322
1355 self.sizer.AddMany([ (wx.StaticText(self, -1, "PP Current:"), 0, wx.ALIGN_CENTER_VERTICAL), 1323 self.sizer.AddMany([ (wx.StaticText(self, -1, "PP Current:"), 0, wx.ALIGN_CENTER_VERTICAL),
1356 (wx.TextCtrl(self, PP_CUR, self.master_dom.getAttribute('current1')), 0, wx.EXPAND), 1324 (wx.TextCtrl(self, PP_CUR, self.xml.get('current1')), 0, wx.EXPAND),
1357 (wx.StaticText(self, -1, "PP Max:"), 0, wx.ALIGN_CENTER_VERTICAL), 1325 (wx.StaticText(self, -1, "PP Max:"), 0, wx.ALIGN_CENTER_VERTICAL),
1358 (wx.TextCtrl(self, PP_MAX, self.master_dom.getAttribute('max1')), 0, wx.EXPAND), 1326 (wx.TextCtrl(self, PP_MAX, self.xml.get('max1')), 0, wx.EXPAND),
1359 (wx.StaticText(self, -1, "Current Free Talants per day:"), 0, wx.ALIGN_CENTER_VERTICAL), 1327 (wx.StaticText(self, -1, "Current Free Talants per day:"), 0, wx.ALIGN_CENTER_VERTICAL),
1360 (wx.TextCtrl(self, PP_FRE, self.master_dom.getAttribute('free')), 0, wx.EXPAND), 1328 (wx.TextCtrl(self, PP_FRE, self.xml.get('free')), 0, wx.EXPAND),
1361 (wx.StaticText(self, -1, "Max Free Talants per day:"), 0, wx.ALIGN_CENTER_VERTICAL), 1329 (wx.StaticText(self, -1, "Max Free Talants per day:"), 0, wx.ALIGN_CENTER_VERTICAL),
1362 (wx.TextCtrl(self, PP_MFRE, self.master_dom.getAttribute('maxfree')), 0, wx.EXPAND), 1330 (wx.TextCtrl(self, PP_MFRE, self.xml.get('maxfree')), 0, wx.EXPAND),
1363 ]) 1331 ])
1364 self.sizer.AddGrowableCol(1) 1332 self.sizer.AddGrowableCol(1)
1365 self.SetSizer(self.sizer) 1333 self.SetSizer(self.sizer)
1366 self.Bind(wx.EVT_SIZE, self.on_size) 1334 self.Bind(wx.EVT_SIZE, self.on_size)
1367 self.Bind(wx.EVT_TEXT, self.on_text, id=PP_MAX) 1335 self.Bind(wx.EVT_TEXT, self.on_text, id=PP_MAX)
1370 self.Bind(wx.EVT_TEXT, self.on_text, id=PP_MFRE) 1338 self.Bind(wx.EVT_TEXT, self.on_text, id=PP_MFRE)
1371 1339
1372 def on_text(self,evt): 1340 def on_text(self,evt):
1373 id = evt.GetId() 1341 id = evt.GetId()
1374 if id == PP_CUR: 1342 if id == PP_CUR:
1375 self.master_dom.setAttribute('current1',evt.GetString()) 1343 self.xml.set('current1',evt.GetString())
1376 elif id == PP_MAX: 1344 elif id == PP_MAX:
1377 self.master_dom.setAttribute('max1',evt.GetString()) 1345 self.xml.set('max1',evt.GetString())
1378 elif id == PP_FRE: 1346 elif id == PP_FRE:
1379 self.master_dom.setAttribute('free',evt.GetString()) 1347 self.xml.set('free',evt.GetString())
1380 elif id == PP_MFRE: 1348 elif id == PP_MFRE:
1381 self.master_dom.setAttribute('maxfree',evt.GetString()) 1349 self.xml.set('maxfree',evt.GetString())
1382 1350
1383 def on_size(self,evt): 1351 def on_size(self,evt):
1384 s = self.GetClientSizeTuple() 1352 s = self.GetClientSizeTuple()
1385 self.sizer.SetDimension(0,0,s[0],s[1]) 1353 self.sizer.SetDimension(0,0,s[0],s[1])
1386 1354
1387 1355
1388 class gen_grid(wx.grid.Grid): 1356 class gen_grid(wx.grid.Grid):
1389 """grid for gen info""" 1357 """grid for gen info"""
1390 def __init__(self, parent, handler): 1358 def __init__(self, parent, handler):
1391 pname = handler.master_dom.setAttribute("name", 'General') 1359 pname = handler.xml.set("name", 'General')
1392 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 1360 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
1393 self.Bind(wx.EVT_SIZE, self.on_size) 1361 self.Bind(wx.EVT_SIZE, self.on_size)
1394 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change) 1362 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
1395 self.handler = handler 1363 self.handler = handler
1396 n_list = handler.master_dom._get_childNodes() 1364 n_list = handler.xml[:]
1397 self.CreateGrid(len(n_list),2) 1365 self.CreateGrid(len(n_list),2)
1398 self.SetRowLabelSize(0) 1366 self.SetRowLabelSize(0)
1399 self.SetColLabelSize(0) 1367 self.SetColLabelSize(0)
1400 self.n_list = n_list 1368 self.n_list = n_list
1401 i = 0 1369 i = 0
1404 1372
1405 def on_cell_change(self,evt): 1373 def on_cell_change(self,evt):
1406 row = evt.GetRow() 1374 row = evt.GetRow()
1407 col = evt.GetCol() 1375 col = evt.GetCol()
1408 value = self.GetCellValue(row,col) 1376 value = self.GetCellValue(row,col)
1409 t_node = self.n_list[row]._get_firstChild() 1377 self.n_list[row].text = value
1410 t_node._set_nodeValue(value)
1411 if row==0: self.handler.on_name_change(value) 1378 if row==0: self.handler.on_name_change(value)
1412 1379
1413 def refresh_row(self,rowi): 1380 def refresh_row(self,rowi):
1414 t_node = component.get('xml').safe_get_text_node(self.n_list[rowi]) 1381 self.SetCellValue(rowi,0,self.n_list[rowi].tag)
1415 self.SetCellValue(rowi,0,self.n_list[rowi]._get_tagName())
1416 self.SetReadOnly(rowi,0) 1382 self.SetReadOnly(rowi,0)
1417 self.SetCellValue(rowi,1,t_node._get_nodeValue()) 1383 self.SetCellValue(rowi,1,self.n_list[rowi].text)
1418 1384
1419 def on_size(self,evt): 1385 def on_size(self,evt):
1420 (w,h) = self.GetClientSizeTuple() 1386 (w,h) = self.GetClientSizeTuple()
1421 cols = self.GetNumberCols() 1387 cols = self.GetNumberCols()
1422 col_w = w/(cols) 1388 col_w = w/(cols)
1426 self.Refresh() 1392 self.Refresh()
1427 1393
1428 class inventory_grid(wx.grid.Grid): 1394 class inventory_grid(wx.grid.Grid):
1429 """grid for gen info""" 1395 """grid for gen info"""
1430 def __init__(self, parent, handler): 1396 def __init__(self, parent, handler):
1431 pname = handler.master_dom.setAttribute("name", 'Money and Inventory') 1397 pname = handler.xml.set("name", 'Money and Inventory')
1432 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 1398 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
1433 self.Bind(wx.EVT_SIZE, self.on_size) 1399 self.Bind(wx.EVT_SIZE, self.on_size)
1434 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change) 1400 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
1435 self.handler = handler 1401 self.handler = handler
1436 n_list = handler.master_dom._get_childNodes() 1402 n_list = handler.xml[:]
1437 self.CreateGrid(len(n_list),2) 1403 self.CreateGrid(len(n_list),2)
1438 self.SetRowLabelSize(0) 1404 self.SetRowLabelSize(0)
1439 self.SetColLabelSize(0) 1405 self.SetColLabelSize(0)
1440 self.n_list = n_list 1406 self.n_list = n_list
1441 i = 0 1407 i = 0
1444 1410
1445 def on_cell_change(self,evt): 1411 def on_cell_change(self,evt):
1446 row = evt.GetRow() 1412 row = evt.GetRow()
1447 col = evt.GetCol() 1413 col = evt.GetCol()
1448 value = self.GetCellValue(row,col) 1414 value = self.GetCellValue(row,col)
1449 t_node = self.n_list[row]._get_firstChild() 1415 self.n_list[row].text = value
1450 t_node._set_nodeValue(value)
1451 if row==0: self.handler.on_name_change(value) 1416 if row==0: self.handler.on_name_change(value)
1452 1417
1453 def refresh_row(self,rowi): 1418 def refresh_row(self,rowi):
1454 t_node = component.get('xml').safe_get_text_node(self.n_list[rowi]) 1419 self.SetCellValue(rowi,0,self.n_list[rowi].tag)
1455 self.SetCellValue(rowi,0,self.n_list[rowi]._get_tagName())
1456 self.SetReadOnly(rowi,0) 1420 self.SetReadOnly(rowi,0)
1457 self.SetCellValue(rowi,1,t_node._get_nodeValue()) 1421 self.SetCellValue(rowi,1,self.n_list[rowi].text)
1458 1422
1459 def on_size(self,evt): 1423 def on_size(self,evt):
1460 (w,h) = self.GetClientSizeTuple() 1424 (w,h) = self.GetClientSizeTuple()
1461 cols = self.GetNumberCols() 1425 cols = self.GetNumberCols()
1462 col_w = w/(cols) 1426 col_w = w/(cols)
1466 self.Refresh() 1430 self.Refresh()
1467 1431
1468 class abil_grid(wx.grid.Grid): 1432 class abil_grid(wx.grid.Grid):
1469 """grid for abilities""" 1433 """grid for abilities"""
1470 def __init__(self, parent, handler): 1434 def __init__(self, parent, handler):
1471 pname = handler.master_dom.setAttribute("name", 'Stats') 1435 pname = handler.xml.set("name", 'Stats')
1472 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 1436 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
1473 self.Bind(wx.EVT_SIZE, self.on_size) 1437 self.Bind(wx.EVT_SIZE, self.on_size)
1474 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change) 1438 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
1475 self.handler = handler 1439 self.handler = handler
1476 stats = handler.master_dom.getElementsByTagName('stat') 1440 stats = handler.xml.findall('stat')
1477 self.CreateGrid(len(stats),3) 1441 self.CreateGrid(len(stats),3)
1478 self.SetRowLabelSize(0) 1442 self.SetRowLabelSize(0)
1479 col_names = ['Ability','Score','Modifier'] 1443 col_names = ['Ability','Score','Modifier']
1480 for i in range(len(col_names)): 1444 for i in range(len(col_names)):
1481 self.SetColLabelValue(i,col_names[i]) 1445 self.SetColLabelValue(i,col_names[i])
1489 row = evt.GetRow() 1453 row = evt.GetRow()
1490 col = evt.GetCol() 1454 col = evt.GetCol()
1491 value = self.GetCellValue(row,col) 1455 value = self.GetCellValue(row,col)
1492 try: 1456 try:
1493 int(value) 1457 int(value)
1494 self.stats[row].setAttribute('base',value) 1458 self.stats[row].set('base',value)
1495 self.refresh_row(row) 1459 self.refresh_row(row)
1496 except: 1460 except:
1497 self.SetCellValue(row,col,"0") 1461 self.SetCellValue(row,col,"0")
1498 if self.char_wnd: 1462 if self.char_wnd:
1499 self.char_wnd.refresh_data() 1463 self.char_wnd.refresh_data()
1500 1464
1501 def refresh_row(self,rowi): 1465 def refresh_row(self,rowi):
1502 s = self.stats[rowi] 1466 s = self.stats[rowi]
1503 name = s.getAttribute('name') 1467 name = s.get('name')
1504 abbr = s.getAttribute('abbr') 1468 abbr = s.get('abbr')
1505 self.SetCellValue(rowi,0,name) 1469 self.SetCellValue(rowi,0,name)
1506 self.SetReadOnly(rowi,0) 1470 self.SetReadOnly(rowi,0)
1507 self.SetCellValue(rowi,1,s.getAttribute('base')) 1471 self.SetCellValue(rowi,1,s.get('base'))
1508 self.SetCellValue(rowi,2,str(self.handler.get_mod(abbr))) 1472 self.SetCellValue(rowi,2,str(self.handler.get_mod(abbr)))
1509 self.SetReadOnly(rowi,2) 1473 self.SetReadOnly(rowi,2)
1510 1474
1511 def on_size(self,evt): 1475 def on_size(self,evt):
1512 (w,h) = self.GetClientSizeTuple() 1476 (w,h) = self.GetClientSizeTuple()
1524 1488
1525 1489
1526 class save_grid(wx.grid.Grid): 1490 class save_grid(wx.grid.Grid):
1527 """grid for saves""" 1491 """grid for saves"""
1528 def __init__(self, parent, handler): 1492 def __init__(self, parent, handler):
1529 pname = handler.master_dom.setAttribute("name", 'Saves') 1493 pname = handler.xml.set("name", 'Saves')
1530 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 1494 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
1531 self.Bind(wx.EVT_SIZE, self.on_size) 1495 self.Bind(wx.EVT_SIZE, self.on_size)
1532 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change) 1496 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
1533 self.handler = handler 1497 self.handler = handler
1534 saves = handler.master_dom.getElementsByTagName('save') 1498 saves = handler.xml.findall('save')
1535 self.stats = handler.char_hander.child_handlers['abilities'] 1499 self.stats = handler.char_hander.child_handlers['abilities']
1536 self.CreateGrid(len(saves),7) 1500 self.CreateGrid(len(saves),7)
1537 self.SetRowLabelSize(0) 1501 self.SetRowLabelSize(0)
1538 col_names = ['Save','Key','base','Abil','Magic','Misc','Total'] 1502 col_names = ['Save','Key','base','Abil','Magic','Misc','Total']
1539 for i in range(len(col_names)): 1503 for i in range(len(col_names)):
1548 col = evt.GetCol() 1512 col = evt.GetCol()
1549 value = self.GetCellValue(row,col) 1513 value = self.GetCellValue(row,col)
1550 try: 1514 try:
1551 int(value) 1515 int(value)
1552 if col == 2: 1516 if col == 2:
1553 self.saves[row].setAttribute('base',value) 1517 self.saves[row].set('base',value)
1554 elif col ==4: 1518 elif col ==4:
1555 self.saves[row].setAttribute('magmod',value) 1519 self.saves[row].set('magmod',value)
1556 elif col ==4: 1520 elif col ==4:
1557 self.saves[row].setAttribute('miscmod',value) 1521 self.saves[row].set('miscmod',value)
1558 self.refresh_row(row) 1522 self.refresh_row(row)
1559 except: 1523 except:
1560 self.SetCellValue(row,col,"0") 1524 self.SetCellValue(row,col,"0")
1561 1525
1562 def refresh_row(self,rowi): 1526 def refresh_row(self,rowi):
1563 s = self.saves[rowi] 1527 s = self.saves[rowi]
1564 name = s.getAttribute('name') 1528 name = s.get('name')
1565 self.SetCellValue(rowi,0,name) 1529 self.SetCellValue(rowi,0,name)
1566 self.SetReadOnly(rowi,0) 1530 self.SetReadOnly(rowi,0)
1567 stat = s.getAttribute('stat') 1531 stat = s.get('stat')
1568 self.SetCellValue(rowi,1,stat) 1532 self.SetCellValue(rowi,1,stat)
1569 self.SetReadOnly(rowi,1) 1533 self.SetReadOnly(rowi,1)
1570 self.SetCellValue(rowi,2,s.getAttribute('base')) 1534 self.SetCellValue(rowi,2,s.get('base'))
1571 self.SetCellValue(rowi,3,str(self.stats.get_mod(stat))) 1535 self.SetCellValue(rowi,3,str(self.stats.get_mod(stat)))
1572 self.SetReadOnly(rowi,3) 1536 self.SetReadOnly(rowi,3)
1573 self.SetCellValue(rowi,4,s.getAttribute('magmod')) 1537 self.SetCellValue(rowi,4,s.get('magmod'))
1574 self.SetCellValue(rowi,5,s.getAttribute('miscmod')) 1538 self.SetCellValue(rowi,5,s.get('miscmod'))
1575 mod = str(self.handler.get_mod(name)) 1539 mod = str(self.handler.get_mod(name))
1576 self.SetCellValue(rowi,6,mod) 1540 self.SetCellValue(rowi,6,mod)
1577 self.SetReadOnly(rowi,6) 1541 self.SetReadOnly(rowi,6)
1578 1542
1579 def on_size(self,evt): 1543 def on_size(self,evt):
1592 1556
1593 1557
1594 class skill_grid(wx.grid.Grid): 1558 class skill_grid(wx.grid.Grid):
1595 """ panel for skills """ 1559 """ panel for skills """
1596 def __init__(self, parent, handler): 1560 def __init__(self, parent, handler):
1597 pname = handler.master_dom.setAttribute("name", 'Skills') 1561 pname = handler.xml.set("name", 'Skills')
1598 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 1562 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
1599 self.Bind(wx.EVT_SIZE, self.on_size) 1563 self.Bind(wx.EVT_SIZE, self.on_size)
1600 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change) 1564 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
1601 self.handler = handler 1565 self.handler = handler
1602 skills = handler.master_dom.getElementsByTagName('skill') 1566 skills = handler.xml.findall('skill')
1603 self.stats = handler.char_hander.child_handlers['abilities'] 1567 self.stats = handler.char_hander.child_handlers['abilities']
1604 self.CreateGrid(len(skills),6) 1568 self.CreateGrid(len(skills),6)
1605 self.SetRowLabelSize(0) 1569 self.SetRowLabelSize(0)
1606 col_names = ['Skill','Key','Rank','Abil','Misc','Total'] 1570 col_names = ['Skill','Key','Rank','Abil','Misc','Total']
1607 for i in range(len(col_names)): 1571 for i in range(len(col_names)):
1616 col = evt.GetCol() 1580 col = evt.GetCol()
1617 value = self.GetCellValue(row,col) 1581 value = self.GetCellValue(row,col)
1618 try: 1582 try:
1619 int(value) 1583 int(value)
1620 if col == 2: 1584 if col == 2:
1621 self.skills[row].setAttribute('rank',value) 1585 self.skills[row].set('rank',value)
1622 elif col ==4: 1586 elif col ==4:
1623 self.skills[row].setAttribute('misc',value) 1587 self.skills[row].set('misc',value)
1624 self.refresh_row(row) 1588 self.refresh_row(row)
1625 except: 1589 except:
1626 self.SetCellValue(row,col,"0") 1590 self.SetCellValue(row,col,"0")
1627 1591
1628 def refresh_row(self,rowi): 1592 def refresh_row(self,rowi):
1629 s = self.skills[rowi] 1593 s = self.skills[rowi]
1630 name = s.getAttribute('name') 1594 name = s.get('name')
1631 self.SetCellValue(rowi,0,name) 1595 self.SetCellValue(rowi,0,name)
1632 self.SetReadOnly(rowi,0) 1596 self.SetReadOnly(rowi,0)
1633 stat = s.getAttribute('stat') 1597 stat = s.get('stat')
1634 self.SetCellValue(rowi,1,stat) 1598 self.SetCellValue(rowi,1,stat)
1635 self.SetReadOnly(rowi,1) 1599 self.SetReadOnly(rowi,1)
1636 self.SetCellValue(rowi,2,s.getAttribute('rank')) 1600 self.SetCellValue(rowi,2,s.get('rank'))
1637 self.SetCellValue(rowi,3,str(self.stats.get_mod(stat))) 1601 self.SetCellValue(rowi,3,str(self.stats.get_mod(stat)))
1638 self.SetReadOnly(rowi,3) 1602 self.SetReadOnly(rowi,3)
1639 self.SetCellValue(rowi,4,s.getAttribute('misc')) 1603 self.SetCellValue(rowi,4,s.get('misc'))
1640 mod = str(self.handler.get_mod(name)) 1604 mod = str(self.handler.get_mod(name))
1641 self.SetCellValue(rowi,5,mod) 1605 self.SetCellValue(rowi,5,mod)
1642 self.SetReadOnly(rowi,5) 1606 self.SetReadOnly(rowi,5)
1643 1607
1644 def on_size(self,evt): 1608 def on_size(self,evt):
1657 1621
1658 1622
1659 1623
1660 class feat_panel(wx.Panel): 1624 class feat_panel(wx.Panel):
1661 def __init__(self, parent, handler): 1625 def __init__(self, parent, handler):
1662 pname = handler.master_dom.setAttribute("name", 'Feats') 1626 pname = handler.xml.set("name", 'Feats')
1663 wx.Panel.__init__(self, parent, -1) 1627 wx.Panel.__init__(self, parent, -1)
1664 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 1628 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
1665 sizer = wx.BoxSizer(wx.HORIZONTAL) 1629 sizer = wx.BoxSizer(wx.HORIZONTAL)
1666 sizer.Add(wx.Button(self, 10, "Remove Feat"), 1, wx.EXPAND) 1630 sizer.Add(wx.Button(self, 10, "Remove Feat"), 1, wx.EXPAND)
1667 sizer.Add(wx.Size(10,10)) 1631 sizer.Add(wx.Size(10,10))
1669 self.sizer = sizer 1633 self.sizer = sizer
1670 self.Bind(wx.EVT_SIZE, self.on_size) 1634 self.Bind(wx.EVT_SIZE, self.on_size)
1671 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10) 1635 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10)
1672 self.Bind(wx.EVT_BUTTON, self.on_add, id=20) 1636 self.Bind(wx.EVT_BUTTON, self.on_add, id=20)
1673 1637
1674 n_list = handler.master_dom._get_childNodes() 1638 n_list = handler.xml[:]
1675 self.n_list = n_list 1639 self.n_list = n_list
1676 self.master_dom = handler.master_dom 1640 self.xml = handler.xml
1677 self.grid.CreateGrid(len(n_list),2,1) 1641 self.grid.CreateGrid(len(n_list),2,1)
1678 self.grid.SetRowLabelSize(0) 1642 self.grid.SetRowLabelSize(0)
1679 self.grid.SetColLabelValue(0,"Feat") 1643 self.grid.SetColLabelValue(0,"Feat")
1680 self.grid.SetColLabelValue(1,"Type") 1644 self.grid.SetColLabelValue(1,"Type")
1681 for i in range(len(n_list)): 1645 for i in range(len(n_list)):
1683 self.temp_dom = None 1647 self.temp_dom = None
1684 self.SetSizer(self.sizer) 1648 self.SetSizer(self.sizer)
1685 1649
1686 def refresh_row(self,i): 1650 def refresh_row(self,i):
1687 feat = self.n_list[i] 1651 feat = self.n_list[i]
1688 name = feat.getAttribute('name') 1652 name = feat.get('name')
1689 type = feat.getAttribute('type') 1653 type = feat.get('type')
1690 self.grid.SetCellValue(i,0,name) 1654 self.grid.SetCellValue(i,0,name)
1691 self.grid.SetReadOnly(i,0) 1655 self.grid.SetReadOnly(i,0)
1692 self.grid.SetCellValue(i,1,type) 1656 self.grid.SetCellValue(i,1,type)
1693 self.grid.SetReadOnly(i,1) 1657 self.grid.SetReadOnly(i,1)
1694 1658
1695 def on_remove(self,evt): 1659 def on_remove(self,evt):
1696 rows = self.grid.GetNumberRows() 1660 rows = self.grid.GetNumberRows()
1697 for i in range(rows): 1661 for i in range(rows):
1698 if self.grid.IsInSelection(i,0): 1662 if self.grid.IsInSelection(i,0):
1699 self.grid.DeleteRows(i) 1663 self.grid.DeleteRows(i)
1700 self.master_dom.removeChild(self.n_list[i]) 1664 self.xml.removeChild(self.n_list[i])
1701 1665
1702 def on_add(self,evt): 1666 def on_add(self,evt):
1703 if not self.temp_dom: 1667 if not self.temp_dom:
1704 tmp = open(orpg.dirpath.dir_struct["d20"]+"d20feats.xml","r") 1668 tree = parse(orpg.dirpath.dir_struct["d20"]+"d20feats.xml")
1705 xml_dom = parseXml_with_dlg(self,tmp.read()) 1669 self.temp_dom = tree.getroot()
1706 xml_dom = xml_dom._get_firstChild() 1670 f_list = self.temp_dom.findall('feat')
1707 tmp.close()
1708 self.temp_dom = xml_dom
1709 f_list = self.temp_dom.getElementsByTagName('feat')
1710 opts = [] 1671 opts = []
1711 for f in f_list: 1672 for f in f_list:
1712 opts.append(f.getAttribute('name')) 1673 opts.append(f.get('name'))
1713 dlg = wx.SingleChoiceDialog(self,'Choose Feat','Feats',opts) 1674 dlg = wx.SingleChoiceDialog(self,'Choose Feat','Feats',opts)
1714 if dlg.ShowModal() == wx.ID_OK: 1675 if dlg.ShowModal() == wx.ID_OK:
1715 i = dlg.GetSelection() 1676 i = dlg.GetSelection()
1716 new_node = self.master_dom.appendChild(f_list[i].cloneNode(False)) 1677 new_node = self.xml.append(XML(tostring(f_list[i])))
1717 self.grid.AppendRows(1) 1678 self.grid.AppendRows(1)
1679 self.n_list = self.xml.findall('feat')
1718 self.refresh_row(self.grid.GetNumberRows()-1) 1680 self.refresh_row(self.grid.GetNumberRows()-1)
1719 dlg.Destroy() 1681 dlg.Destroy()
1720
1721 1682
1722 def on_size(self,event): 1683 def on_size(self,event):
1723 s = self.GetClientSizeTuple() 1684 s = self.GetClientSizeTuple()
1724 self.grid.SetDimensions(0,0,s[0],s[1]-25) 1685 self.grid.SetDimensions(0,0,s[0],s[1]-25)
1725 self.sizer.SetDimension(0,s[1]-25,s[0],25) 1686 self.sizer.SetDimension(0,s[1]-25,s[0],25)
1729 for i in range(0,cols): 1690 for i in range(0,cols):
1730 self.grid.SetColSize(i,col_w) 1691 self.grid.SetColSize(i,col_w)
1731 1692
1732 class spell_panel(wx.Panel): 1693 class spell_panel(wx.Panel):
1733 def __init__(self, parent, handler): 1694 def __init__(self, parent, handler):
1734 pname = handler.master_dom.setAttribute("name", 'Arcane Spells') 1695 pname = handler.xml.set("name", 'Arcane Spells')
1735 wx.Panel.__init__(self, parent, -1) 1696 wx.Panel.__init__(self, parent, -1)
1736 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 1697 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
1737 self.handler = handler 1698 self.handler = handler
1738 sizer = wx.BoxSizer(wx.HORIZONTAL) 1699 sizer = wx.BoxSizer(wx.HORIZONTAL)
1739 sizer.Add(wx.Button(self, 10, "Remove Spell"), 1, wx.EXPAND) 1700 sizer.Add(wx.Button(self, 10, "Remove Spell"), 1, wx.EXPAND)
1746 self.Bind(wx.EVT_SIZE, self.on_size) 1707 self.Bind(wx.EVT_SIZE, self.on_size)
1747 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10) 1708 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10)
1748 self.Bind(wx.EVT_BUTTON, self.on_add, id=20) 1709 self.Bind(wx.EVT_BUTTON, self.on_add, id=20)
1749 self.Bind(wx.EVT_BUTTON, self.on_refresh_spells, id=30) 1710 self.Bind(wx.EVT_BUTTON, self.on_refresh_spells, id=30)
1750 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change) 1711 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
1751 n_list = handler.master_dom._get_childNodes() 1712 n_list = handler.xml[:]
1752 self.n_list = n_list 1713 self.n_list = n_list
1753 self.master_dom = handler.master_dom 1714 self.xml = handler.xml
1754 self.grid.CreateGrid(len(n_list),4,1) 1715 self.grid.CreateGrid(len(n_list),4,1)
1755 self.grid.SetRowLabelSize(0) 1716 self.grid.SetRowLabelSize(0)
1756 self.grid.SetColLabelValue(0,"No.") 1717 self.grid.SetColLabelValue(0,"No.")
1757 self.grid.SetColLabelValue(1,"Lvl") 1718 self.grid.SetColLabelValue(1,"Lvl")
1758 self.grid.SetColLabelValue(2,"Spell") 1719 self.grid.SetColLabelValue(2,"Spell")
1764 def on_cell_change(self,evt): 1725 def on_cell_change(self,evt):
1765 row = evt.GetRow() 1726 row = evt.GetRow()
1766 col = evt.GetCol() 1727 col = evt.GetCol()
1767 value = self.grid.GetCellValue(row,col) 1728 value = self.grid.GetCellValue(row,col)
1768 if col == 0: 1729 if col == 0:
1769 self.n_list[row].setAttribute('memrz',value) 1730 self.n_list[row].set('memrz',value)
1770
1771 1731
1772 def refresh_row(self,i): 1732 def refresh_row(self,i):
1773 spell = self.n_list[i] 1733 spell = self.n_list[i]
1774 memrz = spell.getAttribute('memrz') 1734 memrz = spell.get('memrz')
1775 name = spell.getAttribute('name') 1735 name = spell.get('name')
1776 type = spell.getAttribute('desc') 1736 type = spell.get('desc')
1777 level = spell.getAttribute('level') 1737 level = spell.get('level')
1778 self.grid.SetCellValue(i,0,memrz) 1738 self.grid.SetCellValue(i,0,memrz)
1779 self.grid.SetCellValue(i,2,name) 1739 self.grid.SetCellValue(i,2,name)
1780 self.grid.SetReadOnly(i,2) 1740 self.grid.SetReadOnly(i,2)
1781 self.grid.SetCellValue(i,3,type) 1741 self.grid.SetCellValue(i,3,type)
1782 self.grid.SetReadOnly(i,3) 1742 self.grid.SetReadOnly(i,3)
1786 def on_remove(self,evt): 1746 def on_remove(self,evt):
1787 rows = self.grid.GetNumberRows() 1747 rows = self.grid.GetNumberRows()
1788 for i in range(rows): 1748 for i in range(rows):
1789 if self.grid.IsInSelection(i,0): 1749 if self.grid.IsInSelection(i,0):
1790 self.grid.DeleteRows(i) 1750 self.grid.DeleteRows(i)
1791 self.master_dom.removeChild(self.n_list[i]) 1751 self.xml.removeChild(self.n_list[i])
1792 self.handler.refresh_spells() 1752 self.handler.refresh_spells()
1793 1753
1794 def on_add(self,evt): 1754 def on_add(self,evt):
1795 if not self.temp_dom: 1755 if not self.temp_dom:
1796 tmp = open(orpg.dirpath.dir_struct["d20"]+"d20spells.xml","r") 1756 tree = parse(orpg.dirpath.dir_struct["d20"]+"d20spells.xml")
1797 xml_dom = parseXml_with_dlg(self,tmp.read()) 1757 self.temp_dom = tree.getroot()
1798 xml_dom = xml_dom._get_firstChild() 1758 f_list = self.temp_dom.findall('spell')
1799 tmp.close()
1800 self.temp_dom = xml_dom
1801 f_list = self.temp_dom.getElementsByTagName('spell')
1802 opts = [] 1759 opts = []
1803 # lvl = int(self.handler.get_char_lvl('level')) 1760 # lvl = int(self.handler.get_char_lvl('level'))
1804 # castlvl = lvl / 2 1761 # castlvl = lvl / 2
1805 for f in f_list: 1762 for f in f_list:
1806 opts.append("(" + f.getAttribute('level') + ")" + f.getAttribute('name')) 1763 opts.append("(" + f.get('level') + ")" + f.get('name'))
1807 # spelllvl = f.getAttribute('level') 1764 # spelllvl = f.get('level')
1808 # if spelllvl <= "1": 1765 # if spelllvl <= "1":
1809 # opts.append("(" + f.getAttribute('level') + ")" + f.getAttribute('name')) 1766 # opts.append("(" + f.get('level') + ")" + f.get('name'))
1810 # else: 1767 # else:
1811 # if eval('%d >= %s' %(castlvl, spelllvl)): 1768 # if eval('%d >= %s' %(castlvl, spelllvl)):
1812 # opts.append("(" + f.getAttribute('level') + ")" + f.getAttribute('name')) 1769 # opts.append("(" + f.get('level') + ")" + f.get('name'))
1813 dlg = wx.SingleChoiceDialog(self,'Choose Spell','Spells',opts) 1770 dlg = wx.SingleChoiceDialog(self,'Choose Spell','Spells',opts)
1814 if dlg.ShowModal() == wx.ID_OK: 1771 if dlg.ShowModal() == wx.ID_OK:
1815 i = dlg.GetSelection() 1772 i = dlg.GetSelection()
1816 new_node = self.master_dom.appendChild(f_list[i].cloneNode(False)) 1773 new_node = self.xml.append(XML(tostring(f_list[i])))
1817 self.grid.AppendRows(1) 1774 self.grid.AppendRows(1)
1818 self.n_list = self.master_dom.getElementsByTagName('spell') 1775 self.n_list = self.xml.findall('spell')
1819 self.refresh_row(self.grid.GetNumberRows()-1) 1776 self.refresh_row(self.grid.GetNumberRows()-1)
1820 self.handler.refresh_spells() 1777 self.handler.refresh_spells()
1821 dlg.Destroy() 1778 dlg.Destroy()
1822 1779
1823 def on_refresh_spells( self, evt ): 1780 def on_refresh_spells( self, evt ):
1824 f_list = self.master_dom.getElementsByTagName('spell') 1781 f_list = self.xml.findall('spell')
1825 for spell in f_list: 1782 for spell in f_list:
1826 spell.setAttribute( 'used', '0' ) 1783 spell.set( 'used', '0' )
1827 1784
1828 def on_size(self,event): 1785 def on_size(self,event):
1829 s = self.GetClientSizeTuple() 1786 s = self.GetClientSizeTuple()
1830 self.grid.SetDimensions(0,0,s[0],s[1]-25) 1787 self.grid.SetDimensions(0,0,s[0],s[1]-25)
1831 self.sizer.SetDimension(0,s[1]-25,s[0],25) 1788 self.sizer.SetDimension(0,s[1]-25,s[0],25)
1843 for i in range(len(self.n_list)): 1800 for i in range(len(self.n_list)):
1844 self.refresh_row(i) 1801 self.refresh_row(i)
1845 1802
1846 class divine_panel(wx.Panel): 1803 class divine_panel(wx.Panel):
1847 def __init__(self, parent, handler): 1804 def __init__(self, parent, handler):
1848 pname = handler.master_dom.setAttribute("name", 'Divine Spells') 1805 pname = handler.xml.set("name", 'Divine Spells')
1849 wx.Panel.__init__(self, parent, -1) 1806 wx.Panel.__init__(self, parent, -1)
1850 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 1807 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
1851 self.handler = handler 1808 self.handler = handler
1852 sizer = wx.BoxSizer(wx.HORIZONTAL) 1809 sizer = wx.BoxSizer(wx.HORIZONTAL)
1853 sizer.Add(wx.Button(self, 10, "Remove Spell"), 1, wx.EXPAND) 1810 sizer.Add(wx.Button(self, 10, "Remove Spell"), 1, wx.EXPAND)
1860 self.Bind(wx.EVT_SIZE, self.on_size) 1817 self.Bind(wx.EVT_SIZE, self.on_size)
1861 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10) 1818 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10)
1862 self.Bind(wx.EVT_BUTTON, self.on_add, id=20) 1819 self.Bind(wx.EVT_BUTTON, self.on_add, id=20)
1863 self.Bind(wx.EVT_BUTTON, self.on_refresh_spells, id=30) 1820 self.Bind(wx.EVT_BUTTON, self.on_refresh_spells, id=30)
1864 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change) 1821 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
1865 n_list = handler.master_dom._get_childNodes() 1822 n_list = handler.xml[:]
1866 self.n_list = n_list 1823 self.n_list = n_list
1867 self.master_dom = handler.master_dom 1824 self.xml = handler.xml
1868 self.grid.CreateGrid(len(n_list),4,1) 1825 self.grid.CreateGrid(len(n_list),4,1)
1869 self.grid.SetRowLabelSize(0) 1826 self.grid.SetRowLabelSize(0)
1870 self.grid.SetColLabelValue(0,"No.") 1827 self.grid.SetColLabelValue(0,"No.")
1871 self.grid.SetColLabelValue(1,"Lvl") 1828 self.grid.SetColLabelValue(1,"Lvl")
1872 self.grid.SetColLabelValue(2,"Spell") 1829 self.grid.SetColLabelValue(2,"Spell")
1878 def on_cell_change(self,evt): 1835 def on_cell_change(self,evt):
1879 row = evt.GetRow() 1836 row = evt.GetRow()
1880 col = evt.GetCol() 1837 col = evt.GetCol()
1881 value = self.grid.GetCellValue(row,col) 1838 value = self.grid.GetCellValue(row,col)
1882 if col == 0: 1839 if col == 0:
1883 self.n_list[row].setAttribute('memrz',value) 1840 self.n_list[row].set('memrz',value)
1884 1841
1885 1842
1886 def refresh_row(self,i): 1843 def refresh_row(self,i):
1887 spell = self.n_list[i] 1844 spell = self.n_list[i]
1888 memrz = spell.getAttribute('memrz') 1845 memrz = spell.get('memrz')
1889 name = spell.getAttribute('name') 1846 name = spell.get('name')
1890 type = spell.getAttribute('desc') 1847 type = spell.get('desc')
1891 level = spell.getAttribute('level') 1848 level = spell.get('level')
1892 self.grid.SetCellValue(i,0,memrz) 1849 self.grid.SetCellValue(i,0,memrz)
1893 self.grid.SetCellValue(i,2,name) 1850 self.grid.SetCellValue(i,2,name)
1894 self.grid.SetReadOnly(i,2) 1851 self.grid.SetReadOnly(i,2)
1895 self.grid.SetCellValue(i,3,type) 1852 self.grid.SetCellValue(i,3,type)
1896 self.grid.SetReadOnly(i,3) 1853 self.grid.SetReadOnly(i,3)
1900 def on_remove(self,evt): 1857 def on_remove(self,evt):
1901 rows = self.grid.GetNumberRows() 1858 rows = self.grid.GetNumberRows()
1902 for i in range(rows): 1859 for i in range(rows):
1903 if self.grid.IsInSelection(i,0): 1860 if self.grid.IsInSelection(i,0):
1904 self.grid.DeleteRows(i) 1861 self.grid.DeleteRows(i)
1905 self.master_dom.removeChild(self.n_list[i]) 1862 self.xml.remove(self.n_list[i])
1906 self.handler.refresh_spells() 1863 self.handler.refresh_spells()
1907 1864
1908 def on_add(self,evt): 1865 def on_add(self,evt):
1909 if not self.temp_dom: 1866 if not self.temp_dom:
1910 tmp = open(orpg.dirpath.dir_struct["d20"]+"d20divine.xml","r") 1867 tree = parse(orpg.dirpath.dir_struct["d20"]+"d20divine.xml")
1911 xml_dom = parseXml_with_dlg(self,tmp.read()) 1868 self.temp_dom = tree.getroot()
1912 xml_dom = xml_dom._get_firstChild() 1869 f_list = self.temp_dom.findall('gift')
1913 tmp.close()
1914 self.temp_dom = xml_dom
1915 f_list = self.temp_dom.getElementsByTagName('gift')
1916 opts = [] 1870 opts = []
1917 # lvl = int(self.handler.get_char_lvl('level')) 1871 # lvl = int(self.handler.get_char_lvl('level'))
1918 # castlvl = lvl / 2 1872 # castlvl = lvl / 2
1919 for f in f_list: 1873 for f in f_list:
1920 opts.append("(" + f.getAttribute('level') + ")" + f.getAttribute('name')) 1874 opts.append("(" + f.get('level') + ")" + f.get('name'))
1921 # spelllvl = f.getAttribute('level') 1875 # spelllvl = f.get('level')
1922 # if spelllvl <= "1": 1876 # if spelllvl <= "1":
1923 # opts.append("(" + f.getAttribute('level') + ")" + f.getAttribute('name')) 1877 # opts.append("(" + f.get('level') + ")" + f.get('name'))
1924 # else: 1878 # else:
1925 # if eval('%d >= %s' %(castlvl, spelllvl)): 1879 # if eval('%d >= %s' %(castlvl, spelllvl)):
1926 # opts.append("(" + f.getAttribute('level') + ")" + f.getAttribute('name')) 1880 # opts.append("(" + f.get('level') + ")" + f.get('name'))
1927 dlg = wx.SingleChoiceDialog(self,'Choose Spell','Spells',opts) 1881 dlg = wx.SingleChoiceDialog(self,'Choose Spell','Spells',opts)
1928 if dlg.ShowModal() == wx.ID_OK: 1882 if dlg.ShowModal() == wx.ID_OK:
1929 i = dlg.GetSelection() 1883 i = dlg.GetSelection()
1930 new_node = self.master_dom.appendChild(f_list[i].cloneNode(False)) 1884 new_node = self.xml.append(XML(tostring(f_list[i])))
1931 self.grid.AppendRows(1) 1885 self.grid.AppendRows(1)
1932 self.n_list = self.master_dom.getElementsByTagName('gift') 1886 self.n_list = self.xml.findall('gift')
1933 self.refresh_row(self.grid.GetNumberRows()-1) 1887 self.refresh_row(self.grid.GetNumberRows()-1)
1934 self.handler.refresh_spells() 1888 self.handler.refresh_spells()
1935 dlg.Destroy() 1889 dlg.Destroy()
1936 1890
1937 def on_refresh_spells( self, evt ): 1891 def on_refresh_spells( self, evt ):
1938 f_list = self.master_dom.getElementsByTagName('gift') 1892 f_list = self.xml.findall('gift')
1939 for spell in f_list: 1893 for spell in f_list:
1940 spell.setAttribute( 'used', '0' ) 1894 spell.set( 'used', '0' )
1941 1895
1942 def on_size(self,event): 1896 def on_size(self,event):
1943 s = self.GetClientSizeTuple() 1897 s = self.GetClientSizeTuple()
1944 self.grid.SetDimensions(0,0,s[0],s[1]-25) 1898 self.grid.SetDimensions(0,0,s[0],s[1]-25)
1945 self.sizer.SetDimension(0,s[1]-25,s[0],25) 1899 self.sizer.SetDimension(0,s[1]-25,s[0],25)
1958 self.refresh_row(i) 1912 self.refresh_row(i)
1959 1913
1960 1914
1961 class power_panel(wx.Panel): 1915 class power_panel(wx.Panel):
1962 def __init__(self, parent, handler): 1916 def __init__(self, parent, handler):
1963 pname = handler.master_dom.setAttribute("name", 'Pionic Powers') 1917 pname = handler.xml.set("name", 'Pionic Powers')
1964 wx.Panel.__init__(self, parent, -1) 1918 wx.Panel.__init__(self, parent, -1)
1965 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 1919 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
1966 self.handler = handler 1920 self.handler = handler
1967 sizer = wx.BoxSizer(wx.HORIZONTAL) 1921 sizer = wx.BoxSizer(wx.HORIZONTAL)
1968 sizer.Add(wx.Button(self, 10, "Remove Power"), 1, wx.EXPAND) 1922 sizer.Add(wx.Button(self, 10, "Remove Power"), 1, wx.EXPAND)
1974 self.Bind(wx.EVT_SIZE, self.on_size) 1928 self.Bind(wx.EVT_SIZE, self.on_size)
1975 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10) 1929 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10)
1976 self.Bind(wx.EVT_BUTTON, self.on_add, id=20) 1930 self.Bind(wx.EVT_BUTTON, self.on_add, id=20)
1977 self.Bind(wx.EVT_BUTTON, self.on_refresh_powers, id=30) 1931 self.Bind(wx.EVT_BUTTON, self.on_refresh_powers, id=30)
1978 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change) 1932 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
1979 n_list = handler.master_dom._get_childNodes() 1933 n_list = handler.xml[:]
1980 self.n_list = n_list 1934 self.n_list = n_list
1981 self.master_dom = handler.master_dom 1935 self.xml = handler.xml
1982 self.grid.CreateGrid(len(n_list),5,1) 1936 self.grid.CreateGrid(len(n_list),5,1)
1983 self.grid.SetRowLabelSize(0) 1937 self.grid.SetRowLabelSize(0)
1984 self.grid.SetColLabelValue(0,"PP") 1938 self.grid.SetColLabelValue(0,"PP")
1985 self.grid.SetColLabelValue(1,"Lvl") 1939 self.grid.SetColLabelValue(1,"Lvl")
1986 self.grid.SetColLabelValue(2,"Power") 1940 self.grid.SetColLabelValue(2,"Power")
1995 def on_cell_change(self,evt): 1949 def on_cell_change(self,evt):
1996 row = evt.GetRow() 1950 row = evt.GetRow()
1997 col = evt.GetCol() 1951 col = evt.GetCol()
1998 value = self.grid.GetCellValue(row,col) 1952 value = self.grid.GetCellValue(row,col)
1999 """if col == 0: 1953 """if col == 0:
2000 self.n_list[row].setAttribute('memrz',value)""" 1954 self.n_list[row].set('memrz',value)"""
2001 1955
2002 1956
2003 def refresh_row(self,i): 1957 def refresh_row(self,i):
2004 power = self.n_list[i] 1958 power = self.n_list[i]
2005 point = power.getAttribute('point') 1959 point = power.get('point')
2006 name = power.getAttribute('name') 1960 name = power.get('name')
2007 type = power.getAttribute('desc') 1961 type = power.get('desc')
2008 test = power.getAttribute('test') 1962 test = power.get('test')
2009 level = power.getAttribute('level') 1963 level = power.get('level')
2010 self.grid.SetCellValue(i,0,point) 1964 self.grid.SetCellValue(i,0,point)
2011 self.grid.SetReadOnly(i,0) 1965 self.grid.SetReadOnly(i,0)
2012 self.grid.SetCellValue(i,1,level) 1966 self.grid.SetCellValue(i,1,level)
2013 self.grid.SetReadOnly(i,1) 1967 self.grid.SetReadOnly(i,1)
2014 self.grid.SetCellValue(i,2,name) 1968 self.grid.SetCellValue(i,2,name)
2021 def on_remove(self,evt): 1975 def on_remove(self,evt):
2022 rows = self.grid.GetNumberRows() 1976 rows = self.grid.GetNumberRows()
2023 for i in range(rows): 1977 for i in range(rows):
2024 if self.grid.IsInSelection(i,0): 1978 if self.grid.IsInSelection(i,0):
2025 self.grid.DeleteRows(i) 1979 self.grid.DeleteRows(i)
2026 self.master_dom.removeChild(self.n_list[i]) 1980 self.xml.removeChild(self.n_list[i])
2027 self.handler.refresh_powers() 1981 self.handler.refresh_powers()
2028 1982
2029 def on_add(self,evt): 1983 def on_add(self,evt):
2030 if not self.temp_dom: 1984 if not self.temp_dom:
2031 tmp = open(orpg.dirpath.dir_struct["d20"]+"d20powers.xml","r") 1985 tree = parse(orpg.dirpath.dir_struct["d20"]+"d20powers.xml")
2032 xml_dom = parseXml_with_dlg(self,tmp.read()) 1986 self.temp_dom = tree.getroot()
2033 xml_dom = xml_dom._get_firstChild() 1987 f_list = self.temp_dom.findall('power')
2034 tmp.close()
2035 self.temp_dom = xml_dom
2036 f_list = self.temp_dom.getElementsByTagName('power')
2037 opts = [] 1988 opts = []
2038 # lvl = int(self.handler.get_char_lvl('level')) 1989 # lvl = int(self.handler.get_char_lvl('level'))
2039 # castlvl = lvl / 2 1990 # castlvl = lvl / 2
2040 for f in f_list: 1991 for f in f_list:
2041 opts.append("(" + f.getAttribute('level') + ") - " + f.getAttribute('name') + " - " + f.getAttribute('test')) 1992 opts.append("(" + f.get('level') + ") - " + f.get('name') + " - " + f.get('test'))
2042 # spelllvl = f.getAttribute('level') 1993 # spelllvl = f.get('level')
2043 # if spelllvl <= "1": 1994 # if spelllvl <= "1":
2044 # opts.append("(" + f.getAttribute('level') + ") - " + f.getAttribute('name') + " - " + f.getAttribute('test')) 1995 # opts.append("(" + f.get('level') + ") - " + f.get('name') + " - " + f.get('test'))
2045 # else: 1996 # else:
2046 # if eval('%d >= %s' %(castlvl, spelllvl)): 1997 # if eval('%d >= %s' %(castlvl, spelllvl)):
2047 # opts.append("(" + f.getAttribute('level') + ") - " + f.getAttribute('name') + " - " + f.getAttribute('test')) 1998 # opts.append("(" + f.get('level') + ") - " + f.get('name') + " - " + f.get('test'))
2048 dlg = wx.SingleChoiceDialog(self,'Choose Power','Powers',opts) 1999 dlg = wx.SingleChoiceDialog(self,'Choose Power','Powers',opts)
2049 if dlg.ShowModal() == wx.ID_OK: 2000 if dlg.ShowModal() == wx.ID_OK:
2050 i = dlg.GetSelection() 2001 i = dlg.GetSelection()
2051 new_node = self.master_dom.appendChild(f_list[i].cloneNode(False)) 2002 new_node = self.xml.append(XML(tostring(f_list[i])))
2052 self.grid.AppendRows(1) 2003 self.grid.AppendRows(1)
2053 self.n_list = self.master_dom.getElementsByTagName('power') 2004 self.n_list = self.xml.findall('power')
2054 self.refresh_row(self.grid.GetNumberRows()-1) 2005 self.refresh_row(self.grid.GetNumberRows()-1)
2055 self.handler.refresh_powers() 2006 self.handler.refresh_powers()
2056 dlg.Destroy() 2007 dlg.Destroy()
2057 2008
2058 def on_remove(self,evt): 2009 def on_remove(self,evt):
2059 rows = self.grid.GetNumberRows() 2010 rows = self.grid.GetNumberRows()
2060 for i in range(rows): 2011 for i in range(rows):
2061 if self.grid.IsInSelection(i,0): 2012 if self.grid.IsInSelection(i,0):
2062 self.grid.DeleteRows(i) 2013 self.grid.DeleteRows(i)
2063 self.master_dom.removeChild(self.n_list[i]) 2014 self.xml.remove(self.n_list[i])
2064 self.n_list = self.master_dom.getElementsByTagName('weapon') 2015 self.n_list = self.xml.findall('weapon')
2065 self.handler.refresh_weapons() 2016 self.handler.refresh_weapons()
2066 2017
2067 2018
2068 def on_refresh_powers( self, evt ): 2019 def on_refresh_powers( self, evt ):
2069 mfre = self.handler.get_char_pp('maxfree') 2020 mfre = self.handler.get_char_pp('maxfree')
2091 self.refresh_row(i) 2042 self.refresh_row(i)
2092 2043
2093 class attack_grid(wx.grid.Grid): 2044 class attack_grid(wx.grid.Grid):
2094 """grid for attacks""" 2045 """grid for attacks"""
2095 def __init__(self, parent, handler): 2046 def __init__(self, parent, handler):
2096 pname = handler.master_dom.setAttribute("name", 'Melee') 2047 pname = handler.xml.set("name", 'Melee')
2097 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 2048 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
2098 self.parent = parent 2049 self.parent = parent
2099 self.handler = handler 2050 self.handler = handler
2100 self.babs = self.handler.melee 2051 self.babs = self.handler.melee
2101 self.CreateGrid(1,7) 2052 self.CreateGrid(1,7)
2115 int(value) 2066 int(value)
2116 except: 2067 except:
2117 value = "0" 2068 value = "0"
2118 self.SetCellValue( row, col, value ) 2069 self.SetCellValue( row, col, value )
2119 attribs = ['base','second','third','forth','fifth','sixth','misc'] 2070 attribs = ['base','second','third','forth','fifth','sixth','misc']
2120 self.babs.setAttribute( attribs[col], value ) 2071 self.babs.set( attribs[col], value )
2121 self.parent.refresh_data() 2072 self.parent.refresh_data()
2122 2073
2123 def refresh_data(self): 2074 def refresh_data(self):
2124 attack_mods = self.handler.get_attack_data() 2075 attack_mods = self.handler.get_attack_data()
2125 for i in range(0,7): 2076 for i in range(0,7):
2134 evt.Skip() 2085 evt.Skip()
2135 self.Refresh() 2086 self.Refresh()
2136 2087
2137 class weapon_panel(wx.Panel): 2088 class weapon_panel(wx.Panel):
2138 def __init__(self, parent, handler): 2089 def __init__(self, parent, handler):
2139 pname = handler.master_dom.setAttribute("name", 'Weapons') 2090 pname = handler.xml.set("name", 'Weapons')
2140 wx.Panel.__init__(self, parent, -1) 2091 wx.Panel.__init__(self, parent, -1)
2141 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 2092 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
2142 sizer = wx.BoxSizer(wx.HORIZONTAL) 2093 sizer = wx.BoxSizer(wx.HORIZONTAL)
2143 sizer.Add(wx.Button(self, 10, "Remove Weapon"), 1, wx.EXPAND) 2094 sizer.Add(wx.Button(self, 10, "Remove Weapon"), 1, wx.EXPAND)
2144 sizer.Add(wx.Size(10,10)) 2095 sizer.Add(wx.Size(10,10))
2146 self.sizer = sizer 2097 self.sizer = sizer
2147 self.Bind(wx.EVT_SIZE, self.on_size) 2098 self.Bind(wx.EVT_SIZE, self.on_size)
2148 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10) 2099 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10)
2149 self.Bind(wx.EVT_BUTTON, self.on_add, id=20) 2100 self.Bind(wx.EVT_BUTTON, self.on_add, id=20)
2150 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change) 2101 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
2151 n_list = handler.master_dom.getElementsByTagName('weapon') 2102 n_list = handler.xml.findall('weapon')
2152 self.n_list = n_list 2103 self.n_list = n_list
2153 self.master_dom = handler.master_dom 2104 self.xml = handler.xml
2154 self.handler = handler 2105 self.handler = handler
2155 self.grid.CreateGrid(len(n_list),8,1) 2106 self.grid.CreateGrid(len(n_list),8,1)
2156 self.grid.SetRowLabelSize(0) 2107 self.grid.SetRowLabelSize(0)
2157 col_names = ['Name','damage','mod','critical','type','weight','range','size'] 2108 col_names = ['Name','damage','mod','critical','type','weight','range','size']
2158 for i in range(len(col_names)): 2109 for i in range(len(col_names)):
2164 def on_cell_change(self,evt): 2115 def on_cell_change(self,evt):
2165 row = evt.GetRow() 2116 row = evt.GetRow()
2166 col = evt.GetCol() 2117 col = evt.GetCol()
2167 value = self.grid.GetCellValue(row,col) 2118 value = self.grid.GetCellValue(row,col)
2168 if col == 0: 2119 if col == 0:
2169 self.n_list[row].setAttribute('name',value) 2120 self.n_list[row].set('name',value)
2170 self.handler.refresh_weapons(); 2121 self.handler.refresh_weapons();
2171 else: 2122 else:
2172 self.n_list[row].setAttribute(self.grid.GetColLabelValue(col),value) 2123 self.n_list[row].set(self.grid.GetColLabelValue(col),value)
2173 2124
2174 def refresh_row(self,i): 2125 def refresh_row(self,i):
2175 n = self.n_list[i] 2126 n = self.n_list[i]
2176 name = n.getAttribute('name') 2127 name = n.get('name')
2177 mod = n.getAttribute('mod') 2128 mod = n.get('mod')
2178 ran = n.getAttribute('range') 2129 ran = n.get('range')
2179 self.grid.SetCellValue(i,0,name) 2130 self.grid.SetCellValue(i,0,name)
2180 self.grid.SetCellValue(i,1,n.getAttribute('damage')) 2131 self.grid.SetCellValue(i,1,n.get('damage'))
2181 self.grid.SetCellValue(i,2,mod) 2132 self.grid.SetCellValue(i,2,mod)
2182 self.grid.SetCellValue(i,3,n.getAttribute('critical')) 2133 self.grid.SetCellValue(i,3,n.get('critical'))
2183 self.grid.SetCellValue(i,4,n.getAttribute('type')) 2134 self.grid.SetCellValue(i,4,n.get('type'))
2184 self.grid.SetCellValue(i,5,n.getAttribute('weight')) 2135 self.grid.SetCellValue(i,5,n.get('weight'))
2185 self.grid.SetCellValue(i,6,ran) 2136 self.grid.SetCellValue(i,6,ran)
2186 self.grid.SetCellValue(i,7,n.getAttribute('size') ) 2137 self.grid.SetCellValue(i,7,n.get('size') )
2187 2138
2188 def on_remove(self,evt): 2139 def on_remove(self,evt):
2189 rows = self.grid.GetNumberRows() 2140 rows = self.grid.GetNumberRows()
2190 for i in range(rows): 2141 for i in range(rows):
2191 if self.grid.IsInSelection(i,0): 2142 if self.grid.IsInSelection(i,0):
2192 self.grid.DeleteRows(i) 2143 self.grid.DeleteRows(i)
2193 self.master_dom.removeChild(self.n_list[i]) 2144 self.xml.remove(self.n_list[i])
2194 self.n_list = self.master_dom.getElementsByTagName('weapon') 2145 self.n_list = self.xml.findall('weapon')
2195 self.handler.refresh_weapons() 2146 self.handler.refresh_weapons()
2196 2147
2197 def on_add(self,evt): 2148 def on_add(self,evt):
2198 if not self.temp_dom: 2149 if not self.temp_dom:
2199 tmp = open(orpg.dirpath.dir_struct["d20"]+"d20weapons.xml","r") 2150 tree = parse(orpg.dirpath.dir_struct["d20"]+"d20weapons.xml")
2200 xml_dom = parseXml_with_dlg(self,tmp.read()) 2151 self.temp_dom = tree.getroot()
2201 xml_dom = xml_dom._get_firstChild() 2152 f_list = self.temp_dom.findall('weapon')
2202 tmp.close()
2203 self.temp_dom = xml_dom
2204 f_list = self.temp_dom.getElementsByTagName('weapon')
2205 opts = [] 2153 opts = []
2206 for f in f_list: 2154 for f in f_list:
2207 opts.append(f.getAttribute('name')) 2155 opts.append(f.get('name'))
2208 dlg = wx.SingleChoiceDialog(self,'Choose Weapon','Weapon List',opts) 2156 dlg = wx.SingleChoiceDialog(self,'Choose Weapon','Weapon List',opts)
2209 if dlg.ShowModal() == wx.ID_OK: 2157 if dlg.ShowModal() == wx.ID_OK:
2210 i = dlg.GetSelection() 2158 i = dlg.GetSelection()
2211 new_node = self.master_dom.appendChild(f_list[i].cloneNode(False)) 2159 new_node = self.xml.append(XML(tostring(f_list[i])))
2212 self.grid.AppendRows(1) 2160 self.grid.AppendRows(1)
2213 self.n_list = self.master_dom.getElementsByTagName('weapon') 2161 self.n_list = self.xml.findall('weapon')
2214 self.refresh_row(self.grid.GetNumberRows()-1) 2162 self.refresh_row(self.grid.GetNumberRows()-1)
2215 self.handler.refresh_weapons() 2163 self.handler.refresh_weapons()
2216 dlg.Destroy() 2164 dlg.Destroy()
2217 2165
2218 def on_size(self,event): 2166 def on_size(self,event):
2231 self.refresh_row(i) 2179 self.refresh_row(i)
2232 2180
2233 2181
2234 class attack_panel(wx.Panel): 2182 class attack_panel(wx.Panel):
2235 def __init__(self, parent, handler): 2183 def __init__(self, parent, handler):
2236 pname = handler.master_dom.setAttribute("name", 'Melee') 2184 pname = handler.xml.set("name", 'Melee')
2237 wx.Panel.__init__(self, parent, -1) 2185 wx.Panel.__init__(self, parent, -1)
2238 2186
2239 self.a_grid = attack_grid(self, handler) 2187 self.a_grid = attack_grid(self, handler)
2240 self.w_panel = weapon_panel(self, handler) 2188 self.w_panel = weapon_panel(self, handler)
2241 self.sizer = wx.BoxSizer(wx.VERTICAL) 2189 self.sizer = wx.BoxSizer(wx.VERTICAL)
2253 self.a_grid.refresh_data() 2201 self.a_grid.refresh_data()
2254 2202
2255 2203
2256 class ac_panel(wx.Panel): 2204 class ac_panel(wx.Panel):
2257 def __init__(self, parent, handler): 2205 def __init__(self, parent, handler):
2258 pname = handler.master_dom.setAttribute("name", 'Armor') 2206 pname = handler.xml.set("name", 'Armor')
2259 wx.Panel.__init__(self, parent, -1) 2207 wx.Panel.__init__(self, parent, -1)
2260 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 2208 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
2261 sizer = wx.BoxSizer(wx.HORIZONTAL) 2209 sizer = wx.BoxSizer(wx.HORIZONTAL)
2262 sizer.Add(wx.Button(self, 10, "Remove Armor"), 1, wx.EXPAND) 2210 sizer.Add(wx.Button(self, 10, "Remove Armor"), 1, wx.EXPAND)
2263 sizer.Add(wx.Size(10,10)) 2211 sizer.Add(wx.Size(10,10))
2265 self.sizer = sizer 2213 self.sizer = sizer
2266 self.Bind(wx.EVT_SIZE, self.on_size) 2214 self.Bind(wx.EVT_SIZE, self.on_size)
2267 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10) 2215 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10)
2268 self.Bind(wx.EVT_BUTTON, self.on_add, id=20) 2216 self.Bind(wx.EVT_BUTTON, self.on_add, id=20)
2269 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change) 2217 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
2270 self.master_dom = handler.master_dom 2218 self.xml = handler.xml
2271 n_list = handler.master_dom._get_childNodes() 2219 n_list = handler.xml[:]
2272 self.n_list = n_list 2220 self.n_list = n_list
2273 col_names = ['Armor','bonus','maxdex','cp','sf','weight','speed','type'] 2221 col_names = ['Armor','bonus','maxdex','cp','sf','weight','speed','type']
2274 self.grid.CreateGrid(len(n_list),len(col_names),1) 2222 self.grid.CreateGrid(len(n_list),len(col_names),1)
2275 self.grid.SetRowLabelSize(0) 2223 self.grid.SetRowLabelSize(0)
2276 for i in range(len(col_names)): 2224 for i in range(len(col_names)):
2286 col = evt.GetCol() 2234 col = evt.GetCol()
2287 value = self.grid.GetCellValue(row,col) 2235 value = self.grid.GetCellValue(row,col)
2288 if col >= 1 and col <= 5: 2236 if col >= 1 and col <= 5:
2289 try: 2237 try:
2290 int(value) 2238 int(value)
2291 self.n_list[row].setAttribute(self.atts[col],value) 2239 self.n_list[row].set(self.atts[col],value)
2292 except: 2240 except:
2293 self.grid.SetCellValue(row,col,"0") 2241 self.grid.SetCellValue(row,col,"0")
2294 else: 2242 else:
2295 self.n_list[row].setAttribute(self.atts[col],value) 2243 self.n_list[row].set(self.atts[col],value)
2296 2244
2297 def refresh_row(self,i): 2245 def refresh_row(self,i):
2298 n = self.n_list[i] 2246 n = self.n_list[i]
2299 for y in range(len(self.atts)): 2247 for y in range(len(self.atts)):
2300 self.grid.SetCellValue(i,y,n.getAttribute(self.atts[y])) 2248 self.grid.SetCellValue(i,y,n.get(self.atts[y]))
2301 2249
2302 def on_remove(self,evt): 2250 def on_remove(self,evt):
2303 rows = self.grid.GetNumberRows() 2251 rows = self.grid.GetNumberRows()
2304 for i in range(rows): 2252 for i in range(rows):
2305 if self.grid.IsInSelection(i,0): 2253 if self.grid.IsInSelection(i,0):
2306 self.grid.DeleteRows(i) 2254 self.grid.DeleteRows(i)
2307 self.master_dom.removeChild(self.n_list[i]) 2255 self.xml.remove(self.n_list[i])
2308 2256
2309 def on_add(self,evt): 2257 def on_add(self,evt):
2310 if not self.temp_dom: 2258 if not self.temp_dom:
2311 tmp = open(orpg.dirpath.dir_struct["d20"]+"d20armor.xml","r") 2259 tree = parse(orpg.dirpath.dir_struct["d20"]+"d20armor.xml")
2312 xml_dom = parseXml_with_dlg(self,tmp.read()) 2260 self.temp_dom = tree.getroot()
2313 xml_dom = xml_dom._get_firstChild() 2261 f_list = self.temp_dom.findall('armor')
2314 tmp.close()
2315 self.temp_dom = xml_dom
2316 f_list = self.temp_dom.getElementsByTagName('armor')
2317 opts = [] 2262 opts = []
2318 for f in f_list: 2263 for f in f_list:
2319 opts.append(f.getAttribute('name')) 2264 opts.append(f.get('name'))
2320 dlg = wx.SingleChoiceDialog(self,'Choose Armor:','Armor List',opts) 2265 dlg = wx.SingleChoiceDialog(self,'Choose Armor:','Armor List',opts)
2321 if dlg.ShowModal() == wx.ID_OK: 2266 if dlg.ShowModal() == wx.ID_OK:
2322 i = dlg.GetSelection() 2267 i = dlg.GetSelection()
2323 new_node = self.master_dom.appendChild(f_list[i].cloneNode(False)) 2268 new_node = self.xml.append(XML(tostring(f_list[i])))
2324 self.grid.AppendRows(1) 2269 self.grid.AppendRows(1)
2270 self.n_list = self.xml.findall('armor')
2325 self.refresh_row(self.grid.GetNumberRows()-1) 2271 self.refresh_row(self.grid.GetNumberRows()-1)
2326 dlg.Destroy() 2272 dlg.Destroy()
2273
2327 2274
2328 def on_size(self,event): 2275 def on_size(self,event):
2329 s = self.GetClientSizeTuple() 2276 s = self.GetClientSizeTuple()
2330 self.grid.SetDimensions(0,0,s[0],s[1]-25) 2277 self.grid.SetDimensions(0,0,s[0],s[1]-25)
2331 self.sizer.SetDimension(0,s[1]-25,s[0],25) 2278 self.sizer.SetDimension(0,s[1]-25,s[0],25)
2337 self.grid.SetColSize(i,col_w) 2284 self.grid.SetColSize(i,col_w)
2338 2285
2339 2286
2340 class class_panel(wx.Panel): 2287 class class_panel(wx.Panel):
2341 def __init__(self, parent, handler): 2288 def __init__(self, parent, handler):
2342 pname = handler.master_dom.setAttribute("name", 'Class') 2289 pname = handler.xml.set("name", 'Class')
2343 wx.Panel.__init__(self, parent, -1) 2290 wx.Panel.__init__(self, parent, -1)
2344 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 2291 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
2345 sizer = wx.BoxSizer(wx.HORIZONTAL) 2292 sizer = wx.BoxSizer(wx.HORIZONTAL)
2346 sizer.Add(wx.Button(self, 10, "Remove Class"), 1, wx.EXPAND) 2293 sizer.Add(wx.Button(self, 10, "Remove Class"), 1, wx.EXPAND)
2347 sizer.Add(wx.Size(10,10)) 2294 sizer.Add(wx.Size(10,10))
2351 self.Bind(wx.EVT_SIZE, self.on_size) 2298 self.Bind(wx.EVT_SIZE, self.on_size)
2352 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10) 2299 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10)
2353 self.Bind(wx.EVT_BUTTON, self.on_add, id=20) 2300 self.Bind(wx.EVT_BUTTON, self.on_add, id=20)
2354 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change) 2301 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
2355 2302
2356 n_list = handler.master_dom._get_childNodes() 2303 n_list = handler.xml[:]
2357 self.n_list = n_list 2304 self.n_list = n_list
2358 self.master_dom = handler.master_dom 2305 self.xml = handler.xml
2359 self.grid.CreateGrid(len(n_list),2,1) 2306 self.grid.CreateGrid(len(n_list),2,1)
2360 self.grid.SetRowLabelSize(0) 2307 self.grid.SetRowLabelSize(0)
2361 self.grid.SetColLabelValue(0,"Class") 2308 self.grid.SetColLabelValue(0,"Class")
2362 self.grid.SetColLabelValue(1,"Level") 2309 self.grid.SetColLabelValue(1,"Level")
2363 for i in range(len(n_list)): 2310 for i in range(len(n_list)):
2368 row = evt.GetRow() 2315 row = evt.GetRow()
2369 col = evt.GetCol() 2316 col = evt.GetCol()
2370 value = self.grid.GetCellValue(row,col) 2317 value = self.grid.GetCellValue(row,col)
2371 try: 2318 try:
2372 int(value) 2319 int(value)
2373 self.n_list[row].setAttribute('level',value) 2320 self.n_list[row].set('level',value)
2374 except: 2321 except:
2375 self.grid.SetCellValue(row,col,"1") 2322 self.grid.SetCellValue(row,col,"1")
2376 2323
2377
2378 def refresh_row(self,i): 2324 def refresh_row(self,i):
2379 n = self.n_list[i] 2325 n = self.n_list[i]
2380 name = n.getAttribute('name') 2326 name = n.get('name')
2381 level = n.getAttribute('level') 2327 level = n.get('level')
2382 self.grid.SetCellValue(i,0,name) 2328 self.grid.SetCellValue(i,0,name)
2383 self.grid.SetReadOnly(i,0) 2329 self.grid.SetReadOnly(i,0)
2384 self.grid.SetCellValue(i,1,level) 2330 self.grid.SetCellValue(i,1,level)
2385 #self.grid.SetReadOnly(i,1) 2331 #self.grid.SetReadOnly(i,1)
2386 2332
2387 def on_remove(self,evt): 2333 def on_remove(self,evt):
2388 rows = self.grid.GetNumberRows() 2334 rows = self.grid.GetNumberRows()
2389 for i in range(rows): 2335 for i in range(rows):
2390 if self.grid.IsInSelection(i,0): 2336 if self.grid.IsInSelection(i,0):
2391 self.grid.DeleteRows(i) 2337 self.grid.DeleteRows(i)
2392 self.master_dom.removeChild(self.n_list[i]) 2338 self.xml.remove(self.n_list[i])
2393 2339
2394 def on_add(self,evt): 2340 def on_add(self,evt):
2395 if not self.temp_dom: 2341 if not self.temp_dom:
2396 tmp = open(orpg.dirpath.dir_struct["d20"]+"d20classes.xml","r") 2342 tree = parse(orpg.dirpath.dir_struct["d20"]+"d20classes.xml")
2397 xml_dom = parseXml_with_dlg(self,tmp.read()) 2343 self.temp_dom = tree.getroot()
2398 xml_dom = xml_dom._get_firstChild() 2344 f_list = self.temp_dom.findall('class')
2399 tmp.close()
2400 self.temp_dom = xml_dom
2401 f_list = self.temp_dom.getElementsByTagName('class')
2402 opts = [] 2345 opts = []
2403 for f in f_list: 2346 for f in f_list:
2404 opts.append(f.getAttribute('name')) 2347 opts.append(f.get('name'))
2405 dlg = wx.SingleChoiceDialog(self,'Choose Class','Classes',opts) 2348 dlg = wx.SingleChoiceDialog(self,'Choose Class','Classes',opts)
2406 if dlg.ShowModal() == wx.ID_OK: 2349 if dlg.ShowModal() == wx.ID_OK:
2407 i = dlg.GetSelection() 2350 i = dlg.GetSelection()
2408 new_node = self.master_dom.appendChild(f_list[i].cloneNode(False)) 2351 new_node = self.xml.append(XML(tostring(f_list[i])))
2409 self.grid.AppendRows(1) 2352 self.grid.AppendRows(1)
2353 self.n_list = self.xml.findall('class')
2410 self.refresh_row(self.grid.GetNumberRows()-1) 2354 self.refresh_row(self.grid.GetNumberRows()-1)
2411 dlg.Destroy() 2355 dlg.Destroy()
2412
2413 2356
2414 def on_size(self,event): 2357 def on_size(self,event):
2415 s = self.GetClientSizeTuple() 2358 s = self.GetClientSizeTuple()
2416 self.grid.SetDimensions(0,0,s[0],s[1]-25) 2359 self.grid.SetDimensions(0,0,s[0],s[1]-25)
2417 self.sizer.SetDimension(0,s[1]-25,s[0],25) 2360 self.sizer.SetDimension(0,s[1]-25,s[0],25)