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

Traipse Alpha 'OpenRPG' {091001-01} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user. Update Summary (Cleaning up for Beta) Added Bookmarks Fix to Remote Admin Commands Minor fix to text based Server Fix to Pretty Print, from Core Fix to Splitter Nodes not being created Fix to massive amounts of images loading, from Core Added 'boot' command to remote admin Added confirmation window for sent nodes Minor changes to allow for portability to an OpenSUSE linux OS Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG Zoom Mouse plugin added Images added to Plugin UI Switching to Element Tree Map efficiency, from FlexiRPG Added Status Bar to Update Manager default_manifest.xml renamed to default_upmana.xml Cleaner clode for saved repositories New TrueDebug Class in orpg_log (See documentation for usage) Mercurial's hgweb folder is ported to upmana Happy Halloween!
author sirebral
date Sun, 01 Nov 2009 11:36:14 -0600
parents 2fa8bd6785a5
children 06f10429eedc
comparison
equal deleted inserted replaced
123:174658f839c0 124:8827271fbe1b
3 from core import * 3 from core import *
4 from containers import * 4 from containers import *
5 from string import * #a 1.6003 5 from string import * #a 1.6003
6 from inspect import * #a 1.9001 6 from inspect import * #a 1.9001
7 from orpg.dirpath import dir_struct 7 from orpg.dirpath import dir_struct
8 from xml.etree.ElementTree import parse
8 dnd35_EXPORT = wx.NewId() 9 dnd35_EXPORT = wx.NewId()
9 10
10 ############Global Stuff############## 11 ############Global Stuff##############
11 12
12 HP_CUR = wx.NewId() 13 HP_CUR = wx.NewId()
19 root = target 20 root = target
20 target = target.hparent 21 target = target.hparent
21 return root 22 return root
22 23
23 #a 1.6 convinience function added safeGetAttr 24 #a 1.6 convinience function added safeGetAttr
24 def safeGetAttr(node,lable,defRetV=None): 25 def safeGetAttr(node, label, defRetV=None):
25 cna=node.attributes 26 cna=node.attrib
26 for i2 in range(len(cna)): 27 for key in cna:
27 if cna.item(i2).name == lable: 28 if key == label:
28 return cna.item(i2).value 29 return cna[key]
29 #retV=node.getAttribute(lable) # getAttribute does not distingish between 30 #retV=node.get(lable) # get does not distingish between
30 # the attribute not being present vs it having a value of "" 31 # the attribute not being present vs it having a value of ""
31 # This is bad for this routine, thus not used. 32 # This is bad for this routine, thus not used.
32 return defRetV 33 return defRetV
33 #a 1.6... safeGetAttr end. 34 #a 1.6... safeGetAttr end.
34 35
56 57
57 self.myeditor = None 58 self.myeditor = None
58 59
59 60
60 def new_child_handler(self,tag,text,handler_class,icon='gear'): 61 def new_child_handler(self,tag,text,handler_class,icon='gear'):
61 node_list = self.master_dom.getElementsByTagName(tag) 62 node_list = self.xml.findall(tag)
62 tree = self.tree 63 tree = self.tree
63 i = self.tree.icons[icon] 64 i = self.tree.icons[icon]
64 new_tree_node = tree.AppendItem(self.mytree_node,text,i,i) 65 new_tree_node = tree.AppendItem(self.mytree_node,text,i,i)
65 handler = handler_class(node_list[0],new_tree_node,self) 66 handler = handler_class(node_list[0],new_tree_node,self)
66 tree.SetPyData(new_tree_node,handler) 67 tree.SetPyData(new_tree_node,handler)
135 return 136 return
136 137
137 def on_html(self,evt): 138 def on_html(self,evt):
138 html_str = self.tohtml() 139 html_str = self.tohtml()
139 wnd = http_html_window(self.frame.note,-1) 140 wnd = http_html_window(self.frame.note,-1)
140 wnd.title = self.master_dom.getAttribute('name') 141 wnd.title = self.xml.get('name')
141 self.frame.add_panel(wnd) 142 self.frame.add_panel(wnd)
142 wnd.SetPage(html_str) 143 wnd.SetPage(html_str)
143 144
144 def get_design_panel(self,parent): 145 def get_design_panel(self,parent):
145 pass 146 pass
165 wnd = outline_panel(parent,self,gen_grid,"General Information") 166 wnd = outline_panel(parent,self,gen_grid,"General Information")
166 wnd.title = "General Info" 167 wnd.title = "General Info"
167 return wnd 168 return wnd
168 169
169 def tohtml(self): 170 def tohtml(self):
170 n_list = self.master_dom._get_childNodes() 171 n_list = self.xml.getchildren()
171 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>General Information</th></tr><tr><td>" 172 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>General Information</th></tr><tr><td>"
172 for n in n_list: 173 for n in n_list:
173 t_node = component.get('xml').safe_get_text_node(n) 174 html_str += "<B>"+n.tag.capitalize() +":</B> "
174 html_str += "<B>"+n._get_tagName().capitalize() +":</B> " 175 html_str += n.text + ", "
175 html_str += t_node._get_nodeValue() + ", "
176 html_str = html_str[:len(html_str)-2] + "</td></tr></table>" 176 html_str = html_str[:len(html_str)-2] + "</td></tr></table>"
177 return html_str 177 return html_str
178 178
179 def on_name_change(self,name): 179 def on_name_change(self,name):
180 self.char_hander.rename(name) 180 self.char_hander.rename(name)
181 #o 1.5002 self.char_hander = parent in this case. 181 #o 1.5002 self.char_hander = parent in this case.
182 self.charName = name #a 1.5002 make getting name easier. 182 self.charName = name #a 1.5002 make getting name easier.
183 183
184 184
185 def get_char_name( self ): 185 def get_char_name( self ):
186 node = self.master_dom.getElementsByTagName( 'name' )[0] 186 node = self.xml.findall( 'name' )[0]
187 t_node = component.get('xml').safe_get_text_node( node ) 187 return node.text
188 return t_node._get_nodeValue()
189 188
190 class gen_grid(wx.grid.Grid): 189 class gen_grid(wx.grid.Grid):
191 """grid for gen info""" 190 """grid for gen info"""
192 def __init__(self, parent, handler): 191 def __init__(self, parent, handler):
193 pname = handler.master_dom.setAttribute("name", 'General') 192 pname = handler.xml.set("name", 'General')
194 self.hparent = handler #a 1.5002 allow ability to run up tree, needed 193 self.hparent = handler #a 1.5002 allow ability to run up tree, needed
195 # a 1.5002 parent is functional parent, not invoking parent. 194 # a 1.5002 parent is functional parent, not invoking parent.
196 195
197 196
198 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 197 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
199 #self.Bind(wx.EVT_SIZE, self.on_size) 198 #self.Bind(wx.EVT_SIZE, self.on_size)
200 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change) 199 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
201 self.handler = handler 200 self.handler = handler
202 n_list = handler.master_dom._get_childNodes() 201 n_list = handler.xml.getchildren()
203 self.CreateGrid(len(n_list),2) 202 self.CreateGrid(len(n_list),2)
204 self.SetRowLabelSize(0) 203 self.SetRowLabelSize(0)
205 self.SetColLabelSize(0) 204 self.SetColLabelSize(0)
206 self.n_list = n_list 205 self.n_list = n_list
207 i = 0 206 i = 0
210 209
211 def on_cell_change(self,evt): 210 def on_cell_change(self,evt):
212 row = evt.GetRow() 211 row = evt.GetRow()
213 col = evt.GetCol() 212 col = evt.GetCol()
214 value = self.GetCellValue(row,col) 213 value = self.GetCellValue(row,col)
215 t_node = self.n_list[row]._get_firstChild() 214 t_node = self.n_list[row]
216 t_node._set_nodeValue(value) 215 t_node.text = value
217 if row==0: 216 if row==0:
218 self.handler.on_name_change(value) 217 self.handler.on_name_change(value)
219 #self.AutoSizeColumn(1) 218 #self.AutoSizeColumn(1)
220 219
221 def refresh_row(self,rowi): 220 def refresh_row(self, rowi):
222 t_node = component.get('xml').safe_get_text_node(self.n_list[rowi]) 221 self.SetCellValue(rowi, 0, self.n_list[rowi].tag)
223 222 self.SetReadOnly(rowi, 0)
224 self.SetCellValue(rowi,0,self.n_list[rowi]._get_tagName()) 223 self.SetCellValue(rowi, 1, self.n_list[rowi].text)
225 self.SetReadOnly(rowi,0)
226 self.SetCellValue(rowi,1,t_node._get_nodeValue())
227 self.AutoSizeColumn(1) 224 self.AutoSizeColumn(1)
228 225
229 class dnd35inventory(dnd35_char_child): 226 class dnd35inventory(dnd35_char_child):
230 """ Node Handler for general information. This handler will be 227 """ Node Handler for general information. This handler will be
231 created by dnd35char_handler. 228 created by dnd35char_handler.
240 wnd = inventory_pane(parent, self) #outline_panel(parent,self,inventory_grid,"Inventory") 237 wnd = inventory_pane(parent, self) #outline_panel(parent,self,inventory_grid,"Inventory")
241 wnd.title = "Inventory" 238 wnd.title = "Inventory"
242 return wnd 239 return wnd
243 240
244 def tohtml(self): 241 def tohtml(self):
245 n_list = self.master_dom._get_childNodes() 242 n_list = self.xml.getchildren()
246 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>Inventory</th></tr><tr><td>" 243 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>Inventory</th></tr><tr><td>"
247 for n in n_list: 244 for n in n_list:
248 t_node = component.get('xml').safe_get_text_node(n) 245 html_str += "<B>"+n.tag.capitalize() +":</B> "
249 html_str += "<B>"+n._get_tagName().capitalize() +":</B> " 246 html_str += n.text + "<br />"
250 html_str += t_node._get_nodeValue() + "<br />"
251 html_str = html_str[:len(html_str)-2] + "</td></tr></table>" 247 html_str = html_str[:len(html_str)-2] + "</td></tr></table>"
252 return html_str 248 return html_str
253 249
254 class inventory_pane(wx.Panel): 250 class inventory_pane(wx.Panel):
255 def __init__(self, parent, handler): 251 def __init__(self, parent, handler):
256 wx.Panel.__init__(self, parent, wx.ID_ANY) 252 wx.Panel.__init__(self, parent, wx.ID_ANY)
257 253
258 self.n_list = handler.master_dom._get_childNodes() 254 self.n_list = handler.xml.getchildren()
259 self.autosize = False 255 self.autosize = False
260 256
261 self.sizer = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY, "Inventroy"), wx.VERTICAL) 257 self.sizer = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY, "Inventroy"), wx.VERTICAL)
262 258
263 self.lang = wx.TextCtrl(self, wx.ID_ANY, "", style=wx.TE_MULTILINE | wx.TE_BESTWRAP, name="Languages") 259 self.lang = wx.TextCtrl(self, wx.ID_ANY, "", style=wx.TE_MULTILINE | wx.TE_BESTWRAP, name="Languages")
315 nodeName = 'Languages' 311 nodeName = 'Languages'
316 value = self.lang.GetValue() 312 value = self.lang.GetValue()
317 313
318 for node in self.n_list: 314 for node in self.n_list:
319 if node._get_tagName() == nodeName: 315 if node._get_tagName() == nodeName:
320 t_node = component.get('xml').safe_get_text_node(node) 316 node.text = value
321 t_node._set_nodeValue(value)
322 317
323 def saveMoney(self, row, col): 318 def saveMoney(self, row, col):
324 value = self.grid.GetCellValue(row, col) 319 value = self.grid.GetCellValue(row, col)
325 t_node = component.get('xml').safe_get_text_node(self.n_list[row]) 320 self.n_list[row].text = value
326 t_node._set_nodeValue(value)
327 321
328 def on_cell_change(self, evt): 322 def on_cell_change(self, evt):
329 row = evt.GetRow() 323 row = evt.GetRow()
330 col = evt.GetCol() 324 col = evt.GetCol()
331 self.grid.AutoSizeColumn(col) 325 self.grid.AutoSizeColumn(col)
332 wx.CallAfter(self.saveMoney, row, col) 326 wx.CallAfter(self.saveMoney, row, col)
333 327
334 328
335 329
336 def refresh_row(self, row): 330 def refresh_row(self, row):
337 t_node = component.get('xml').safe_get_text_node(self.n_list[row]) 331 tagname = self.n_list[row].tag
338 tagname = self.n_list[row]._get_tagName() 332 value = self.n_list[row].text
339 value = t_node._get_nodeValue()
340 if tagname == 'Gear': 333 if tagname == 'Gear':
341 self.fillTextNode(tagname, value) 334 self.fillTextNode(tagname, value)
342 elif tagname == 'Magic': 335 elif tagname == 'Magic':
343 self.fillTextNode(tagname, value) 336 self.fillTextNode(tagname, value)
344 elif tagname == 'Languages': 337 elif tagname == 'Languages':
365 self.new_child_handler('saves','Saves',dnd35saves,'skull') 358 self.new_child_handler('saves','Saves',dnd35saves,'skull')
366 self.myeditor = None 359 self.myeditor = None
367 360
368 361
369 def new_child_handler(self,tag,text,handler_class,icon='gear'): 362 def new_child_handler(self,tag,text,handler_class,icon='gear'):
370 node_list = self.master_dom.getElementsByTagName(tag) 363 node_list = self.xml.findall(tag)
371 tree = self.tree 364 tree = self.tree
372 i = self.tree.icons[icon] 365 i = self.tree.icons[icon]
373 new_tree_node = tree.AppendItem(self.mytree_node,text,i,i) 366 new_tree_node = tree.AppendItem(self.mytree_node,text,i,i)
374 handler = handler_class(node_list[0],new_tree_node,self) 367 handler = handler_class(node_list[0],new_tree_node,self)
375 tree.SetPyData(new_tree_node,handler) 368 tree.SetPyData(new_tree_node,handler)
403 return 396 return
404 397
405 def on_html(self,evt): 398 def on_html(self,evt):
406 html_str = self.tohtml() 399 html_str = self.tohtml()
407 wnd = http_html_window(self.frame.note,-1) 400 wnd = http_html_window(self.frame.note,-1)
408 wnd.title = self.master_dom.getAttribute('name') 401 wnd.title = self.xml.get('name')
409 self.frame.add_panel(wnd) 402 self.frame.add_panel(wnd)
410 wnd.SetPage(html_str) 403 wnd.SetPage(html_str)
411 404
412 def get_design_panel(self,parent): 405 def get_design_panel(self,parent):
413 pass 406 pass
427 self.hparent = parent #a 1.5002 allow ability to run up tree. 420 self.hparent = parent #a 1.5002 allow ability to run up tree.
428 self.root = getRoot(self) #a 1.5002 get top of our local function tree. 421 self.root = getRoot(self) #a 1.5002 get top of our local function tree.
429 self.root.abilities = self #a 1.5002 let other classes find me. 422 self.root.abilities = self #a 1.5002 let other classes find me.
430 423
431 self.abilities = {} 424 self.abilities = {}
432 node_list = self.master_dom.getElementsByTagName('stat') 425 node_list = self.xml.findall('stat')
433 tree = self.tree 426 tree = self.tree
434 icons = tree.icons 427 icons = tree.icons
435 428
436 for n in node_list: 429 for n in node_list:
437 name = n.getAttribute('abbr') 430 name = n.get('abbr')
438 self.abilities[name] = n 431 self.abilities[name] = n
439 new_tree_node = tree.AppendItem( self.mytree_node, name, icons['gear'], icons['gear'] ) 432 new_tree_node = tree.AppendItem( self.mytree_node, name, icons['gear'], icons['gear'] )
440 tree.SetPyData( new_tree_node, self ) 433 tree.SetPyData( new_tree_node, self )
441 #print "dnd35ability - init self.abilities",self.abilities #a (debug) 1.5002 434 #print "dnd35ability - init self.abilities",self.abilities #a (debug) 1.5002
442 435
455 chat = self.chat 448 chat = self.chat
456 txt = '%s check: [1d20%s%s]' % ( name, mod1, mod ) 449 txt = '%s check: [1d20%s%s]' % ( name, mod1, mod )
457 chat.ParsePost( txt, True, True ) 450 chat.ParsePost( txt, True, True )
458 451
459 def get_mod(self,abbr): 452 def get_mod(self,abbr):
460 score = int(self.abilities[abbr].getAttribute('base')) 453 score = int(self.abilities[abbr].get('base'))
461 mod = (score - 10) / 2 454 mod = (score - 10) / 2
462 mod = int(mod) 455 mod = int(mod)
463 return mod 456 return mod
464 457
465 def set_score(self,abbr,score): 458 def set_score(self,abbr,score):
466 if score >= 0: 459 if score >= 0:
467 self.abilities[abbr].setAttribute("base",str(score)) 460 self.abilities[abbr].set("base",str(score))
468 461
469 def get_design_panel(self,parent): 462 def get_design_panel(self,parent):
470 wnd = outline_panel(parent,self,abil_grid,"Abilities") 463 wnd = outline_panel(parent,self,abil_grid,"Abilities")
471 wnd.title = "Abilities (edit)" 464 wnd.title = "Abilities (edit)"
472 return wnd 465 return wnd
473 466
474 def tohtml(self): 467 def tohtml(self):
475 html_str = """<table border='1' width=100%><tr BGCOLOR=#E9E9E9 ><th width='50%'>Ability</th> 468 html_str = """<table border='1' width=100%><tr BGCOLOR=#E9E9E9 ><th width='50%'>Ability</th>
476 <th>Base</th><th>Modifier</th></tr>""" 469 <th>Base</th><th>Modifier</th></tr>"""
477 node_list = self.master_dom.getElementsByTagName('stat') 470 node_list = self.xml.findall('stat')
478 for n in node_list: 471 for n in node_list:
479 name = n.getAttribute('name') 472 name = n.get('name')
480 abbr = n.getAttribute('abbr') 473 abbr = n.get('abbr')
481 base = n.getAttribute('base') 474 base = n.get('base')
482 mod = str(self.get_mod(abbr)) 475 mod = str(self.get_mod(abbr))
483 if int(mod) >= 0: #m 1.6013 added "int(" and ")" 476 if int(mod) >= 0: #m 1.6013 added "int(" and ")"
484 mod1 = "+" 477 mod1 = "+"
485 else: 478 else:
486 mod1 = "" 479 mod1 = ""
490 return html_str 483 return html_str
491 484
492 class abil_grid(wx.grid.Grid): 485 class abil_grid(wx.grid.Grid):
493 """grid for abilities""" 486 """grid for abilities"""
494 def __init__(self, parent, handler): 487 def __init__(self, parent, handler):
495 pname = handler.master_dom.setAttribute("name", 'Stats') 488 pname = handler.xml.set("name", 'Stats')
496 self.hparent = handler #a 1.5002 allow ability to run up tree. 489 self.hparent = handler #a 1.5002 allow ability to run up tree.
497 self.root = getRoot(self) 490 self.root = getRoot(self)
498 #a 1.5002 in this case, we need the functional parent, not the invoking parent. 491 #a 1.5002 in this case, we need the functional parent, not the invoking parent.
499 492
500 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 493 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
501 self.Bind(wx.EVT_SIZE, self.on_size) 494 self.Bind(wx.EVT_SIZE, self.on_size)
502 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change) 495 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
503 self.handler = handler 496 self.handler = handler
504 stats = handler.master_dom.getElementsByTagName('stat') 497 stats = handler.xml.findall('stat')
505 self.CreateGrid(len(stats),3) 498 self.CreateGrid(len(stats),3)
506 self.SetRowLabelSize(0) 499 self.SetRowLabelSize(0)
507 col_names = ['Ability','Score','Modifier'] 500 col_names = ['Ability','Score','Modifier']
508 for i in range(len(col_names)): 501 for i in range(len(col_names)):
509 self.SetColLabelValue(i,col_names[i]) 502 self.SetColLabelValue(i,col_names[i])
518 col = evt.GetCol() 511 col = evt.GetCol()
519 value = self.GetCellValue(row,col) 512 value = self.GetCellValue(row,col)
520 #print value 513 #print value
521 try: 514 try:
522 int(value) 515 int(value)
523 self.stats[row].setAttribute('base',value) 516 self.stats[row].set('base',value)
524 self.refresh_row(row) 517 self.refresh_row(row)
525 except: 518 except:
526 self.SetCellValue(row,col,"0") 519 self.SetCellValue(row,col,"0")
527 if self.char_wnd: 520 if self.char_wnd:
528 self.char_wnd.refresh_data() 521 self.char_wnd.refresh_data()
530 #mark5 523 #mark5
531 524
532 def refresh_row(self,rowi): 525 def refresh_row(self,rowi):
533 s = self.stats[rowi] 526 s = self.stats[rowi]
534 527
535 name = s.getAttribute('name') 528 name = s.get('name')
536 abbr = s.getAttribute('abbr') 529 abbr = s.get('abbr')
537 self.SetCellValue(rowi,0,name) 530 self.SetCellValue(rowi,0,name)
538 self.SetReadOnly(rowi,0) 531 self.SetReadOnly(rowi,0)
539 self.SetCellValue(rowi,1,s.getAttribute('base')) 532 self.SetCellValue(rowi,1,s.get('base'))
540 self.SetCellValue(rowi,2,str(self.handler.get_mod(abbr))) 533 self.SetCellValue(rowi,2,str(self.handler.get_mod(abbr)))
541 self.SetReadOnly(rowi,2) 534 self.SetReadOnly(rowi,2)
542 #if self.root.saves.saveGrid: #a 1.6018 d 1.9002 whole if clause 535 #if self.root.saves.saveGrid: #a 1.6018 d 1.9002 whole if clause
543 #print getmembers(self.root.saves.saveGrid) 536 #print getmembers(self.root.saves.saveGrid)
544 #self.root.saves.saveGrid.refresh_data() #a 1.6018 537 #self.root.saves.saveGrid.refresh_data() #a 1.6018
576 wnd.title = "Classes" 569 wnd.title = "Classes"
577 return wnd 570 return wnd
578 571
579 def tohtml(self): 572 def tohtml(self):
580 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>Classes</th></tr><tr><td>" 573 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>Classes</th></tr><tr><td>"
581 n_list = self.master_dom._get_childNodes() 574 n_list = self.xml.getchildren()
582 for n in n_list: 575 for n in n_list:
583 html_str += n.getAttribute('name') + " ("+n.getAttribute('level')+"), " 576 html_str += n.get('name') + " ("+n.get('level')+"), "
584 html_str = html_str[:len(html_str)-2] + "</td></tr></table>" 577 html_str = html_str[:len(html_str)-2] + "</td></tr></table>"
585 return html_str 578 return html_str
586 579
587 def get_char_lvl( self, attr ): 580 def get_char_lvl( self, attr ):
588 node_list = self.master_dom.getElementsByTagName('class') 581 node_list = self.xml.findall('class')
589 # print "eclasses - get_char_lvl node_list",node_list 582 # print "eclasses - get_char_lvl node_list",node_list
590 tot = 0 #a 1.5009 actually, slipping in a quick enhancement ;-) 583 tot = 0 #a 1.5009 actually, slipping in a quick enhancement ;-)
591 for n in node_list: 584 for n in node_list:
592 lvl = n.getAttribute('level') #o 1.5009 not sure of the value of this 585 lvl = n.get('level') #o 1.5009 not sure of the value of this
593 tot += int(lvl) #a 1.5009 586 tot += int(lvl) #a 1.5009
594 type = n.getAttribute('name') #o 1.5009 not sure of the value of this 587 type = n.get('name') #o 1.5009 not sure of the value of this
595 #print type,lvl #a (debug) 1.5009 588 #print type,lvl #a (debug) 1.5009
596 if attr == "level": 589 if attr == "level":
597 return lvl #o 1.5009 this returns the level of someone's first class. ??? 590 return lvl #o 1.5009 this returns the level of someone's first class. ???
598 elif attr == "class": 591 elif attr == "class":
599 return type #o 1.5009 this returns one of the char's classes. ??? 592 return type #o 1.5009 this returns one of the char's classes. ???
600 if attr == "lvl": #a 1.5009 this has value, adding this. 593 if attr == "lvl": #a 1.5009 this has value, adding this.
601 return tot #a 1.5009 return character's "overall" level. 594 return tot #a 1.5009 return character's "overall" level.
602 595
603 def get_class_lvl( self, classN ): #a 1.5009 need to be able to get monk lvl 596 def get_class_lvl( self, classN ): #a 1.5009 need to be able to get monk lvl
604 #a 1.5009 this function is new. 597 #a 1.5009 this function is new.
605 node_list = self.master_dom.getElementsByTagName('class') 598 node_list = self.xml.findall('class')
606 #print "eclasses - get_class_lvl node_list",node_list 599 #print "eclasses - get_class_lvl node_list",node_list
607 for n in node_list: 600 for n in node_list:
608 lvl = n.getAttribute('level') 601 lvl = n.get('level')
609 type = n.getAttribute('name') 602 type = n.get('name')
610 if classN == type: 603 if classN == type:
611 return lvl 604 return lvl
612 605
613 class class_panel(wx.Panel): 606 class class_panel(wx.Panel):
614 def __init__(self, parent, handler): 607 def __init__(self, parent, handler):
615 pname = handler.master_dom.setAttribute("name", 'Class') 608 pname = handler.xml.set("name", 'Class')
616 609
617 wx.Panel.__init__(self, parent, -1) 610 wx.Panel.__init__(self, parent, -1)
618 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 611 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
619 sizer = wx.BoxSizer(wx.VERTICAL) 612 sizer = wx.BoxSizer(wx.VERTICAL)
620 sizer.Add(self.grid, 1, wx.EXPAND) 613 sizer.Add(self.grid, 1, wx.EXPAND)
632 625
633 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10) 626 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10)
634 self.Bind(wx.EVT_BUTTON, self.on_add, id=20) 627 self.Bind(wx.EVT_BUTTON, self.on_add, id=20)
635 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change) 628 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
636 629
637 n_list = handler.master_dom._get_childNodes() 630 n_list = handler.xml.getchildren()
638 self.n_list = n_list 631 self.n_list = n_list
639 self.master_dom = handler.master_dom 632 self.xml = handler.xml
640 self.grid.CreateGrid(len(n_list),3,1) 633 self.grid.CreateGrid(len(n_list),3,1)
641 self.grid.SetRowLabelSize(0) 634 self.grid.SetRowLabelSize(0)
642 self.grid.SetColLabelValue(0,"Class") 635 self.grid.SetColLabelValue(0,"Class")
643 self.grid.SetColLabelValue(1,"Level") 636 self.grid.SetColLabelValue(1,"Level")
644 self.grid.SetColLabelValue(2,"Refrence") 637 self.grid.SetColLabelValue(2,"Refrence")
650 row = evt.GetRow() 643 row = evt.GetRow()
651 col = evt.GetCol() 644 col = evt.GetCol()
652 value = self.grid.GetCellValue(row,col) 645 value = self.grid.GetCellValue(row,col)
653 try: 646 try:
654 int(value) 647 int(value)
655 self.n_list[row].setAttribute('level',value) 648 self.n_list[row].set('level',value)
656 except: 649 except:
657 self.grid.SetCellValue(row,col,"1") 650 self.grid.SetCellValue(row,col,"1")
658 651
659 652
660 def refresh_row(self,i): 653 def refresh_row(self,i):
661 n = self.n_list[i] 654 n = self.n_list[i]
662 655
663 name = n.getAttribute('name') 656 name = n.get('name')
664 level = n.getAttribute('level') 657 level = n.get('level')
665 book = n.getAttribute('book') 658 book = n.get('book')
666 self.grid.SetCellValue(i,0,name) 659 self.grid.SetCellValue(i,0,name)
667 self.grid.SetReadOnly(i,0) 660 self.grid.SetReadOnly(i,0)
668 self.grid.SetCellValue(i,1,level) 661 self.grid.SetCellValue(i,1,level)
669 self.grid.SetCellValue(i,2,book) 662 self.grid.SetCellValue(i,2,book)
670 self.grid.SetReadOnly(i,0) 663 self.grid.SetReadOnly(i,0)
675 def on_remove(self,evt): 668 def on_remove(self,evt):
676 rows = self.grid.GetNumberRows() 669 rows = self.grid.GetNumberRows()
677 for i in range(rows): 670 for i in range(rows):
678 if self.grid.IsInSelection(i,0): 671 if self.grid.IsInSelection(i,0):
679 self.grid.DeleteRows(i) 672 self.grid.DeleteRows(i)
680 self.master_dom.removeChild(self.n_list[i]) 673 self.xml.remove(self.n_list[i])
681 674
682 def on_add(self,evt): 675 def on_add(self,evt):
683 if not self.temp_dom: 676 if not self.temp_dom:
684 tmp = open(dir_struct["dnd35"]+"dnd35classes.xml","r") 677 tree = parse(dir_struct["dnd35"]+"dnd35classes.xml")
685 xml_dom = parseXml_with_dlg(self,tmp.read()) 678 xml_dom = tree.getroot()
686 xml_dom = xml_dom._get_firstChild()
687 tmp.close()
688 self.temp_dom = xml_dom 679 self.temp_dom = xml_dom
689 f_list = self.temp_dom.getElementsByTagName('class') 680 f_list = self.temp_dom.findall('class')
690 opts = [] 681 opts = []
691 for f in f_list: 682 for f in f_list:
692 opts.append(f.getAttribute('name')) 683 opts.append(f.get('name'))
693 dlg = wx.SingleChoiceDialog(self,'Choose Class','Classes',opts) 684 dlg = wx.SingleChoiceDialog(self,'Choose Class','Classes',opts)
694 if dlg.ShowModal() == wx.ID_OK: 685 if dlg.ShowModal() == wx.ID_OK:
695 i = dlg.GetSelection() 686 i = dlg.GetSelection()
696 new_node = self.master_dom.appendChild(f_list[i].cloneNode(False)) 687 new_node = self.xml.append(f_list[i])
697 self.grid.AppendRows(1) 688 self.grid.AppendRows(1)
698 self.refresh_row(self.grid.GetNumberRows()-1) 689 self.refresh_row(self.grid.GetNumberRows()-1)
699 dlg.Destroy() 690 dlg.Destroy()
700 691
701 692
723 tree = self.tree 714 tree = self.tree
724 icons = self.tree.icons 715 icons = self.tree.icons
725 716
726 self.root = getRoot(self) #a 1.5002 717 self.root = getRoot(self) #a 1.5002
727 self.root.saves = self #a 1.6009 718 self.root.saves = self #a 1.6009
728 node_list = self.master_dom.getElementsByTagName('save') 719 node_list = self.xml.findall('save')
729 self.saves={} 720 self.saves={}
730 for n in node_list: 721 for n in node_list:
731 name = n.getAttribute('name') 722 name = n.get('name')
732 self.saves[name] = n 723 self.saves[name] = n
733 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear']) 724 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear'])
734 tree.SetPyData(new_tree_node,self) 725 tree.SetPyData(new_tree_node,self)
735 726
736 #a 1.9002 this whole method 727 #a 1.9002 this whole method
744 else: 735 else:
745 self.saveGridFrame.remove(x) 736 self.saveGridFrame.remove(x)
746 737
747 def get_mod(self,name): 738 def get_mod(self,name):
748 save = self.saves[name] 739 save = self.saves[name]
749 stat = save.getAttribute('stat') 740 stat = save.get('stat')
750 #print "dnd35saves, get_mod: self,root",self,self.root #a (debug) 1.5002 741 #print "dnd35saves, get_mod: self,root",self,self.root #a (debug) 1.5002
751 #print "and abilities",self.root.abilities #a (debug) 1.5002 742 #print "and abilities",self.root.abilities #a (debug) 1.5002
752 stat_mod = self.root.abilities.get_mod(stat) #a 1.5002 743 stat_mod = self.root.abilities.get_mod(stat) #a 1.5002
753 base = int(save.getAttribute('base')) 744 base = int(save.get('base'))
754 miscmod = int(save.getAttribute('miscmod')) 745 miscmod = int(save.get('miscmod'))
755 magmod = int(save.getAttribute('magmod')) 746 magmod = int(save.get('magmod'))
756 total = stat_mod + base + miscmod + magmod 747 total = stat_mod + base + miscmod + magmod
757 return total 748 return total
758 749
759 def on_rclick(self,evt): 750 def on_rclick(self,evt):
760 751
786 def tohtml(self): 777 def tohtml(self):
787 html_str = """<table border='1' width=100% ><tr BGCOLOR=#E9E9E9 > 778 html_str = """<table border='1' width=100% ><tr BGCOLOR=#E9E9E9 >
788 <th width='30%'>Save</th> 779 <th width='30%'>Save</th>
789 <th>Key</th><th>Base</th><th>Abil</th><th>Magic</th> 780 <th>Key</th><th>Base</th><th>Abil</th><th>Magic</th>
790 <th>Misc</th><th>Total</th></tr>""" 781 <th>Misc</th><th>Total</th></tr>"""
791 node_list = self.master_dom.getElementsByTagName('save') 782 node_list = self.xml.findall('save')
792 for n in node_list: 783 for n in node_list:
793 name = n.getAttribute('name') 784 name = n.get('name')
794 stat = n.getAttribute('stat') 785 stat = n.get('stat')
795 base = n.getAttribute('base') 786 base = n.get('base')
796 html_str = html_str + "<tr ALIGN='center'><td>"+name+"</td><td>"+stat+"</td><td>"+base+"</td>" 787 html_str = html_str + "<tr ALIGN='center'><td>"+name+"</td><td>"+stat+"</td><td>"+base+"</td>"
797 #stat_mod = str(dnd_globals["stats"][stat]) #d 1.5002 788 #stat_mod = str(dnd_globals["stats"][stat]) #d 1.5002
798 stat_mod = self.root.abilities.get_mod(stat) #a 1.5002 789 stat_mod = self.root.abilities.get_mod(stat) #a 1.5002
799 790
800 mag = n.getAttribute('magmod') 791 mag = n.get('magmod')
801 misc = n.getAttribute('miscmod') 792 misc = n.get('miscmod')
802 mod = str(self.get_mod(name)) 793 mod = str(self.get_mod(name))
803 if mod >= 0: 794 if mod >= 0:
804 mod1 = "+" 795 mod1 = "+"
805 else: 796 else:
806 mod1 = "" 797 mod1 = ""
812 803
813 #mark6 804 #mark6
814 class save_grid(wx.grid.Grid): 805 class save_grid(wx.grid.Grid):
815 """grid for saves""" 806 """grid for saves"""
816 def __init__(self, parent, handler): 807 def __init__(self, parent, handler):
817 pname = handler.master_dom.setAttribute("name", 'Saves') 808 pname = handler.xml.set("name", 'Saves')
818 self.hparent = handler #a 1.5002 allow ability to run up tree. 809 self.hparent = handler #a 1.5002 allow ability to run up tree.
819 #a 1.5002 in this case, we need the functional parent, not the invoking parent. 810 #a 1.5002 in this case, we need the functional parent, not the invoking parent.
820 self.root = getRoot(self) 811 self.root = getRoot(self)
821 812
822 #self.hparent.saveGrid = self #a 1.6018 d 1.9001 813 #self.hparent.saveGrid = self #a 1.6018 d 1.9001
824 815
825 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 816 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
826 self.Bind(wx.EVT_SIZE, self.on_size) 817 self.Bind(wx.EVT_SIZE, self.on_size)
827 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change) 818 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
828 self.handler = handler 819 self.handler = handler
829 saves = handler.master_dom.getElementsByTagName('save') 820 saves = handler.xml.findall('save')
830 self.CreateGrid(len(saves),7) 821 self.CreateGrid(len(saves),7)
831 self.SetRowLabelSize(0) 822 self.SetRowLabelSize(0)
832 col_names = ['Save','Key','base','Abil','Magic','Misc','Total'] 823 col_names = ['Save','Key','base','Abil','Magic','Misc','Total']
833 for i in range(len(col_names)): 824 for i in range(len(col_names)):
834 self.SetColLabelValue(i,col_names[i]) 825 self.SetColLabelValue(i,col_names[i])
855 col = evt.GetCol() 846 col = evt.GetCol()
856 value = self.GetCellValue(row,col) 847 value = self.GetCellValue(row,col)
857 try: 848 try:
858 int(value) 849 int(value)
859 if col == 2: 850 if col == 2:
860 self.saves[row].setAttribute('base',value) 851 self.saves[row].set('base',value)
861 elif col ==4: 852 elif col ==4:
862 self.saves[row].setAttribute('magmod',value) 853 self.saves[row].set('magmod',value)
863 elif col ==5: # 1.5001 854 elif col ==5: # 1.5001
864 self.saves[row].setAttribute('miscmod',value) 855 self.saves[row].set('miscmod',value)
865 self.refresh_row(row) 856 self.refresh_row(row)
866 except: 857 except:
867 self.SetCellValue(row,col,"0") 858 self.SetCellValue(row,col,"0")
868 859
869 def refresh_row(self,rowi): 860 def refresh_row(self,rowi):
870 s = self.saves[rowi] 861 s = self.saves[rowi]
871 862
872 name = s.getAttribute('name') 863 name = s.get('name')
873 self.SetCellValue(rowi,0,name) 864 self.SetCellValue(rowi,0,name)
874 self.SetReadOnly(rowi,0) 865 self.SetReadOnly(rowi,0)
875 stat = s.getAttribute('stat') 866 stat = s.get('stat')
876 self.SetCellValue(rowi,1,stat) 867 self.SetCellValue(rowi,1,stat)
877 self.SetReadOnly(rowi,1) 868 self.SetReadOnly(rowi,1)
878 self.SetCellValue(rowi,2,s.getAttribute('base')) 869 self.SetCellValue(rowi,2,s.get('base'))
879 self.SetCellValue(rowi,3,str(self.root.abilities.get_mod(stat))) 870 self.SetCellValue(rowi,3,str(self.root.abilities.get_mod(stat)))
880 self.SetReadOnly(rowi,3) 871 self.SetReadOnly(rowi,3)
881 self.SetCellValue(rowi,4,s.getAttribute('magmod')) 872 self.SetCellValue(rowi,4,s.get('magmod'))
882 self.SetCellValue(rowi,5,s.getAttribute('miscmod')) 873 self.SetCellValue(rowi,5,s.get('miscmod'))
883 mod = str(self.handler.get_mod(name)) 874 mod = str(self.handler.get_mod(name))
884 self.SetCellValue(rowi,6,mod) 875 self.SetCellValue(rowi,6,mod)
885 self.SetReadOnly(rowi,6) 876 self.SetReadOnly(rowi,6)
886 877
887 def on_size(self,evt): 878 def on_size(self,evt):
914 self.new_child_handler('feats','Feats',dnd35feats,'book') 905 self.new_child_handler('feats','Feats',dnd35feats,'book')
915 self.myeditor = None 906 self.myeditor = None
916 907
917 908
918 def new_child_handler(self,tag,text,handler_class,icon='gear'): 909 def new_child_handler(self,tag,text,handler_class,icon='gear'):
919 node_list = self.master_dom.getElementsByTagName(tag) 910 node_list = self.xml.findall(tag)
920 tree = self.tree 911 tree = self.tree
921 i = self.tree.icons[icon] 912 i = self.tree.icons[icon]
922 new_tree_node = tree.AppendItem(self.mytree_node,text,i,i) 913 new_tree_node = tree.AppendItem(self.mytree_node,text,i,i)
923 handler = handler_class(node_list[0],new_tree_node,self) 914 handler = handler_class(node_list[0],new_tree_node,self)
924 tree.SetPyData(new_tree_node,handler) 915 tree.SetPyData(new_tree_node,handler)
954 return 945 return
955 946
956 def on_html(self,evt): 947 def on_html(self,evt):
957 html_str = self.tohtml() 948 html_str = self.tohtml()
958 wnd = http_html_window(self.frame.note,-1) 949 wnd = http_html_window(self.frame.note,-1)
959 wnd.title = self.master_dom.getAttribute('name') 950 wnd.title = self.xml.get('name')
960 self.frame.add_panel(wnd) 951 self.frame.add_panel(wnd)
961 wnd.SetPage(html_str) 952 wnd.SetPage(html_str)
962 953
963 def get_design_panel(self,parent): 954 def get_design_panel(self,parent):
964 pass 955 pass
980 self.root.skills = self #a 1.6009 971 self.root.skills = self #a 1.6009
981 972
982 skills_char_child.__init__(self,xml_dom,tree_node,parent) 973 skills_char_child.__init__(self,xml_dom,tree_node,parent)
983 tree = self.tree 974 tree = self.tree
984 icons = self.tree.icons 975 icons = self.tree.icons
985 node_list = self.master_dom.getElementsByTagName('skill') 976 node_list = self.xml.findall('skill')
986 977
987 self.skills={} 978 self.skills={}
988 #Adding code to not display skills you can not use -mgt 979 #Adding code to not display skills you can not use -mgt
989 for n in node_list: 980 for n in node_list:
990 name = n.getAttribute('name') 981 name = n.get('name')
991 self.skills[name] = n 982 self.skills[name] = n
992 skill_check = self.skills[name] 983 skill_check = self.skills[name]
993 ranks = int(skill_check.getAttribute('rank')) 984 ranks = int(skill_check.get('rank'))
994 trained = int(skill_check.getAttribute('untrained')) 985 trained = int(skill_check.get('untrained'))
995 986
996 if ranks > 0 or trained == 1: 987 if ranks > 0 or trained == 1:
997 new_tree_node = tree.AppendItem(self.mytree_node,name, 988 new_tree_node = tree.AppendItem(self.mytree_node,name,
998 icons['gear'],icons['gear']) 989 icons['gear'],icons['gear'])
999 else: 990 else:
1007 #Adding this so when you update the grid the tree will reflect 998 #Adding this so when you update the grid the tree will reflect
1008 #The change. -mgt 999 #The change. -mgt
1009 tree = self.tree 1000 tree = self.tree
1010 icons = self.tree.icons 1001 icons = self.tree.icons
1011 tree.CollapseAndReset(self.mytree_node) 1002 tree.CollapseAndReset(self.mytree_node)
1012 node_list = self.master_dom.getElementsByTagName('skill') 1003 node_list = self.xml.findall('skill')
1013 1004
1014 self.skills={} 1005 self.skills={}
1015 for n in node_list: 1006 for n in node_list:
1016 name = n.getAttribute('name') 1007 name = n.get('name')
1017 self.skills[name] = n 1008 self.skills[name] = n
1018 skill_check = self.skills[name] 1009 skill_check = self.skills[name]
1019 ranks = int(skill_check.getAttribute('rank')) 1010 ranks = int(skill_check.get('rank'))
1020 trained = int(skill_check.getAttribute('untrained')) 1011 trained = int(skill_check.get('untrained'))
1021 1012
1022 if ranks > 0 or trained == 1: 1013 if ranks > 0 or trained == 1:
1023 new_tree_node = tree.AppendItem(self.mytree_node,name, 1014 new_tree_node = tree.AppendItem(self.mytree_node,name,
1024 icons['gear'],icons['gear']) 1015 icons['gear'],icons['gear'])
1025 else: 1016 else:
1027 1018
1028 tree.SetPyData(new_tree_node,self) 1019 tree.SetPyData(new_tree_node,self)
1029 1020
1030 def get_mod(self,name): 1021 def get_mod(self,name):
1031 skill = self.skills[name] 1022 skill = self.skills[name]
1032 stat = skill.getAttribute('stat') 1023 stat = skill.get('stat')
1033 #stat_mod = int(dnd_globals["stats"][stat]) #d 1.5002 1024 #stat_mod = int(dnd_globals["stats"][stat]) #d 1.5002
1034 stat_mod = self.root.abilities.get_mod(stat) #a 1.5002 1025 stat_mod = self.root.abilities.get_mod(stat) #a 1.5002
1035 rank = int(skill.getAttribute('rank')) 1026 rank = int(skill.get('rank'))
1036 misc = int(skill.getAttribute('misc')) 1027 misc = int(skill.get('misc'))
1037 total = stat_mod + rank + misc 1028 total = stat_mod + rank + misc
1038 return total 1029 return total
1039 1030
1040 def on_rclick(self,evt): 1031 def on_rclick(self,evt):
1041 item = self.tree.GetSelection() 1032 item = self.tree.GetSelection()
1050 # it's what it used to try to do. 1041 # it's what it used to try to do.
1051 ac = self.root.ac.get_check_pen() #a 1.5002 for 1.5004 verify fix. 1042 ac = self.root.ac.get_check_pen() #a 1.5002 for 1.5004 verify fix.
1052 1043
1053 skill = self.skills[name] 1044 skill = self.skills[name]
1054 1045
1055 untr = skill.getAttribute('untrained') #a 1.6004 1046 untr = skill.get('untrained') #a 1.6004
1056 rank = skill.getAttribute('rank') #a 1.6004 1047 rank = skill.get('rank') #a 1.6004
1057 if eval('%s == 0' % (untr)): #a 1.6004 1048 if eval('%s == 0' % (untr)): #a 1.6004
1058 if eval('%s == 0' % (rank)): #a 1.6004 1049 if eval('%s == 0' % (rank)): #a 1.6004
1059 res = 'You fumble around, accomplishing nothing' #a 1.6004 1050 res = 'You fumble around, accomplishing nothing' #a 1.6004
1060 txt = '%s Skill Check: %s' % (name, res) #a 1.6004 1051 txt = '%s Skill Check: %s' % (name, res) #a 1.6004
1061 chat = self.chat #a 1.6004 1052 chat = self.chat #a 1.6004
1063 return #a 1.6004 1054 return #a 1.6004
1064 1055
1065 armor = '' 1056 armor = ''
1066 acCp = '' 1057 acCp = ''
1067 if ac < 0: #acCp >= 1 #m 1.5004 this is stored as negatives. 1058 if ac < 0: #acCp >= 1 #m 1.5004 this is stored as negatives.
1068 armorCheck = int(skill.getAttribute('armorcheck')) 1059 armorCheck = int(skill.get('armorcheck'))
1069 #print "ac,armorCheck",ac,armorCheck 1060 #print "ac,armorCheck",ac,armorCheck
1070 if armorCheck == 1: 1061 if armorCheck == 1:
1071 acCp=ac 1062 acCp=ac
1072 armor = '(includes Armor Penalty of %s)' % (acCp) 1063 armor = '(includes Armor Penalty of %s)' % (acCp)
1073 if item == self.mytree_node: 1064 if item == self.mytree_node:
1093 1084
1094 def tohtml(self): 1085 def tohtml(self):
1095 html_str = """<table border='1' width=100% ><tr BGCOLOR=#E9E9E9 > 1086 html_str = """<table border='1' width=100% ><tr BGCOLOR=#E9E9E9 >
1096 <th width='30%'>Skill</th><th>Key</th> 1087 <th width='30%'>Skill</th><th>Key</th>
1097 <th>Rank</th><th>Abil</th><th>Misc</th><th>Total</th></tr>""" 1088 <th>Rank</th><th>Abil</th><th>Misc</th><th>Total</th></tr>"""
1098 node_list = self.master_dom.getElementsByTagName('skill') 1089 node_list = self.xml.findall('skill')
1099 1090
1100 for n in node_list: 1091 for n in node_list:
1101 name = n.getAttribute('name') 1092 name = n.get('name')
1102 stat = n.getAttribute('stat') 1093 stat = n.get('stat')
1103 rank = n.getAttribute('rank') 1094 rank = n.get('rank')
1104 untr = n.getAttribute('untrained') #a 1.6004 1095 untr = n.get('untrained') #a 1.6004
1105 #Filter unsuable skills out of pretty print -mgt 1096 #Filter unsuable skills out of pretty print -mgt
1106 if eval('%s > 0' % (rank)) or eval('%s == 1' % (untr)): 1097 if eval('%s > 0' % (rank)) or eval('%s == 1' % (untr)):
1107 if eval('%s >=1' % (rank)): 1098 if eval('%s >=1' % (rank)):
1108 html_str += "<tr ALIGN='center' bgcolor='#CCCCFF'><td>" #a 1.6004 1099 html_str += "<tr ALIGN='center' bgcolor='#CCCCFF'><td>" #a 1.6004
1109 #html_str += "<tr ALIGN='center' bgcolor='green'><td>" #d 1.6004 1100 #html_str += "<tr ALIGN='center' bgcolor='green'><td>" #d 1.6004
1116 html_str += stat+"</td><td>"+rank+"</td>" 1107 html_str += stat+"</td><td>"+rank+"</td>"
1117 else: 1108 else:
1118 continue 1109 continue
1119 stat_mod = self.root.abilities.get_mod(stat) #a 1.5002 1110 stat_mod = self.root.abilities.get_mod(stat) #a 1.5002
1120 #stat_mod = str(dnd_globals["stats"][stat]) #d 1.5002 1111 #stat_mod = str(dnd_globals["stats"][stat]) #d 1.5002
1121 misc = n.getAttribute('misc') 1112 misc = n.get('misc')
1122 mod = str(self.get_mod(name)) 1113 mod = str(self.get_mod(name))
1123 if mod >= 0: 1114 if mod >= 0:
1124 mod1 = "+" 1115 mod1 = "+"
1125 else: 1116 else:
1126 mod1 = "" 1117 mod1 = ""
1133 class skill_grid(wx.grid.Grid): 1124 class skill_grid(wx.grid.Grid):
1134 """ panel for skills """ 1125 """ panel for skills """
1135 def __init__(self, parent, handler): 1126 def __init__(self, parent, handler):
1136 self.hparent = handler #a 1.5002 need function parent, not invoker 1127 self.hparent = handler #a 1.5002 need function parent, not invoker
1137 self.root = getRoot(self) #a 1.5002 1128 self.root = getRoot(self) #a 1.5002
1138 pname = handler.master_dom.setAttribute("name", 'Skills') 1129 pname = handler.xml.set("name", 'Skills')
1139 1130
1140 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 1131 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
1141 self.Bind(wx.EVT_SIZE, self.on_size) 1132 self.Bind(wx.EVT_SIZE, self.on_size)
1142 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change) 1133 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
1143 self.handler = handler 1134 self.handler = handler
1144 skills = handler.master_dom.getElementsByTagName('skill') 1135 skills = handler.xml.findall('skill')
1145 #xelf.stats = dnd_globals["stats"] #d 1.5002 1136 #xelf.stats = dnd_globals["stats"] #d 1.5002
1146 1137
1147 self.CreateGrid(len(skills),6) 1138 self.CreateGrid(len(skills),6)
1148 self.SetRowLabelSize(0) 1139 self.SetRowLabelSize(0)
1149 col_names = ['Skill','Key','Rank','Abil','Misc','Total'] 1140 col_names = ['Skill','Key','Rank','Abil','Misc','Total']
1160 value = self.GetCellValue(row,col) 1151 value = self.GetCellValue(row,col)
1161 #print value 1152 #print value
1162 try: 1153 try:
1163 int(value) 1154 int(value)
1164 if col == 2: 1155 if col == 2:
1165 self.skills[row].setAttribute('rank',value) 1156 self.skills[row].set('rank',value)
1166 elif col ==4: 1157 elif col ==4:
1167 self.skills[row].setAttribute('misc',value) 1158 self.skills[row].set('misc',value)
1168 self.refresh_row(row) 1159 self.refresh_row(row)
1169 except: 1160 except:
1170 self.SetCellValue(row,col,"0") 1161 self.SetCellValue(row,col,"0")
1171 1162
1172 #call refresh_skills 1163 #call refresh_skills
1173 self.handler.refresh_skills() 1164 self.handler.refresh_skills()
1174 1165
1175 def refresh_row(self,rowi): 1166 def refresh_row(self,rowi):
1176 s = self.skills[rowi] 1167 s = self.skills[rowi]
1177 name = s.getAttribute('name') 1168 name = s.get('name')
1178 self.SetCellValue(rowi,0,name) 1169 self.SetCellValue(rowi,0,name)
1179 self.SetReadOnly(rowi,0) 1170 self.SetReadOnly(rowi,0)
1180 stat = s.getAttribute('stat') 1171 stat = s.get('stat')
1181 self.SetCellValue(rowi,1,stat) 1172 self.SetCellValue(rowi,1,stat)
1182 self.SetReadOnly(rowi,1) 1173 self.SetReadOnly(rowi,1)
1183 self.SetCellValue(rowi,2,s.getAttribute('rank')) 1174 self.SetCellValue(rowi,2,s.get('rank'))
1184 #self.SetCellValue(rowi,3,str(dnd_globals["stats"][stat])) #d 1.5002 1175 #self.SetCellValue(rowi,3,str(dnd_globals["stats"][stat])) #d 1.5002
1185 if self.root.abilities: #a 1.5002 sanity check. 1176 if self.root.abilities: #a 1.5002 sanity check.
1186 stat_mod=self.root.abilities.get_mod(stat) #a 1.5002 1177 stat_mod=self.root.abilities.get_mod(stat) #a 1.5002
1187 else: #a 1.5002 1178 else: #a 1.5002
1188 stat_mod = -6 #a 1.5002 this can happen if code is changed so 1179 stat_mod = -6 #a 1.5002 this can happen if code is changed so
1189 #a 1.5002 that abilities are not defined prior invokation of init. 1180 #a 1.5002 that abilities are not defined prior invokation of init.
1190 print "Please advise dnd35 maintainer alert 1.5002 raised" 1181 print "Please advise dnd35 maintainer alert 1.5002 raised"
1191 1182
1192 self.SetCellValue(rowi,3,str(stat_mod)) #a 1.5002 1183 self.SetCellValue(rowi,3,str(stat_mod)) #a 1.5002
1193 self.SetReadOnly(rowi,3) 1184 self.SetReadOnly(rowi,3)
1194 self.SetCellValue(rowi,4,s.getAttribute('misc')) 1185 self.SetCellValue(rowi,4,s.get('misc'))
1195 mod = str(self.handler.get_mod(name)) 1186 mod = str(self.handler.get_mod(name))
1196 self.SetCellValue(rowi,5,mod) 1187 self.SetCellValue(rowi,5,mod)
1197 self.SetReadOnly(rowi,5) 1188 self.SetReadOnly(rowi,5)
1198 1189
1199 def on_size(self,evt): 1190 def on_size(self,evt):
1233 #wnd.title = "Feats - " + self.charName 1224 #wnd.title = "Feats - " + self.charName
1234 return wnd 1225 return wnd
1235 1226
1236 def tohtml(self): 1227 def tohtml(self):
1237 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>Feats</th></tr><tr><td>" 1228 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>Feats</th></tr><tr><td>"
1238 n_list = self.master_dom._get_childNodes() 1229 n_list = self.xml.getchildren()
1239 for n in n_list: 1230 for n in n_list:
1240 html_str += n.getAttribute('name')+ ", " 1231 html_str += n.get('name')+ ", "
1241 html_str = html_str[:len(html_str)-2] + "</td></tr></table>" 1232 html_str = html_str[:len(html_str)-2] + "</td></tr></table>"
1242 return html_str 1233 return html_str
1243 1234
1244 class feat_panel(wx.Panel): 1235 class feat_panel(wx.Panel):
1245 def __init__(self, parent, handler): 1236 def __init__(self, parent, handler):
1246 1237
1247 self.hparent = handler #a 1.5002 allow ability to run up tree. 1238 self.hparent = handler #a 1.5002 allow ability to run up tree.
1248 #a 1.5002 in this case, we need the functional parent, not the invoking parent. 1239 #a 1.5002 in this case, we need the functional parent, not the invoking parent.
1249 self.root = getRoot(self) #a 1.5002 1240 self.root = getRoot(self) #a 1.5002
1250 #tempTitle= 'Feats - ' + self.root.general.charName #a 1.5010 1241 #tempTitle= 'Feats - ' + self.root.general.charName #a 1.5010
1251 #pname = handler.master_dom.setAttribute("name", tempTitle) #a 1.5010 1242 #pname = handler.xml.set("name", tempTitle) #a 1.5010
1252 pname = handler.master_dom.setAttribute("name", 'Feats') #d 1.5010 1243 pname = handler.xml.set("name", 'Feats') #d 1.5010
1253 1244
1254 wx.Panel.__init__(self, parent, -1) 1245 wx.Panel.__init__(self, parent, -1)
1255 self.grid = wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 1246 self.grid = wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
1256 sizer = wx.BoxSizer(wx.VERTICAL) 1247 sizer = wx.BoxSizer(wx.VERTICAL)
1257 sizer.Add(self.grid, 1, wx.EXPAND) 1248 sizer.Add(self.grid, 1, wx.EXPAND)
1270 1261
1271 #self.Bind(wx.EVT_SIZE, self.on_size) 1262 #self.Bind(wx.EVT_SIZE, self.on_size)
1272 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10) 1263 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10)
1273 self.Bind(wx.EVT_BUTTON, self.on_add, id=20) 1264 self.Bind(wx.EVT_BUTTON, self.on_add, id=20)
1274 1265
1275 n_list = handler.master_dom._get_childNodes() 1266 n_list = handler.xml.getchildren()
1276 self.n_list = n_list 1267 self.n_list = n_list
1277 self.master_dom = handler.master_dom 1268 self.xml = handler.xml
1278 self.grid.CreateGrid(len(n_list),3,1) 1269 self.grid.CreateGrid(len(n_list),3,1)
1279 self.grid.SetRowLabelSize(0) 1270 self.grid.SetRowLabelSize(0)
1280 self.grid.SetColLabelValue(0,"Feat") 1271 self.grid.SetColLabelValue(0,"Feat")
1281 self.grid.SetColLabelValue(1,"Reference") 1272 self.grid.SetColLabelValue(1,"Reference")
1282 self.grid.SetColLabelValue(2,"Description") #m 1.6 typo correction. 1273 self.grid.SetColLabelValue(2,"Description") #m 1.6 typo correction.
1289 self.temp_dom = None 1280 self.temp_dom = None
1290 1281
1291 def refresh_row(self,i): 1282 def refresh_row(self,i):
1292 feat = self.n_list[i] 1283 feat = self.n_list[i]
1293 1284
1294 name = feat.getAttribute('name') 1285 name = feat.get('name')
1295 type = feat.getAttribute('type') 1286 type = feat.get('type')
1296 desc = feat.getAttribute('desc') #m 1.6 correct typo 1287 desc = feat.get('desc') #m 1.6 correct typo
1297 self.grid.SetCellValue(i,0,name) 1288 self.grid.SetCellValue(i,0,name)
1298 self.grid.SetReadOnly(i,0) 1289 self.grid.SetReadOnly(i,0)
1299 self.grid.SetCellValue(i,1,type) 1290 self.grid.SetCellValue(i,1,type)
1300 self.grid.SetReadOnly(i,1) 1291 self.grid.SetReadOnly(i,1)
1301 self.grid.SetCellValue(i,2,desc) #m 1.6 correct typo 1292 self.grid.SetCellValue(i,2,desc) #m 1.6 correct typo
1308 def on_remove(self,evt): 1299 def on_remove(self,evt):
1309 rows = self.grid.GetNumberRows() 1300 rows = self.grid.GetNumberRows()
1310 for i in range(rows): 1301 for i in range(rows):
1311 if self.grid.IsInSelection(i,0): 1302 if self.grid.IsInSelection(i,0):
1312 self.grid.DeleteRows(i) 1303 self.grid.DeleteRows(i)
1313 self.master_dom.removeChild(self.n_list[i]) 1304 self.xml.remove(self.n_list[i])
1314 1305
1315 def on_add(self,evt): 1306 def on_add(self,evt):
1316 1307
1317 if not self.temp_dom: 1308 if not self.temp_dom:
1318 tmp = open(dir_struct["dnd35"]+"dnd35feats.xml","r") 1309 tree = parse(dir_struct["dnd35"]+"dnd35feats.xml")
1319 xml_dom = parseXml_with_dlg(self,tmp.read()) 1310 xml_dom = tree.getroot()
1320 xml_dom = xml_dom._get_firstChild()
1321 tmp.close()
1322 self.temp_dom = xml_dom 1311 self.temp_dom = xml_dom
1323 f_list = self.temp_dom.getElementsByTagName('feat') 1312 f_list = self.temp_dom.findall('feat')
1324 opts = [] 1313 opts = []
1325 for f in f_list: 1314 for f in f_list:
1326 opts.append(f.getAttribute('name') + " - [" + 1315 opts.append(f.get('name') + " - [" +
1327 f.getAttribute('type') + "] - " + f.getAttribute('desc')) 1316 f.get('type') + "] - " + f.get('desc'))
1328 dlg = wx.SingleChoiceDialog(self,'Choose Feat','Feats',opts) 1317 dlg = wx.SingleChoiceDialog(self,'Choose Feat','Feats',opts)
1329 if dlg.ShowModal() == wx.ID_OK: 1318 if dlg.ShowModal() == wx.ID_OK:
1330 i = dlg.GetSelection() 1319 i = dlg.GetSelection()
1331 new_node = self.master_dom.appendChild(f_list[i].cloneNode(False)) 1320 new_node = self.xml.append(f_list[i])
1332 self.grid.AppendRows(1) 1321 self.grid.AppendRows(1)
1333 self.refresh_row(self.grid.GetNumberRows()-1) 1322 self.refresh_row(self.grid.GetNumberRows()-1)
1334 f_list=0; opts=0 1323 f_list=0; opts=0
1335 dlg.Destroy() 1324 dlg.Destroy()
1336 1325
1369 #wxMenuItem(self.tree.std_menu, dnd35_EXPORT, "Export...", "Export") 1358 #wxMenuItem(self.tree.std_menu, dnd35_EXPORT, "Export...", "Export")
1370 self.myeditor = None 1359 self.myeditor = None
1371 1360
1372 1361
1373 def new_child_handler(self,tag,text,handler_class,icon='gear'): 1362 def new_child_handler(self,tag,text,handler_class,icon='gear'):
1374 node_list = self.master_dom.getElementsByTagName(tag) 1363 node_list = self.xml.findall(tag)
1375 tree = self.tree 1364 tree = self.tree
1376 i = self.tree.icons[icon] 1365 i = self.tree.icons[icon]
1377 new_tree_node = tree.AppendItem(self.mytree_node,text,i,i) 1366 new_tree_node = tree.AppendItem(self.mytree_node,text,i,i)
1378 handler = handler_class(node_list[0],new_tree_node,self) 1367 handler = handler_class(node_list[0],new_tree_node,self)
1379 tree.SetPyData(new_tree_node,handler) 1368 tree.SetPyData(new_tree_node,handler)
1408 return 1397 return
1409 1398
1410 def on_html(self,evt): 1399 def on_html(self,evt):
1411 html_str = self.tohtml() 1400 html_str = self.tohtml()
1412 wnd = http_html_window(self.frame.note,-1) 1401 wnd = http_html_window(self.frame.note,-1)
1413 wnd.title = self.master_dom.getAttribute('name') 1402 wnd.title = self.xml.get('name')
1414 self.frame.add_panel(wnd) 1403 self.frame.add_panel(wnd)
1415 wnd.SetPage(html_str) 1404 wnd.SetPage(html_str)
1416 1405
1417 def get_design_panel(self,parent): 1406 def get_design_panel(self,parent):
1418 pass 1407 pass
1437 wnd = outline_panel(parent,self,hp_panel,"Hit Points") 1426 wnd = outline_panel(parent,self,hp_panel,"Hit Points")
1438 wnd.title = "Hit Points" 1427 wnd.title = "Hit Points"
1439 return wnd 1428 return wnd
1440 1429
1441 def on_rclick( self, evt ): 1430 def on_rclick( self, evt ):
1442 chp = self.master_dom.getAttribute('current') 1431 chp = self.xml.get('current')
1443 mhp = self.master_dom.getAttribute('max') 1432 mhp = self.xml.get('max')
1444 txt = '((HP: %s / %s))' % ( chp, mhp ) 1433 txt = '((HP: %s / %s))' % ( chp, mhp )
1445 self.chat.ParsePost( txt, True, True ) 1434 self.chat.ParsePost( txt, True, True )
1446 1435
1447 def tohtml(self): 1436 def tohtml(self):
1448 html_str = "<table width=100% border=1 >" 1437 html_str = "<table width=100% border=1 >"
1449 html_str += "<tr BGCOLOR=#E9E9E9 ><th colspan=4>Hit Points</th></tr>" 1438 html_str += "<tr BGCOLOR=#E9E9E9 ><th colspan=4>Hit Points</th></tr>"
1450 html_str += "<tr><th>Max:</th>" 1439 html_str += "<tr><th>Max:</th>"
1451 html_str += "<td>"+self.master_dom.getAttribute('max')+"</td>" 1440 html_str += "<td>"+self.xml.get('max')+"</td>"
1452 html_str += "<th>Current:</th>" 1441 html_str += "<th>Current:</th>"
1453 html_str += "<td>"+self.master_dom.getAttribute('current')+"</td>" 1442 html_str += "<td>"+self.xml.get('current')+"</td>"
1454 html_str += "</tr></table>" 1443 html_str += "</tr></table>"
1455 return html_str 1444 return html_str
1456 1445
1457 class hp_panel(wx.Panel): 1446 class hp_panel(wx.Panel):
1458 def __init__(self, parent, handler): 1447 def __init__(self, parent, handler):
1459 wx.Panel.__init__(self, parent, -1) 1448 wx.Panel.__init__(self, parent, -1)
1460 self.hparent = handler #a 1.5002 allow ability to run up tree. In this 1449 self.hparent = handler #a 1.5002 allow ability to run up tree. In this
1461 #a 1.5002 case, we need the functional parent, not the invoking parent. 1450 #a 1.5002 case, we need the functional parent, not the invoking parent.
1462 1451
1463 pname = handler.master_dom.setAttribute("name", 'HitPoints') 1452 pname = handler.xml.set("name", 'HitPoints')
1464 self.sizer = wx.FlexGridSizer(2, 4, 2, 2) # rows, cols, hgap, vgap 1453 self.sizer = wx.FlexGridSizer(2, 4, 2, 2) # rows, cols, hgap, vgap
1465 self.master_dom = handler.master_dom 1454 self.xml = handler.xml
1466 self.sizer.AddMany([ (wx.StaticText(self, -1, "HP Current:"), 0, 1455 self.sizer.AddMany([ (wx.StaticText(self, -1, "HP Current:"), 0,
1467 wx.ALIGN_CENTER_VERTICAL), 1456 wx.ALIGN_CENTER_VERTICAL),
1468 (wx.TextCtrl(self, HP_CUR, 1457 (wx.TextCtrl(self, HP_CUR,
1469 self.master_dom.getAttribute('current')), 0, wx.EXPAND), 1458 self.xml.get('current')), 0, wx.EXPAND),
1470 (wx.StaticText(self, -1, "HP Max:"), 0, wx.ALIGN_CENTER_VERTICAL), 1459 (wx.StaticText(self, -1, "HP Max:"), 0, wx.ALIGN_CENTER_VERTICAL),
1471 (wx.TextCtrl(self, HP_MAX, self.master_dom.getAttribute('max')), 1460 (wx.TextCtrl(self, HP_MAX, self.xml.get('max')),
1472 0, wx.EXPAND), 1461 0, wx.EXPAND),
1473 ]) 1462 ])
1474 self.sizer.AddGrowableCol(1) 1463 self.sizer.AddGrowableCol(1)
1475 self.SetSizer(self.sizer) 1464 self.SetSizer(self.sizer)
1476 self.SetAutoLayout(True) 1465 self.SetAutoLayout(True)
1481 self.Bind(wx.EVT_TEXT, self.on_text, id=HP_CUR) 1470 self.Bind(wx.EVT_TEXT, self.on_text, id=HP_CUR)
1482 1471
1483 def on_text(self,evt): 1472 def on_text(self,evt):
1484 id = evt.GetId() 1473 id = evt.GetId()
1485 if id == HP_CUR: 1474 if id == HP_CUR:
1486 self.master_dom.setAttribute('current',evt.GetString()) 1475 self.xml.set('current',evt.GetString())
1487 elif id == HP_MAX: 1476 elif id == HP_MAX:
1488 self.master_dom.setAttribute('max',evt.GetString()) 1477 self.xml.set('max',evt.GetString())
1489 1478
1490 def on_size(self,evt): 1479 def on_size(self,evt):
1491 s = self.GetClientSizeTuple() 1480 s = self.GetClientSizeTuple()
1492 self.sizer.SetDimension(0,0,s[0],s[1]) 1481 self.sizer.SetDimension(0,0,s[0],s[1])
1493 1482
1523 """<table border='1' width=100% ><tr BGCOLOR=#E9E9E9 > 1512 """<table border='1' width=100% ><tr BGCOLOR=#E9E9E9 >
1524 <th width='80%'>Weapon Name</th><th>Added Footnote</th></tr>\n""") 1513 <th width='80%'>Weapon Name</th><th>Added Footnote</th></tr>\n""")
1525 self.temp_dom={} 1514 self.temp_dom={}
1526 #a 1.5012 end a1b 1515 #a 1.5012 end a1b
1527 1516
1528 node_list = self.master_dom.getElementsByTagName('melee') 1517 node_list = self.xml.findall('melee')
1529 self.melee = node_list[0] 1518 self.melee = node_list[0]
1530 node_list = self.master_dom.getElementsByTagName('ranged') 1519 node_list = self.xml.findall('ranged')
1531 self.ranged = node_list[0] 1520 self.ranged = node_list[0]
1532 self.refresh_weapons() # this causes self.weapons to be loaded. 1521 self.refresh_weapons() # this causes self.weapons to be loaded.
1533 1522
1534 #a 1.5012 this whole if clause. 1523 #a 1.5012 this whole if clause.
1535 if self.updateFootNotes == True: 1524 if self.updateFootNotes == True:
1543 fnFrame = wx.Frame(masterFrame, -1, title) 1532 fnFrame = wx.Frame(masterFrame, -1, title)
1544 fnFrame.panel = wx.html.HtmlWindow(fnFrame,-1) 1533 fnFrame.panel = wx.html.HtmlWindow(fnFrame,-1)
1545 fnFrame.panel.SetPage(self.html_str) 1534 fnFrame.panel.SetPage(self.html_str)
1546 fnFrame.Show() 1535 fnFrame.Show()
1547 1536
1548 #weaponsH = self.master_dom.getElementsByTagName('attacks') 1537 #weaponsH = self.xml.findall('attacks')
1549 #mark7 1538 #mark7
1550 1539
1551 #a 1.9001 this whole method 1540 #a 1.9001 this whole method
1552 def refreshMRdata(self): # refresh the data in the melee/ranged section 1541 def refreshMRdata(self): # refresh the data in the melee/ranged section
1553 # of the attack chart. 1542 # of the attack chart.
1563 self.weapons = {} 1552 self.weapons = {}
1564 1553
1565 tree = self.tree 1554 tree = self.tree
1566 icons = self.tree.icons 1555 icons = self.tree.icons
1567 tree.CollapseAndReset(self.mytree_node) 1556 tree.CollapseAndReset(self.mytree_node)
1568 node_list = self.master_dom.getElementsByTagName('weapon') 1557 node_list = self.xml.findall('weapon')
1569 for n in node_list: 1558 for n in node_list:
1570 name = n.getAttribute('name') 1559 name = n.get('name')
1571 fn = safeGetAttr(n,'fn') #a 1.5012 can be removed when 1560 fn = safeGetAttr(n,'fn') #a 1.5012 can be removed when
1572 #a 1.5012 confident all characters in the world have footnotes. 1561 #a 1.5012 confident all characters in the world have footnotes.
1573 #if self.updateFootNotes: 1562 #if self.updateFootNotes:
1574 if fn == None:#a 1.5012 1563 if fn == None:#a 1.5012
1575 self.updateFootNotes=True 1564 self.updateFootNotes=True
1579 tree.SetPyData(new_tree_node,self) 1568 tree.SetPyData(new_tree_node,self)
1580 self.weapons[name]=n 1569 self.weapons[name]=n
1581 1570
1582 def updateFootN(self,n):#a 1.5012 this whole function 1571 def updateFootN(self,n):#a 1.5012 this whole function
1583 if not self.temp_dom: 1572 if not self.temp_dom:
1584 tmp = open(dir_struct["dnd35"]+"dnd35weapons.xml","r") 1573 tree = parse(dir_struct["dnd35"]+"dnd35weapons.xml")
1585 #tmp = open("c:\clh\codeSamples\sample1.xml","r") #a (debug) 1.5012 1574 self.temp_dom = tree.getroot()
1586 self.temp_dom = xml.dom.minidom.parse(tmp) 1575 nameF = n.get('name')
1587 1576 w_list = self.temp_dom.findall('weapon')
1588 #self.temp_dom = parseXml_with_dlg(self,tmp.read())
1589 self.temp_dom = self.temp_dom._get_firstChild()
1590 tmp.close()
1591 nameF = n.getAttribute('name')
1592 w_list = self.temp_dom.getElementsByTagName('weapon')
1593 found = False 1577 found = False
1594 for w in w_list: 1578 for w in w_list:
1595 if nameF == w.getAttribute('name'): 1579 if nameF == w.get('name'):
1596 found = True 1580 found = True
1597 fnN = safeGetAttr(n,'fn') 1581 fnN = safeGetAttr(n,'fn')
1598 if fnN == None or fnN == 'None': 1582 if fnN == None or fnN == 'None':
1599 fnW = w.getAttribute('fn') 1583 fnW = w.get('fn')
1600 #print "weapon",nameF,"footnotes are updated to",fnW 1584 #print "weapon",nameF,"footnotes are updated to",fnW
1601 self.html_str += ("<tr ALIGN='center'><td>"+nameF+"</td>"+ 1585 self.html_str += ("<tr ALIGN='center'><td>"+nameF+"</td>"+
1602 "<td>"+fnW+"</td></tr>\n") 1586 "<td>"+fnW+"</td></tr>\n")
1603 n.setAttribute('fn',fnW) 1587 n.set('fn',fnW)
1604 break 1588 break
1605 if not found: 1589 if not found:
1606 self.html_str += ("<tr ALIGN='center'><td>"+nameF+" - Custom "+ 1590 self.html_str += ("<tr ALIGN='center'><td>"+nameF+" - Custom "+
1607 "Weapon, research "+ 1591 "Weapon, research "+
1608 "and update manually; setting footnote to indicate custom</td>"+ 1592 "and update manually; setting footnote to indicate custom</td>"+
1609 "<td>"+'X'+"</td></tr>\n") 1593 "<td>"+'X'+"</td></tr>\n")
1610 n.setAttribute('fn','X') 1594 n.set('fn','X')
1611 1595
1612 1596
1613 def get_mod(self,type='m'): 1597 def get_mod(self,type='m'):
1614 (base, base2, base3, base4, base5, base6, stat_mod, misc) \ 1598 (base, base2, base3, base4, base5, base6, stat_mod, misc) \
1615 = self.get_attack_data(type) 1599 = self.get_attack_data(type)
1623 stat = 'Dex' #m was dnd_globals["stats"]['Dex'] 1.5002 1607 stat = 'Dex' #m was dnd_globals["stats"]['Dex'] 1.5002
1624 temp = self.ranged 1608 temp = self.ranged
1625 stat_mod = -7 1609 stat_mod = -7
1626 stat_mod = self.root.abilities.get_mod(stat) #a 1.5002 1610 stat_mod = self.root.abilities.get_mod(stat) #a 1.5002
1627 #print "Big test - stat_mod",stat_mod #a (debug) 1.6000 1611 #print "Big test - stat_mod",stat_mod #a (debug) 1.6000
1628 base = int(temp.getAttribute('base')) 1612 base = int(temp.get('base'))
1629 base2 = int(temp.getAttribute('second')) 1613 base2 = int(temp.get('second'))
1630 base3 = int(temp.getAttribute('third')) 1614 base3 = int(temp.get('third'))
1631 base4 = int(temp.getAttribute('forth')) 1615 base4 = int(temp.get('forth'))
1632 base5 = int(temp.getAttribute('fifth')) 1616 base5 = int(temp.get('fifth'))
1633 base6 = int(temp.getAttribute('sixth')) 1617 base6 = int(temp.get('sixth'))
1634 misc = int(temp.getAttribute('misc')) 1618 misc = int(temp.get('misc'))
1635 return (base, base2, base3, base4, base5, base6, stat_mod ,misc) 1619 return (base, base2, base3, base4, base5, base6, stat_mod ,misc)
1636 1620
1637 def on_rclick(self,evt): 1621 def on_rclick(self,evt):
1638 item = self.tree.GetSelection() 1622 item = self.tree.GetSelection()
1639 1623
1643 return #a 1.6015 1627 return #a 1.6015
1644 #dnd35_char_child.on_ldclick(self,evt)#d 1.6015 1628 #dnd35_char_child.on_ldclick(self,evt)#d 1.6015
1645 #self.frame.add_panel(self.get_design_panel(self.frame.note)) 1629 #self.frame.add_panel(self.get_design_panel(self.frame.note))
1646 else: 1630 else:
1647 #print "entering attack phase" 1631 #print "entering attack phase"
1648 mod = int(self.weapons[name].getAttribute('mod')) 1632 mod = int(self.weapons[name].get('mod'))
1649 wepMod = mod #a 1.5008 1633 wepMod = mod #a 1.5008
1650 footNotes = safeGetAttr(self.weapons[name],'fn','') 1634 footNotes = safeGetAttr(self.weapons[name],'fn','')
1651 cat = self.weapons[name].getAttribute('category') #a1.6001 1635 cat = self.weapons[name].get('category') #a1.6001
1652 result = split(cat,"-",2) #a 1.6001 1636 result = split(cat,"-",2) #a 1.6001
1653 if len(result) < 2: #a 1.6021 this if & else 1637 if len(result) < 2: #a 1.6021 this if & else
1654 print "warning: 1.6002 unable to interpret weapon category" 1638 print "warning: 1.6002 unable to interpret weapon category"
1655 print "format 'type weapon-[Range|Melee]', probably missing" 1639 print "format 'type weapon-[Range|Melee]', probably missing"
1656 print "the hyphen. Assuming Melee" 1640 print "the hyphen. Assuming Melee"
1658 tres="Melee" 1642 tres="Melee"
1659 else: 1643 else:
1660 tres=result[1] 1644 tres=result[1]
1661 #print "print FootNotes,tres",footNotes,tres 1645 #print "print FootNotes,tres",footNotes,tres
1662 if tres == 'Melee': #a 1.6001 #m 1.6022 use of tres here and... 1646 if tres == 'Melee': #a 1.6001 #m 1.6022 use of tres here and...
1663 #if self.weapons[name].getAttribute('range') == '0':#d 1.6001 1647 #if self.weapons[name].get('range') == '0':#d 1.6001
1664 rangeOrMelee = 'm' #a 1.5008 code demote for next comment block 1648 rangeOrMelee = 'm' #a 1.5008 code demote for next comment block
1665 elif tres == 'Ranged': #m 1.6001 (was just else) #m 1.6022 here 1649 elif tres == 'Ranged': #m 1.6001 (was just else) #m 1.6022 here
1666 rangeOrMelee = 'r' #a 1.5008 1650 rangeOrMelee = 'r' #a 1.5008
1667 else:#a 1.6001 add this whole else clause. 1651 else:#a 1.6001 add this whole else clause.
1668 print "warning: 1.6001 unable to interpret weapon category" 1652 print "warning: 1.6001 unable to interpret weapon category"
1669 print "treating weapon as Melee, please correct xml" 1653 print "treating weapon as Melee, please correct xml"
1670 print "weapon name:",name 1654 print "weapon name:",name
1671 rangeOrMelee ='m' 1655 rangeOrMelee ='m'
1672 mod = mod + self.get_mod(rangeOrMelee) #a 1.5008 1656 mod = mod + self.get_mod(rangeOrMelee) #a 1.5008
1673 chat = self.chat 1657 chat = self.chat
1674 dmg = self.weapons[name].getAttribute('damage') 1658 dmg = self.weapons[name].get('damage')
1675 1659
1676 #a 1.6003 start code fix instance a 1660 #a 1.6003 start code fix instance a
1677 result = split(dmg,"/",2) 1661 result = split(dmg,"/",2)
1678 dmg = result[0] 1662 dmg = result[0]
1679 #print "1.6003 check:dmg",dmg,";result",result 1663 #print "1.6003 check:dmg",dmg,";result",result
1856 html_str += "<td>"+str(ranged[0]+ranged[1]+ranged[2])+"</td>" 1840 html_str += "<td>"+str(ranged[0]+ranged[1]+ranged[2])+"</td>"
1857 html_str += "<td>"+str(ranged[0])+"</td>" 1841 html_str += "<td>"+str(ranged[0])+"</td>"
1858 html_str += "<td>"+str(ranged[1])+"</td>" 1842 html_str += "<td>"+str(ranged[1])+"</td>"
1859 html_str += "<td>"+str(ranged[2])+"</td></tr></table>" 1843 html_str += "<td>"+str(ranged[2])+"</td></tr></table>"
1860 1844
1861 n_list = self.master_dom.getElementsByTagName('weapon') 1845 n_list = self.xml.findall('weapon')
1862 for n in n_list: 1846 for n in n_list:
1863 mod = n.getAttribute('mod') 1847 mod = n.get('mod')
1864 if mod >= 0: 1848 if mod >= 0:
1865 mod1 = "+" 1849 mod1 = "+"
1866 else: 1850 else:
1867 mod1 = "" 1851 mod1 = ""
1868 ran = n.getAttribute('range') 1852 ran = n.get('range')
1869 total = str(int(mod) + self.get_mod(ran)) 1853 total = str(int(mod) + self.get_mod(ran))
1870 html_str += """<P><table width=100% border=1 ><tr BGCOLOR=#E9E9E9 > 1854 html_str += """<P><table width=100% border=1 ><tr BGCOLOR=#E9E9E9 >
1871 <th colspan=2>Weapon</th> 1855 <th colspan=2>Weapon</th>
1872 <th>Attack</th><th >Damage</th><th>Critical</th></tr>""" 1856 <th>Attack</th><th >Damage</th><th>Critical</th></tr>"""
1873 html_str += "<tr ALIGN='center' ><td colspan=2>" 1857 html_str += "<tr ALIGN='center' ><td colspan=2>"
1874 html_str += n.getAttribute('name')+"</td><td>"+total+"</td>" 1858 html_str += n.get('name')+"</td><td>"+total+"</td>"
1875 html_str += "<td>"+n.getAttribute('damage')+"</td><td>" 1859 html_str += "<td>"+n.get('damage')+"</td><td>"
1876 html_str += n.getAttribute('critical')+"</td></tr>" 1860 html_str += n.get('critical')+"</td></tr>"
1877 html_str += """<tr BGCOLOR=#E9E9E9 ><th>Range</th><th>Weight</th> 1861 html_str += """<tr BGCOLOR=#E9E9E9 ><th>Range</th><th>Weight</th>
1878 <th>Type</th><th>Size</th><th>Misc Mod</th></tr>""" 1862 <th>Type</th><th>Size</th><th>Misc Mod</th></tr>"""
1879 html_str += "<tr ALIGN='center'><td>"+ran+"</td><td>" 1863 html_str += "<tr ALIGN='center'><td>"+ran+"</td><td>"
1880 html_str += n.getAttribute('weight')+"</td>" 1864 html_str += n.get('weight')+"</td>"
1881 html_str += "<td>"+n.getAttribute('type')+"</td><td>" 1865 html_str += "<td>"+n.get('type')+"</td><td>"
1882 html_str += n.getAttribute('size')+"</td>" 1866 html_str += n.get('size')+"</td>"
1883 html_str += '<td>%s%s</td></tr>' % (mod1, mod) 1867 html_str += '<td>%s%s</td></tr>' % (mod1, mod)
1884 #a 1.5012 add next two lines to pretty print footnotes. 1868 #a 1.5012 add next two lines to pretty print footnotes.
1885 html_str += """<tr><th BGCOLOR=#E9E9E9 colspan=2>Footnotes:</th>""" 1869 html_str += """<tr><th BGCOLOR=#E9E9E9 colspan=2>Footnotes:</th>"""
1886 html_str += "<th colspan=3>"+safeGetAttr(n,'fn','')+"</th></tr>" 1870 html_str += "<th colspan=3>"+safeGetAttr(n,'fn','')+"</th></tr>"
1887 html_str += '</table>' 1871 html_str += '</table>'
1888 return html_str 1872 return html_str
1889 1873
1890 class attack_grid(wx.grid.Grid): 1874 class attack_grid(wx.grid.Grid):
1891 """grid for attacks""" 1875 """grid for attacks"""
1892 def __init__(self, parent, handler): 1876 def __init__(self, parent, handler):
1893 pname = handler.master_dom.setAttribute("name", 'Melee') 1877 pname = handler.xml.set("name", 'Melee')
1894 self.hparent = handler #a 1.5002 allow ability to run up tree. 1878 self.hparent = handler #a 1.5002 allow ability to run up tree.
1895 #a 1.5002 we need the functional parent, not the invoking parent. 1879 #a 1.5002 we need the functional parent, not the invoking parent.
1896 1880
1897 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 1881 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
1898 1882
1930 col = evt.GetCol() 1914 col = evt.GetCol()
1931 value = self.GetCellValue(row,col) 1915 value = self.GetCellValue(row,col)
1932 try: 1916 try:
1933 int(value) 1917 int(value)
1934 if col==1: 1918 if col==1:
1935 self.rows[row].setAttribute('base',value) 1919 self.rows[row].set('base',value)
1936 elif col==2: 1920 elif col==2:
1937 self.rows[row].setAttribute('second',value) 1921 self.rows[row].set('second',value)
1938 elif col==3: 1922 elif col==3:
1939 self.rows[row].setAttribute('third',value) 1923 self.rows[row].set('third',value)
1940 elif col==4: 1924 elif col==4:
1941 self.rows[row].setAttribute('forth',value) 1925 self.rows[row].set('forth',value)
1942 elif col==5: 1926 elif col==5:
1943 self.rows[row].setAttribute('fifth',value) 1927 self.rows[row].set('fifth',value)
1944 elif col==6: 1928 elif col==6:
1945 self.rows[row].setAttribute('sixth',value) 1929 self.rows[row].set('sixth',value)
1946 elif col==8: 1930 elif col==8:
1947 self.rows[row].setAttribute('misc',value) 1931 self.rows[row].set('misc',value)
1948 self.parent.refresh_data() 1932 self.parent.refresh_data()
1949 except: 1933 except:
1950 self.SetCellValue(row,col,"0") 1934 self.SetCellValue(row,col,"0")
1951 1935
1952 def refresh_data(self): 1936 def refresh_data(self):
1981 class weapon_panel(wx.Panel): 1965 class weapon_panel(wx.Panel):
1982 def __init__(self, parent, handler): 1966 def __init__(self, parent, handler):
1983 self.hparent = handler #a 1.5012 1967 self.hparent = handler #a 1.5012
1984 self.root = getRoot(self) 1968 self.root = getRoot(self)
1985 1969
1986 pname = handler.master_dom.setAttribute("name", 'Weapons') 1970 pname = handler.xml.set("name", 'Weapons')
1987 1971
1988 wx.Panel.__init__(self, parent, -1) 1972 wx.Panel.__init__(self, parent, -1)
1989 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 1973 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
1990 sizer = wx.BoxSizer(wx.VERTICAL) 1974 sizer = wx.BoxSizer(wx.VERTICAL)
1991 sizer.Add(self.grid, 1, wx.EXPAND) 1975 sizer.Add(self.grid, 1, wx.EXPAND)
2006 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10) 1990 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10)
2007 self.Bind(wx.EVT_BUTTON, self.on_add, id=20) 1991 self.Bind(wx.EVT_BUTTON, self.on_add, id=20)
2008 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change) 1992 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
2009 self.grid.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK, self.on_gridRclick)#a 1.5012 1993 self.grid.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK, self.on_gridRclick)#a 1.5012
2010 1994
2011 n_list = handler.master_dom.getElementsByTagName('weapon') 1995 n_list = handler.xml.findall('weapon')
2012 self.n_list = n_list 1996 self.n_list = n_list
2013 self.master_dom = handler.master_dom 1997 self.xml = handler.xml
2014 self.handler = handler 1998 self.handler = handler
2015 #trash=input("weapon panel init colnames") 1999 #trash=input("weapon panel init colnames")
2016 self.colAttr = ['name','damage','mod','critical','type','weight', 2000 self.colAttr = ['name','damage','mod','critical','type','weight',
2017 'range','size','Total','fn', 'comment'] #a 1.5012 2001 'range','size','Total','fn', 'comment'] #a 1.5012
2018 col_names = ['Name','Damage','To hit\nmod','Critical','Type','Weight', 2002 col_names = ['Name','Damage','To hit\nmod','Critical','Type','Weight',
2036 col = evt.GetCol() 2020 col = evt.GetCol()
2037 value = self.grid.GetCellValue(row,col) 2021 value = self.grid.GetCellValue(row,col)
2038 #print "wp, on rclick,grid row,col,value",row,col,value 2022 #print "wp, on rclick,grid row,col,value",row,col,value
2039 if col == 9 and value != 'None': 2023 if col == 9 and value != 'None':
2040 n = self.n_list[row] 2024 n = self.n_list[row]
2041 name = n.getAttribute('name') 2025 name = n.get('name')
2042 #print "we want a panel!" 2026 #print "we want a panel!"
2043 handler = self.hparent 2027 handler = self.hparent
2044 #print "handler:",handler 2028 #print "handler:",handler
2045 # A handler is a node, and nodes have a reference to 2029 # A handler is a node, and nodes have a reference to
2046 # the master frame 2030 # the master frame
2048 #print "masterFrame:",masterFrame 2032 #print "masterFrame:",masterFrame
2049 title = name+"'s Special Weapon Characteristics" 2033 title = name+"'s Special Weapon Characteristics"
2050 fnFrame = wx.Frame(masterFrame, -1, title) 2034 fnFrame = wx.Frame(masterFrame, -1, title)
2051 fnFrame.panel = wx.html.HtmlWindow(fnFrame,-1) 2035 fnFrame.panel = wx.html.HtmlWindow(fnFrame,-1)
2052 if not self.temp_dom: 2036 if not self.temp_dom:
2053 tmp = open(dir_struct["dnd35"]+ 2037 tree = parse(dir_struct["dnd35"]+ "dnd35weapons.xml")
2054 "dnd35weapons.xml","r") 2038 self.temp_dom = tree.getroot()
2055 #tmp = open("c:\clh\codeSamples\sample1.xml","r") 2039 f_list = self.temp_dom.findall('f') # the footnotes
2056 xml_dom = parseXml_with_dlg(self,tmp.read())
2057 xml_dom = xml_dom._get_firstChild()
2058 tmp.close()
2059 self.temp_dom = xml_dom
2060 f_list = self.temp_dom.getElementsByTagName('f') # the footnotes
2061 #print "weapon_panel - on_rclick f_list",f_list#a 1.6 2040 #print "weapon_panel - on_rclick f_list",f_list#a 1.6
2062 n = self.n_list[row] 2041 n = self.n_list[row]
2063 name = n.getAttribute('name') 2042 name = n.get('name')
2064 footnotes = n.getAttribute('fn') 2043 footnotes = n.get('fn')
2065 html_str = "<html><body>" 2044 html_str = "<html><body>"
2066 html_str += """<table border='1' width=100% ><tr BGCOLOR=#E9E9E9 > 2045 html_str += """<table border='1' width=100% ><tr BGCOLOR=#E9E9E9 >
2067 <th width='10%'>Note</th><th>Description</th></tr>\n""" 2046 <th width='10%'>Note</th><th>Description</th></tr>\n"""
2068 #print "rclick,name,fn",name,footnotes 2047 #print "rclick,name,fn",name,footnotes
2069 if footnotes == "": 2048 if footnotes == "":
2071 html_str += " <td>This weapon has no footnotes</td></tr>" 2050 html_str += " <td>This weapon has no footnotes</td></tr>"
2072 for i in range(len(footnotes)): 2051 for i in range(len(footnotes)):
2073 aNote=footnotes[i] 2052 aNote=footnotes[i]
2074 found=False 2053 found=False
2075 for f in f_list: 2054 for f in f_list:
2076 if f.getAttribute('mark') == aNote: 2055 if f.get('mark') == aNote:
2077 found=True 2056 found=True
2078 text=f.getAttribute('txt') 2057 text=f.get('txt')
2079 html_str += ("<tr ALIGN='center'><td>"+aNote+"</td>"+ 2058 html_str += ("<tr ALIGN='center'><td>"+aNote+"</td>"+
2080 "<td>"+text+"</td></tr>\n") 2059 "<td>"+text+"</td></tr>\n")
2081 if not found: 2060 if not found:
2082 html_str += ("<tr ALIGN='center'><td>"+aNote+"</td>"+ 2061 html_str += ("<tr ALIGN='center'><td>"+aNote+"</td>"+
2083 "<td>is not a recognized footnote</td></tr>\n") 2062 "<td>is not a recognized footnote</td></tr>\n")
2097 row = evt.GetRow() 2076 row = evt.GetRow()
2098 col = evt.GetCol() 2077 col = evt.GetCol()
2099 value = self.grid.GetCellValue(row,col) 2078 value = self.grid.GetCellValue(row,col)
2100 if col == 2 and not int(value): # special case for mod, demoted 2079 if col == 2 and not int(value): # special case for mod, demoted
2101 value = "0" #a 5.012 demoted 2080 value = "0" #a 5.012 demoted
2102 self.n_list[row].setAttribute('mod',value) # a 5.012 demoted 2081 self.n_list[row].set('mod',value) # a 5.012 demoted
2103 if not (col == 9 and value == "None" and 2082 if not (col == 9 and value == "None" and
2104 self.n_list[row].getAttribute('fn') == "None" 2083 self.n_list[row].get('fn') == "None"
2105 ): #a 5.012 special case for footnotes 2084 ): #a 5.012 special case for footnotes
2106 self.n_list[row].setAttribute(self.colAttr[col],value)#a 5.012 2085 self.n_list[row].set(self.colAttr[col],value)#a 5.012
2107 2086
2108 2087
2109 def refresh_row(self,i): 2088 def refresh_row(self,i):
2110 n = self.n_list[i] 2089 n = self.n_list[i]
2111 fn = n.getAttribute('fn') 2090 fn = n.get('fn')
2112 #print "fn=",fn 2091 #print "fn=",fn
2113 name = n.getAttribute('name') 2092 name = n.get('name')
2114 mod = n.getAttribute('mod') 2093 mod = n.get('mod')
2115 ran = n.getAttribute('range') 2094 ran = n.get('range')
2116 total = str(int(mod) + self.handler.get_mod(ran)) 2095 total = str(int(mod) + self.handler.get_mod(ran))
2117 self.grid.SetCellValue(i,0,name) 2096 self.grid.SetCellValue(i,0,name)
2118 self.grid.SetCellValue(i,1,n.getAttribute('damage')) 2097 self.grid.SetCellValue(i,1,n.get('damage'))
2119 self.grid.SetCellValue(i,2,mod) 2098 self.grid.SetCellValue(i,2,mod)
2120 self.grid.SetCellValue(i,3,n.getAttribute('critical')) 2099 self.grid.SetCellValue(i,3,n.get('critical'))
2121 self.grid.SetCellValue(i,4,n.getAttribute('type')) 2100 self.grid.SetCellValue(i,4,n.get('type'))
2122 self.grid.SetCellValue(i,5,n.getAttribute('weight')) 2101 self.grid.SetCellValue(i,5,n.get('weight'))
2123 self.grid.SetCellValue(i,6,ran) 2102 self.grid.SetCellValue(i,6,ran)
2124 self.grid.SetCellValue(i,7,n.getAttribute('size') ) 2103 self.grid.SetCellValue(i,7,n.get('size') )
2125 self.grid.SetCellValue(i,8,total) 2104 self.grid.SetCellValue(i,8,total)
2126 self.grid.SetCellValue(i,9,safeGetAttr(n,'fn','None')) #a 1.5012 2105 self.grid.SetCellValue(i,9,safeGetAttr(n,'fn','None')) #a 1.5012
2127 self.grid.SetCellValue(i,10,safeGetAttr(n,'comment','')) #a 1.5012 2106 self.grid.SetCellValue(i,10,safeGetAttr(n,'comment','')) #a 1.5012
2128 #fn=safeGetAttr(n,'fn','None') #a (debug) 1.5012 2107 #fn=safeGetAttr(n,'fn','None') #a (debug) 1.5012
2129 #print "fn ",fn,"<" #a (debug) 1.5012 2108 #print "fn ",fn,"<" #a (debug) 1.5012
2135 rows = self.grid.GetNumberRows() 2114 rows = self.grid.GetNumberRows()
2136 #for i in range(rows): #d 1.6011 do it backwards, 2115 #for i in range(rows): #d 1.6011 do it backwards,
2137 for i in range(rows-1,-1,-1): #a 1.6011 or you lose context 2116 for i in range(rows-1,-1,-1): #a 1.6011 or you lose context
2138 if self.grid.IsInSelection(i,0): 2117 if self.grid.IsInSelection(i,0):
2139 self.grid.DeleteRows(i) 2118 self.grid.DeleteRows(i)
2140 self.master_dom.removeChild(self.n_list[i]) 2119 self.xml.remove(self.n_list[i])
2141 self.n_list = self.master_dom.getElementsByTagName('weapon') 2120 self.n_list = self.xml.findall('weapon')
2142 self.handler.refresh_weapons() 2121 self.handler.refresh_weapons()
2143 2122
2144 def on_add(self,evt): 2123 def on_add(self,evt):
2145 if not self.temp_dom: 2124 if not self.temp_dom:
2146 tmp = open(dir_struct["dnd35"]+"dnd35weapons.xml","r") 2125 tree = parse(dir_struct["dnd35"]+"dnd35weapons.xml")
2147 #tmp = open("c:\clh\codeSamples\sample1.xml","r") #a (debug) 1.5012 2126 self.temp_dom = tree.getroot()
2148 xml_dom = parseXml_with_dlg(self,tmp.read()) 2127 f_list = self.temp_dom.findall('weapon')
2149 xml_dom = xml_dom._get_firstChild()
2150 tmp.close(); print
2151 self.temp_dom = xml_dom
2152 f_list = self.temp_dom.getElementsByTagName('weapon')
2153 opts = [] 2128 opts = []
2154 #print "weapon_panel - on_add f_list",f_list#a 1.6 2129 #print "weapon_panel - on_add f_list",f_list#a 1.6
2155 for f in f_list: 2130 for f in f_list:
2156 opts.append(f.getAttribute('name')) 2131 opts.append(f.get('name'))
2157 dlg = wx.SingleChoiceDialog(self,'Choose Weapon','Weapon List',opts) 2132 dlg = wx.SingleChoiceDialog(self,'Choose Weapon','Weapon List',opts)
2158 if dlg.ShowModal() == wx.ID_OK: 2133 if dlg.ShowModal() == wx.ID_OK:
2159 i = dlg.GetSelection() 2134 i = dlg.GetSelection()
2160 #print f_list[i] # DOM Element: weapon. 2135 #print f_list[i] # DOM Element: weapon.
2161 new_node = self.master_dom.appendChild(f_list[i].cloneNode(False)) 2136 new_node = self.xml.append(f_list[i])
2162 #print self.grid.AppendRows # a bound method of wxGrid 2137 #print self.grid.AppendRows # a bound method of wxGrid
2163 self.grid.AppendRows(1) 2138 self.grid.AppendRows(1)
2164 self.n_list = self.master_dom.getElementsByTagName('weapon') 2139 self.n_list = self.xml.findall('weapon')
2165 #print "self.n_list",self.n_list # list of DOM weapons 2140 #print "self.n_list",self.n_list # list of DOM weapons
2166 self.refresh_row(self.grid.GetNumberRows()-1) 2141 self.refresh_row(self.grid.GetNumberRows()-1)
2167 self.handler.refresh_weapons() 2142 self.handler.refresh_weapons()
2168 dlg.Destroy() 2143 dlg.Destroy()
2169 2144
2185 self.refresh_row(i) 2160 self.refresh_row(i)
2186 2161
2187 2162
2188 class attack_panel(wx.Panel): 2163 class attack_panel(wx.Panel):
2189 def __init__(self, parent, handler): 2164 def __init__(self, parent, handler):
2190 pname = handler.master_dom.setAttribute("name", 'Melee') 2165 pname = handler.xml.set("name", 'Melee')
2191 self.parent = parent #a 1.9001 2166 self.parent = parent #a 1.9001
2192 2167
2193 wx.Panel.__init__(self, parent, -1) 2168 wx.Panel.__init__(self, parent, -1)
2194 2169
2195 self.a_grid = attack_grid(self, handler) 2170 self.a_grid = attack_grid(self, handler)
2241 else: 2216 else:
2242 ac_total += max_dex 2217 ac_total += max_dex
2243 return ac_total 2218 return ac_total
2244 2219
2245 def get_max_dex(self): 2220 def get_max_dex(self):
2246 armor_list = self.master_dom.getElementsByTagName('armor') 2221 armor_list = self.xml.findall('armor')
2247 dex = 10 2222 dex = 10
2248 for a in armor_list: 2223 for a in armor_list:
2249 temp = int(a.getAttribute("maxdex")) 2224 temp = int(a.get("maxdex"))
2250 if temp < dex: 2225 if temp < dex:
2251 dex = temp 2226 dex = temp
2252 return dex 2227 return dex
2253 2228
2254 def get_total(self,attr): 2229 def get_total(self,attr):
2255 armor_list = self.master_dom.getElementsByTagName('armor') 2230 armor_list = self.xml.findall('armor')
2256 total = 0 2231 total = 0
2257 for a in armor_list: 2232 for a in armor_list:
2258 total += int(a.getAttribute(attr)) 2233 total += int(a.get(attr))
2259 return total 2234 return total
2260 2235
2261 def get_design_panel(self,parent): 2236 def get_design_panel(self,parent):
2262 wnd = outline_panel(parent,self,ac_panel,"Armor") 2237 wnd = outline_panel(parent,self,ac_panel,"Armor")
2263 wnd.title = "Armor" 2238 wnd.title = "Armor"
2278 html_str += "<td>"+str(self.get_armor_class())+"</td>" 2253 html_str += "<td>"+str(self.get_armor_class())+"</td>"
2279 html_str += "<td>"+str(self.get_check_pen())+"</td>" 2254 html_str += "<td>"+str(self.get_check_pen())+"</td>"
2280 html_str += "<td>"+str(self.get_spell_failure())+"</td>" 2255 html_str += "<td>"+str(self.get_spell_failure())+"</td>"
2281 html_str += "<td>"+str(self.get_max_dex())+"</td>" 2256 html_str += "<td>"+str(self.get_max_dex())+"</td>"
2282 html_str += "<td>"+str(self.get_total_weight())+"</td></tr></table>" 2257 html_str += "<td>"+str(self.get_total_weight())+"</td></tr></table>"
2283 n_list = self.master_dom._get_childNodes() 2258 n_list = self.xml.getchildren()
2284 for n in n_list: 2259 for n in n_list:
2285 html_str += """<P><table width=100% border=1 ><tr BGCOLOR=#E9E9E9 > 2260 html_str += """<P><table width=100% border=1 ><tr BGCOLOR=#E9E9E9 >
2286 <th colspan=3>Armor</th><th>Type</th><th >Bonus</th></tr>""" 2261 <th colspan=3>Armor</th><th>Type</th><th >Bonus</th></tr>"""
2287 html_str += "<tr ALIGN='center' >" 2262 html_str += "<tr ALIGN='center' >"
2288 html_str += "<td colspan=3>"+n.getAttribute('name')+"</td>" 2263 html_str += "<td colspan=3>"+n.get('name')+"</td>"
2289 html_str += "<td>"+n.getAttribute('type')+"</td>" 2264 html_str += "<td>"+n.get('type')+"</td>"
2290 html_str += "<td>"+n.getAttribute('bonus')+"</td></tr>" 2265 html_str += "<td>"+n.get('bonus')+"</td></tr>"
2291 html_str += """<tr BGCOLOR=#E9E9E9 >""" 2266 html_str += """<tr BGCOLOR=#E9E9E9 >"""
2292 html_str += "<th>Check Penalty</th><th>Spell Failure</th>" 2267 html_str += "<th>Check Penalty</th><th>Spell Failure</th>"
2293 html_str += "<th>Max Dex</th><th>Speed</th><th>Weight</th></tr>" 2268 html_str += "<th>Max Dex</th><th>Speed</th><th>Weight</th></tr>"
2294 html_str += "<tr ALIGN='center'>" 2269 html_str += "<tr ALIGN='center'>"
2295 html_str += "<td>"+n.getAttribute('checkpenalty')+"</td>" 2270 html_str += "<td>"+n.get('checkpenalty')+"</td>"
2296 html_str += "<td>"+n.getAttribute('spellfailure')+"</td>" 2271 html_str += "<td>"+n.get('spellfailure')+"</td>"
2297 html_str += "<td>"+n.getAttribute('maxdex')+"</td>" 2272 html_str += "<td>"+n.get('maxdex')+"</td>"
2298 html_str += "<td>"+n.getAttribute('speed')+"</td>" 2273 html_str += "<td>"+n.get('speed')+"</td>"
2299 html_str += "<td>"+n.getAttribute('weight')+"</td></tr></table>" 2274 html_str += "<td>"+n.get('weight')+"</td></tr></table>"
2300 return html_str 2275 return html_str
2301 2276
2302 2277
2303 class ac_panel(wx.Panel): 2278 class ac_panel(wx.Panel):
2304 def __init__(self, parent, handler): 2279 def __init__(self, parent, handler):
2305 pname = handler.master_dom.setAttribute("name", 'Armor') 2280 pname = handler.xml.set("name", 'Armor')
2306 self.hparent = handler #a 1.5002 allow ability to run up tree. 2281 self.hparent = handler #a 1.5002 allow ability to run up tree.
2307 #a 1.5002 we need the functional parent, not the invoking parent. 2282 #a 1.5002 we need the functional parent, not the invoking parent.
2308 2283
2309 wx.Panel.__init__(self, parent, -1) 2284 wx.Panel.__init__(self, parent, -1)
2310 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) 2285 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
2325 2300
2326 #self.Bind(wx.EVT_SIZE, self.on_size) 2301 #self.Bind(wx.EVT_SIZE, self.on_size)
2327 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10) 2302 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10)
2328 self.Bind(wx.EVT_BUTTON, self.on_add, id=20) 2303 self.Bind(wx.EVT_BUTTON, self.on_add, id=20)
2329 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change) 2304 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
2330 self.master_dom = handler.master_dom 2305 self.xml = handler.xml
2331 n_list = handler.master_dom._get_childNodes() 2306 n_list = handler.xml.getchildren()
2332 self.n_list = n_list 2307 self.n_list = n_list
2333 col_names = ['Armor','bonus','maxdex','cp','sf','weight','speed','type'] 2308 col_names = ['Armor','bonus','maxdex','cp','sf','weight','speed','type']
2334 self.grid.CreateGrid(len(n_list),len(col_names),1) 2309 self.grid.CreateGrid(len(n_list),len(col_names),1)
2335 self.grid.SetRowLabelSize(0) 2310 self.grid.SetRowLabelSize(0)
2336 for i in range(len(col_names)): 2311 for i in range(len(col_names)):
2347 col = evt.GetCol() 2322 col = evt.GetCol()
2348 value = self.grid.GetCellValue(row,col) 2323 value = self.grid.GetCellValue(row,col)
2349 if col >= 1 and col <= 5: 2324 if col >= 1 and col <= 5:
2350 try: 2325 try:
2351 int(value) 2326 int(value)
2352 self.n_list[row].setAttribute(self.atts[col],value) 2327 self.n_list[row].set(self.atts[col],value)
2353 except: 2328 except:
2354 self.grid.SetCellValue(row,col,"0") 2329 self.grid.SetCellValue(row,col,"0")
2355 else: 2330 else:
2356 self.n_list[row].setAttribute(self.atts[col],value) 2331 self.n_list[row].set(self.atts[col],value)
2357 2332
2358 def refresh_row(self,i): 2333 def refresh_row(self,i):
2359 n = self.n_list[i] 2334 n = self.n_list[i]
2360 2335
2361 for y in range(len(self.atts)): 2336 for y in range(len(self.atts)):
2362 self.grid.SetCellValue(i,y,n.getAttribute(self.atts[y])) 2337 self.grid.SetCellValue(i,y,n.get(self.atts[y]))
2363 2338
2364 def on_remove(self,evt): 2339 def on_remove(self,evt):
2365 rows = self.grid.GetNumberRows() 2340 rows = self.grid.GetNumberRows()
2366 for i in range(rows): 2341 for i in range(rows):
2367 if self.grid.IsInSelection(i,0): 2342 if self.grid.IsInSelection(i,0):
2368 self.grid.DeleteRows(i) 2343 self.grid.DeleteRows(i)
2369 self.master_dom.removeChild(self.n_list[i]) 2344 self.xml.remove(self.n_list[i])
2370 2345
2371 def on_add(self,evt): 2346 def on_add(self,evt):
2372 if not self.temp_dom: 2347 if not self.temp_dom:
2373 tmp = open(dir_struct["dnd35"]+"dnd35armor.xml","r") 2348 tree = parse(dir_struct["dnd35"]+"dnd35armor.xml")
2374 xml_dom = parseXml_with_dlg(self,tmp.read()) 2349 self.temp_dom = tree.getroot()
2375 xml_dom = xml_dom._get_firstChild() 2350 f_list = self.temp_dom.findall('armor')
2376 tmp.close()
2377 self.temp_dom = xml_dom
2378 f_list = self.temp_dom.getElementsByTagName('armor')
2379 opts = [] 2351 opts = []
2380 for f in f_list: 2352 for f in f_list:
2381 opts.append(f.getAttribute('name')) 2353 opts.append(f.get('name'))
2382 dlg = wx.SingleChoiceDialog(self,'Choose Armor:','Armor List',opts) 2354 dlg = wx.SingleChoiceDialog(self,'Choose Armor:','Armor List',opts)
2383 if dlg.ShowModal() == wx.ID_OK: 2355 if dlg.ShowModal() == wx.ID_OK:
2384 i = dlg.GetSelection() 2356 i = dlg.GetSelection()
2385 new_node = self.master_dom.appendChild(f_list[i].cloneNode(False)) 2357 new_node = self.xml.append(f_list[i])
2386 self.grid.AppendRows(1) 2358 self.grid.AppendRows(1)
2387 self.refresh_row(self.grid.GetNumberRows()-1) 2359 self.refresh_row(self.grid.GetNumberRows()-1)
2388 dlg.Destroy() 2360 dlg.Destroy()
2389 2361
2390 def on_size(self,event): 2362 def on_size(self,event):