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