"
max = tree.GetChildrenCount(handler.mytree_node)
@@ -127,38 +129,36 @@
def on_version(self,old_version):
node_handler.on_version(self,old_version)
if old_version == "":
- tmp = open(dir_struct["nodes"]+"StarWars_d20character.xml","r")
- xml_dom = parseXml_with_dlg(self.tree,tmp.read())
- xml_dom = xml_dom._get_firstChild()
- tmp.close()
+ tree = parse(dir_struct["nodes"]+"StarWars_d20character.xml")
+ xml_dom = tree.getroot()
## add new nodes
for tag in ("howtouse","inventory","powers","divine","pp"):
- node_list = xml_dom.getElementsByTagName(tag)
- self.master_dom.appendChild(node_list[0])
+ node_list = xml_dom.findall(tag)
+ self.xml.append(node_list[0])
## add new atts
- melee_attack = self.master_dom.getElementsByTagName('melee')[0]
- melee_attack.setAttribute("second","0")
- melee_attack.setAttribute("third","0")
- melee_attack.setAttribute("forth","0")
- melee_attack.setAttribute("fifth","0")
- melee_attack.setAttribute("sixth","0")
- range_attack = self.master_dom.getElementsByTagName('ranged')[0]
- range_attack.setAttribute("second","0")
- range_attack.setAttribute("third","0")
- range_attack.setAttribute("forth","0")
- range_attack.setAttribute("fifth","0")
- range_attack.setAttribute("sixth","0")
+ melee_attack = self.xml.findall('melee')[0]
+ melee_attack.set("second","0")
+ melee_attack.set("third","0")
+ melee_attack.set("forth","0")
+ melee_attack.set("fifth","0")
+ melee_attack.set("sixth","0")
+ range_attack = self.xml.findall('ranged')[0]
+ range_attack.set("second","0")
+ range_attack.set("third","0")
+ range_attack.set("forth","0")
+ range_attack.set("fifth","0")
+ range_attack.set("sixth","0")
- gen_list = self.master_dom.getElementsByTagName('general')[0]
+ gen_list = self.xml.findall('general')[0]
for tag in ("currentxp","xptolevel"):
- node_list = xml_dom.getElementsByTagName(tag)
- gen_list.appendChild(node_list[0])
+ node_list = xml_dom.findall(tag)
+ gen_list.append(node_list[0])
## temp fix
- #parent = self.master_dom._get_parentNode()
- #old_dom = parent.replaceChild(xml_dom,self.master_dom)
- #self.master_dom = xml_dom
+ #parent = self.xml._get_parentNode()
+ #old_dom = parent.replaceChild(xml_dom,self.xml)
+ #self.xml = xml_dom
print old_version
@@ -176,7 +176,7 @@
def new_child_handler(self,tag,text,handler_class,icon='gear'):
- node_list = self.master_dom.getElementsByTagName(tag)
+ node_list = self.xml.findall(tag)
tree = self.tree
i = self.tree.icons[icon]
new_tree_node = tree.AppendItem(self.mytree_node,text,i,i)
@@ -257,7 +257,7 @@
panel = obj.get_design_panel(self)
else:
panel = obj.get_use_panel(self)
- name = obj.master_dom.getAttribute("name")
+ name = obj.xml.get("name")
if panel:
self.AddPage(panel,name)
@@ -288,42 +288,33 @@
created by SWd20char_handler.
"""
def __init__(self, xml_dom, tree_node, parent):
- node_handler.__init__(self,xml_dom, tree_node)
+ node_handler.__init__(self, xml_dom, tree_node)
self.char_hander = parent
self.drag = False
self.frame = component.get('frame')
self.myeditor = None
- def on_drop(self,evt):
+ def on_drop(self, evt):
pass
- def on_rclick(self,evt):
+ def on_rclick(self, evt):
pass
- def on_ldclick(self,evt): #Function needs help. Needs an OnClose I think.
- if self.myeditor == None or self.myeditor.destroyed:
- title = self.master_dom.getAttribute('name') + " Editor"
- # Frame created in correctly.
- self.myeditor = wx.Frame(self.frame,title,dir_struct["icon"]+'grid.ico')
- wnd = self.get_design_panel(self.myeditor)
- self.myeditor.panel = wnd
- self.wnd = wnd
- self.myeditor.Show(1)
- else:
- self.myeditor.Raise()
+ def on_ldclick(self, evt):
+ return
- def on_html(self,evt):
+ def on_html(self, evt):
html_str = self.tohtml()
wnd = http_html_window(self.frame.note,-1)
- wnd.title = self.master_dom.getAttribute('name')
+ wnd.title = self.xml.get('name')
self.frame.add_panel(wnd)
wnd.SetPage(html_str)
- def get_design_panel(self,parent):
+ def get_design_panel(self, parent):
pass
- def get_use_panel(self,parent):
+ def get_use_panel(self, parent):
return self.get_design_panel(parent)
def delete(self):
@@ -338,23 +329,23 @@
SWd20_char_child.__init__(self, xml_dom, tree_node, parent)
tree = self.tree
icons = self.tree.icons
- node_list = self.master_dom.getElementsByTagName('skill')
+ node_list = self.xml.findall('skill')
self.skills={}
for n in node_list:
- name = n.getAttribute('name')
+ name = n.get('name')
self.skills[name] = n
new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear'])
tree.SetPyData(new_tree_node,self)
def get_mod(self,name):
skill = self.skills[name]
- stat = skill.getAttribute('stat')
- ac = int(skill.getAttribute('armorcheck'))
+ stat = skill.get('stat')
+ ac = int(skill.get('armorcheck'))
if ac:
ac = self.char_hander.child_handlers['ac'].get_check_pen()
stat_mod = self.char_hander.child_handlers['abilities'].get_mod(stat)
- rank = int(skill.getAttribute('rank'))
- misc = int(skill.getAttribute('misc'))
+ rank = int(skill.get('rank'))
+ misc = int(skill.get('misc'))
total = stat_mod + rank + misc + ac
return total
@@ -363,8 +354,8 @@
item = self.tree.GetSelection()
name = self.tree.GetItemText(item)
skill = self.skills[name]
- rank = int(skill.getAttribute('rank'))
- untrained = int(skill.getAttribute('untrained'))
+ rank = int(skill.get('rank'))
+ untrained = int(skill.get('untrained'))
chat = self.chat
if item == self.mytree_node:
SWd20_char_child.on_ldclick(self,evt)
@@ -388,14 +379,14 @@
def tohtml(self):
html_str = """Skill | Key |
Rank | Abil | Misc | Total | """
- node_list = self.master_dom.getElementsByTagName('skill')
+ node_list = self.xml.findall('skill')
for n in node_list:
- name = n.getAttribute('name')
- stat = n.getAttribute('stat')
- rank = n.getAttribute('rank')
+ name = n.get('name')
+ stat = n.get('stat')
+ rank = n.get('rank')
html_str = html_str + ""+name+" | "+stat+" | "+rank+" | "
stat_mod = str(self.char_hander.child_handlers['abilities'].get_mod(stat))
- misc = n.getAttribute('misc')
+ misc = n.get('misc')
mod = str(self.get_mod(name))
if mod >= 0:
mod1 = "+"
@@ -413,11 +404,11 @@
def __init__(self, xml_dom, tree_node, parent):
SWd20_char_child.__init__(self, xml_dom, tree_node, parent)
self.abilities = {}
- node_list = self.master_dom.getElementsByTagName('stat')
+ node_list = self.xml.findall('stat')
tree = self.tree
icons = tree.icons
for n in node_list:
- name = n.getAttribute('abbr')
+ name = n.get('abbr')
self.abilities[name] = n
new_tree_node = tree.AppendItem( self.mytree_node, name, icons['gear'], icons['gear'] )
tree.SetPyData( new_tree_node, self )
@@ -438,13 +429,13 @@
chat.ParsePost( txt, True, True )
def get_mod(self,abbr):
- score = int(self.abilities[abbr].getAttribute('base'))
+ score = int(self.abilities[abbr].get('base'))
mod = (score - 10) / 2
return mod
def set_score(self,abbr,score):
if score >= 0:
- self.abilities[abbr].setAttribute("base",str(score))
+ self.abilities[abbr].set("base",str(score))
def get_design_panel(self,parent):
wnd = outline_panel(parent,self,abil_grid,"Abilities")
@@ -454,11 +445,11 @@
def tohtml(self):
html_str = """Ability |
Base | Modifier | """
- node_list = self.master_dom.getElementsByTagName('stat')
+ node_list = self.xml.findall('stat')
for n in node_list:
- name = n.getAttribute('name')
- abbr = n.getAttribute('abbr')
- base = n.getAttribute('base')
+ name = n.get('name')
+ abbr = n.get('abbr')
+ base = n.get('base')
mod = str(self.get_mod(abbr))
if mod >= 0:
mod1 = "+"
@@ -476,21 +467,21 @@
SWd20_char_child.__init__(self, xml_dom, tree_node, parent)
tree = self.tree
icons = self.tree.icons
- node_list = self.master_dom.getElementsByTagName('save')
+ node_list = self.xml.findall('save')
self.saves={}
for n in node_list:
- name = n.getAttribute('name')
+ name = n.get('name')
self.saves[name] = n
new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear'])
tree.SetPyData(new_tree_node,self)
def get_mod(self,name):
save = self.saves[name]
- stat = save.getAttribute('stat')
+ stat = save.get('stat')
stat_mod = self.char_hander.child_handlers['abilities'].get_mod(stat)
- base = int(save.getAttribute('base'))
- miscmod = int(save.getAttribute('miscmod'))
-# magmod = int(save.getAttribute('magmod'))
+ base = int(save.get('base'))
+ miscmod = int(save.get('miscmod'))
+# magmod = int(save.get('magmod'))
# total = stat_mod + base + miscmod + magmod
total = stat_mod + base + miscmod
return total
@@ -522,15 +513,15 @@
html_str = """Save |
Key | Base | Abil | Magic |
Misc | Total | """
- node_list = self.master_dom.getElementsByTagName('save')
+ node_list = self.xml.findall('save')
for n in node_list:
- name = n.getAttribute('name')
- stat = n.getAttribute('stat')
- base = n.getAttribute('base')
+ name = n.get('name')
+ stat = n.get('stat')
+ base = n.get('base')
html_str = html_str + ""+name+" | "+stat+" | "+base+" | "
stat_mod = str(self.char_hander.child_handlers['abilities'].get_mod(stat))
- mag = n.getAttribute('magmod')
- misc = n.getAttribute('miscmod')
+ mag = n.get('magmod')
+ misc = n.get('miscmod')
mod = str(self.get_mod(name))
if mod >= 0:
mod1 = "+"
@@ -555,12 +546,11 @@
return wnd
def tohtml(self):
- n_list = self.master_dom._get_childNodes()
+ n_list = self.xml.getchildren()
html_str = "General Information |
---|
"
for n in n_list:
- t_node = component.get('xml').safe_get_text_node(n)
- html_str += ""+n._get_tagName().capitalize() +": "
- html_str += t_node._get_nodeValue() + ", "
+ html_str += ""+n.tag.capitalize() +": "
+ html_str += n.text + ", "
html_str = html_str[:len(html_str)-2] + " | "
return html_str
@@ -568,9 +558,8 @@
self.char_hander.rename(name)
def get_char_name( self ):
- node = self.master_dom.getElementsByTagName( 'name' )[0]
- t_node = component.get('xml').safe_get_text_node( node )
- return t_node._get_nodeValue()
+ node = self.xml.findall( 'name' )[0]
+ return node.text
class SWd20classes(SWd20_char_child):
@@ -587,17 +576,17 @@
def tohtml(self):
html_str = "Classes |
---|
"
- n_list = self.master_dom._get_childNodes()
+ n_list = self.xml.getchildren()
for n in n_list:
- html_str += n.getAttribute('name') + " ("+n.getAttribute('level')+"), "
+ html_str += n.get('name') + " ("+n.get('level')+"), "
html_str = html_str[:len(html_str)-2] + " | "
return html_str
def get_char_lvl( self, attr ):
- node_list = self.master_dom.getElementsByTagName('class')
+ node_list = self.xml.findall('class')
for n in node_list:
- lvl = n.getAttribute('level')
- type = n.getAttribute('name')
+ lvl = n.get('level')
+ type = n.get('name')
if attr == "level":
return lvl
elif attr == "class":
@@ -618,9 +607,9 @@
def tohtml(self):
html_str = "Feats |
---|
"
- n_list = self.master_dom._get_childNodes()
+ n_list = self.xml.getchildren()
for n in n_list:
- html_str += n.getAttribute('name')+ ", "
+ html_str += n.get('name')+ ", "
html_str = html_str[:len(html_str)-2] + " | "
return html_str
@@ -649,12 +638,11 @@
return wnd
def tohtml(self):
- n_list = self.master_dom._get_childNodes()
+ n_list = self.xml.getchildren()
html_str = "General Information |
---|
"
for n in n_list:
- t_node = component.get('xml').safe_get_text_node(n)
- html_str += ""+n._get_tagName().capitalize() +": "
- html_str += t_node._get_nodeValue() + " "
+ html_str += ""+n.tag.capitalize() +": "
+ html_str += n.text + " "
html_str = html_str[:len(html_str)-2] + " | "
return html_str
@@ -662,9 +650,8 @@
self.char_hander.rename(name)
def get_char_name( self ):
- node = self.master_dom.getElementsByTagName( 'name' )[0]
- t_node = component.get('xml').safe_get_text_node( node )
- return t_node._get_nodeValue()
+ node = self.xml.findall( 'name' )[0]
+ return node.text
class SWd20hp(SWd20_char_child):
""" Node Handler for hit points. This handler will be
@@ -680,19 +667,19 @@
def tohtml(self):
html_str = "Wound Points | "
- html_str += "Max: | "+self.master_dom.getAttribute('max')+" | "
- html_str += "Current: | "+self.master_dom.getAttribute('current')+" | "
+ html_str += "
---|
Max: | "+self.xml.get('max')+" | "
+ html_str += "Current: | "+self.xml.get('current')+" | "
html_str += "
---|
"
return html_str
def get_max_hp( self ):
try:
- return eval( self.master_dom.getAttribute( 'max' ) )
+ return eval( self.xml.get( 'max' ) )
except:
return 0
def get_current_hp( self ):
try:
- return eval( self.master_dom.getAttribute( 'current' ) )
+ return eval( self.xml.get( 'current' ) )
except:
return 0
@@ -710,19 +697,19 @@
def tohtml(self):
html_str = "Vitality Points | "
- html_str += "Max: | "+self.master_dom.getAttribute('max')+" | "
- html_str += "Current: | "+self.master_dom.getAttribute('current')+" | "
+ html_str += "
---|
Max: | "+self.xml.get('max')+" | "
+ html_str += "Current: | "+self.xml.get('current')+" | "
html_str += "
---|
"
return html_str
def get_max_vp( self ):
try:
- return eval( self.master_dom.getAttribute( 'max' ) )
+ return eval( self.xml.get( 'max' ) )
except:
return 0
def get_current_vp( self ):
try:
- return eval( self.master_dom.getAttribute( 'current' ) )
+ return eval( self.xml.get( 'current' ) )
except:
return 0
@@ -732,9 +719,9 @@
"""
def __init__(self,xml_dom,tree_node,parent):
SWd20_char_child.__init__(self,xml_dom,tree_node,parent)
- node_list = self.master_dom.getElementsByTagName('melee')
+ node_list = self.xml.findall('melee')
self.melee = node_list[0]
- node_list = self.master_dom.getElementsByTagName('ranged')
+ node_list = self.xml.findall('ranged')
self.ranged = node_list[0]
self.refresh_weapons()
@@ -743,9 +730,9 @@
tree = self.tree
icons = self.tree.icons
tree.CollapseAndReset(self.mytree_node)
- node_list = self.master_dom.getElementsByTagName('weapon')
+ node_list = self.xml.findall('weapon')
for n in node_list:
- name = n.getAttribute('name')
+ name = n.get('name')
new_tree_node = tree.AppendItem(self.mytree_node,name,icons['sword'],icons['sword'])
tree.SetPyData(new_tree_node,self)
self.weapons[name]=n
@@ -761,13 +748,13 @@
else:
stat_mod = self.char_hander.child_handlers['abilities'].get_mod('Dex')
temp = self.ranged
- base = int(temp.getAttribute('base'))
- base2 = int(temp.getAttribute('second'))
- base3 = int(temp.getAttribute('third'))
- base4 = int(temp.getAttribute('forth'))
- base5 = int(temp.getAttribute('fifth'))
- base6 = int(temp.getAttribute('sixth'))
- misc = int(temp.getAttribute('misc'))
+ base = int(temp.get('base'))
+ base2 = int(temp.get('second'))
+ base3 = int(temp.get('third'))
+ base4 = int(temp.get('forth'))
+ base5 = int(temp.get('fifth'))
+ base6 = int(temp.get('sixth'))
+ misc = int(temp.get('misc'))
return (base, base2, base3, base4, base5, base6, stat_mod ,misc)
def on_rclick(self,evt):
@@ -778,8 +765,8 @@
SWd20_char_child.on_ldclick(self,evt)
#self.frame.add_panel(self.get_design_panel(self.frame.note))
else:
- mod = int(self.weapons[name].getAttribute('mod'))
- if self.weapons[name].getAttribute('range') == '0':
+ mod = int(self.weapons[name].get('mod'))
+ if self.weapons[name].get('range') == '0':
mod = mod + self.get_mod('m')
if mod >= 0:
mod1 = "+"
@@ -792,7 +779,7 @@
else:
mod1 = ""
chat = self.chat
- dmg = self.weapons[name].getAttribute('damage')
+ dmg = self.weapons[name].get('damage')
lvl = self.get_char_lvl('level')
cname = self.char_hander.get_char_name()
txt = '%s %s Attack Roll: [1d20%s%s] ===> DMG: [%s%s%s]' % (cname, name, mod1, mod, dmg, mod1, mod)
@@ -825,23 +812,23 @@
html_str += ""+str(ranged[1])+" | "
html_str += ""+str(ranged[2])+" | "
- n_list = self.master_dom.getElementsByTagName('weapon')
+ n_list = self.xml.findall('weapon')
for n in n_list:
- mod = n.getAttribute('mod')
+ mod = n.get('mod')
if mod >= 0:
mod1 = "+"
else:
mod1 = ""
- ran = n.getAttribute('range')
+ ran = n.get('range')
total = str(int(mod) + self.get_mod(ran))
html_str += """Weapon |
Attack | Damage | Critical | """
- html_str += ""+n.getAttribute('name')+" | "+total+" | "
- html_str += ""+n.getAttribute('damage')+" | "+n.getAttribute('critical')+" | "
+ html_str += ""+n.get('name')+" | "+total+" | "
+ html_str += ""+n.get('damage')+" | "+n.get('critical')+" | "
html_str += """Range | Weight |
Type | Size | Misc Mod | """
- html_str += ""+ran+" | "+n.getAttribute('weight')+" | "
- html_str += ""+n.getAttribute('type')+" | "+n.getAttribute('size')+" | "
+ html_str += " "+ran+" | "+n.get('weight')+" | "
+ html_str += ""+n.get('type')+" | "+n.get('size')+" | "
html_str += '%s%s | ' % (mod1, mod)
return html_str
@@ -870,19 +857,19 @@
return ac_total
def get_max_dex(self):
- armor_list = self.master_dom.getElementsByTagName('armor')
+ armor_list = self.xml.findall('armor')
dex = 10
for a in armor_list:
- temp = int(a.getAttribute("maxdex"))
+ temp = int(a.get("maxdex"))
if temp < dex:
dex = temp
return dex
def get_total(self,attr):
- armor_list = self.master_dom.getElementsByTagName('armor')
+ armor_list = self.xml.findall('armor')
total = 0
for a in armor_list:
- total += int(a.getAttribute(attr))
+ total += int(a.get(attr))
return total
def get_design_panel(self,parent):
@@ -898,19 +885,19 @@
html_str += ""+str(self.get_spell_failure())+" | "
html_str += ""+str(self.get_max_dex())+" | "
html_str += ""+str(self.get_total_weight())+" | "
- n_list = self.master_dom._get_childNodes()
+ n_list = self.xml.getchildren()
for n in n_list:
html_str += """Armor |
Type | Bonus | """
- html_str += ""+n.getAttribute('name')+" | "
- html_str += ""+n.getAttribute('type')+" | "
- html_str += ""+n.getAttribute('bonus')+" | "
+ html_str += ""+n.get('name')+" | "
+ html_str += ""+n.get('type')+" | "
+ html_str += ""+n.get('bonus')+" | "
html_str += """Check Penalty | Spell Failure |
Max Dex | Speed | Weight | """
- html_str += ""+n.getAttribute('checkpenalty')+" | "
- html_str += ""+n.getAttribute('maxdex')+" | "
- html_str += ""+n.getAttribute('speed')+" | "
- html_str += ""+n.getAttribute('weight')+" | "
+ html_str += " "+n.get('checkpenalty')+" | "
+ html_str += ""+n.get('maxdex')+" | "
+ html_str += ""+n.get('speed')+" | "
+ html_str += ""+n.get('weight')+" | "
return html_str
@@ -943,7 +930,7 @@
class char_panel(wx.ScrolledWindow):
def __init__(self, parent, handler):
- pname = handler.master_dom.setAttribute("name", 'TWO')
+ pname = handler.xml.set("name", 'TWO')
wx.ScrolledWindow.__init__(self, parent, -1,style=wx.VSCROLL | wx.SUNKEN_BORDER )
self.height = 1200
self.SetScrollbars(10, 10,80, self.height/10)
@@ -999,13 +986,12 @@
class howto_panel(wx.Panel):
def __init__(self, parent, handler):
wx.Panel.__init__(self, parent, -1)
- pname = handler.master_dom.setAttribute("name", 'How To')
+ pname = handler.xml.set("name", 'How To')
self.sizer = wx.FlexGridSizer(2, 4, 2, 2) # rows, cols, hgap, vgap
- self.master_dom = handler.master_dom
- n_list = self.master_dom._get_childNodes()
+ self.xml = handler.xml
+ n_list = self.xml.getchildren()
for n in n_list:
- t_node = component.get('xml').safe_get_text_node(n)
- self.sizer.AddMany([ (wx.StaticText(self, -1, t_node._get_nodeValue()), 0, wx.ALIGN_CENTER_VERTICAL),
+ self.sizer.AddMany([ (wx.StaticText(self, -1, n.text), 0, wx.ALIGN_CENTER_VERTICAL),
])
self.sizer.AddGrowableCol(1)
self.SetSizer(self.sizer)
@@ -1017,13 +1003,13 @@
class hp_panel(wx.Panel):
def __init__(self, parent, handler):
wx.Panel.__init__(self, parent, -1)
- pname = handler.master_dom.setAttribute("name", 'WoundPoints')
+ pname = handler.xml.set("name", 'WoundPoints')
self.sizer = wx.FlexGridSizer(2, 4, 2, 2) # rows, cols, hgap, vgap
- self.master_dom = handler.master_dom
+ self.xml = handler.xml
self.sizer.AddMany([ (wx.StaticText(self, -1, "WP Current:"), 0, wx.ALIGN_CENTER_VERTICAL),
- (wx.TextCtrl(self, WP_CUR, self.master_dom.getAttribute('current')), 0, wx.EXPAND),
+ (wx.TextCtrl(self, WP_CUR, self.xml.get('current')), 0, wx.EXPAND),
(wx.StaticText(self, -1, "WP Max:"), 0, wx.ALIGN_CENTER_VERTICAL),
- (wx.TextCtrl(self, WP_MAX, self.master_dom.getAttribute('max')), 0, wx.EXPAND),
+ (wx.TextCtrl(self, WP_MAX, self.xml.get('max')), 0, wx.EXPAND),
])
self.sizer.AddGrowableCol(1)
self.Bind(wx.EVT_SIZE, self.on_size)
@@ -1034,9 +1020,9 @@
def on_text(self,evt):
id = evt.GetId()
if id == WP_CUR:
- self.master_dom.setAttribute('current',evt.GetString())
+ self.xml.set('current',evt.GetString())
elif id == WP_MAX:
- self.master_dom.setAttribute('max',evt.GetString())
+ self.xml.set('max',evt.GetString())
def on_size(self,evt):
s = self.GetClientSizeTuple()
@@ -1048,13 +1034,13 @@
class vp_panel(wx.Panel):
def __init__(self, parent, handler):
wx.Panel.__init__(self, parent, -1)
- pname = handler.master_dom.setAttribute("name", 'VitalityPoints')
+ pname = handler.xml.set("name", 'VitalityPoints')
self.sizer = wx.FlexGridSizer(2, 4, 2, 2) # rows, cols, hgap, vgap
- self.master_dom = handler.master_dom
+ self.xml = handler.xml
self.sizer.AddMany([ (wx.StaticText(self, -1, "VP Current:"), 0, wx.ALIGN_CENTER_VERTICAL),
- (wx.TextCtrl(self, VP_CUR, self.master_dom.getAttribute('current')), 0, wx.EXPAND),
+ (wx.TextCtrl(self, VP_CUR, self.xml.get('current')), 0, wx.EXPAND),
(wx.StaticText(self, -1, "VP Max:"), 0, wx.ALIGN_CENTER_VERTICAL),
- (wx.TextCtrl(self, VP_MAX, self.master_dom.getAttribute('max')), 0, wx.EXPAND),
+ (wx.TextCtrl(self, VP_MAX, self.xml.get('max')), 0, wx.EXPAND),
])
self.sizer.AddGrowableCol(1)
self.Bind(wx.EVT_SIZE, self.on_size)
@@ -1065,9 +1051,9 @@
def on_text(self,evt):
id = evt.GetId()
if id == VP_CUR:
- self.master_dom.setAttribute('current',evt.GetString())
+ self.xml.set('current',evt.GetString())
elif id == VP_MAX:
- self.master_dom.setAttribute('max',evt.GetString())
+ self.xml.set('max',evt.GetString())
def on_size(self,evt):
s = self.GetClientSizeTuple()
@@ -1081,18 +1067,18 @@
#class pp_panel(wx.Panel):
# def __init__(self, parent, handler):
# wx.Panel.__init__(self, parent, -1)
-# pname = handler.master_dom.setAttribute("name", 'PowerPoints')
+# pname = handler.xml.set("name", 'PowerPoints')
# self.sizer = wx.FlexGridSizer(2, 4, 2, 2) # rows, cols, hgap, vgap
-# self.master_dom = handler.master_dom
+# self.xml = handler.xml
#
# self.sizer.AddMany([ (wx.StaticText(self, -1, "PP Current:"), 0, wx.ALIGN_CENTER_VERTICAL),
-# (wx.TextCtrl(self, PP_CUR, self.master_dom.getAttribute('current1')), 0, wx.EXPAND),
+# (wx.TextCtrl(self, PP_CUR, self.xml.get('current1')), 0, wx.EXPAND),
# (wx.StaticText(self, -1, "PP Max:"), 0, wx.ALIGN_CENTER_VERTICAL),
-# (wx.TextCtrl(self, PP_MAX, self.master_dom.getAttribute('max1')), 0, wx.EXPAND),
+# (wx.TextCtrl(self, PP_MAX, self.xml.get('max1')), 0, wx.EXPAND),
# (wx.StaticText(self, -1, "Current Free Talants per day:"), 0, wx.ALIGN_CENTER_VERTICAL),
-# (wx.TextCtrl(self, PP_FRE, self.master_dom.getAttribute('free')), 0, wx.EXPAND),
+# (wx.TextCtrl(self, PP_FRE, self.xml.get('free')), 0, wx.EXPAND),
# (wx.StaticText(self, -1, "Max Free Talants per day:"), 0, wx.ALIGN_CENTER_VERTICAL),
-# (wx.TextCtrl(self, PP_MFRE, self.master_dom.getAttribute('maxfree')), 0, wx.EXPAND),
+# (wx.TextCtrl(self, PP_MFRE, self.xml.get('maxfree')), 0, wx.EXPAND),
# ])
# self.sizer.AddGrowableCol(1)
# self.Bind(wx.EVT_SIZE, self.on_size)
@@ -1104,13 +1090,13 @@
# def on_text(self,evt):
# id = evt.GetId()
# if id == PP_CUR:
-# self.master_dom.setAttribute('current1',evt.GetString())
+# self.xml.set('current1',evt.GetString())
# elif id == PP_MAX:
-# self.master_dom.setAttribute('max1',evt.GetString())
+# self.xml.set('max1',evt.GetString())
# elif id == PP_FRE:
-# self.master_dom.setAttribute('free',evt.GetString())
+# self.xml.set('free',evt.GetString())
# elif id == PP_MFRE:
-# self.master_dom.setAttribute('maxfree',evt.GetString())
+# self.xml.set('maxfree',evt.GetString())
#
# def on_size(self,evt):
# s = self.GetClientSizeTuple()
@@ -1120,12 +1106,12 @@
class gen_grid(wx.grid.Grid):
"""grid for gen info"""
def __init__(self, parent, handler):
- pname = handler.master_dom.setAttribute("name", 'General')
+ pname = handler.xml.set("name", 'General')
wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
self.Bind(wx.EVT_SIZE, self.on_size)
self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
self.handler = handler
- n_list = handler.master_dom._get_childNodes()
+ n_list = handler.xml.getchildren()
self.CreateGrid(len(n_list),2)
self.SetRowLabelSize(0)
self.SetColLabelSize(0)
@@ -1138,15 +1124,13 @@
row = evt.GetRow()
col = evt.GetCol()
value = self.GetCellValue(row,col)
- t_node = self.n_list[row]._get_firstChild()
- t_node._set_nodeValue(value)
+ self.n_list[row].text = value
if row==0: self.handler.on_name_change(value)
def refresh_row(self,rowi):
- t_node = component.get('xml').safe_get_text_node(self.n_list[rowi])
- self.SetCellValue(rowi,0,self.n_list[rowi]._get_tagName())
+ self.SetCellValue(rowi,0,self.n_list[rowi].tag)
self.SetReadOnly(rowi,0)
- self.SetCellValue(rowi,1,t_node._get_nodeValue())
+ self.SetCellValue(rowi,1,self.n_list[rowi].text)
def on_size(self,evt):
(w,h) = self.GetClientSizeTuple()
@@ -1160,12 +1144,12 @@
class inventory_grid(wx.grid.Grid):
"""grid for gen info"""
def __init__(self, parent, handler):
- pname = handler.master_dom.setAttribute("name", 'Money and Inventory')
+ pname = handler.xml.set("name", 'Money and Inventory')
wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
self.Bind(wx.EVT_SIZE, self.on_size)
self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
self.handler = handler
- n_list = handler.master_dom._get_childNodes()
+ n_list = handler.xml.getchildren()
self.CreateGrid(len(n_list),2)
self.SetRowLabelSize(0)
self.SetColLabelSize(0)
@@ -1178,15 +1162,13 @@
row = evt.GetRow()
col = evt.GetCol()
value = self.GetCellValue(row,col)
- t_node = self.n_list[row]._get_firstChild()
- t_node._set_nodeValue(value)
+ self.n_list[row].text = value
if row==0: self.handler.on_name_change(value)
def refresh_row(self,rowi):
- t_node = component.get('xml').safe_get_text_node(self.n_list[rowi])
- self.SetCellValue(rowi,0,self.n_list[rowi]._get_tagName())
+ self.SetCellValue(rowi,0, self.n_list[rowi].tag)
self.SetReadOnly(rowi,0)
- self.SetCellValue(rowi,1,t_node._get_nodeValue())
+ self.SetCellValue(rowi,1,self.n_list[rowi].text)
def on_size(self,evt):
(w,h) = self.GetClientSizeTuple()
@@ -1200,12 +1182,12 @@
class abil_grid(wx.grid.Grid):
"""grid for abilities"""
def __init__(self, parent, handler):
- pname = handler.master_dom.setAttribute("name", 'Stats')
+ pname = handler.xml.set("name", 'Stats')
wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
self.Bind(wx.EVT_SIZE, self.on_size)
self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
self.handler = handler
- stats = handler.master_dom.getElementsByTagName('stat')
+ stats = handler.xml.findall('stat')
self.CreateGrid(len(stats),3)
self.SetRowLabelSize(0)
col_names = ['Ability','Score','Modifier']
@@ -1223,7 +1205,7 @@
value = self.GetCellValue(row,col)
try:
int(value)
- self.stats[row].setAttribute('base',value)
+ self.stats[row].set('base',value)
self.refresh_row(row)
except:
self.SetCellValue(row,col,"0")
@@ -1232,11 +1214,11 @@
def refresh_row(self,rowi):
s = self.stats[rowi]
- name = s.getAttribute('name')
- abbr = s.getAttribute('abbr')
+ name = s.get('name')
+ abbr = s.get('abbr')
self.SetCellValue(rowi,0,name)
self.SetReadOnly(rowi,0)
- self.SetCellValue(rowi,1,s.getAttribute('base'))
+ self.SetCellValue(rowi,1,s.get('base'))
self.SetCellValue(rowi,2,str(self.handler.get_mod(abbr)))
self.SetReadOnly(rowi,2)
@@ -1258,12 +1240,12 @@
class save_grid(wx.grid.Grid):
"""grid for saves"""
def __init__(self, parent, handler):
- pname = handler.master_dom.setAttribute("name", 'Saves')
+ pname = handler.xml.set("name", 'Saves')
wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
self.Bind(wx.EVT_SIZE, self.on_size)
self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
self.handler = handler
- saves = handler.master_dom.getElementsByTagName('save')
+ saves = handler.xml.findall('save')
self.stats = handler.char_hander.child_handlers['abilities']
self.CreateGrid(len(saves),7)
self.SetRowLabelSize(0)
@@ -1282,28 +1264,28 @@
try:
int(value)
if col == 2:
- self.saves[row].setAttribute('base',value)
+ self.saves[row].set('base',value)
elif col ==4:
- self.saves[row].setAttribute('magmod',value)
+ self.saves[row].set('magmod',value)
elif col ==4:
- self.saves[row].setAttribute('miscmod',value)
+ self.saves[row].set('miscmod',value)
self.refresh_row(row)
except:
self.SetCellValue(row,col,"0")
def refresh_row(self,rowi):
s = self.saves[rowi]
- name = s.getAttribute('name')
+ name = s.get('name')
self.SetCellValue(rowi,0,name)
self.SetReadOnly(rowi,0)
- stat = s.getAttribute('stat')
+ stat = s.get('stat')
self.SetCellValue(rowi,1,stat)
self.SetReadOnly(rowi,1)
- self.SetCellValue(rowi,2,s.getAttribute('base'))
+ self.SetCellValue(rowi,2,s.get('base'))
self.SetCellValue(rowi,3,str(self.stats.get_mod(stat)))
self.SetReadOnly(rowi,3)
- self.SetCellValue(rowi,4,s.getAttribute('magmod'))
- self.SetCellValue(rowi,5,s.getAttribute('miscmod'))
+ self.SetCellValue(rowi,4,s.get('magmod'))
+ self.SetCellValue(rowi,5,s.get('miscmod'))
mod = str(self.handler.get_mod(name))
self.SetCellValue(rowi,6,mod)
self.SetReadOnly(rowi,6)
@@ -1326,12 +1308,12 @@
class skill_grid(wx.grid.Grid):
""" panel for skills """
def __init__(self, parent, handler):
- pname = handler.master_dom.setAttribute("name", 'Skills')
+ pname = handler.xml.set("name", 'Skills')
wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
self.Bind(wx.EVT_SIZE, self.on_size)
self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
self.handler = handler
- skills = handler.master_dom.getElementsByTagName('skill')
+ skills = handler.xml.findall('skill')
self.stats = handler.char_hander.child_handlers['abilities']
self.CreateGrid(len(skills),7)
self.SetRowLabelSize(0)
@@ -1351,28 +1333,28 @@
try:
int(value)
if col == 3:
- self.skills[row].setAttribute('rank',value)
+ self.skills[row].set('rank',value)
elif col ==5:
- self.skills[row].setAttribute('misc',value)
+ self.skills[row].set('misc',value)
elif col == 1:
- self.skills[row].setAttribute('untrained',value)
+ self.skills[row].set('untrained',value)
self.refresh_row(row)
except:
self.SetCellValue(row,col,"0")
def refresh_row(self,rowi):
s = self.skills[rowi]
- name = s.getAttribute('name')
+ name = s.get('name')
self.SetCellValue(rowi,0,name)
self.SetReadOnly(rowi,0)
- self.SetCellValue(rowi,1,s.getAttribute('untrained'))
- stat = s.getAttribute('stat')
+ self.SetCellValue(rowi,1,s.get('untrained'))
+ stat = s.get('stat')
self.SetCellValue(rowi,2,stat)
self.SetReadOnly(rowi,2)
- self.SetCellValue(rowi,3,s.getAttribute('rank'))
+ self.SetCellValue(rowi,3,s.get('rank'))
self.SetCellValue(rowi,4,str(self.stats.get_mod(stat)))
self.SetReadOnly(rowi,4)
- self.SetCellValue(rowi,5,s.getAttribute('misc'))
+ self.SetCellValue(rowi,5,s.get('misc'))
mod = str(self.handler.get_mod(name))
self.SetCellValue(rowi,6,mod)
self.SetReadOnly(rowi,6)
@@ -1395,7 +1377,7 @@
class feat_panel(wx.Panel):
def __init__(self, parent, handler):
- pname = handler.master_dom.setAttribute("name", 'Feats')
+ pname = handler.xml.set("name", 'Feats')
wx.Panel.__init__(self, parent, -1)
self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
sizer = wx.BoxSizer(wx.HORIZONTAL)
@@ -1410,9 +1392,9 @@
self.Bind(wx.EVT_BUTTON, self.on_remove, remove_btn)
self.Bind(wx.EVT_BUTTON, self.on_add, add_btn)
- n_list = handler.master_dom._get_childNodes()
+ n_list = handler.xml.getchildren()
self.n_list = n_list
- self.master_dom = handler.master_dom
+ self.xml = handler.xml
self.grid.CreateGrid(len(n_list),2,1)
self.grid.SetRowLabelSize(0)
self.grid.SetColLabelValue(0,"Feat")
@@ -1423,8 +1405,8 @@
def refresh_row(self,i):
feat = self.n_list[i]
- name = feat.getAttribute('name')
- type = feat.getAttribute('type')
+ name = feat.get('name')
+ type = feat.get('type')
self.grid.SetCellValue(i,0,name)
self.grid.SetReadOnly(i,0)
self.grid.SetCellValue(i,1,type)
@@ -1435,23 +1417,20 @@
for i in range(rows):
if self.grid.IsInSelection(i,0):
self.grid.DeleteRows(i)
- self.master_dom.removeChild(self.n_list[i])
+ self.xml.remove(self.n_list[i])
def on_add(self,evt):
if not self.temp_dom:
- tmp = open(dir_struct["SWd20"]+"d20feats.xml","r")
- xml_dom = parseXml_with_dlg(self,tmp.read())
- xml_dom = xml_dom._get_firstChild()
- tmp.close()
- self.temp_dom = xml_dom
- f_list = self.temp_dom.getElementsByTagName('feat')
+ tree = parse(dir_struct["SWd20"]+"d20feats.xml")
+ self.temp_dom = tree.getroot()
+ f_list = self.temp_dom.findall('feat')
opts = []
for f in f_list:
- opts.append(f.getAttribute('name'))
+ opts.append(f.get('name'))
dlg = wx.SingleChoiceDialog(self,'Choose Feat','Feats',opts)
if dlg.ShowModal() == wx.ID_OK:
i = dlg.GetSelection()
- new_node = self.master_dom.appendChild(f_list[i].cloneNode(False))
+ new_node = self.xml.append(f_list[i])
self.grid.AppendRows(1)
self.refresh_row(self.grid.GetNumberRows()-1)
dlg.Destroy()
@@ -1470,7 +1449,7 @@
class attack_grid(wx.grid.Grid):
"""grid for attacks"""
def __init__(self, parent, handler):
- pname = handler.master_dom.setAttribute("name", 'Melee')
+ pname = handler.xml.set("name", 'Melee')
wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
self.parent = parent
self.handler = handler
@@ -1493,19 +1472,19 @@
try:
int(value)
if col==1:
- self.rows[row].setAttribute('base',value)
+ self.rows[row].set('base',value)
elif col==2:
- self.rows[row].setAttribute('second',value)
+ self.rows[row].set('second',value)
elif col==3:
- self.rows[row].setAttribute('third',value)
+ self.rows[row].set('third',value)
elif col==4:
- self.rows[row].setAttribute('forth',value)
+ self.rows[row].set('forth',value)
elif col==5:
- self.rows[row].setAttribute('fifth',value)
+ self.rows[row].set('fifth',value)
elif col==6:
- self.rows[row].setAttribute('sixth',value)
+ self.rows[row].set('sixth',value)
elif col==8:
- self.rows[row].setAttribute('misc',value)
+ self.rows[row].set('misc',value)
self.parent.refresh_data()
except:
self.SetCellValue(row,col,"0")
@@ -1538,7 +1517,7 @@
class weapon_panel(wx.Panel):
def __init__(self, parent, handler):
- pname = handler.master_dom.setAttribute("name", 'Weapons')
+ pname = handler.xml.set("name", 'Weapons')
wx.Panel.__init__(self, parent, -1)
self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
sizer = wx.BoxSizer(wx.HORIZONTAL)
@@ -1553,9 +1532,9 @@
self.Bind(wx.EVT_BUTTON, self.on_remove, remove_btn)
self.Bind(wx.EVT_BUTTON, self.on_add, add_btn)
self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
- n_list = handler.master_dom.getElementsByTagName('weapon')
+ n_list = handler.xml.findall('weapon')
self.n_list = n_list
- self.master_dom = handler.master_dom
+ self.xml = handler.xml
self.handler = handler
self.grid.CreateGrid(len(n_list),9,1)
self.grid.SetRowLabelSize(0)
@@ -1570,31 +1549,31 @@
col = evt.GetCol()
value = self.grid.GetCellValue(row,col)
if col == 0:
- self.n_list[row].setAttribute('name',value)
+ self.n_list[row].set('name',value)
elif col == 2:
try:
int(value)
- self.n_list[row].setAttribute('mod',value)
+ self.n_list[row].set('mod',value)
self.refresh_row(row)
except:
self.grid.SetCellValue(row,col,"1")
else:
- self.n_list[row].setAttribute(self.grid.GetColLabelValue(col),value)
+ self.n_list[row].set(self.grid.GetColLabelValue(col),value)
def refresh_row(self,i):
n = self.n_list[i]
- name = n.getAttribute('name')
- mod = n.getAttribute('mod')
- ran = n.getAttribute('range')
+ name = n.get('name')
+ mod = n.get('mod')
+ ran = n.get('range')
total = str(int(mod) + self.handler.get_mod(ran))
self.grid.SetCellValue(i,0,name)
- self.grid.SetCellValue(i,1,n.getAttribute('damage'))
+ self.grid.SetCellValue(i,1,n.get('damage'))
self.grid.SetCellValue(i,2,mod)
- self.grid.SetCellValue(i,3,n.getAttribute('critical'))
- self.grid.SetCellValue(i,4,n.getAttribute('type'))
- self.grid.SetCellValue(i,5,n.getAttribute('weight'))
+ self.grid.SetCellValue(i,3,n.get('critical'))
+ self.grid.SetCellValue(i,4,n.get('type'))
+ self.grid.SetCellValue(i,5,n.get('weight'))
self.grid.SetCellValue(i,6,ran)
- self.grid.SetCellValue(i,7,n.getAttribute('size') )
+ self.grid.SetCellValue(i,7,n.get('size') )
self.grid.SetCellValue(i,8,total)
self.grid.SetReadOnly(i,8)
@@ -1603,27 +1582,24 @@
for i in range(rows):
if self.grid.IsInSelection(i,0):
self.grid.DeleteRows(i)
- self.master_dom.removeChild(self.n_list[i])
- self.n_list = self.master_dom.getElementsByTagName('weapon')
+ self.xml.remove(self.n_list[i])
+ self.n_list = self.xml.findall('weapon')
self.handler.refresh_weapons()
def on_add(self,evt):
if not self.temp_dom:
- tmp = open(dir_struct["SWd20"]+"d20weapons.xml","r")
- xml_dom = parseXml_with_dlg(self,tmp.read())
- xml_dom = xml_dom._get_firstChild()
- tmp.close()
- self.temp_dom = xml_dom
- f_list = self.temp_dom.getElementsByTagName('weapon')
+ tree = parse(dir_struct["SWd20"]+"d20weapons.xml")
+ self.temp_dom = tree.getroot()
+ f_list = self.temp_dom.findall('weapon')
opts = []
for f in f_list:
- opts.append(f.getAttribute('name'))
+ opts.append(f.get('name'))
dlg = wx.SingleChoiceDialog(self,'Choose Weapon','Weapon List',opts)
if dlg.ShowModal() == wx.ID_OK:
i = dlg.GetSelection()
- new_node = self.master_dom.appendChild(f_list[i].cloneNode(False))
+ new_node = self.xml.append(f_list[i])
self.grid.AppendRows(1)
- self.n_list = self.master_dom.getElementsByTagName('weapon')
+ self.n_list = self.xml.findall('weapon')
self.refresh_row(self.grid.GetNumberRows()-1)
self.handler.refresh_weapons()
dlg.Destroy()
@@ -1646,7 +1622,7 @@
class attack_panel(wx.Panel):
def __init__(self, parent, handler):
- pname = handler.master_dom.setAttribute("name", 'Melee')
+ pname = handler.xml.set("name", 'Melee')
wx.Panel.__init__(self, parent, -1)
self.a_grid = attack_grid(self, handler)
@@ -1668,7 +1644,7 @@
class ac_panel(wx.Panel):
def __init__(self, parent, handler):
- pname = handler.master_dom.setAttribute("name", 'Armor')
+ pname = handler.xml.set("name", 'Armor')
wx.Panel.__init__(self, parent, -1)
self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
sizer = wx.BoxSizer(wx.HORIZONTAL)
@@ -1683,8 +1659,8 @@
self.Bind(wx.EVT_BUTTON, self.on_remove, remove_btn)
self.Bind(wx.EVT_BUTTON, self.on_add, add_btn)
self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
- self.master_dom = handler.master_dom
- n_list = handler.master_dom._get_childNodes()
+ self.xml = handler.xml
+ n_list = handler.xml.getchildren()
self.n_list = n_list
col_names = ['Armor','DR','Max Dex','Check Penalty','Weight','Speed (10)','Speed (6)','type']
self.grid.CreateGrid(len(n_list),len(col_names),1)
@@ -1704,39 +1680,36 @@
if col >= 1 and col <= 5:
try:
int(value)
- self.n_list[row].setAttribute(self.atts[col],value)
+ self.n_list[row].set(self.atts[col],value)
except:
self.grid.SetCellValue(row,col,"0")
else:
- self.n_list[row].setAttribute(self.atts[col],value)
+ self.n_list[row].set(self.atts[col],value)
def refresh_row(self,i):
n = self.n_list[i]
for y in range(len(self.atts)):
- self.grid.SetCellValue(i,y,n.getAttribute(self.atts[y]))
+ self.grid.SetCellValue(i,y,n.get(self.atts[y]))
def on_remove(self,evt):
rows = self.grid.GetNumberRows()
for i in range(rows):
if self.grid.IsInSelection(i,0):
self.grid.DeleteRows(i)
- self.master_dom.removeChild(self.n_list[i])
+ self.xml.remove(self.n_list[i])
def on_add(self,evt):
if not self.temp_dom:
- tmp = open(dir_struct["SWd20"]+"d20armor.xml","r")
- xml_dom = parseXml_with_dlg(self,tmp.read())
- xml_dom = xml_dom._get_firstChild()
- tmp.close()
- self.temp_dom = xml_dom
- f_list = self.temp_dom.getElementsByTagName('armor')
+ tree = parse(dir_struct["SWd20"]+"d20armor.xml")
+ self.temp_dom = tree.getroot()
+ f_list = self.temp_dom.findall('armor')
opts = []
for f in f_list:
- opts.append(f.getAttribute('name'))
+ opts.append(f.get('name'))
dlg = wx.SingleChoiceDialog(self,'Choose Armor:','Armor List',opts)
if dlg.ShowModal() == wx.ID_OK:
i = dlg.GetSelection()
- new_node = self.master_dom.appendChild(f_list[i].cloneNode(False))
+ new_node = self.xml.append(f_list[i])
self.grid.AppendRows(1)
self.refresh_row(self.grid.GetNumberRows()-1)
dlg.Destroy()
@@ -1755,7 +1728,7 @@
class class_panel(wx.Panel):
def __init__(self, parent, handler):
- pname = handler.master_dom.setAttribute("name", 'Class')
+ pname = handler.xml.set("name", 'Class')
wx.Panel.__init__(self, parent, -1)
self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
sizer = wx.BoxSizer(wx.HORIZONTAL)
@@ -1771,9 +1744,9 @@
self.Bind(wx.EVT_BUTTON, self.on_add, add_btn)
self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
- n_list = handler.master_dom._get_childNodes()
+ n_list = handler.xml.getchildren()
self.n_list = n_list
- self.master_dom = handler.master_dom
+ self.xml = handler.xml
self.grid.CreateGrid(len(n_list),2,1)
self.grid.SetRowLabelSize(0)
self.grid.SetColLabelValue(0,"Class")
@@ -1788,15 +1761,15 @@
value = self.grid.GetCellValue(row,col)
try:
int(value)
- self.n_list[row].setAttribute('level',value)
+ self.n_list[row].set('level',value)
except:
self.grid.SetCellValue(row,col,"1")
def refresh_row(self,i):
n = self.n_list[i]
- name = n.getAttribute('name')
- level = n.getAttribute('level')
+ name = n.get('name')
+ level = n.get('level')
self.grid.SetCellValue(i,0,name)
self.grid.SetReadOnly(i,0)
self.grid.SetCellValue(i,1,level)
@@ -1807,23 +1780,20 @@
for i in range(rows):
if self.grid.IsInSelection(i,0):
self.grid.DeleteRows(i)
- self.master_dom.removeChild(self.n_list[i])
+ self.xml.remove(self.n_list[i])
def on_add(self,evt):
if not self.temp_dom:
- tmp = open(dir_struct["SWd20"]+"SWd20classes.xml","r")
- xml_dom = parseXml_with_dlg(self,tmp.read())
- xml_dom = xml_dom._get_firstChild()
- tmp.close()
- self.temp_dom = xml_dom
- f_list = self.temp_dom.getElementsByTagName('class')
+ tree = parse(dir_struct["SWd20"]+"SWd20classes.xml")
+ self.temp_dom = tree.getroot()
+ f_list = self.temp_dom.findall('class')
opts = []
for f in f_list:
- opts.append(f.getAttribute('name'))
+ opts.append(f.get('name'))
dlg = wx.SingleChoiceDialog(self,'Choose Class','Classes',opts)
if dlg.ShowModal() == wx.ID_OK:
i = dlg.GetSelection()
- new_node = self.master_dom.appendChild(f_list[i].cloneNode(False))
+ new_node = self.xml.append(f_list[i])
self.grid.AppendRows(1)
self.refresh_row(self.grid.GetNumberRows()-1)
dlg.Destroy()
diff -r 174658f839c0 -r 8827271fbe1b orpg/gametree/nodehandlers/d20.py
--- a/orpg/gametree/nodehandlers/d20.py Sun Nov 01 01:12:50 2009 -0600
+++ b/orpg/gametree/nodehandlers/d20.py Sun Nov 01 11:36:14 2009 -0600
@@ -31,7 +31,8 @@
from core import *
import re
from xml.etree.ElementTree import ElementTree, Element, iselement
-from xml.etree.ElementTree import fromstring, tostring, parse, XML
+from xml.etree.ElementTree import fromstring, tostring, parse, XML
+from orpg.tools.orpg_log import debug
D20_EXPORT = wx.NewId()
############################
@@ -49,7 +50,7 @@
self.load_children()
def load_children(self):
- children = self.xml._get_childNodes()
+ children = self.xml.getchildren()
for c in children:
self.tree.load_xml(c,self.mytree_node)
@@ -63,7 +64,7 @@
opt = wx.MessageBox("Add node as child?","Container Node",wx.YES_NO|wx.CANCEL)
if opt == wx.YES:
xml = self.tree.drag_obj.delete()
- xml = self.xml.insertBefore(xml,None)
+ xml = self.xml.append(xml,None)
self.tree.load_xml(xml, self.mytree_node)
self.tree.Expand(self.mytree_node)
elif opt == wx.NO:
diff -r 174658f839c0 -r 8827271fbe1b orpg/gametree/nodehandlers/dnd35.py
--- a/orpg/gametree/nodehandlers/dnd35.py Sun Nov 01 01:12:50 2009 -0600
+++ b/orpg/gametree/nodehandlers/dnd35.py Sun Nov 01 11:36:14 2009 -0600
@@ -5,6 +5,7 @@
from string import * #a 1.6003
from inspect import * #a 1.9001
from orpg.dirpath import dir_struct
+from xml.etree.ElementTree import parse
dnd35_EXPORT = wx.NewId()
############Global Stuff##############
@@ -21,12 +22,12 @@
return root
#a 1.6 convinience function added safeGetAttr
-def safeGetAttr(node,lable,defRetV=None):
- cna=node.attributes
- for i2 in range(len(cna)):
- if cna.item(i2).name == lable:
- return cna.item(i2).value
- #retV=node.getAttribute(lable) # getAttribute does not distingish between
+def safeGetAttr(node, label, defRetV=None):
+ cna=node.attrib
+ for key in cna:
+ if key == label:
+ return cna[key]
+ #retV=node.get(lable) # get does not distingish between
# the attribute not being present vs it having a value of ""
# This is bad for this routine, thus not used.
return defRetV
@@ -58,7 +59,7 @@
def new_child_handler(self,tag,text,handler_class,icon='gear'):
- node_list = self.master_dom.getElementsByTagName(tag)
+ node_list = self.xml.findall(tag)
tree = self.tree
i = self.tree.icons[icon]
new_tree_node = tree.AppendItem(self.mytree_node,text,i,i)
@@ -137,7 +138,7 @@
def on_html(self,evt):
html_str = self.tohtml()
wnd = http_html_window(self.frame.note,-1)
- wnd.title = self.master_dom.getAttribute('name')
+ wnd.title = self.xml.get('name')
self.frame.add_panel(wnd)
wnd.SetPage(html_str)
@@ -167,12 +168,11 @@
return wnd
def tohtml(self):
- n_list = self.master_dom._get_childNodes()
+ n_list = self.xml.getchildren()
html_str = "General Information |
---|
"
for n in n_list:
- t_node = component.get('xml').safe_get_text_node(n)
- html_str += ""+n._get_tagName().capitalize() +": "
- html_str += t_node._get_nodeValue() + ", "
+ html_str += ""+n.tag.capitalize() +": "
+ html_str += n.text + ", "
html_str = html_str[:len(html_str)-2] + " | "
return html_str
@@ -183,14 +183,13 @@
def get_char_name( self ):
- node = self.master_dom.getElementsByTagName( 'name' )[0]
- t_node = component.get('xml').safe_get_text_node( node )
- return t_node._get_nodeValue()
+ node = self.xml.findall( 'name' )[0]
+ return node.text
class gen_grid(wx.grid.Grid):
"""grid for gen info"""
def __init__(self, parent, handler):
- pname = handler.master_dom.setAttribute("name", 'General')
+ pname = handler.xml.set("name", 'General')
self.hparent = handler #a 1.5002 allow ability to run up tree, needed
# a 1.5002 parent is functional parent, not invoking parent.
@@ -199,7 +198,7 @@
#self.Bind(wx.EVT_SIZE, self.on_size)
self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
self.handler = handler
- n_list = handler.master_dom._get_childNodes()
+ n_list = handler.xml.getchildren()
self.CreateGrid(len(n_list),2)
self.SetRowLabelSize(0)
self.SetColLabelSize(0)
@@ -212,18 +211,16 @@
row = evt.GetRow()
col = evt.GetCol()
value = self.GetCellValue(row,col)
- t_node = self.n_list[row]._get_firstChild()
- t_node._set_nodeValue(value)
+ t_node = self.n_list[row]
+ t_node.text = value
if row==0:
self.handler.on_name_change(value)
#self.AutoSizeColumn(1)
- def refresh_row(self,rowi):
- t_node = component.get('xml').safe_get_text_node(self.n_list[rowi])
-
- self.SetCellValue(rowi,0,self.n_list[rowi]._get_tagName())
- self.SetReadOnly(rowi,0)
- self.SetCellValue(rowi,1,t_node._get_nodeValue())
+ def refresh_row(self, rowi):
+ self.SetCellValue(rowi, 0, self.n_list[rowi].tag)
+ self.SetReadOnly(rowi, 0)
+ self.SetCellValue(rowi, 1, self.n_list[rowi].text)
self.AutoSizeColumn(1)
class dnd35inventory(dnd35_char_child):
@@ -242,12 +239,11 @@
return wnd
def tohtml(self):
- n_list = self.master_dom._get_childNodes()
+ n_list = self.xml.getchildren()
html_str = "Inventory |
---|
"
for n in n_list:
- t_node = component.get('xml').safe_get_text_node(n)
- html_str += ""+n._get_tagName().capitalize() +": "
- html_str += t_node._get_nodeValue() + " "
+ html_str += ""+n.tag.capitalize() +": "
+ html_str += n.text + " "
html_str = html_str[:len(html_str)-2] + " | "
return html_str
@@ -255,7 +251,7 @@
def __init__(self, parent, handler):
wx.Panel.__init__(self, parent, wx.ID_ANY)
- self.n_list = handler.master_dom._get_childNodes()
+ self.n_list = handler.xml.getchildren()
self.autosize = False
self.sizer = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY, "Inventroy"), wx.VERTICAL)
@@ -317,13 +313,11 @@
for node in self.n_list:
if node._get_tagName() == nodeName:
- t_node = component.get('xml').safe_get_text_node(node)
- t_node._set_nodeValue(value)
+ node.text = value
def saveMoney(self, row, col):
value = self.grid.GetCellValue(row, col)
- t_node = component.get('xml').safe_get_text_node(self.n_list[row])
- t_node._set_nodeValue(value)
+ self.n_list[row].text = value
def on_cell_change(self, evt):
row = evt.GetRow()
@@ -334,9 +328,8 @@
def refresh_row(self, row):
- t_node = component.get('xml').safe_get_text_node(self.n_list[row])
- tagname = self.n_list[row]._get_tagName()
- value = t_node._get_nodeValue()
+ tagname = self.n_list[row].tag
+ value = self.n_list[row].text
if tagname == 'Gear':
self.fillTextNode(tagname, value)
elif tagname == 'Magic':
@@ -367,7 +360,7 @@
def new_child_handler(self,tag,text,handler_class,icon='gear'):
- node_list = self.master_dom.getElementsByTagName(tag)
+ node_list = self.xml.findall(tag)
tree = self.tree
i = self.tree.icons[icon]
new_tree_node = tree.AppendItem(self.mytree_node,text,i,i)
@@ -405,7 +398,7 @@
def on_html(self,evt):
html_str = self.tohtml()
wnd = http_html_window(self.frame.note,-1)
- wnd.title = self.master_dom.getAttribute('name')
+ wnd.title = self.xml.get('name')
self.frame.add_panel(wnd)
wnd.SetPage(html_str)
@@ -429,12 +422,12 @@
self.root.abilities = self #a 1.5002 let other classes find me.
self.abilities = {}
- node_list = self.master_dom.getElementsByTagName('stat')
+ node_list = self.xml.findall('stat')
tree = self.tree
icons = tree.icons
for n in node_list:
- name = n.getAttribute('abbr')
+ name = n.get('abbr')
self.abilities[name] = n
new_tree_node = tree.AppendItem( self.mytree_node, name, icons['gear'], icons['gear'] )
tree.SetPyData( new_tree_node, self )
@@ -457,14 +450,14 @@
chat.ParsePost( txt, True, True )
def get_mod(self,abbr):
- score = int(self.abilities[abbr].getAttribute('base'))
+ score = int(self.abilities[abbr].get('base'))
mod = (score - 10) / 2
mod = int(mod)
return mod
def set_score(self,abbr,score):
if score >= 0:
- self.abilities[abbr].setAttribute("base",str(score))
+ self.abilities[abbr].set("base",str(score))
def get_design_panel(self,parent):
wnd = outline_panel(parent,self,abil_grid,"Abilities")
@@ -474,11 +467,11 @@
def tohtml(self):
html_str = """Ability |
Base | Modifier | """
- node_list = self.master_dom.getElementsByTagName('stat')
+ node_list = self.xml.findall('stat')
for n in node_list:
- name = n.getAttribute('name')
- abbr = n.getAttribute('abbr')
- base = n.getAttribute('base')
+ name = n.get('name')
+ abbr = n.get('abbr')
+ base = n.get('base')
mod = str(self.get_mod(abbr))
if int(mod) >= 0: #m 1.6013 added "int(" and ")"
mod1 = "+"
@@ -492,7 +485,7 @@
class abil_grid(wx.grid.Grid):
"""grid for abilities"""
def __init__(self, parent, handler):
- pname = handler.master_dom.setAttribute("name", 'Stats')
+ pname = handler.xml.set("name", 'Stats')
self.hparent = handler #a 1.5002 allow ability to run up tree.
self.root = getRoot(self)
#a 1.5002 in this case, we need the functional parent, not the invoking parent.
@@ -501,7 +494,7 @@
self.Bind(wx.EVT_SIZE, self.on_size)
self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
self.handler = handler
- stats = handler.master_dom.getElementsByTagName('stat')
+ stats = handler.xml.findall('stat')
self.CreateGrid(len(stats),3)
self.SetRowLabelSize(0)
col_names = ['Ability','Score','Modifier']
@@ -520,7 +513,7 @@
#print value
try:
int(value)
- self.stats[row].setAttribute('base',value)
+ self.stats[row].set('base',value)
self.refresh_row(row)
except:
self.SetCellValue(row,col,"0")
@@ -532,11 +525,11 @@
def refresh_row(self,rowi):
s = self.stats[rowi]
- name = s.getAttribute('name')
- abbr = s.getAttribute('abbr')
+ name = s.get('name')
+ abbr = s.get('abbr')
self.SetCellValue(rowi,0,name)
self.SetReadOnly(rowi,0)
- self.SetCellValue(rowi,1,s.getAttribute('base'))
+ self.SetCellValue(rowi,1,s.get('base'))
self.SetCellValue(rowi,2,str(self.handler.get_mod(abbr)))
self.SetReadOnly(rowi,2)
#if self.root.saves.saveGrid: #a 1.6018 d 1.9002 whole if clause
@@ -578,20 +571,20 @@
def tohtml(self):
html_str = "Classes |
---|
"
- n_list = self.master_dom._get_childNodes()
+ n_list = self.xml.getchildren()
for n in n_list:
- html_str += n.getAttribute('name') + " ("+n.getAttribute('level')+"), "
+ html_str += n.get('name') + " ("+n.get('level')+"), "
html_str = html_str[:len(html_str)-2] + " | "
return html_str
def get_char_lvl( self, attr ):
- node_list = self.master_dom.getElementsByTagName('class')
+ node_list = self.xml.findall('class')
# print "eclasses - get_char_lvl node_list",node_list
tot = 0 #a 1.5009 actually, slipping in a quick enhancement ;-)
for n in node_list:
- lvl = n.getAttribute('level') #o 1.5009 not sure of the value of this
+ lvl = n.get('level') #o 1.5009 not sure of the value of this
tot += int(lvl) #a 1.5009
- type = n.getAttribute('name') #o 1.5009 not sure of the value of this
+ type = n.get('name') #o 1.5009 not sure of the value of this
#print type,lvl #a (debug) 1.5009
if attr == "level":
return lvl #o 1.5009 this returns the level of someone's first class. ???
@@ -602,17 +595,17 @@
def get_class_lvl( self, classN ): #a 1.5009 need to be able to get monk lvl
#a 1.5009 this function is new.
- node_list = self.master_dom.getElementsByTagName('class')
+ node_list = self.xml.findall('class')
#print "eclasses - get_class_lvl node_list",node_list
for n in node_list:
- lvl = n.getAttribute('level')
- type = n.getAttribute('name')
+ lvl = n.get('level')
+ type = n.get('name')
if classN == type:
return lvl
class class_panel(wx.Panel):
def __init__(self, parent, handler):
- pname = handler.master_dom.setAttribute("name", 'Class')
+ pname = handler.xml.set("name", 'Class')
wx.Panel.__init__(self, parent, -1)
self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
@@ -634,9 +627,9 @@
self.Bind(wx.EVT_BUTTON, self.on_add, id=20)
self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
- n_list = handler.master_dom._get_childNodes()
+ n_list = handler.xml.getchildren()
self.n_list = n_list
- self.master_dom = handler.master_dom
+ self.xml = handler.xml
self.grid.CreateGrid(len(n_list),3,1)
self.grid.SetRowLabelSize(0)
self.grid.SetColLabelValue(0,"Class")
@@ -652,7 +645,7 @@
value = self.grid.GetCellValue(row,col)
try:
int(value)
- self.n_list[row].setAttribute('level',value)
+ self.n_list[row].set('level',value)
except:
self.grid.SetCellValue(row,col,"1")
@@ -660,9 +653,9 @@
def refresh_row(self,i):
n = self.n_list[i]
- name = n.getAttribute('name')
- level = n.getAttribute('level')
- book = n.getAttribute('book')
+ name = n.get('name')
+ level = n.get('level')
+ book = n.get('book')
self.grid.SetCellValue(i,0,name)
self.grid.SetReadOnly(i,0)
self.grid.SetCellValue(i,1,level)
@@ -677,23 +670,21 @@
for i in range(rows):
if self.grid.IsInSelection(i,0):
self.grid.DeleteRows(i)
- self.master_dom.removeChild(self.n_list[i])
+ self.xml.remove(self.n_list[i])
def on_add(self,evt):
if not self.temp_dom:
- tmp = open(dir_struct["dnd35"]+"dnd35classes.xml","r")
- xml_dom = parseXml_with_dlg(self,tmp.read())
- xml_dom = xml_dom._get_firstChild()
- tmp.close()
+ tree = parse(dir_struct["dnd35"]+"dnd35classes.xml")
+ xml_dom = tree.getroot()
self.temp_dom = xml_dom
- f_list = self.temp_dom.getElementsByTagName('class')
+ f_list = self.temp_dom.findall('class')
opts = []
for f in f_list:
- opts.append(f.getAttribute('name'))
+ opts.append(f.get('name'))
dlg = wx.SingleChoiceDialog(self,'Choose Class','Classes',opts)
if dlg.ShowModal() == wx.ID_OK:
i = dlg.GetSelection()
- new_node = self.master_dom.appendChild(f_list[i].cloneNode(False))
+ new_node = self.xml.append(f_list[i])
self.grid.AppendRows(1)
self.refresh_row(self.grid.GetNumberRows()-1)
dlg.Destroy()
@@ -725,10 +716,10 @@
self.root = getRoot(self) #a 1.5002
self.root.saves = self #a 1.6009
- node_list = self.master_dom.getElementsByTagName('save')
+ node_list = self.xml.findall('save')
self.saves={}
for n in node_list:
- name = n.getAttribute('name')
+ name = n.get('name')
self.saves[name] = n
new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear'])
tree.SetPyData(new_tree_node,self)
@@ -746,13 +737,13 @@
def get_mod(self,name):
save = self.saves[name]
- stat = save.getAttribute('stat')
+ stat = save.get('stat')
#print "dnd35saves, get_mod: self,root",self,self.root #a (debug) 1.5002
#print "and abilities",self.root.abilities #a (debug) 1.5002
stat_mod = self.root.abilities.get_mod(stat) #a 1.5002
- base = int(save.getAttribute('base'))
- miscmod = int(save.getAttribute('miscmod'))
- magmod = int(save.getAttribute('magmod'))
+ base = int(save.get('base'))
+ miscmod = int(save.get('miscmod'))
+ magmod = int(save.get('magmod'))
total = stat_mod + base + miscmod + magmod
return total
@@ -788,17 +779,17 @@
Save |
Key | Base | Abil | Magic |
Misc | Total | """
- node_list = self.master_dom.getElementsByTagName('save')
+ node_list = self.xml.findall('save')
for n in node_list:
- name = n.getAttribute('name')
- stat = n.getAttribute('stat')
- base = n.getAttribute('base')
+ name = n.get('name')
+ stat = n.get('stat')
+ base = n.get('base')
html_str = html_str + ""+name+" | "+stat+" | "+base+" | "
#stat_mod = str(dnd_globals["stats"][stat]) #d 1.5002
stat_mod = self.root.abilities.get_mod(stat) #a 1.5002
- mag = n.getAttribute('magmod')
- misc = n.getAttribute('miscmod')
+ mag = n.get('magmod')
+ misc = n.get('miscmod')
mod = str(self.get_mod(name))
if mod >= 0:
mod1 = "+"
@@ -814,7 +805,7 @@
class save_grid(wx.grid.Grid):
"""grid for saves"""
def __init__(self, parent, handler):
- pname = handler.master_dom.setAttribute("name", 'Saves')
+ pname = handler.xml.set("name", 'Saves')
self.hparent = handler #a 1.5002 allow ability to run up tree.
#a 1.5002 in this case, we need the functional parent, not the invoking parent.
self.root = getRoot(self)
@@ -826,7 +817,7 @@
self.Bind(wx.EVT_SIZE, self.on_size)
self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
self.handler = handler
- saves = handler.master_dom.getElementsByTagName('save')
+ saves = handler.xml.findall('save')
self.CreateGrid(len(saves),7)
self.SetRowLabelSize(0)
col_names = ['Save','Key','base','Abil','Magic','Misc','Total']
@@ -857,11 +848,11 @@
try:
int(value)
if col == 2:
- self.saves[row].setAttribute('base',value)
+ self.saves[row].set('base',value)
elif col ==4:
- self.saves[row].setAttribute('magmod',value)
+ self.saves[row].set('magmod',value)
elif col ==5: # 1.5001
- self.saves[row].setAttribute('miscmod',value)
+ self.saves[row].set('miscmod',value)
self.refresh_row(row)
except:
self.SetCellValue(row,col,"0")
@@ -869,17 +860,17 @@
def refresh_row(self,rowi):
s = self.saves[rowi]
- name = s.getAttribute('name')
+ name = s.get('name')
self.SetCellValue(rowi,0,name)
self.SetReadOnly(rowi,0)
- stat = s.getAttribute('stat')
+ stat = s.get('stat')
self.SetCellValue(rowi,1,stat)
self.SetReadOnly(rowi,1)
- self.SetCellValue(rowi,2,s.getAttribute('base'))
+ self.SetCellValue(rowi,2,s.get('base'))
self.SetCellValue(rowi,3,str(self.root.abilities.get_mod(stat)))
self.SetReadOnly(rowi,3)
- self.SetCellValue(rowi,4,s.getAttribute('magmod'))
- self.SetCellValue(rowi,5,s.getAttribute('miscmod'))
+ self.SetCellValue(rowi,4,s.get('magmod'))
+ self.SetCellValue(rowi,5,s.get('miscmod'))
mod = str(self.handler.get_mod(name))
self.SetCellValue(rowi,6,mod)
self.SetReadOnly(rowi,6)
@@ -916,7 +907,7 @@
def new_child_handler(self,tag,text,handler_class,icon='gear'):
- node_list = self.master_dom.getElementsByTagName(tag)
+ node_list = self.xml.findall(tag)
tree = self.tree
i = self.tree.icons[icon]
new_tree_node = tree.AppendItem(self.mytree_node,text,i,i)
@@ -956,7 +947,7 @@
def on_html(self,evt):
html_str = self.tohtml()
wnd = http_html_window(self.frame.note,-1)
- wnd.title = self.master_dom.getAttribute('name')
+ wnd.title = self.xml.get('name')
self.frame.add_panel(wnd)
wnd.SetPage(html_str)
@@ -982,16 +973,16 @@
skills_char_child.__init__(self,xml_dom,tree_node,parent)
tree = self.tree
icons = self.tree.icons
- node_list = self.master_dom.getElementsByTagName('skill')
+ node_list = self.xml.findall('skill')
self.skills={}
#Adding code to not display skills you can not use -mgt
for n in node_list:
- name = n.getAttribute('name')
+ name = n.get('name')
self.skills[name] = n
skill_check = self.skills[name]
- ranks = int(skill_check.getAttribute('rank'))
- trained = int(skill_check.getAttribute('untrained'))
+ ranks = int(skill_check.get('rank'))
+ trained = int(skill_check.get('untrained'))
if ranks > 0 or trained == 1:
new_tree_node = tree.AppendItem(self.mytree_node,name,
@@ -1009,15 +1000,15 @@
tree = self.tree
icons = self.tree.icons
tree.CollapseAndReset(self.mytree_node)
- node_list = self.master_dom.getElementsByTagName('skill')
+ node_list = self.xml.findall('skill')
self.skills={}
for n in node_list:
- name = n.getAttribute('name')
+ name = n.get('name')
self.skills[name] = n
skill_check = self.skills[name]
- ranks = int(skill_check.getAttribute('rank'))
- trained = int(skill_check.getAttribute('untrained'))
+ ranks = int(skill_check.get('rank'))
+ trained = int(skill_check.get('untrained'))
if ranks > 0 or trained == 1:
new_tree_node = tree.AppendItem(self.mytree_node,name,
@@ -1029,11 +1020,11 @@
def get_mod(self,name):
skill = self.skills[name]
- stat = skill.getAttribute('stat')
+ stat = skill.get('stat')
#stat_mod = int(dnd_globals["stats"][stat]) #d 1.5002
stat_mod = self.root.abilities.get_mod(stat) #a 1.5002
- rank = int(skill.getAttribute('rank'))
- misc = int(skill.getAttribute('misc'))
+ rank = int(skill.get('rank'))
+ misc = int(skill.get('misc'))
total = stat_mod + rank + misc
return total
@@ -1052,8 +1043,8 @@
skill = self.skills[name]
- untr = skill.getAttribute('untrained') #a 1.6004
- rank = skill.getAttribute('rank') #a 1.6004
+ untr = skill.get('untrained') #a 1.6004
+ rank = skill.get('rank') #a 1.6004
if eval('%s == 0' % (untr)): #a 1.6004
if eval('%s == 0' % (rank)): #a 1.6004
res = 'You fumble around, accomplishing nothing' #a 1.6004
@@ -1065,7 +1056,7 @@
armor = ''
acCp = ''
if ac < 0: #acCp >= 1 #m 1.5004 this is stored as negatives.
- armorCheck = int(skill.getAttribute('armorcheck'))
+ armorCheck = int(skill.get('armorcheck'))
#print "ac,armorCheck",ac,armorCheck
if armorCheck == 1:
acCp=ac
@@ -1095,13 +1086,13 @@
html_str = """
Skill | Key |
Rank | Abil | Misc | Total | """
- node_list = self.master_dom.getElementsByTagName('skill')
+ node_list = self.xml.findall('skill')
for n in node_list:
- name = n.getAttribute('name')
- stat = n.getAttribute('stat')
- rank = n.getAttribute('rank')
- untr = n.getAttribute('untrained') #a 1.6004
+ name = n.get('name')
+ stat = n.get('stat')
+ rank = n.get('rank')
+ untr = n.get('untrained') #a 1.6004
#Filter unsuable skills out of pretty print -mgt
if eval('%s > 0' % (rank)) or eval('%s == 1' % (untr)):
if eval('%s >=1' % (rank)):
@@ -1118,7 +1109,7 @@
continue
stat_mod = self.root.abilities.get_mod(stat) #a 1.5002
#stat_mod = str(dnd_globals["stats"][stat]) #d 1.5002
- misc = n.getAttribute('misc')
+ misc = n.get('misc')
mod = str(self.get_mod(name))
if mod >= 0:
mod1 = "+"
@@ -1135,13 +1126,13 @@
def __init__(self, parent, handler):
self.hparent = handler #a 1.5002 need function parent, not invoker
self.root = getRoot(self) #a 1.5002
- pname = handler.master_dom.setAttribute("name", 'Skills')
+ pname = handler.xml.set("name", 'Skills')
wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
self.Bind(wx.EVT_SIZE, self.on_size)
self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
self.handler = handler
- skills = handler.master_dom.getElementsByTagName('skill')
+ skills = handler.xml.findall('skill')
#xelf.stats = dnd_globals["stats"] #d 1.5002
self.CreateGrid(len(skills),6)
@@ -1162,9 +1153,9 @@
try:
int(value)
if col == 2:
- self.skills[row].setAttribute('rank',value)
+ self.skills[row].set('rank',value)
elif col ==4:
- self.skills[row].setAttribute('misc',value)
+ self.skills[row].set('misc',value)
self.refresh_row(row)
except:
self.SetCellValue(row,col,"0")
@@ -1174,13 +1165,13 @@
def refresh_row(self,rowi):
s = self.skills[rowi]
- name = s.getAttribute('name')
+ name = s.get('name')
self.SetCellValue(rowi,0,name)
self.SetReadOnly(rowi,0)
- stat = s.getAttribute('stat')
+ stat = s.get('stat')
self.SetCellValue(rowi,1,stat)
self.SetReadOnly(rowi,1)
- self.SetCellValue(rowi,2,s.getAttribute('rank'))
+ self.SetCellValue(rowi,2,s.get('rank'))
#self.SetCellValue(rowi,3,str(dnd_globals["stats"][stat])) #d 1.5002
if self.root.abilities: #a 1.5002 sanity check.
stat_mod=self.root.abilities.get_mod(stat) #a 1.5002
@@ -1191,7 +1182,7 @@
self.SetCellValue(rowi,3,str(stat_mod)) #a 1.5002
self.SetReadOnly(rowi,3)
- self.SetCellValue(rowi,4,s.getAttribute('misc'))
+ self.SetCellValue(rowi,4,s.get('misc'))
mod = str(self.handler.get_mod(name))
self.SetCellValue(rowi,5,mod)
self.SetReadOnly(rowi,5)
@@ -1235,9 +1226,9 @@
def tohtml(self):
html_str = "Feats |
---|
"
- n_list = self.master_dom._get_childNodes()
+ n_list = self.xml.getchildren()
for n in n_list:
- html_str += n.getAttribute('name')+ ", "
+ html_str += n.get('name')+ ", "
html_str = html_str[:len(html_str)-2] + " | "
return html_str
@@ -1248,8 +1239,8 @@
#a 1.5002 in this case, we need the functional parent, not the invoking parent.
self.root = getRoot(self) #a 1.5002
#tempTitle= 'Feats - ' + self.root.general.charName #a 1.5010
- #pname = handler.master_dom.setAttribute("name", tempTitle) #a 1.5010
- pname = handler.master_dom.setAttribute("name", 'Feats') #d 1.5010
+ #pname = handler.xml.set("name", tempTitle) #a 1.5010
+ pname = handler.xml.set("name", 'Feats') #d 1.5010
wx.Panel.__init__(self, parent, -1)
self.grid = wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
@@ -1272,9 +1263,9 @@
self.Bind(wx.EVT_BUTTON, self.on_remove, id=10)
self.Bind(wx.EVT_BUTTON, self.on_add, id=20)
- n_list = handler.master_dom._get_childNodes()
+ n_list = handler.xml.getchildren()
self.n_list = n_list
- self.master_dom = handler.master_dom
+ self.xml = handler.xml
self.grid.CreateGrid(len(n_list),3,1)
self.grid.SetRowLabelSize(0)
self.grid.SetColLabelValue(0,"Feat")
@@ -1291,9 +1282,9 @@
def refresh_row(self,i):
feat = self.n_list[i]
- name = feat.getAttribute('name')
- type = feat.getAttribute('type')
- desc = feat.getAttribute('desc') #m 1.6 correct typo
+ name = feat.get('name')
+ type = feat.get('type')
+ desc = feat.get('desc') #m 1.6 correct typo
self.grid.SetCellValue(i,0,name)
self.grid.SetReadOnly(i,0)
self.grid.SetCellValue(i,1,type)
@@ -1310,25 +1301,23 @@
for i in range(rows):
if self.grid.IsInSelection(i,0):
self.grid.DeleteRows(i)
- self.master_dom.removeChild(self.n_list[i])
+ self.xml.remove(self.n_list[i])
def on_add(self,evt):
if not self.temp_dom:
- tmp = open(dir_struct["dnd35"]+"dnd35feats.xml","r")
- xml_dom = parseXml_with_dlg(self,tmp.read())
- xml_dom = xml_dom._get_firstChild()
- tmp.close()
+ tree = parse(dir_struct["dnd35"]+"dnd35feats.xml")
+ xml_dom = tree.getroot()
self.temp_dom = xml_dom
- f_list = self.temp_dom.getElementsByTagName('feat')
+ f_list = self.temp_dom.findall('feat')
opts = []
for f in f_list:
- opts.append(f.getAttribute('name') + " - [" +
- f.getAttribute('type') + "] - " + f.getAttribute('desc'))
+ opts.append(f.get('name') + " - [" +
+ f.get('type') + "] - " + f.get('desc'))
dlg = wx.SingleChoiceDialog(self,'Choose Feat','Feats',opts)
if dlg.ShowModal() == wx.ID_OK:
i = dlg.GetSelection()
- new_node = self.master_dom.appendChild(f_list[i].cloneNode(False))
+ new_node = self.xml.append(f_list[i])
self.grid.AppendRows(1)
self.refresh_row(self.grid.GetNumberRows()-1)
f_list=0; opts=0
@@ -1371,7 +1360,7 @@
def new_child_handler(self,tag,text,handler_class,icon='gear'):
- node_list = self.master_dom.getElementsByTagName(tag)
+ node_list = self.xml.findall(tag)
tree = self.tree
i = self.tree.icons[icon]
new_tree_node = tree.AppendItem(self.mytree_node,text,i,i)
@@ -1410,7 +1399,7 @@
def on_html(self,evt):
html_str = self.tohtml()
wnd = http_html_window(self.frame.note,-1)
- wnd.title = self.master_dom.getAttribute('name')
+ wnd.title = self.xml.get('name')
self.frame.add_panel(wnd)
wnd.SetPage(html_str)
@@ -1439,8 +1428,8 @@
return wnd
def on_rclick( self, evt ):
- chp = self.master_dom.getAttribute('current')
- mhp = self.master_dom.getAttribute('max')
+ chp = self.xml.get('current')
+ mhp = self.xml.get('max')
txt = '((HP: %s / %s))' % ( chp, mhp )
self.chat.ParsePost( txt, True, True )
@@ -1448,9 +1437,9 @@
html_str = ""
html_str += "Hit Points | "
html_str += "Max: | "
- html_str += ""+self.master_dom.getAttribute('max')+" | "
+ html_str += ""+self.xml.get('max')+" | "
html_str += "Current: | "
- html_str += ""+self.master_dom.getAttribute('current')+" | "
+ html_str += ""+self.xml.get('current')+" | "
html_str += "
---|
"
return html_str
@@ -1460,15 +1449,15 @@
self.hparent = handler #a 1.5002 allow ability to run up tree. In this
#a 1.5002 case, we need the functional parent, not the invoking parent.
- pname = handler.master_dom.setAttribute("name", 'HitPoints')
+ pname = handler.xml.set("name", 'HitPoints')
self.sizer = wx.FlexGridSizer(2, 4, 2, 2) # rows, cols, hgap, vgap
- self.master_dom = handler.master_dom
+ self.xml = handler.xml
self.sizer.AddMany([ (wx.StaticText(self, -1, "HP Current:"), 0,
wx.ALIGN_CENTER_VERTICAL),
(wx.TextCtrl(self, HP_CUR,
- self.master_dom.getAttribute('current')), 0, wx.EXPAND),
+ self.xml.get('current')), 0, wx.EXPAND),
(wx.StaticText(self, -1, "HP Max:"), 0, wx.ALIGN_CENTER_VERTICAL),
- (wx.TextCtrl(self, HP_MAX, self.master_dom.getAttribute('max')),
+ (wx.TextCtrl(self, HP_MAX, self.xml.get('max')),
0, wx.EXPAND),
])
self.sizer.AddGrowableCol(1)
@@ -1483,9 +1472,9 @@
def on_text(self,evt):
id = evt.GetId()
if id == HP_CUR:
- self.master_dom.setAttribute('current',evt.GetString())
+ self.xml.set('current',evt.GetString())
elif id == HP_MAX:
- self.master_dom.setAttribute('max',evt.GetString())
+ self.xml.set('max',evt.GetString())
def on_size(self,evt):
s = self.GetClientSizeTuple()
@@ -1525,9 +1514,9 @@
self.temp_dom={}
#a 1.5012 end a1b
- node_list = self.master_dom.getElementsByTagName('melee')
+ node_list = self.xml.findall('melee')
self.melee = node_list[0]
- node_list = self.master_dom.getElementsByTagName('ranged')
+ node_list = self.xml.findall('ranged')
self.ranged = node_list[0]
self.refresh_weapons() # this causes self.weapons to be loaded.
@@ -1545,7 +1534,7 @@
fnFrame.panel.SetPage(self.html_str)
fnFrame.Show()
- #weaponsH = self.master_dom.getElementsByTagName('attacks')
+ #weaponsH = self.xml.findall('attacks')
#mark7
#a 1.9001 this whole method
@@ -1565,9 +1554,9 @@
tree = self.tree
icons = self.tree.icons
tree.CollapseAndReset(self.mytree_node)
- node_list = self.master_dom.getElementsByTagName('weapon')
+ node_list = self.xml.findall('weapon')
for n in node_list:
- name = n.getAttribute('name')
+ name = n.get('name')
fn = safeGetAttr(n,'fn') #a 1.5012 can be removed when
#a 1.5012 confident all characters in the world have footnotes.
#if self.updateFootNotes:
@@ -1581,33 +1570,28 @@
def updateFootN(self,n):#a 1.5012 this whole function
if not self.temp_dom:
- tmp = open(dir_struct["dnd35"]+"dnd35weapons.xml","r")
- #tmp = open("c:\clh\codeSamples\sample1.xml","r") #a (debug) 1.5012
- self.temp_dom = xml.dom.minidom.parse(tmp)
-
- #self.temp_dom = parseXml_with_dlg(self,tmp.read())
- self.temp_dom = self.temp_dom._get_firstChild()
- tmp.close()
- nameF = n.getAttribute('name')
- w_list = self.temp_dom.getElementsByTagName('weapon')
+ tree = parse(dir_struct["dnd35"]+"dnd35weapons.xml")
+ self.temp_dom = tree.getroot()
+ nameF = n.get('name')
+ w_list = self.temp_dom.findall('weapon')
found = False
for w in w_list:
- if nameF == w.getAttribute('name'):
+ if nameF == w.get('name'):
found = True
fnN = safeGetAttr(n,'fn')
if fnN == None or fnN == 'None':
- fnW = w.getAttribute('fn')
+ fnW = w.get('fn')
#print "weapon",nameF,"footnotes are updated to",fnW
self.html_str += (""+nameF+" | "+
""+fnW+" | \n")
- n.setAttribute('fn',fnW)
+ n.set('fn',fnW)
break
if not found:
self.html_str += (""+nameF+" - Custom "+
"Weapon, research "+
"and update manually; setting footnote to indicate custom | "+
""+'X'+" | \n")
- n.setAttribute('fn','X')
+ n.set('fn','X')
def get_mod(self,type='m'):
@@ -1625,13 +1609,13 @@
stat_mod = -7
stat_mod = self.root.abilities.get_mod(stat) #a 1.5002
#print "Big test - stat_mod",stat_mod #a (debug) 1.6000
- base = int(temp.getAttribute('base'))
- base2 = int(temp.getAttribute('second'))
- base3 = int(temp.getAttribute('third'))
- base4 = int(temp.getAttribute('forth'))
- base5 = int(temp.getAttribute('fifth'))
- base6 = int(temp.getAttribute('sixth'))
- misc = int(temp.getAttribute('misc'))
+ base = int(temp.get('base'))
+ base2 = int(temp.get('second'))
+ base3 = int(temp.get('third'))
+ base4 = int(temp.get('forth'))
+ base5 = int(temp.get('fifth'))
+ base6 = int(temp.get('sixth'))
+ misc = int(temp.get('misc'))
return (base, base2, base3, base4, base5, base6, stat_mod ,misc)
def on_rclick(self,evt):
@@ -1645,10 +1629,10 @@
#self.frame.add_panel(self.get_design_panel(self.frame.note))
else:
#print "entering attack phase"
- mod = int(self.weapons[name].getAttribute('mod'))
+ mod = int(self.weapons[name].get('mod'))
wepMod = mod #a 1.5008
footNotes = safeGetAttr(self.weapons[name],'fn','')
- cat = self.weapons[name].getAttribute('category') #a1.6001
+ cat = self.weapons[name].get('category') #a1.6001
result = split(cat,"-",2) #a 1.6001
if len(result) < 2: #a 1.6021 this if & else
print "warning: 1.6002 unable to interpret weapon category"
@@ -1660,7 +1644,7 @@
tres=result[1]
#print "print FootNotes,tres",footNotes,tres
if tres == 'Melee': #a 1.6001 #m 1.6022 use of tres here and...
- #if self.weapons[name].getAttribute('range') == '0':#d 1.6001
+ #if self.weapons[name].get('range') == '0':#d 1.6001
rangeOrMelee = 'm' #a 1.5008 code demote for next comment block
elif tres == 'Ranged': #m 1.6001 (was just else) #m 1.6022 here
rangeOrMelee = 'r' #a 1.5008
@@ -1671,7 +1655,7 @@
rangeOrMelee ='m'
mod = mod + self.get_mod(rangeOrMelee) #a 1.5008
chat = self.chat
- dmg = self.weapons[name].getAttribute('damage')
+ dmg = self.weapons[name].get('damage')
#a 1.6003 start code fix instance a
result = split(dmg,"/",2)
@@ -1858,28 +1842,28 @@
html_str += ""+str(ranged[1])+" | "
html_str += ""+str(ranged[2])+" | "
- n_list = self.master_dom.getElementsByTagName('weapon')
+ n_list = self.xml.findall('weapon')
for n in n_list:
- mod = n.getAttribute('mod')
+ mod = n.get('mod')
if mod >= 0:
mod1 = "+"
else:
mod1 = ""
- ran = n.getAttribute('range')
+ ran = n.get('range')
total = str(int(mod) + self.get_mod(ran))
html_str += """
Weapon |
Attack | Damage | Critical | """
html_str += ""
- html_str += n.getAttribute('name')+" | "+total+" | "
- html_str += ""+n.getAttribute('damage')+" | "
- html_str += n.getAttribute('critical')+" | "
+ html_str += n.get('name')+""+total+" | "
+ html_str += ""+n.get('damage')+" | "
+ html_str += n.get('critical')+" | "
html_str += """Range | Weight |
Type | Size | Misc Mod | """
html_str += ""+ran+" | "
- html_str += n.getAttribute('weight')+" | "
- html_str += ""+n.getAttribute('type')+" | "
- html_str += n.getAttribute('size')+" | "
+ html_str += n.get('weight')+""
+ html_str += ""+n.get('type')+" | "
+ html_str += n.get('size')+" | "
html_str += '%s%s | ' % (mod1, mod)
#a 1.5012 add next two lines to pretty print footnotes.
html_str += """Footnotes: | """
@@ -1890,7 +1874,7 @@
class attack_grid(wx.grid.Grid):
"""grid for attacks"""
def __init__(self, parent, handler):
- pname = handler.master_dom.setAttribute("name", 'Melee')
+ pname = handler.xml.set("name", 'Melee')
self.hparent = handler #a 1.5002 allow ability to run up tree.
#a 1.5002 we need the functional parent, not the invoking parent.
@@ -1932,19 +1916,19 @@
try:
int(value)
if col==1:
- self.rows[row].setAttribute('base',value)
+ self.rows[row].set('base',value)
elif col==2:
- self.rows[row].setAttribute('second',value)
+ self.rows[row].set('second',value)
elif col==3:
- self.rows[row].setAttribute('third',value)
+ self.rows[row].set('third',value)
elif col==4:
- self.rows[row].setAttribute('forth',value)
+ self.rows[row].set('forth',value)
elif col==5:
- self.rows[row].setAttribute('fifth',value)
+ self.rows[row].set('fifth',value)
elif col==6:
- self.rows[row].setAttribute('sixth',value)
+ self.rows[row].set('sixth',value)
elif col==8:
- self.rows[row].setAttribute('misc',value)
+ self.rows[row].set('misc',value)
self.parent.refresh_data()
except:
self.SetCellValue(row,col,"0")
@@ -1983,7 +1967,7 @@
self.hparent = handler #a 1.5012
self.root = getRoot(self)
- pname = handler.master_dom.setAttribute("name", 'Weapons')
+ pname = handler.xml.set("name", 'Weapons')
wx.Panel.__init__(self, parent, -1)
self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
@@ -2008,9 +1992,9 @@
self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
self.grid.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK, self.on_gridRclick)#a 1.5012
- n_list = handler.master_dom.getElementsByTagName('weapon')
+ n_list = handler.xml.findall('weapon')
self.n_list = n_list
- self.master_dom = handler.master_dom
+ self.xml = handler.xml
self.handler = handler
#trash=input("weapon panel init colnames")
self.colAttr = ['name','damage','mod','critical','type','weight',
@@ -2038,7 +2022,7 @@
#print "wp, on rclick,grid row,col,value",row,col,value
if col == 9 and value != 'None':
n = self.n_list[row]
- name = n.getAttribute('name')
+ name = n.get('name')
#print "we want a panel!"
handler = self.hparent
#print "handler:",handler
@@ -2050,18 +2034,13 @@
fnFrame = wx.Frame(masterFrame, -1, title)
fnFrame.panel = wx.html.HtmlWindow(fnFrame,-1)
if not self.temp_dom:
- tmp = open(dir_struct["dnd35"]+
- "dnd35weapons.xml","r")
- #tmp = open("c:\clh\codeSamples\sample1.xml","r")
- xml_dom = parseXml_with_dlg(self,tmp.read())
- xml_dom = xml_dom._get_firstChild()
- tmp.close()
- self.temp_dom = xml_dom
- f_list = self.temp_dom.getElementsByTagName('f') # the footnotes
+ tree = parse(dir_struct["dnd35"]+ "dnd35weapons.xml")
+ self.temp_dom = tree.getroot()
+ f_list = self.temp_dom.findall('f') # the footnotes
#print "weapon_panel - on_rclick f_list",f_list#a 1.6
n = self.n_list[row]
- name = n.getAttribute('name')
- footnotes = n.getAttribute('fn')
+ name = n.get('name')
+ footnotes = n.get('fn')
html_str = ""
html_str += """
Note | Description | \n"""
@@ -2073,9 +2052,9 @@
aNote=footnotes[i]
found=False
for f in f_list:
- if f.getAttribute('mark') == aNote:
+ if f.get('mark') == aNote:
found=True
- text=f.getAttribute('txt')
+ text=f.get('txt')
html_str += (""+aNote+" | "+
""+text+" | \n")
if not found:
@@ -2099,29 +2078,29 @@
value = self.grid.GetCellValue(row,col)
if col == 2 and not int(value): # special case for mod, demoted
value = "0" #a 5.012 demoted
- self.n_list[row].setAttribute('mod',value) # a 5.012 demoted
+ self.n_list[row].set('mod',value) # a 5.012 demoted
if not (col == 9 and value == "None" and
- self.n_list[row].getAttribute('fn') == "None"
+ self.n_list[row].get('fn') == "None"
): #a 5.012 special case for footnotes
- self.n_list[row].setAttribute(self.colAttr[col],value)#a 5.012
+ self.n_list[row].set(self.colAttr[col],value)#a 5.012
def refresh_row(self,i):
n = self.n_list[i]
- fn = n.getAttribute('fn')
+ fn = n.get('fn')
#print "fn=",fn
- name = n.getAttribute('name')
- mod = n.getAttribute('mod')
- ran = n.getAttribute('range')
+ name = n.get('name')
+ mod = n.get('mod')
+ ran = n.get('range')
total = str(int(mod) + self.handler.get_mod(ran))
self.grid.SetCellValue(i,0,name)
- self.grid.SetCellValue(i,1,n.getAttribute('damage'))
+ self.grid.SetCellValue(i,1,n.get('damage'))
self.grid.SetCellValue(i,2,mod)
- self.grid.SetCellValue(i,3,n.getAttribute('critical'))
- self.grid.SetCellValue(i,4,n.getAttribute('type'))
- self.grid.SetCellValue(i,5,n.getAttribute('weight'))
+ self.grid.SetCellValue(i,3,n.get('critical'))
+ self.grid.SetCellValue(i,4,n.get('type'))
+ self.grid.SetCellValue(i,5,n.get('weight'))
self.grid.SetCellValue(i,6,ran)
- self.grid.SetCellValue(i,7,n.getAttribute('size') )
+ self.grid.SetCellValue(i,7,n.get('size') )
self.grid.SetCellValue(i,8,total)
self.grid.SetCellValue(i,9,safeGetAttr(n,'fn','None')) #a 1.5012
self.grid.SetCellValue(i,10,safeGetAttr(n,'comment','')) #a 1.5012
@@ -2137,31 +2116,27 @@
for i in range(rows-1,-1,-1): #a 1.6011 or you lose context
if self.grid.IsInSelection(i,0):
self.grid.DeleteRows(i)
- self.master_dom.removeChild(self.n_list[i])
- self.n_list = self.master_dom.getElementsByTagName('weapon')
+ self.xml.remove(self.n_list[i])
+ self.n_list = self.xml.findall('weapon')
self.handler.refresh_weapons()
def on_add(self,evt):
if not self.temp_dom:
- tmp = open(dir_struct["dnd35"]+"dnd35weapons.xml","r")
- #tmp = open("c:\clh\codeSamples\sample1.xml","r") #a (debug) 1.5012
- xml_dom = parseXml_with_dlg(self,tmp.read())
- xml_dom = xml_dom._get_firstChild()
- tmp.close(); print
- self.temp_dom = xml_dom
- f_list = self.temp_dom.getElementsByTagName('weapon')
+ tree = parse(dir_struct["dnd35"]+"dnd35weapons.xml")
+ self.temp_dom = tree.getroot()
+ f_list = self.temp_dom.findall('weapon')
opts = []
#print "weapon_panel - on_add f_list",f_list#a 1.6
for f in f_list:
- opts.append(f.getAttribute('name'))
+ opts.append(f.get('name'))
dlg = wx.SingleChoiceDialog(self,'Choose Weapon','Weapon List',opts)
if dlg.ShowModal() == wx.ID_OK:
i = dlg.GetSelection()
#print f_list[i] # DOM Element: weapon.
- new_node = self.master_dom.appendChild(f_list[i].cloneNode(False))
+ new_node = self.xml.append(f_list[i])
#print self.grid.AppendRows # a bound method of wxGrid
self.grid.AppendRows(1)
- self.n_list = self.master_dom.getElementsByTagName('weapon')
+ self.n_list = self.xml.findall('weapon')
#print "self.n_list",self.n_list # list of DOM weapons
self.refresh_row(self.grid.GetNumberRows()-1)
self.handler.refresh_weapons()
@@ -2187,7 +2162,7 @@
class attack_panel(wx.Panel):
def __init__(self, parent, handler):
- pname = handler.master_dom.setAttribute("name", 'Melee')
+ pname = handler.xml.set("name", 'Melee')
self.parent = parent #a 1.9001
wx.Panel.__init__(self, parent, -1)
@@ -2243,19 +2218,19 @@
return ac_total
def get_max_dex(self):
- armor_list = self.master_dom.getElementsByTagName('armor')
+ armor_list = self.xml.findall('armor')
dex = 10
for a in armor_list:
- temp = int(a.getAttribute("maxdex"))
+ temp = int(a.get("maxdex"))
if temp < dex:
dex = temp
return dex
def get_total(self,attr):
- armor_list = self.master_dom.getElementsByTagName('armor')
+ armor_list = self.xml.findall('armor')
total = 0
for a in armor_list:
- total += int(a.getAttribute(attr))
+ total += int(a.get(attr))
return total
def get_design_panel(self,parent):
@@ -2280,29 +2255,29 @@
html_str += ""+str(self.get_spell_failure())+" | "
html_str += ""+str(self.get_max_dex())+" | "
html_str += ""+str(self.get_total_weight())+" | "
- n_list = self.master_dom._get_childNodes()
+ n_list = self.xml.getchildren()
for n in n_list:
html_str += """
Armor | Type | Bonus | """
html_str += ""
- html_str += ""+n.getAttribute('name')+" | "
- html_str += ""+n.getAttribute('type')+" | "
- html_str += ""+n.getAttribute('bonus')+" | "
+ html_str += ""+n.get('name')+" | "
+ html_str += ""+n.get('type')+" | "
+ html_str += ""+n.get('bonus')+" | "
html_str += """"""
html_str += "Check Penalty | Spell Failure | "
html_str += "Max Dex | Speed | Weight | "
html_str += ""
- html_str += ""+n.getAttribute('checkpenalty')+" | "
- html_str += ""+n.getAttribute('spellfailure')+" | "
- html_str += ""+n.getAttribute('maxdex')+" | "
- html_str += ""+n.getAttribute('speed')+" | "
- html_str += ""+n.getAttribute('weight')+" | "
+ html_str += ""+n.get('checkpenalty')+" | "
+ html_str += ""+n.get('spellfailure')+" | "
+ html_str += ""+n.get('maxdex')+" | "
+ html_str += ""+n.get('speed')+" | "
+ html_str += ""+n.get('weight')+" |
---|
"
return html_str
class ac_panel(wx.Panel):
def __init__(self, parent, handler):
- pname = handler.master_dom.setAttribute("name", 'Armor')
+ pname = handler.xml.set("name", 'Armor')
self.hparent = handler #a 1.5002 allow ability to run up tree.
#a 1.5002 we need the functional parent, not the invoking parent.
@@ -2327,8 +2302,8 @@
self.Bind(wx.EVT_BUTTON, self.on_remove, id=10)
self.Bind(wx.EVT_BUTTON, self.on_add, id=20)
self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
- self.master_dom = handler.master_dom
- n_list = handler.master_dom._get_childNodes()
+ self.xml = handler.xml
+ n_list = handler.xml.getchildren()
self.n_list = n_list
col_names = ['Armor','bonus','maxdex','cp','sf','weight','speed','type']
self.grid.CreateGrid(len(n_list),len(col_names),1)
@@ -2349,40 +2324,37 @@
if col >= 1 and col <= 5:
try:
int(value)
- self.n_list[row].setAttribute(self.atts[col],value)
+ self.n_list[row].set(self.atts[col],value)
except:
self.grid.SetCellValue(row,col,"0")
else:
- self.n_list[row].setAttribute(self.atts[col],value)
+ self.n_list[row].set(self.atts[col],value)
def refresh_row(self,i):
n = self.n_list[i]
for y in range(len(self.atts)):
- self.grid.SetCellValue(i,y,n.getAttribute(self.atts[y]))
+ self.grid.SetCellValue(i,y,n.get(self.atts[y]))
def on_remove(self,evt):
rows = self.grid.GetNumberRows()
for i in range(rows):
if self.grid.IsInSelection(i,0):
self.grid.DeleteRows(i)
- self.master_dom.removeChild(self.n_list[i])
+ self.xml.remove(self.n_list[i])
def on_add(self,evt):
if not self.temp_dom:
- tmp = open(dir_struct["dnd35"]+"dnd35armor.xml","r")
- xml_dom = parseXml_with_dlg(self,tmp.read())
- xml_dom = xml_dom._get_firstChild()
- tmp.close()
- self.temp_dom = xml_dom
- f_list = self.temp_dom.getElementsByTagName('armor')
+ tree = parse(dir_struct["dnd35"]+"dnd35armor.xml")
+ self.temp_dom = tree.getroot()
+ f_list = self.temp_dom.findall('armor')
opts = []
for f in f_list:
- opts.append(f.getAttribute('name'))
+ opts.append(f.get('name'))
dlg = wx.SingleChoiceDialog(self,'Choose Armor:','Armor List',opts)
if dlg.ShowModal() == wx.ID_OK:
i = dlg.GetSelection()
- new_node = self.master_dom.appendChild(f_list[i].cloneNode(False))
+ new_node = self.xml.append(f_list[i])
self.grid.AppendRows(1)
self.refresh_row(self.grid.GetNumberRows()-1)
dlg.Destroy()
diff -r 174658f839c0 -r 8827271fbe1b orpg/gametree/nodehandlers/dnd3e.py
--- a/orpg/gametree/nodehandlers/dnd3e.py Sun Nov 01 01:12:50 2009 -0600
+++ b/orpg/gametree/nodehandlers/dnd3e.py Sun Nov 01 11:36:14 2009 -0600
@@ -151,6 +151,8 @@
from string import * #a 1.6003
from inspect import * #a 1.9001
from orpg.dirpath import dir_struct
+from orpg.tools.orpg_log import debug
+from xml.etree.ElementTree import parse
dnd3e_EXPORT = wx.NewId()
############Global Stuff##############
@@ -209,12 +211,12 @@
# return None
#a 1.6 convinience function added safeGetAttr
-def safeGetAttr(node,lable,defRetV=None):
- cna=node.attributes
- for i2 in range(len(cna)):
- if cna.item(i2).name == lable:
- return cna.item(i2).value
- #retV=node.getAttribute(lable) # getAttribute does not distingish between
+def safeGetAttr(node, label, defRetV=None):
+ cna=node.attrib
+ for key in cna:
+ if key == label:
+ return cna[key]
+ #retV=node.get(lable) # get does not distingish between
# the attribute not being present vs it having a value of ""
# This is bad for this routine, thus not used.
return defRetV
@@ -230,7 +232,7 @@
node_handler.__init__(self,xml_dom,tree_node)
self.Version = "v1.901" #a 1.6000 general documentation, usage.
- print "dnd3echar_handler - version:",self.Version #m 1.6000
+ print "dnd3echar_handler - version:", self.Version #m 1.6000
self.hparent = None #a 1.5002 allow ability to run up tree, this is the
#a 1.5002 top of the handler tree, this is used to flag where to stop
@@ -252,7 +254,7 @@
def new_child_handler(self,tag,text,handler_class,icon='gear'):
- node_list = self.master_dom.getElementsByTagName(tag)
+ node_list = self.xml.findall(tag)
tree = self.tree
i = self.tree.icons[icon]
new_tree_node = tree.AppendItem(self.mytree_node,text,i,i)
@@ -353,7 +355,7 @@
def on_html(self,evt):
html_str = self.tohtml()
wnd = http_html_window(self.frame.note,-1)
- wnd.title = self.master_dom.getAttribute('name')
+ wnd.title = self.xml.get('name')
self.frame.add_panel(wnd)
wnd.SetPage(html_str)
@@ -384,13 +386,12 @@
def __init__(self, parent, handler):
wx.Panel.__init__(self, parent, -1)
- pname = handler.master_dom.setAttribute("name", 'How To')
+ pname = handler.xml.set("name", 'How To')
self.sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, 'How To'), wx.VERTICAL)
- self.master_dom = handler.master_dom
- n_list = self.master_dom._get_childNodes()
+ self.xml = handler.xml
+ n_list = self.xml.getchildren()
for n in n_list:
- t_node = component.get('xml').safe_get_text_node(n)
- self.sizer.Add(wx.StaticText(self, -1, t_node._get_nodeValue()), 1, wx.EXPAND)
+ self.sizer.Add(wx.StaticText(self, -1, n.text), 1, wx.EXPAND)
self.SetSizer(self.sizer)
self.SetAutoLayout(True)
self.Fit()
@@ -412,12 +413,12 @@
return wnd
def tohtml(self):
- n_list = self.master_dom._get_childNodes()
+ n_list = self.xml.getchildren()
html_str = "General Information |
---|
"
- for n in n_list:
- t_node = component.get('xml').safe_get_text_node(n)
- html_str += ""+n._get_tagName().capitalize() +": "
- html_str += t_node._get_nodeValue() + ", "
+ for n in n_list:
+ debug(n)
+ html_str += ""+n.tag.capitalize() +": "
+ html_str += n.text + ", "
html_str = html_str[:len(html_str)-2] + " | "
return html_str
@@ -428,14 +429,13 @@
def get_char_name( self ):
- node = self.master_dom.getElementsByTagName( 'name' )[0]
- t_node = component.get('xml').safe_get_text_node( node )
- return t_node._get_nodeValue()
+ node = self.xml.findall( 'name' )[0]
+ return node.text
class gen_grid(wx.grid.Grid):
"""grid for gen info"""
def __init__(self, parent, handler):
- pname = handler.master_dom.setAttribute("name", 'General')
+ pname = handler.xml.set("name", 'General')
self.hparent = handler #a 1.5002 allow ability to run up tree, needed
# a 1.5002 parent is functional parent, not invoking parent.
@@ -444,7 +444,7 @@
#self.Bind(wx.EVT_SIZE, self.on_size)
self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
self.handler = handler
- n_list = handler.master_dom._get_childNodes()
+ n_list = handler.xml.getchildren()
self.CreateGrid(len(n_list),2)
self.SetRowLabelSize(0)
self.SetColLabelSize(0)
@@ -457,18 +457,15 @@
row = evt.GetRow()
col = evt.GetCol()
value = self.GetCellValue(row,col)
- t_node = self.n_list[row]._get_firstChild()
- t_node._set_nodeValue(value)
+ self.n_list[row].text = value
if row==0:
self.handler.on_name_change(value)
#self.AutoSizeColumn(1)
- def refresh_row(self,rowi):
- t_node = component.get('xml').safe_get_text_node(self.n_list[rowi])
-
- self.SetCellValue(rowi,0,self.n_list[rowi]._get_tagName())
+ def refresh_row(self,rowi):
+ self.SetCellValue(rowi,0,self.n_list[rowi].tag)
self.SetReadOnly(rowi,0)
- self.SetCellValue(rowi,1,t_node._get_nodeValue())
+ self.SetCellValue(rowi,1,self.n_list[rowi].text)
self.AutoSizeColumn(1)
class dnd3einventory(dnd3e_char_child):
@@ -487,69 +484,53 @@
return wnd
def tohtml(self):
- n_list = self.master_dom._get_childNodes()
+ n_list = self.xml.getchildren()
html_str = "General Information |
---|
"
- for n in n_list:
- t_node = component.get('xml').safe_get_text_node(n)
- html_str += ""+n._get_tagName().capitalize() +": "
- html_str += t_node._get_nodeValue() + " "
+ for n in n_list:
+ debug((n))
+ html_str += ""+n.tag.capitalize() +": "
+ html_str += n.text + " "
html_str = html_str[:len(html_str)-2] + " | "
return html_str
class inventory_pane(wx.Panel):
def __init__(self, parent, handler):
wx.Panel.__init__(self, parent, wx.ID_ANY)
-
- self.n_list = handler.master_dom._get_childNodes()
+ self.n_list = handler.xml.getchildren()
self.autosize = False
-
self.sizer = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY, "Inventroy"), wx.VERTICAL)
-
self.lang = wx.TextCtrl(self, wx.ID_ANY, "", style=wx.TE_MULTILINE | wx.TE_BESTWRAP, name="Languages")
self.gear = wx.TextCtrl(self, wx.ID_ANY, "", style=wx.TE_MULTILINE | wx.TE_BESTWRAP, name="Gear")
self.magic = wx.TextCtrl(self, wx.ID_ANY, "", style=wx.TE_MULTILINE | wx.TE_BESTWRAP, name="Magic")
self.grid = wx.grid.Grid(self, wx.ID_ANY, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
-
self.grid.CreateGrid(len(self.n_list)-3,2)
self.grid.SetRowLabelSize(0)
self.grid.SetColLabelSize(0)
-
for i in xrange(len(self.n_list)):
self.refresh_row(i)
-
sizer1 = wx.BoxSizer(wx.HORIZONTAL)
sizer1.Add(self.grid, 1, wx.EXPAND)
sizer1.Add(self.lang, 1, wx.EXPAND)
-
self.sizer.Add(sizer1, 0, wx.EXPAND)
-
sizer2 = wx.BoxSizer(wx.HORIZONTAL)
sizer2.Add(self.gear, 1, wx.EXPAND)
sizer2.Add(self.magic, 1, wx.EXPAND)
-
self.sizer.Add(sizer2, 1, wx.EXPAND)
-
self.SetSizer(self.sizer)
self.SetAutoLayout(True)
self.Fit()
-
self.Bind(wx.EVT_TEXT, self.onTextNodeChange, self.lang)
self.Bind(wx.EVT_TEXT, self.onTextNodeChange, self.gear)
self.Bind(wx.EVT_TEXT, self.onTextNodeChange, self.magic)
self.Bind(wx.grid.EVT_GRID_EDITOR_HIDDEN, self.on_cell_change, self.grid)
-
def fillTextNode(self, name, value):
- if name == 'Languages':
- self.lang.SetValue(value)
- elif name == 'Gear':
- self.gear.SetValue(value)
- elif name == 'Magic':
- self.magic.SetValue(value)
+ if name == 'Languages': self.lang.SetValue(value)
+ elif name == 'Gear': self.gear.SetValue(value)
+ elif name == 'Magic': self.magic.SetValue(value)
def onTextNodeChange(self, event):
id = event.GetId()
-
if id == self.gear.GetId():
nodeName = 'Gear'
value = self.gear.GetValue()
@@ -559,16 +540,15 @@
elif id == self.lang.GetId():
nodeName = 'Languages'
value = self.lang.GetValue()
-
for node in self.n_list:
- if node._get_tagName() == nodeName:
- t_node = component.get('xml').safe_get_text_node(node)
- t_node._set_nodeValue(value)
+ if node.tag == nodeName:
+ debug(node)
+ node.text = value
def saveMoney(self, row, col):
- value = self.grid.GetCellValue(row, col)
- t_node = component.get('xml').safe_get_text_node(self.n_list[row])
- t_node._set_nodeValue(value)
+ value = self.grid.GetCellValue(row, col)
+ debug(self.n_list[row])
+ self.n_list[row].text = value
def on_cell_change(self, evt):
row = evt.GetRow()
@@ -576,18 +556,12 @@
self.grid.AutoSizeColumn(col)
wx.CallAfter(self.saveMoney, row, col)
-
-
- def refresh_row(self, row):
- t_node = component.get('xml').safe_get_text_node(self.n_list[row])
- tagname = self.n_list[row]._get_tagName()
- value = t_node._get_nodeValue()
- if tagname == 'Gear':
- self.fillTextNode(tagname, value)
- elif tagname == 'Magic':
- self.fillTextNode(tagname, value)
- elif tagname == 'Languages':
- self.fillTextNode(tagname, value)
+ def refresh_row(self, row):
+ tagname = self.n_list[row].tag
+ value = self.n_list[row].text
+ if tagname == 'Gear': self.fillTextNode(tagname, value)
+ elif tagname == 'Magic': self.fillTextNode(tagname, value)
+ elif tagname == 'Languages': self.fillTextNode(tagname, value)
else:
self.grid.SetCellValue(row, 0, tagname)
self.grid.SetReadOnly(row, 0)
@@ -612,7 +586,7 @@
def new_child_handler(self,tag,text,handler_class,icon='gear'):
- node_list = self.master_dom.getElementsByTagName(tag)
+ node_list = self.xml.findall(tag)
tree = self.tree
i = self.tree.icons[icon]
new_tree_node = tree.AppendItem(self.mytree_node,text,i,i)
@@ -650,7 +624,7 @@
def on_html(self,evt):
html_str = self.tohtml()
wnd = http_html_window(self.frame.note,-1)
- wnd.title = self.master_dom.getAttribute('name')
+ wnd.title = self.xml.get('name')
self.frame.add_panel(wnd)
wnd.SetPage(html_str)
@@ -672,14 +646,12 @@
self.hparent = parent #a 1.5002 allow ability to run up tree.
self.root = getRoot(self) #a 1.5002 get top of our local function tree.
self.root.abilities = self #a 1.5002 let other classes find me.
-
self.abilities = {}
- node_list = self.master_dom.getElementsByTagName('stat')
+ node_list = self.xml.findall('stat')
tree = self.tree
icons = tree.icons
-
for n in node_list:
- name = n.getAttribute('abbr')
+ name = n.get('abbr')
self.abilities[name] = n
new_tree_node = tree.AppendItem( self.mytree_node, name, icons['gear'], icons['gear'] )
tree.SetPyData( new_tree_node, self )
@@ -702,14 +674,14 @@
chat.ParsePost( txt, True, True )
def get_mod(self,abbr):
- score = int(self.abilities[abbr].getAttribute('base'))
+ score = int(self.abilities[abbr].get('base'))
mod = (score - 10) / 2
mod = int(mod)
return mod
def set_score(self,abbr,score):
if score >= 0:
- self.abilities[abbr].setAttribute("base",str(score))
+ self.abilities[abbr].set("base",str(score))
def get_design_panel(self,parent):
wnd = outline_panel(parent,self,abil_grid,"Abilities")
@@ -719,11 +691,11 @@
def tohtml(self):
html_str = """Ability |
Base | Modifier | """
- node_list = self.master_dom.getElementsByTagName('stat')
+ node_list = self.xml.findall('stat')
for n in node_list:
- name = n.getAttribute('name')
- abbr = n.getAttribute('abbr')
- base = n.getAttribute('base')
+ name = n.get('name')
+ abbr = n.get('abbr')
+ base = n.get('base')
mod = str(self.get_mod(abbr))
if int(mod) >= 0: #m 1.6013 added "int(" and ")"
mod1 = "+"
@@ -737,7 +709,7 @@
class abil_grid(wx.grid.Grid):
"""grid for abilities"""
def __init__(self, parent, handler):
- pname = handler.master_dom.setAttribute("name", 'Stats')
+ pname = handler.xml.set("name", 'Stats')
self.hparent = handler #a 1.5002 allow ability to run up tree.
self.root = getRoot(self)
#a 1.5002 in this case, we need the functional parent, not the invoking parent.
@@ -746,7 +718,7 @@
self.Bind(wx.EVT_SIZE, self.on_size)
self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
self.handler = handler
- stats = handler.master_dom.getElementsByTagName('stat')
+ stats = handler.xml.findall('stat')
self.CreateGrid(len(stats),3)
self.SetRowLabelSize(0)
col_names = ['Ability','Score','Modifier']
@@ -765,23 +737,21 @@
#print value
try:
int(value)
- self.stats[row].setAttribute('base',value)
+ self.stats[row].set('base',value)
self.refresh_row(row)
except:
self.SetCellValue(row,col,"0")
if self.char_wnd:
self.char_wnd.refresh_data()
- #mark5
-
def refresh_row(self,rowi):
s = self.stats[rowi]
- name = s.getAttribute('name')
- abbr = s.getAttribute('abbr')
+ name = s.get('name')
+ abbr = s.get('abbr')
self.SetCellValue(rowi,0,name)
self.SetReadOnly(rowi,0)
- self.SetCellValue(rowi,1,s.getAttribute('base'))
+ self.SetCellValue(rowi,1,s.get('base'))
self.SetCellValue(rowi,2,str(self.handler.get_mod(abbr)))
self.SetReadOnly(rowi,2)
#if self.root.saves.saveGrid: #a 1.6018 d 1.9002 whole if clause
@@ -823,20 +793,20 @@
def tohtml(self):
html_str = "Classes |
---|
"
- n_list = self.master_dom._get_childNodes()
+ n_list = self.xml.getchildren()
for n in n_list:
- html_str += n.getAttribute('name') + " ("+n.getAttribute('level')+"), "
+ html_str += n.get('name') + " ("+n.get('level')+"), "
html_str = html_str[:len(html_str)-2] + " | "
return html_str
def get_char_lvl( self, attr ):
- node_list = self.master_dom.getElementsByTagName('class')
+ node_list = self.xml.findall('class')
# print "eclasses - get_char_lvl node_list",node_list
tot = 0 #a 1.5009 actually, slipping in a quick enhancement ;-)
for n in node_list:
- lvl = n.getAttribute('level') #o 1.5009 not sure of the value of this
+ lvl = n.get('level') #o 1.5009 not sure of the value of this
tot += int(lvl) #a 1.5009
- type = n.getAttribute('name') #o 1.5009 not sure of the value of this
+ type = n.get('name') #o 1.5009 not sure of the value of this
#print type,lvl #a (debug) 1.5009
if attr == "level":
return lvl #o 1.5009 this returns the level of someone's first class. ???
@@ -847,17 +817,17 @@
def get_class_lvl( self, classN ): #a 1.5009 need to be able to get monk lvl
#a 1.5009 this function is new.
- node_list = self.master_dom.getElementsByTagName('class')
+ node_list = self.xml.findall('class')
#print "eclasses - get_class_lvl node_list",node_list
for n in node_list:
- lvl = n.getAttribute('level')
- type = n.getAttribute('name')
+ lvl = n.get('level')
+ type = n.get('name')
if classN == type:
return lvl
class class_panel(wx.Panel):
def __init__(self, parent, handler):
- pname = handler.master_dom.setAttribute("name", 'Class')
+ pname = handler.xml.set("name", 'Class')
wx.Panel.__init__(self, parent, -1)
self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
@@ -880,9 +850,9 @@
self.Bind(wx.EVT_BUTTON, self.on_add, id=20)
self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
- n_list = handler.master_dom._get_childNodes()
+ n_list = handler.xml.getchildren()
self.n_list = n_list
- self.master_dom = handler.master_dom
+ self.xml = handler.xml
self.grid.CreateGrid(len(n_list),2,1)
self.grid.SetRowLabelSize(0)
self.grid.SetColLabelValue(0,"Class")
@@ -897,16 +867,13 @@
value = self.grid.GetCellValue(row,col)
try:
int(value)
- self.n_list[row].setAttribute('level',value)
- except:
- self.grid.SetCellValue(row,col,"1")
-
+ self.n_list[row].set('level',value)
+ except: self.grid.SetCellValue(row,col,"1")
def refresh_row(self,i):
n = self.n_list[i]
-
- name = n.getAttribute('name')
- level = n.getAttribute('level')
+ name = n.get('name')
+ level = n.get('level')
self.grid.SetCellValue(i,0,name)
self.grid.SetReadOnly(i,0)
self.grid.SetCellValue(i,1,level)
@@ -917,28 +884,25 @@
for i in range(rows):
if self.grid.IsInSelection(i,0):
self.grid.DeleteRows(i)
- self.master_dom.removeChild(self.n_list[i])
+ self.xml.remove(self.n_list[i])
def on_add(self,evt):
if not self.temp_dom:
- tmp = open(dir_struct["dnd3e"]+"dnd3eclasses.xml","r")
- xml_dom = parseXml_with_dlg(self,tmp.read())
- xml_dom = xml_dom._get_firstChild()
- tmp.close()
+ tree = parse(dir_struct["dnd3e"]+"dnd3eclasses.xml")
+ xml_dom = tree.getroot()
self.temp_dom = xml_dom
- f_list = self.temp_dom.getElementsByTagName('class')
+ f_list = self.temp_dom.findall('class')
opts = []
for f in f_list:
- opts.append(f.getAttribute('name'))
+ opts.append(f.get('name'))
dlg = wx.SingleChoiceDialog(self,'Choose Class','Classes',opts)
if dlg.ShowModal() == wx.ID_OK:
i = dlg.GetSelection()
- new_node = self.master_dom.appendChild(f_list[i].cloneNode(False))
+ new_node = self.xml.append(f_list[i])
self.grid.AppendRows(1)
self.refresh_row(self.grid.GetNumberRows()-1)
dlg.Destroy()
-
def on_size(self,event):
s = self.GetClientSizeTuple()
self.grid.SetDimensions(0,0,s[0],s[1]-25)
@@ -965,10 +929,10 @@
self.root = getRoot(self) #a 1.5002
self.root.saves = self #a 1.6009
- node_list = self.master_dom.getElementsByTagName('save')
+ node_list = self.xml.findall('save')
self.saves={}
for n in node_list:
- name = n.getAttribute('name')
+ name = n.get('name')
self.saves[name] = n
new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear'])
tree.SetPyData(new_tree_node,self)
@@ -986,18 +950,17 @@
def get_mod(self,name):
save = self.saves[name]
- stat = save.getAttribute('stat')
+ stat = save.get('stat')
#print "dnd3esaves, get_mod: self,root",self,self.root #a (debug) 1.5002
#print "and abilities",self.root.abilities #a (debug) 1.5002
stat_mod = self.root.abilities.get_mod(stat) #a 1.5002
- base = int(save.getAttribute('base'))
- miscmod = int(save.getAttribute('miscmod'))
- magmod = int(save.getAttribute('magmod'))
+ base = int(save.get('base'))
+ miscmod = int(save.get('miscmod'))
+ magmod = int(save.get('magmod'))
total = stat_mod + base + miscmod + magmod
return total
def on_rclick(self,evt):
-
item = self.tree.GetSelection()
name = self.tree.GetItemText(item)
if item == self.mytree_node:
@@ -1010,10 +973,8 @@
#self.frame.add_panel(wnd)
else:
mod = self.get_mod(name)
- if mod >= 0:
- mod1 = "+"
- else:
- mod1 = ""
+ if mod >= 0: mod1 = "+"
+ else: mod1 = ""
chat = self.chat
txt = '%s save: [1d20%s%s]' % (name, mod1, mod)
chat.ParsePost( txt, True, True )
@@ -1028,17 +989,17 @@
Save |
Key | Base | Abil | Magic |
Misc | Total | """
- node_list = self.master_dom.getElementsByTagName('save')
+ node_list = self.xml.findall('save')
for n in node_list:
- name = n.getAttribute('name')
- stat = n.getAttribute('stat')
- base = n.getAttribute('base')
+ name = n.get('name')
+ stat = n.get('stat')
+ base = n.get('base')
html_str = html_str + ""+name+" | "+stat+" | "+base+" | "
#stat_mod = str(dnd_globals["stats"][stat]) #d 1.5002
stat_mod = self.root.abilities.get_mod(stat) #a 1.5002
- mag = n.getAttribute('magmod')
- misc = n.getAttribute('miscmod')
+ mag = n.get('magmod')
+ misc = n.get('miscmod')
mod = str(self.get_mod(name))
if mod >= 0:
mod1 = "+"
@@ -1054,19 +1015,16 @@
class save_grid(wx.grid.Grid):
"""grid for saves"""
def __init__(self, parent, handler):
- pname = handler.master_dom.setAttribute("name", 'Saves')
+ pname = handler.xml.set("name", 'Saves')
self.hparent = handler #a 1.5002 allow ability to run up tree.
#a 1.5002 in this case, we need the functional parent, not the invoking parent.
self.root = getRoot(self)
-
#self.hparent.saveGrid = self #a 1.6018 d 1.9001
-
-
wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
self.Bind(wx.EVT_SIZE, self.on_size)
self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
self.handler = handler
- saves = handler.master_dom.getElementsByTagName('save')
+ saves = handler.xml.findall('save')
self.CreateGrid(len(saves),7)
self.SetRowLabelSize(0)
col_names = ['Save','Key','base','Abil','Magic','Misc','Total']
@@ -1074,10 +1032,7 @@
self.SetColLabelValue(i,col_names[i])
self.saves = saves
i = 0
- for i in range(len(saves)):
- self.refresh_row(i)
-
-
+ for i in range(len(saves)): self.refresh_row(i)
#a 1.9002 remainder of code in this method.
climber = parent
nameNode = climber.GetClassName()
@@ -1087,7 +1042,6 @@
masterFrame=climber
masterFrame.refresh_data=self.refresh_data
#print getmembers(masterFrame)
-
handler.saveGridFrame.append(masterFrame)
def on_cell_change(self,evt):
@@ -1097,29 +1051,28 @@
try:
int(value)
if col == 2:
- self.saves[row].setAttribute('base',value)
+ self.saves[row].set('base',value)
elif col ==4:
- self.saves[row].setAttribute('magmod',value)
+ self.saves[row].set('magmod',value)
elif col ==5: # 1.5001
- self.saves[row].setAttribute('miscmod',value)
+ self.saves[row].set('miscmod',value)
self.refresh_row(row)
except:
self.SetCellValue(row,col,"0")
def refresh_row(self,rowi):
s = self.saves[rowi]
-
- name = s.getAttribute('name')
+ name = s.get('name')
self.SetCellValue(rowi,0,name)
self.SetReadOnly(rowi,0)
- stat = s.getAttribute('stat')
+ stat = s.get('stat')
self.SetCellValue(rowi,1,stat)
self.SetReadOnly(rowi,1)
- self.SetCellValue(rowi,2,s.getAttribute('base'))
+ self.SetCellValue(rowi,2,s.get('base'))
self.SetCellValue(rowi,3,str(self.root.abilities.get_mod(stat)))
self.SetReadOnly(rowi,3)
- self.SetCellValue(rowi,4,s.getAttribute('magmod'))
- self.SetCellValue(rowi,5,s.getAttribute('miscmod'))
+ self.SetCellValue(rowi,4,s.get('magmod'))
+ self.SetCellValue(rowi,5,s.get('miscmod'))
mod = str(self.handler.get_mod(name))
self.SetCellValue(rowi,6,mod)
self.SetReadOnly(rowi,6)
@@ -1159,9 +1112,8 @@
#wxMenuItem(self.tree.std_menu, dnd3e_EXPORT, "Export...", "Export")
self.myeditor = None
-
def new_child_handler(self,tag,text,handler_class,icon='gear'):
- node_list = self.master_dom.getElementsByTagName(tag)
+ node_list = self.xml.findall(tag)
tree = self.tree
i = self.tree.icons[icon]
new_tree_node = tree.AppendItem(self.mytree_node,text,i,i)
@@ -1172,7 +1124,6 @@
def get_design_panel(self,parent):
return tabbed_panel(parent,self,1)
-
def get_use_panel(self,parent):
return tabbed_panel(parent,self,2)
@@ -1187,8 +1138,6 @@
self.frame = component.get('frame')
self.myeditor = None
-
-
def on_drop(self,evt):
pass
@@ -1201,7 +1150,7 @@
def on_html(self,evt):
html_str = self.tohtml()
wnd = http_html_window(self.frame.note,-1)
- wnd.title = self.master_dom.getAttribute('name')
+ wnd.title = self.xml.get('name')
self.frame.add_panel(wnd)
wnd.SetPage(html_str)
@@ -1227,58 +1176,53 @@
skills_char_child.__init__(self,xml_dom,tree_node,parent)
tree = self.tree
icons = self.tree.icons
- node_list = self.master_dom.getElementsByTagName('skill')
+ node_list = self.xml.findall('skill')
self.skills={}
#Adding code to not display skills you can not use -mgt
for n in node_list:
- name = n.getAttribute('name')
+ name = n.get('name')
self.skills[name] = n
skill_check = self.skills[name]
- ranks = int(skill_check.getAttribute('rank'))
- trained = int(skill_check.getAttribute('untrained'))
+ ranks = int(skill_check.get('rank'))
+ trained = int(skill_check.get('untrained'))
if ranks > 0 or trained == 1:
new_tree_node = tree.AppendItem(self.mytree_node,name,
icons['gear'],icons['gear'])
- else:
- continue
-
+ else: continue
tree.SetPyData(new_tree_node,self)
-
def refresh_skills(self):
- #Adding this so when you update the grid the tree will reflect
- #The change. -mgt
+ #Adding this so when you update the grid the tree will reflect
+ #The change. -mgt
tree = self.tree
icons = self.tree.icons
tree.CollapseAndReset(self.mytree_node)
- node_list = self.master_dom.getElementsByTagName('skill')
+ node_list = self.xml.findall('skill')
self.skills={}
for n in node_list:
- name = n.getAttribute('name')
+ name = n.get('name')
self.skills[name] = n
skill_check = self.skills[name]
- ranks = int(skill_check.getAttribute('rank'))
- trained = int(skill_check.getAttribute('untrained'))
+ ranks = int(skill_check.get('rank'))
+ trained = int(skill_check.get('untrained'))
if ranks > 0 or trained == 1:
new_tree_node = tree.AppendItem(self.mytree_node,name,
icons['gear'],icons['gear'])
- else:
- continue
-
+ else: continue
tree.SetPyData(new_tree_node,self)
def get_mod(self,name):
skill = self.skills[name]
- stat = skill.getAttribute('stat')
+ stat = skill.get('stat')
#stat_mod = int(dnd_globals["stats"][stat]) #d 1.5002
stat_mod = self.root.abilities.get_mod(stat) #a 1.5002
- rank = int(skill.getAttribute('rank'))
- misc = int(skill.getAttribute('misc'))
+ rank = int(skill.get('rank'))
+ misc = int(skill.get('misc'))
total = stat_mod + rank + misc
return total
@@ -1294,11 +1238,9 @@
#dnd3e_char_child.on_ldclick(self,evt) #d 1.6014
# it's what it used to try to do.
ac = self.root.ac.get_check_pen() #a 1.5002 for 1.5004 verify fix.
-
skill = self.skills[name]
-
- untr = skill.getAttribute('untrained') #a 1.6004
- rank = skill.getAttribute('rank') #a 1.6004
+ untr = skill.get('untrained') #a 1.6004
+ rank = skill.get('rank') #a 1.6004
if eval('%s == 0' % (untr)): #a 1.6004
if eval('%s == 0' % (rank)): #a 1.6004
res = 'You fumble around, accomplishing nothing' #a 1.6004
@@ -1310,7 +1252,7 @@
armor = ''
acCp = ''
if ac < 0: #acCp >= 1 #m 1.5004 this is stored as negatives.
- armorCheck = int(skill.getAttribute('armorcheck'))
+ armorCheck = int(skill.get('armorcheck'))
#print "ac,armorCheck",ac,armorCheck
if armorCheck == 1:
acCp=ac
@@ -1322,10 +1264,8 @@
#self.frame.add_panel(wnd)
else:
mod = self.get_mod(name)
- if mod >= 0:
- mod1 = "+"
- else:
- mod1 = ""
+ if mod >= 0: mod1 = "+"
+ else: mod1 = ""
chat = self.chat
txt = '%s Skill Check: [1d20%s%s%s] %s' % (
name, mod1, mod, acCp, armor)
@@ -1340,13 +1280,13 @@
html_str = """
Skill | Key |
Rank | Abil | Misc | Total | """
- node_list = self.master_dom.getElementsByTagName('skill')
+ node_list = self.xml.findall('skill')
for n in node_list:
- name = n.getAttribute('name')
- stat = n.getAttribute('stat')
- rank = n.getAttribute('rank')
- untr = n.getAttribute('untrained') #a 1.6004
+ name = n.get('name')
+ stat = n.get('stat')
+ rank = n.get('rank')
+ untr = n.get('untrained') #a 1.6004
#Filter unsuable skills out of pretty print -mgt
if eval('%s > 0' % (rank)) or eval('%s == 1' % (untr)):
if eval('%s >=1' % (rank)):
@@ -1363,7 +1303,7 @@
continue
stat_mod = self.root.abilities.get_mod(stat) #a 1.5002
#stat_mod = str(dnd_globals["stats"][stat]) #d 1.5002
- misc = n.getAttribute('misc')
+ misc = n.get('misc')
mod = str(self.get_mod(name))
if mod >= 0:
mod1 = "+"
@@ -1380,13 +1320,13 @@
def __init__(self, parent, handler):
self.hparent = handler #a 1.5002 need function parent, not invoker
self.root = getRoot(self) #a 1.5002
- pname = handler.master_dom.setAttribute("name", 'Skills')
+ pname = handler.xml.set("name", 'Skills')
wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
self.Bind(wx.EVT_SIZE, self.on_size)
self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
self.handler = handler
- skills = handler.master_dom.getElementsByTagName('skill')
+ skills = handler.xml.findall('skill')
#xelf.stats = dnd_globals["stats"] #d 1.5002
self.CreateGrid(len(skills),6)
@@ -1407,9 +1347,9 @@
try:
int(value)
if col == 2:
- self.skills[row].setAttribute('rank',value)
+ self.skills[row].set('rank',value)
elif col ==4:
- self.skills[row].setAttribute('misc',value)
+ self.skills[row].set('misc',value)
self.refresh_row(row)
except:
self.SetCellValue(row,col,"0")
@@ -1419,13 +1359,13 @@
def refresh_row(self,rowi):
s = self.skills[rowi]
- name = s.getAttribute('name')
+ name = s.get('name')
self.SetCellValue(rowi,0,name)
self.SetReadOnly(rowi,0)
- stat = s.getAttribute('stat')
+ stat = s.get('stat')
self.SetCellValue(rowi,1,stat)
self.SetReadOnly(rowi,1)
- self.SetCellValue(rowi,2,s.getAttribute('rank'))
+ self.SetCellValue(rowi,2,s.get('rank'))
#self.SetCellValue(rowi,3,str(dnd_globals["stats"][stat])) #d 1.5002
if self.root.abilities: #a 1.5002 sanity check.
stat_mod=self.root.abilities.get_mod(stat) #a 1.5002
@@ -1436,7 +1376,7 @@
self.SetCellValue(rowi,3,str(stat_mod)) #a 1.5002
self.SetReadOnly(rowi,3)
- self.SetCellValue(rowi,4,s.getAttribute('misc'))
+ self.SetCellValue(rowi,4,s.get('misc'))
mod = str(self.handler.get_mod(name))
self.SetCellValue(rowi,5,mod)
self.SetReadOnly(rowi,5)
@@ -1480,9 +1420,9 @@
def tohtml(self):
html_str = "Feats |
---|
"
- n_list = self.master_dom._get_childNodes()
+ n_list = self.xml.getchildren()
for n in n_list:
- html_str += n.getAttribute('name')+ ", "
+ html_str += n.get('name')+ ", "
html_str = html_str[:len(html_str)-2] + " | "
return html_str
@@ -1493,8 +1433,8 @@
#a 1.5002 in this case, we need the functional parent, not the invoking parent.
self.root = getRoot(self) #a 1.5002
#tempTitle= 'Feats - ' + self.root.general.charName #a 1.5010
- #pname = handler.master_dom.setAttribute("name", tempTitle) #a 1.5010
- pname = handler.master_dom.setAttribute("name", 'Feats') #d 1.5010
+ #pname = handler.xml.set("name", tempTitle) #a 1.5010
+ pname = handler.xml.set("name", 'Feats') #d 1.5010
wx.Panel.__init__(self, parent, -1)
self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
@@ -1517,9 +1457,9 @@
self.Bind(wx.EVT_BUTTON, self.on_remove, id=10)
self.Bind(wx.EVT_BUTTON, self.on_add, id=20)
- n_list = handler.master_dom._get_childNodes()
+ n_list = handler.xml.getchildren()
self.n_list = n_list
- self.master_dom = handler.master_dom
+ self.xml = handler.xml
self.grid.CreateGrid(len(n_list),3,1)
self.grid.SetRowLabelSize(0)
self.grid.SetColLabelValue(0,"Feat")
@@ -1532,9 +1472,9 @@
def refresh_row(self,i):
feat = self.n_list[i]
- name = feat.getAttribute('name')
- type = feat.getAttribute('type')
- desc = feat.getAttribute('desc') #m 1.6 correct typo
+ name = feat.get('name')
+ type = feat.get('type')
+ desc = feat.get('desc') #m 1.6 correct typo
self.grid.SetCellValue(i,0,name)
self.grid.SetReadOnly(i,0)
self.grid.SetCellValue(i,1,type)
@@ -1547,25 +1487,22 @@
for i in range(rows):
if self.grid.IsInSelection(i,0):
self.grid.DeleteRows(i)
- self.master_dom.removeChild(self.n_list[i])
+ self.xml.remove(self.n_list[i])
def on_add(self,evt):
if not self.temp_dom:
- tmp = open(dir_struct["dnd3e"]+"dnd3efeats.xml","r")
- xml_dom = parseXml_with_dlg(self,tmp.read())
- xml_dom = xml_dom._get_firstChild()
- tmp.close()
- temp_dom = xml_dom
- f_list = temp_dom.getElementsByTagName('feat')
+ tree = parse(dir_struct["dnd3e"]+"dnd3efeats.xml")
+ temp_dom = tree.getroot()
+ f_list = temp_dom.findall('feat')
opts = []
for f in f_list:
- opts.append(f.getAttribute('name') + " - [" +
- f.getAttribute('type') + "] - " + f.getAttribute('desc'))
+ opts.append(f.get('name') + " - [" +
+ f.get('type') + "] - " + f.get('desc'))
dlg = wx.SingleChoiceDialog(self,'Choose Feat','Feats',opts)
if dlg.ShowModal() == wx.ID_OK:
i = dlg.GetSelection()
- new_node = self.master_dom.appendChild(f_list[i].cloneNode(False))
+ new_node = self.xml.append(f_list[i])
self.grid.AppendRows(1)
self.refresh_row(self.grid.GetNumberRows()-1)
dlg.Destroy()
@@ -1607,7 +1544,7 @@
def new_child_handler(self,tag,text,handler_class,icon='gear'):
- node_list = self.master_dom.getElementsByTagName(tag)
+ node_list = self.xml.findall(tag)
tree = self.tree
i = self.tree.icons[icon]
new_tree_node = tree.AppendItem(self.mytree_node,text,i,i)
@@ -1646,7 +1583,7 @@
def on_html(self,evt):
html_str = self.tohtml()
wnd = http_html_window(self.frame.note,-1)
- wnd.title = self.master_dom.getAttribute('name')
+ wnd.title = self.xml.get('name')
self.frame.add_panel(wnd)
wnd.SetPage(html_str)
@@ -1675,8 +1612,8 @@
return wnd
def on_rclick( self, evt ):
- chp = self.master_dom.getAttribute('current')
- mhp = self.master_dom.getAttribute('max')
+ chp = self.xml.get('current')
+ mhp = self.xml.get('max')
txt = '((HP: %s / %s))' % ( chp, mhp )
self.chat.ParsePost( txt, True, True )
@@ -1684,9 +1621,9 @@
html_str = ""
html_str += "Hit Points | "
html_str += "Max: | "
- html_str += ""+self.master_dom.getAttribute('max')+" | "
+ html_str += ""+self.xml.get('max')+" | "
html_str += "Current: | "
- html_str += ""+self.master_dom.getAttribute('current')+" | "
+ html_str += ""+self.xml.get('current')+" | "
html_str += "
---|
"
return html_str
@@ -1696,15 +1633,15 @@
self.hparent = handler #a 1.5002 allow ability to run up tree. In this
#a 1.5002 case, we need the functional parent, not the invoking parent.
- pname = handler.master_dom.setAttribute("name", 'HitPoints')
+ pname = handler.xml.set("name", 'HitPoints')
self.sizer = wx.FlexGridSizer(2, 4, 2, 2) # rows, cols, hgap, vgap
- self.master_dom = handler.master_dom
+ self.xml = handler.xml
self.sizer.AddMany([ (wx.StaticText(self, -1, "HP Current:"), 0,
wx.ALIGN_CENTER_VERTICAL),
(wx.TextCtrl(self, HP_CUR,
- self.master_dom.getAttribute('current')), 0, wx.EXPAND),
+ self.xml.get('current')), 0, wx.EXPAND),
(wx.StaticText(self, -1, "HP Max:"), 0, wx.ALIGN_CENTER_VERTICAL),
- (wx.TextCtrl(self, HP_MAX, self.master_dom.getAttribute('max')),
+ (wx.TextCtrl(self, HP_MAX, self.xml.get('max')),
0, wx.EXPAND),
])
self.sizer.AddGrowableCol(1)
@@ -1719,9 +1656,9 @@
def on_text(self,evt):
id = evt.GetId()
if id == HP_CUR:
- self.master_dom.setAttribute('current',evt.GetString())
+ self.xml.set('current',evt.GetString())
elif id == HP_MAX:
- self.master_dom.setAttribute('max',evt.GetString())
+ self.xml.set('max',evt.GetString())
def on_size(self,evt):
s = self.GetClientSizeTuple()
@@ -1761,9 +1698,9 @@
self.temp_dom={}
#a 1.5012 end a1b
- node_list = self.master_dom.getElementsByTagName('melee')
+ node_list = self.xml.findall('melee')
self.melee = node_list[0]
- node_list = self.master_dom.getElementsByTagName('ranged')
+ node_list = self.xml.findall('ranged')
self.ranged = node_list[0]
self.refresh_weapons() # this causes self.weapons to be loaded.
@@ -1781,7 +1718,7 @@
fnFrame.panel.SetPage(self.html_str)
fnFrame.Show()
- #weaponsH = self.master_dom.getElementsByTagName('attacks')
+ #weaponsH = self.xml.findall('attacks')
#mark7
#a 1.9001 this whole method
@@ -1801,9 +1738,9 @@
tree = self.tree
icons = self.tree.icons
tree.CollapseAndReset(self.mytree_node)
- node_list = self.master_dom.getElementsByTagName('weapon')
+ node_list = self.xml.findall('weapon')
for n in node_list:
- name = n.getAttribute('name')
+ name = n.get('name')
fn = safeGetAttr(n,'fn') #a 1.5012 can be removed when
#a 1.5012 confident all characters in the world have footnotes.
#if self.updateFootNotes:
@@ -1817,33 +1754,28 @@
def updateFootN(self,n):#a 1.5012 this whole function
if not self.temp_dom:
- tmp = open(dir_struct["dnd3e"]+"dnd3eweapons.xml","r")
- #tmp = open("c:\clh\codeSamples\sample1.xml","r") #a (debug) 1.5012
- self.temp_dom = xml.dom.minidom.parse(tmp)
-
- #self.temp_dom = parseXml_with_dlg(self,tmp.read())
- self.temp_dom = self.temp_dom._get_firstChild()
- tmp.close()
- nameF = n.getAttribute('name')
- w_list = self.temp_dom.getElementsByTagName('weapon')
+ tree = parse(dir_struct["dnd3e"]+"dnd3eweapons.xml")
+ self.temp_dom = tree.getroot()
+ nameF = n.get('name')
+ w_list = self.temp_dom.findall('weapon')
found = False
for w in w_list:
- if nameF == w.getAttribute('name'):
+ if nameF == w.get('name'):
found = True
fnN = safeGetAttr(n,'fn')
if fnN == None or fnN == 'None':
- fnW = w.getAttribute('fn')
+ fnW = w.get('fn')
#print "weapon",nameF,"footnotes are updated to",fnW
self.html_str += (""+nameF+" | "+
""+fnW+" | \n")
- n.setAttribute('fn',fnW)
+ n.set('fn',fnW)
break
if not found:
self.html_str += (""+nameF+" - Custom "+
"Weapon, research "+
"and update manually; setting footnote to indicate custom | "+
""+'X'+" | \n")
- n.setAttribute('fn','X')
+ n.set('fn','X')
def get_mod(self,type='m'):
@@ -1861,13 +1793,13 @@
stat_mod = -7
stat_mod = self.root.abilities.get_mod(stat) #a 1.5002
#print "Big test - stat_mod",stat_mod #a (debug) 1.6000
- base = int(temp.getAttribute('base'))
- base2 = int(temp.getAttribute('second'))
- base3 = int(temp.getAttribute('third'))
- base4 = int(temp.getAttribute('forth'))
- base5 = int(temp.getAttribute('fifth'))
- base6 = int(temp.getAttribute('sixth'))
- misc = int(temp.getAttribute('misc'))
+ base = int(temp.get('base'))
+ base2 = int(temp.get('second'))
+ base3 = int(temp.get('third'))
+ base4 = int(temp.get('forth'))
+ base5 = int(temp.get('fifth'))
+ base6 = int(temp.get('sixth'))
+ misc = int(temp.get('misc'))
return (base, base2, base3, base4, base5, base6, stat_mod ,misc)
def on_rclick(self,evt):
@@ -1881,10 +1813,10 @@
#self.frame.add_panel(self.get_design_panel(self.frame.note))
else:
#print "entering attack phase"
- mod = int(self.weapons[name].getAttribute('mod'))
+ mod = int(self.weapons[name].get('mod'))
wepMod = mod #a 1.5008
footNotes = safeGetAttr(self.weapons[name],'fn','')
- cat = self.weapons[name].getAttribute('category') #a1.6001
+ cat = self.weapons[name].get('category') #a1.6001
result = split(cat,"-",2) #a 1.6001
if len(result) < 2: #a 1.6021 this if & else
print "warning: 1.6002 unable to interpret weapon category"
@@ -1896,7 +1828,7 @@
tres=result[1]
#print "print FootNotes,tres",footNotes,tres
if tres == 'Melee': #a 1.6001 #m 1.6022 use of tres here and...
- #if self.weapons[name].getAttribute('range') == '0':#d 1.6001
+ #if self.weapons[name].get('range') == '0':#d 1.6001
rangeOrMelee = 'm' #a 1.5008 code demote for next comment block
elif tres == 'Ranged': #m 1.6001 (was just else) #m 1.6022 here
rangeOrMelee = 'r' #a 1.5008
@@ -1907,7 +1839,7 @@
rangeOrMelee ='m'
mod = mod + self.get_mod(rangeOrMelee) #a 1.5008
chat = self.chat
- dmg = self.weapons[name].getAttribute('damage')
+ dmg = self.weapons[name].get('damage')
#a 1.6003 start code fix instance a
result = split(dmg,"/",2)
@@ -2037,28 +1969,28 @@
html_str += ""+str(ranged[1])+" | "
html_str += ""+str(ranged[2])+" | "
- n_list = self.master_dom.getElementsByTagName('weapon')
+ n_list = self.xml.findall('weapon')
for n in n_list:
- mod = n.getAttribute('mod')
+ mod = n.get('mod')
if mod >= 0:
mod1 = "+"
else:
mod1 = ""
- ran = n.getAttribute('range')
+ ran = n.get('range')
total = str(int(mod) + self.get_mod(ran))
html_str += """
Weapon |
Attack | Damage | Critical | """
html_str += ""
- html_str += n.getAttribute('name')+" | "+total+" | "
- html_str += ""+n.getAttribute('damage')+" | "
- html_str += n.getAttribute('critical')+" | "
+ html_str += n.get('name')+""+total+" | "
+ html_str += ""+n.get('damage')+" | "
+ html_str += n.get('critical')+" | "
html_str += """Range | Weight |
Type | Size | Misc Mod | """
html_str += ""+ran+" | "
- html_str += n.getAttribute('weight')+" | "
- html_str += ""+n.getAttribute('type')+" | "
- html_str += n.getAttribute('size')+" | "
+ html_str += n.get('weight')+""
+ html_str += ""+n.get('type')+" | "
+ html_str += n.get('size')+" | "
html_str += '%s%s | ' % (mod1, mod)
#a 1.5012 add next two lines to pretty print footnotes.
html_str += """Footnotes: | """
@@ -2069,7 +2001,7 @@
class attack_grid(wx.grid.Grid):
"""grid for attacks"""
def __init__(self, parent, handler):
- pname = handler.master_dom.setAttribute("name", 'Melee')
+ pname = handler.xml.set("name", 'Melee')
self.hparent = handler #a 1.5002 allow ability to run up tree.
#a 1.5002 we need the functional parent, not the invoking parent.
@@ -2128,19 +2060,19 @@
try:
int(value)
if col==1:
- self.rows[row].setAttribute('base',value)
+ self.rows[row].set('base',value)
elif col==2:
- self.rows[row].setAttribute('second',value)
+ self.rows[row].set('second',value)
elif col==3:
- self.rows[row].setAttribute('third',value)
+ self.rows[row].set('third',value)
elif col==4:
- self.rows[row].setAttribute('forth',value)
+ self.rows[row].set('forth',value)
elif col==5:
- self.rows[row].setAttribute('fifth',value)
+ self.rows[row].set('fifth',value)
elif col==6:
- self.rows[row].setAttribute('sixth',value)
+ self.rows[row].set('sixth',value)
elif col==8:
- self.rows[row].setAttribute('misc',value)
+ self.rows[row].set('misc',value)
#print "row:",row,"value",value,self.rows[row]
self.parent.refresh_data()
except:
@@ -2181,7 +2113,7 @@
self.hparent = handler #a 1.5012
self.root = getRoot(self)
- pname = handler.master_dom.setAttribute("name", 'Weapons')
+ pname = handler.xml.set("name", 'Weapons')
wx.Panel.__init__(self, parent, -1)
self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
@@ -2207,9 +2139,9 @@
self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
self.grid.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK, self.on_gridRclick)#a 1.5012
- n_list = handler.master_dom.getElementsByTagName('weapon')
+ n_list = handler.xml.findall('weapon')
self.n_list = n_list
- self.master_dom = handler.master_dom
+ self.xml = handler.xml
self.handler = handler
#trash=input("weapon panel init colnames")
self.colAttr = ['name','damage','mod','critical','type','weight',
@@ -2238,7 +2170,7 @@
#print "wp, on rclick,grid row,col,value",row,col,value
if col == 9 and value != 'None':
n = self.n_list[row]
- name = n.getAttribute('name')
+ name = n.get('name')
#print "we want a panel!"
handler = self.hparent
#print "handler:",handler
@@ -2250,18 +2182,14 @@
fnFrame = wx.Frame(masterFrame, -1, title)
fnFrame.panel = wx.html.HtmlWindow(fnFrame,-1)
if not self.temp_dom:
- tmp = open(dir_struct["dnd3e"]+
- "dnd3eweapons.xml","r")
- #tmp = open("c:\clh\codeSamples\sample1.xml","r")
- xml_dom = parseXml_with_dlg(self,tmp.read())
- xml_dom = xml_dom._get_firstChild()
- tmp.close()
+ tree = parse(dir_struct["dnd3e"]+"dnd3eweapons.xml")
+ xml_dom = tree.getroot()
self.temp_dom = xml_dom
- f_list = self.temp_dom.getElementsByTagName('f') # the footnotes
+ f_list = self.temp_dom.findall('f') # the footnotes
#print "weapon_panel - on_rclick f_list",f_list#a 1.6
n = self.n_list[row]
- name = n.getAttribute('name')
- footnotes = n.getAttribute('fn')
+ name = n.get('name')
+ footnotes = n.get('fn')
html_str = ""
html_str += """
Note | Description | \n"""
@@ -2273,9 +2201,9 @@
aNote=footnotes[i]
found=False
for f in f_list:
- if f.getAttribute('mark') == aNote:
+ if f.get('mark') == aNote:
found=True
- text=f.getAttribute('txt')
+ text=f.get('txt')
html_str += (""+aNote+" | "+
""+text+" | \n")
if not found:
@@ -2299,42 +2227,42 @@
value = self.grid.GetCellValue(row,col)
if col == 2 and not int(value): # special case for mod, demoted
value = "0" #a 5.012 demoted
- self.n_list[row].setAttribute('mod',value) # a 5.012 demoted
+ self.n_list[row].set('mod',value) # a 5.012 demoted
if not (col == 9 and value == "None" and
- self.n_list[row].getAttribute('fn') == "None"
+ self.n_list[row].get('fn') == "None"
): #a 5.012 special case for footnotes
- self.n_list[row].setAttribute(self.colAttr[col],value)#a 5.012
+ self.n_list[row].set(self.colAttr[col],value)#a 5.012
#print "cell change",row,col,value
#if col == 0:#d 5.012 use of colAttr removed need for this.
- # self.n_list[row].setAttribute('name',value) #d 5.012
+ # self.n_list[row].set('name',value) #d 5.012
#elif col == 2: #d 5.012
# try:#d 5.012 simplifying... remove this block.
# int(value)
- # self.n_list[row].setAttribute('mod',value)
+ # self.n_list[row].set('mod',value)
# #self.refresh_row(row) #d 5.012 did nothing.
# except:
# value = "0"
- # self.n_list[row].setAttribute('mod',value)
+ # self.n_list[row].set('mod',value)
#else: #d 5.012 demoted self.n set.
- # self.n_list[row].setAttribute(self.grid.GetColLabelValue(col),value)
+ # self.n_list[row].set(self.grid.GetColLabelValue(col),value)
def refresh_row(self,i):
n = self.n_list[i]
- fn = n.getAttribute('fn')
+ fn = n.get('fn')
#print "fn=",fn
- name = n.getAttribute('name')
- mod = n.getAttribute('mod')
- ran = n.getAttribute('range')
+ name = n.get('name')
+ mod = n.get('mod')
+ ran = n.get('range')
total = str(int(mod) + self.handler.get_mod(ran))
self.grid.SetCellValue(i,0,name)
- self.grid.SetCellValue(i,1,n.getAttribute('damage'))
+ self.grid.SetCellValue(i,1,n.get('damage'))
self.grid.SetCellValue(i,2,mod)
- self.grid.SetCellValue(i,3,n.getAttribute('critical'))
- self.grid.SetCellValue(i,4,n.getAttribute('type'))
- self.grid.SetCellValue(i,5,n.getAttribute('weight'))
+ self.grid.SetCellValue(i,3,n.get('critical'))
+ self.grid.SetCellValue(i,4,n.get('type'))
+ self.grid.SetCellValue(i,5,n.get('weight'))
self.grid.SetCellValue(i,6,ran)
- self.grid.SetCellValue(i,7,n.getAttribute('size') )
+ self.grid.SetCellValue(i,7,n.get('size') )
self.grid.SetCellValue(i,8,total)
self.grid.SetCellValue(i,9,safeGetAttr(n,'fn','None')) #a 1.5012
self.grid.SetCellValue(i,10,safeGetAttr(n,'comment','')) #a 1.5012
@@ -2350,31 +2278,28 @@
for i in range(rows-1,-1,-1): #a 1.6011 or you lose context
if self.grid.IsInSelection(i,0):
self.grid.DeleteRows(i)
- self.master_dom.removeChild(self.n_list[i])
- self.n_list = self.master_dom.getElementsByTagName('weapon')
+ self.xml.remove(self.n_list[i])
+ self.n_list = self.xml.findall('weapon')
self.handler.refresh_weapons()
def on_add(self,evt):
if not self.temp_dom:
- tmp = open(dir_struct["dnd3e"]+"dnd3eweapons.xml","r")
- #tmp = open("c:\clh\codeSamples\sample1.xml","r") #a (debug) 1.5012
- xml_dom = parseXml_with_dlg(self,tmp.read())
- xml_dom = xml_dom._get_firstChild()
- tmp.close()
+ tree = parse(dir_struct["dnd3e"]+"dnd3eweapons.xml")
+ xml_dom = tree.getroot()
self.temp_dom = xml_dom
- f_list = self.temp_dom.getElementsByTagName('weapon')
+ f_list = self.temp_dom.findall('weapon')
opts = []
#print "weapon_panel - on_add f_list",f_list#a 1.6
for f in f_list:
- opts.append(f.getAttribute('name'))
+ opts.append(f.get('name'))
dlg = wx.SingleChoiceDialog(self,'Choose Weapon','Weapon List',opts)
if dlg.ShowModal() == wx.ID_OK:
i = dlg.GetSelection()
#print f_list[i] # DOM Element: weapon.
- new_node = self.master_dom.appendChild(f_list[i].cloneNode(False))
+ new_node = self.xml.append(f_list[i])
#print self.grid.AppendRows # a bound method of wxGrid
self.grid.AppendRows(1)
- self.n_list = self.master_dom.getElementsByTagName('weapon')
+ self.n_list = self.xml.findall('weapon')
#print "self.n_list",self.n_list # list of DOM weapons
self.refresh_row(self.grid.GetNumberRows()-1)
self.handler.refresh_weapons()
@@ -2400,7 +2325,7 @@
class attack_panel(wx.Panel):
def __init__(self, parent, handler):
- pname = handler.master_dom.setAttribute("name", 'Melee')
+ pname = handler.xml.set("name", 'Melee')
self.parent = parent #a 1.9001
wx.Panel.__init__(self, parent, -1)
@@ -2456,19 +2381,19 @@
return ac_total
def get_max_dex(self):
- armor_list = self.master_dom.getElementsByTagName('armor')
+ armor_list = self.xml.findall('armor')
dex = 10
for a in armor_list:
- temp = int(a.getAttribute("maxdex"))
+ temp = int(a.get("maxdex"))
if temp < dex:
dex = temp
return dex
def get_total(self,attr):
- armor_list = self.master_dom.getElementsByTagName('armor')
+ armor_list = self.xml.findall('armor')
total = 0
for a in armor_list:
- total += int(a.getAttribute(attr))
+ total += int(a.get(attr))
return total
def get_design_panel(self,parent):
@@ -2493,29 +2418,29 @@
html_str += ""+str(self.get_spell_failure())+" | "
html_str += ""+str(self.get_max_dex())+" | "
html_str += ""+str(self.get_total_weight())+" | "
- n_list = self.master_dom._get_childNodes()
+ n_list = self.xml.getchildren()
for n in n_list:
html_str += """
Armor | Type | Bonus | """
html_str += ""
- html_str += ""+n.getAttribute('name')+" | "
- html_str += ""+n.getAttribute('type')+" | "
- html_str += ""+n.getAttribute('bonus')+" | "
+ html_str += ""+n.get('name')+" | "
+ html_str += ""+n.get('type')+" | "
+ html_str += ""+n.get('bonus')+" | "
html_str += """"""
html_str += "Check Penalty | Spell Failure | "
html_str += "Max Dex | Speed | Weight | "
html_str += ""
- html_str += ""+n.getAttribute('checkpenalty')+" | "
- html_str += ""+n.getAttribute('spellfailure')+" | "
- html_str += ""+n.getAttribute('maxdex')+" | "
- html_str += ""+n.getAttribute('speed')+" | "
- html_str += ""+n.getAttribute('weight')+" | "
+ html_str += ""+n.get('checkpenalty')+" | "
+ html_str += ""+n.get('spellfailure')+" | "
+ html_str += ""+n.get('maxdex')+" | "
+ html_str += ""+n.get('speed')+" | "
+ html_str += ""+n.get('weight')+" |
---|
"
return html_str
class ac_panel(wx.Panel):
def __init__(self, parent, handler):
- pname = handler.master_dom.setAttribute("name", 'Armor')
+ pname = handler.xml.set("name", 'Armor')
self.hparent = handler #a 1.5002 allow ability to run up tree.
#a 1.5002 we need the functional parent, not the invoking parent.
@@ -2540,8 +2465,8 @@
self.Bind(wx.EVT_BUTTON, self.on_remove, id=10)
self.Bind(wx.EVT_BUTTON, self.on_add, id=20)
self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
- self.master_dom = handler.master_dom
- n_list = handler.master_dom._get_childNodes()
+ self.xml = handler.xml
+ n_list = handler.xml.getchildren()
self.n_list = n_list
col_names = ['Armor','bonus','maxdex','cp','sf','weight','speed','type']
self.grid.CreateGrid(len(n_list),len(col_names),1)
@@ -2562,40 +2487,38 @@
if col >= 1 and col <= 5:
try:
int(value)
- self.n_list[row].setAttribute(self.atts[col],value)
+ self.n_list[row].set(self.atts[col],value)
except:
self.grid.SetCellValue(row,col,"0")
else:
- self.n_list[row].setAttribute(self.atts[col],value)
+ self.n_list[row].set(self.atts[col],value)
def refresh_row(self,i):
n = self.n_list[i]
for y in range(len(self.atts)):
- self.grid.SetCellValue(i,y,n.getAttribute(self.atts[y]))
+ self.grid.SetCellValue(i,y,n.get(self.atts[y]))
def on_remove(self,evt):
rows = self.grid.GetNumberRows()
for i in range(rows):
if self.grid.IsInSelection(i,0):
self.grid.DeleteRows(i)
- self.master_dom.removeChild(self.n_list[i])
+ self.xml.remove(self.n_list[i])
def on_add(self,evt):
if not self.temp_dom:
- tmp = open(dir_struct["dnd3e"]+"dnd3earmor.xml","r")
- xml_dom = parseXml_with_dlg(self,tmp.read())
- xml_dom = xml_dom._get_firstChild()
- tmp.close()
+ tree = parse(dir_struct["dnd3e"]+"dnd3earmor.xml")
+ xml_dom = tree.getroot()
self.temp_dom = xml_dom
- f_list = self.temp_dom.getElementsByTagName('armor')
+ f_list = self.temp_dom.findall('armor')
opts = []
for f in f_list:
- opts.append(f.getAttribute('name'))
+ opts.append(f.get('name'))
dlg = wx.SingleChoiceDialog(self,'Choose Armor:','Armor List',opts)
if dlg.ShowModal() == wx.ID_OK:
i = dlg.GetSelection()
- new_node = self.master_dom.appendChild(f_list[i].cloneNode(False))
+ new_node = self.xml.append(f_list[i])
self.grid.AppendRows(1)
self.refresh_row(self.grid.GetNumberRows()-1)
dlg.Destroy()
@@ -2631,7 +2554,7 @@
self.myeditor = None
def new_child_handler(self,tag,text,handler_class,icon='gear'):
- node_list = self.master_dom.getElementsByTagName(tag)
+ node_list = self.xml.findall(tag)
tree = self.tree
i = self.tree.icons[icon]
new_tree_node = tree.AppendItem(self.mytree_node,text,i,i)
@@ -2677,7 +2600,7 @@
def on_html(self,evt):
html_str = self.tohtml()
wnd = http_html_window(self.frame.note,-1)
- wnd.title = self.master_dom.getAttribute('name')
+ wnd.title = self.xml.get('name')
self.frame.add_panel(wnd)
wnd.SetPage(html_str)
@@ -2702,12 +2625,12 @@
self.root.spells = self #a 1.6009
- node_list = self.master_dom.getElementsByTagName( 'spell' )
+ node_list = self.xml.findall( 'spell' )
self.spells = {}
tree = self.tree
icons = self.tree.icons
for n in node_list:
- name = n.getAttribute('name')
+ name = n.get('name')
self.spells[ name ] = n
new_tree_node = tree.AppendItem( self.mytree_node, name, icons['gear'], icons['gear'] )
tree.SetPyData( new_tree_node, self )
@@ -2718,10 +2641,10 @@
if item == self.mytree_node:
dnd3e_char_child.on_ldclick( self, evt )
else:
- level = self.spells[ name ].getAttribute( 'level' )
- descr = self.spells[ name ].getAttribute( 'desc' )
- use = self.spells[ name ].getAttribute( 'used' )
- memrz = self.spells[ name ].getAttribute( 'memrz' )
+ level = self.spells[ name ].get( 'level' )
+ descr = self.spells[ name ].get( 'desc' )
+ use = self.spells[ name ].get( 'used' )
+ memrz = self.spells[ name ].get( 'memrz' )
use += '+1'
charNameL=self.root.general.charName #a 1.5002
left = eval( '%s - ( %s )' % ( memrz, use ) )
@@ -2740,16 +2663,16 @@
#txt = '%s can cast %s %d more time%s' % ( dnd_globals["gen"]["Name"], name, left, s )#d 1.5002
txt = '%s can cast %s %d more time%s' % ( charNameL, name, left, s ) #a 1.5002
self.chat.ParsePost( txt, False, False )
- self.spells[ name ].setAttribute( 'used', `eval( use )` )
+ self.spells[ name ].set( 'used', `eval( use )` )
def refresh_spells(self):
self.spells = {}
tree = self.tree
icons = self.tree.icons
tree.CollapseAndReset(self.mytree_node)
- node_list = self.master_dom.getElementsByTagName('spell')
+ node_list = self.xml.findall('spell')
for n in node_list:
- name = n.getAttribute('name')
+ name = n.get('name')
new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear'])
tree.SetPyData(new_tree_node,self)
self.spells[name]=n
@@ -2761,9 +2684,9 @@
def tohtml(self):
html_str = "Arcane Spells |
---|
"
- n_list = self.master_dom._get_childNodes()
+ n_list = self.xml.getchildren()
for n in n_list:
- html_str += "(" + n.getAttribute('level') + ") " + n.getAttribute('name')+ ", "
+ html_str += "(" + n.get('level') + ") " + n.get('name')+ ", "
html_str = html_str[:len(html_str)-2] + " | "
return html_str
@@ -2772,7 +2695,7 @@
class spells_panel(wx.Panel):
def __init__(self, parent, handler):
- pname = handler.master_dom.setAttribute("name", 'Arcane Spells')
+ pname = handler.xml.set("name", 'Arcane Spells')
self.hparent = handler #a 1.5002 allow ability to run up tree.
#a 1.5002 in this case, we need the functional parent, not the invoking parent.
@@ -2800,9 +2723,9 @@
self.Bind(wx.EVT_BUTTON, self.on_add, id=20)
self.Bind(wx.EVT_BUTTON, self.on_refresh_spells, id=30)
self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
- n_list = handler.master_dom._get_childNodes()
+ n_list = handler.xml.getchildren()
self.n_list = n_list
- self.master_dom = handler.master_dom
+ self.xml = handler.xml
self.grid.CreateGrid(len(n_list),4,1)
self.grid.SetRowLabelSize(0)
self.grid.SetColLabelValue(0,"No.")
@@ -2818,16 +2741,16 @@
col = evt.GetCol()
value = self.grid.GetCellValue(row,col)
if col == 0:
- self.n_list[row].setAttribute('memrz',value)
+ self.n_list[row].set('memrz',value)
def refresh_row(self,i):
spell = self.n_list[i]
- memrz = spell.getAttribute('memrz')
- name = spell.getAttribute('name')
- type = spell.getAttribute('desc')
- level = spell.getAttribute('level')
+ memrz = spell.get('memrz')
+ name = spell.get('name')
+ type = spell.get('desc')
+ level = spell.get('level')
self.grid.SetCellValue(i,0,memrz)
self.grid.SetCellValue(i,2,name)
self.grid.SetReadOnly(i,2)
@@ -2841,42 +2764,41 @@
for i in range(rows):
if self.grid.IsInSelection(i,0):
self.grid.DeleteRows(i)
- self.master_dom.removeChild(self.n_list[i])
+ self.xml.remove(self.n_list[i])
def on_add(self,evt):
-
+ debug()
if not self.temp_dom:
- tmp = open(dir_struct["dnd3e"]+"dnd3espells.xml","r")
- xml_dom = parseXml_with_dlg(self,tmp.read())
- xml_dom = xml_dom._get_firstChild()
- tmp.close()
- self.temp_dom = xml_dom
- f_list = self.temp_dom.getElementsByTagName('spell')
+ tree = parse(dir_struct["dnd3e"]+"dnd3espells.xml")
+ xml_dom = tree.getroot()
+ self.temp_dom = xml_dom
+ debug(self.temp_dom)
+ f_list = self.temp_dom.findall('spell')
opts = []
#lvl = int(dnd3e_char_child.get_char_lvl('level'))
#castlvl = eval('%s/2' % (lvl))
for f in f_list:
- spelllvl = f.getAttribute('level')
+ spelllvl = f.get('level')
#if spelllvl <= "1":
- # opts.append("(" + f.getAttribute('level') + ")" + f.getAttribute('name'))
+ # opts.append("(" + f.get('level') + ")" + f.get('name'))
#else:
# if eval('%d >= %s' %(castlvl, spelllvl)):
- opts.append("(" + f.getAttribute('level') + ")" + f.getAttribute('name'))
+ opts.append("(" + f.get('level') + ")" + f.get('name'))
dlg = wx.SingleChoiceDialog(self,'Choose Spell','Spells',opts)
if dlg.ShowModal() == wx.ID_OK:
i = dlg.GetSelection()
- new_node = self.master_dom.appendChild(f_list[i].cloneNode(False))
+ new_node = self.xml.append(f_list[i])
self.grid.AppendRows(1)
- self.n_list = self.master_dom.getElementsByTagName('spell')
+ self.n_list = self.xml.findall('spell')
self.refresh_row(self.grid.GetNumberRows()-1)
self.handler.refresh_spells()
dlg.Destroy()
def on_refresh_spells( self, evt ):
- f_list = self.master_dom.getElementsByTagName('spell')
+ f_list = self.xml.findall('spell')
for spell in f_list:
- spell.setAttribute( 'used', '0' )
+ spell.set( 'used', '0' )
def on_size(self,event):
s = self.GetClientSizeTuple()
@@ -2907,12 +2829,12 @@
self.root.divine = self #a 1.6009
- node_list = self.master_dom.getElementsByTagName( 'gift' )
+ node_list = self.xml.findall( 'gift' )
self.spells = {}
tree = self.tree
icons = self.tree.icons
for n in node_list:
- name = n.getAttribute('name')
+ name = n.get('name')
self.spells[ name ] = n
new_tree_node = tree.AppendItem( self.mytree_node, name, icons['flask'], icons['flask'] )
tree.SetPyData( new_tree_node, self )
@@ -2924,10 +2846,10 @@
if item == self.mytree_node:
dnd3e_char_child.on_ldclick( self, evt )
else:
- level = self.spells[ name ].getAttribute( 'level' )
- descr = self.spells[ name ].getAttribute( 'desc' )
- use = self.spells[ name ].getAttribute( 'used' )
- memrz = self.spells[ name ].getAttribute( 'memrz' )
+ level = self.spells[ name ].get( 'level' )
+ descr = self.spells[ name ].get( 'desc' )
+ use = self.spells[ name ].get( 'used' )
+ memrz = self.spells[ name ].get( 'memrz' )
use += '+1'
left = eval( '%s - ( %s )' % ( memrz, use ) )
if left < 0:
@@ -2945,7 +2867,7 @@
#txt = '%s can cast %s %d more time%s' % ( dnd_globals["gen"]["Name"], name, left, s ) #d 1.5002
txt = '%s can cast %s %d more time%s' % ( charNameL, name, left, s ) #a 1.5002
self.chat.ParsePost( txt, False, False )
- self.spells[ name ].setAttribute( 'used', `eval( use )` )
+ self.spells[ name ].set( 'used', `eval( use )` )
def refresh_spells(self):
self.spells = {}
@@ -2953,9 +2875,9 @@
icons = self.tree.icons
tree.CollapseAndReset(self.mytree_node)
- node_list = self.master_dom.getElementsByTagName('gift')
+ node_list = self.xml.findall('gift')
for n in node_list:
- name = n.getAttribute('name')
+ name = n.get('name')
new_tree_node = tree.AppendItem(self.mytree_node,name,icons['flask'],icons['flask'])
tree.SetPyData(new_tree_node,self)
self.spells[name]=n
@@ -2967,9 +2889,9 @@
def tohtml(self):
html_str = "Divine Spells |
---|
"
- n_list = self.master_dom._get_childNodes()
+ n_list = self.xml.getchildren()
for n in n_list:
- html_str += "(" + n.getAttribute('level') + ") " + n.getAttribute('name')+ ", "
+ html_str += "(" + n.get('level') + ") " + n.get('name')+ ", "
html_str = html_str[:len(html_str)-2] + " | "
return html_str
@@ -2978,7 +2900,7 @@
class divine_panel(wx.Panel):
def __init__(self, parent, handler):
- pname = handler.master_dom.setAttribute("name", 'Divine Spells')
+ pname = handler.xml.set("name", 'Divine Spells')
self.hparent = handler #a 1.5002 allow ability to run up tree.
#a 1.5002 in this case, we need the functional parent, not the invoking parent.
@@ -3007,9 +2929,9 @@
self.Bind(wx.EVT_BUTTON, self.on_refresh_spells, id=30)
self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
- n_list = handler.master_dom._get_childNodes()
+ n_list = handler.xml.getchildren()
self.n_list = n_list
- self.master_dom = handler.master_dom
+ self.xml = handler.xml
self.grid.CreateGrid(len(n_list),4,1)
self.grid.SetRowLabelSize(0)
self.grid.SetColLabelValue(0,"No.")
@@ -3026,16 +2948,16 @@
col = evt.GetCol()
value = self.grid.GetCellValue(row,col)
if col == 0:
- self.n_list[row].setAttribute('memrz',value)
+ self.n_list[row].set('memrz',value)
def refresh_row(self,i):
spell = self.n_list[i]
- memrz = spell.getAttribute('memrz')
- name = spell.getAttribute('name')
- type = spell.getAttribute('desc')
- level = spell.getAttribute('level')
+ memrz = spell.get('memrz')
+ name = spell.get('name')
+ type = spell.get('desc')
+ level = spell.get('level')
self.grid.SetCellValue(i,0,memrz)
self.grid.SetCellValue(i,2,name)
self.grid.SetReadOnly(i,2)
@@ -3049,41 +2971,38 @@
for i in range(rows):
if self.grid.IsInSelection(i,0):
self.grid.DeleteRows(i)
- self.master_dom.removeChild(self.n_list[i])
+ self.xml.remove(self.n_list[i])
def on_add(self,evt):
if not self.temp_dom:
- tmp = open(dir_struct["dnd3e"]+"dnd3edivine.xml","r")
-
- xml_dom = parseXml_with_dlg(self,tmp.read())
- xml_dom = xml_dom._get_firstChild()
- tmp.close()
+ tree = parse(dir_struct["dnd3e"]+"dnd3edivine.xml")
+ xml_dom = tree.getroot()
self.temp_dom = xml_dom
- f_list = self.temp_dom.getElementsByTagName('gift')
+ f_list = self.temp_dom.findall('gift')
opts = []
#lvl = int(dnd3e_char_child.get_char_lvl('level'))
#castlvl = lvl / 2
for f in f_list:
- spelllvl = f.getAttribute('level')
+ spelllvl = f.get('level')
#if spelllvl <= "1":
- # opts.append("(" + f.getAttribute('level') + ")" + f.getAttribute('name'))
+ # opts.append("(" + f.get('level') + ")" + f.get('name'))
#else:
# if eval('%d >= %s' %(castlvl, spelllvl)):
- opts.append("(" + f.getAttribute('level') + ")" + f.getAttribute('name'))
+ opts.append("(" + f.get('level') + ")" + f.get('name'))
dlg = wx.SingleChoiceDialog(self,'Choose Spell','Spells',opts)
if dlg.ShowModal() == wx.ID_OK:
i = dlg.GetSelection()
- new_node = self.master_dom.appendChild(f_list[i].cloneNode(False))
+ new_node = self.xml.append(f_list[i])
self.grid.AppendRows(1)
- self.n_list = self.master_dom.getElementsByTagName('gift')
+ self.n_list = self.xml.findall('gift')
self.refresh_row(self.grid.GetNumberRows()-1)
self.handler.refresh_spells()
dlg.Destroy()
def on_refresh_spells( self, evt ):
- f_list = self.master_dom.getElementsByTagName('gift')
+ f_list = self.xml.findall('gift')
for spell in f_list:
- spell.setAttribute( 'used', '0' )
+ spell.set( 'used', '0' )
def on_size(self,event):
s = self.GetClientSizeTuple()
@@ -3115,12 +3034,12 @@
self.root = getRoot(self) #a 1.5002
self.root.powers = self #a 1.6009
- node_list = self.master_dom.getElementsByTagName( 'power' )
+ node_list = self.xml.findall( 'power' )
self.powers = {}
tree = self.tree
icons = self.tree.icons
for n in node_list:
- name = n.getAttribute('name')
+ name = n.get('name')
self.powers[ name ] = n
new_tree_node = tree.AppendItem( self.mytree_node, name,
icons['gear'], icons['gear'] )
@@ -3135,11 +3054,11 @@
if item == self.mytree_node:
dnd3e_char_child.on_ldclick( self, evt )
else:
- level = int(self.powers[ name ].getAttribute( 'level' ))
- descr = self.powers[ name ].getAttribute( 'desc' )
+ level = int(self.powers[ name ].get( 'level' ))
+ descr = self.powers[ name ].get( 'desc' )
#use can be removed -mgt
- #use = self.powers[ name ].getAttribute( 'used' )
- points = self.powers[ name ].getAttribute( 'point' )
+ #use = self.powers[ name ].get( 'used' )
+ points = self.powers[ name ].get( 'point' )
#cpp and fre are strings without the eval -mgt
cpp = eval(self.root.pp.get_char_pp('current1')) #a 1.5002
fre = eval(self.root.pp.get_char_pp('free')) #a 1.5002
@@ -3186,9 +3105,9 @@
tree = self.tree
icons = self.tree.icons
tree.CollapseAndReset(self.mytree_node)
- node_list = self.master_dom.getElementsByTagName('power')
+ node_list = self.xml.findall('power')
for n in node_list:
- name = n.getAttribute('name')
+ name = n.get('name')
new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear'])
tree.SetPyData(new_tree_node,self)
self.powers[name]=n
@@ -3200,9 +3119,9 @@
def tohtml(self):
html_str = "Powers |
---|
"
- n_list = self.master_dom._get_childNodes()
+ n_list = self.xml.getchildren()
for n in n_list:
- html_str += "(" + n.getAttribute('level') + ") " + n.getAttribute('name')+ ", "
+ html_str += "(" + n.get('level') + ") " + n.get('name')+ ", "
html_str = html_str[:len(html_str)-2] + " | "
return html_str
@@ -3210,7 +3129,7 @@
class power_panel(wx.Panel):
def __init__(self, parent, handler):
#m 1.5015 corrected typo, was Pionic.
- pname = handler.master_dom.setAttribute("name", 'Psionic Powers')
+ pname = handler.xml.set("name", 'Psionic Powers')
self.hparent = handler #a 1.5002 allow ability to run up tree. In this
#a 1.5002 case, we need the functional parent, not the invoking parent.
self.root = getRoot(self) #a (debug) 1.5002,1.5014
@@ -3239,9 +3158,9 @@
self.Bind(wx.EVT_BUTTON, self.on_add, id=20)
self.Bind(wx.EVT_BUTTON, self.on_refresh_powers, id=30)
self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
- n_list = handler.master_dom._get_childNodes()
+ n_list = handler.xml.getchildren()
self.n_list = n_list
- self.master_dom = handler.master_dom
+ self.xml = handler.xml
self.grid.CreateGrid(len(n_list),5,1)
self.grid.SetRowLabelSize(0)
self.grid.SetColLabelValue(0,"PP")
@@ -3259,17 +3178,17 @@
col = evt.GetCol()
value = self.grid.GetCellValue(row,col)
"""if col == 0:
- self.n_list[row].setAttribute('memrz',value)"""
+ self.n_list[row].set('memrz',value)"""
def refresh_row(self,i):
power = self.n_list[i]
- point = power.getAttribute('point')
- name = power.getAttribute('name')
- type = power.getAttribute('desc')
- test = power.getAttribute('test')
- level = power.getAttribute('level')
+ point = power.get('point')
+ name = power.get('name')
+ type = power.get('desc')
+ test = power.get('test')
+ level = power.get('level')
self.grid.SetCellValue(i,0,point)
self.grid.SetReadOnly(i,0)
self.grid.SetCellValue(i,1,level)
@@ -3286,34 +3205,33 @@
for i in range(rows):
if self.grid.IsInSelection(i,0):
self.grid.DeleteRows(i)
- self.master_dom.removeChild(self.n_list[i])
-
- def on_add(self,evt):
+ self.xml.remove(self.n_list[i])
+
+ def on_add(self,evt):
+ debug()
if not self.temp_dom:
- tmp = open(dir_struct["dnd3e"]+"dnd3epowers.xml","r")
-
- xml_dom = parseXml_with_dlg(self,tmp.read())
- xml_dom = xml_dom._get_firstChild()
- tmp.close()
- self.temp_dom = xml_dom
- f_list = self.temp_dom.getElementsByTagName('power')
+ tree = parse(dir_struct["dnd3e"]+"dnd3epowers.xml")
+ xml_dom = tree.getroot()
+ self.temp_dom = xml_dom
+ debug(self.temp)
+ f_list = self.temp_dom.findall('power')
opts = []
#lvl = int(dnd3e_char_child.get_char_lvl('level'))
#castlvl = lvl / 2
for f in f_list:
- spelllvl = f.getAttribute('level')
+ spelllvl = f.get('level')
#if spelllvl <= "1":
- # opts.append("(" + f.getAttribute('level') + ") - " + f.getAttribute('name') + " - " + f.getAttribute('test'))
+ # opts.append("(" + f.get('level') + ") - " + f.get('name') + " - " + f.get('test'))
#else:
# if eval('%d >= %s' %(castlvl, spelllvl)):
- opts.append("(" + f.getAttribute('level') + ") - " +
- f.getAttribute('name') + " - " + f.getAttribute('test'))
+ opts.append("(" + f.get('level') + ") - " +
+ f.get('name') + " - " + f.get('test'))
dlg = wx.SingleChoiceDialog(self,'Choose Power','Powers',opts)
if dlg.ShowModal() == wx.ID_OK:
i = dlg.GetSelection()
- new_node = self.master_dom.appendChild(f_list[i].cloneNode(False))
+ new_node = self.xml.append(f_list[i])
self.grid.AppendRows(1)
- self.n_list = self.master_dom.getElementsByTagName('power')
+ self.n_list = self.xml.findall('power')
self.refresh_row(self.grid.GetNumberRows()-1)
self.handler.refresh_powers()
dlg.Destroy()
@@ -3323,8 +3241,8 @@
for i in range(rows):
if self.grid.IsInSelection(i,0):
self.grid.DeleteRows(i)
- self.master_dom.removeChild(self.n_list[i])
- self.n_list = self.master_dom.getElementsByTagName('weapon')
+ self.xml.remove(self.n_list[i])
+ self.n_list = self.xml.findall('weapon')
self.handler.refresh_powers()
def on_refresh_powers( self, evt ):
@@ -3380,25 +3298,25 @@
#m 1.6010 rearanged everything below to "return html_str"
html_str += " "
html_str += "Max: | "
- html_str += ""+self.master_dom.getAttribute('max1')+" | "
+ html_str += ""+self.xml.get('max1')+" | "
html_str += "Max Talents/day: | "
- html_str += ""+self.master_dom.getAttribute('maxfree')+" | "
+ html_str += ""+self.xml.get('maxfree')+" | "
html_str += " "
html_str += "Current: | "
- html_str += ""+self.master_dom.getAttribute('current1')+" | "
+ html_str += ""+self.xml.get('current1')+" | "
html_str += "Current Talents/day: | "
- html_str += ""+self.master_dom.getAttribute('free')+" | "
+ html_str += ""+self.xml.get('free')+" | "
html_str += " "
return html_str
def get_char_pp( self, attr ):
- pp = self.master_dom.getAttribute(attr)
+ pp = self.xml.get(attr)
#print "dnd3epp -get_char_pp: attr,pp",attr,pp
return pp
def set_char_pp( self, attr, evl ):
qSub = str(evl) #a 1.5014 must force it to be a string for next call.
- self.master_dom.setAttribute(attr, qSub)
+ self.xml.set(attr, qSub)
#This function needs to be looked at the idea is to refresh the power panel
#But it causes a seg fault when you refresh from powers -mgt
#if self.ppPanel: #a 1.5015
@@ -3412,33 +3330,33 @@
#a 1.5002 we need the functional parent, not the invoking parent.
self.hparent.ppPanel=self #a 1.5xx
- pname = handler.master_dom.setAttribute("name", 'PowerPoints')
+ pname = handler.xml.set("name", 'PowerPoints')
self.sizer = wx.FlexGridSizer(2, 4, 2, 2) # rows, cols, hgap, vgap
- self.master_dom = handler.master_dom
+ self.xml = handler.xml
self.static1= wx.StaticText(self, -1, "PP Current:") #a 1.5015
self.dyn1= wx.TextCtrl(self, PP_CUR,
- self.master_dom.getAttribute('current1')) #a 1.5015
+ self.xml.get('current1')) #a 1.5015
self.dyn3= wx.TextCtrl(self, PP_FRE,
- self.master_dom.getAttribute('free')) #a 1.5015
+ self.xml.get('free')) #a 1.5015
# self.sizer.AddMany([ (wx.StaticText(self, -1, "PP Current:"), #d 1.5015
# 0, wx.ALIGN_CENTER_VERTICAL),
# (wx.TextCtrl(self, PP_CUR, #d 1.5015
-# self.master_dom.getAttribute('current1')), 0, wx.EXPAND),
+# self.xml.get('current1')), 0, wx.EXPAND),
self.sizer.AddMany([ (self.static1, 0, wx.ALIGN_CENTER_VERTICAL),
(self.dyn1, 0, wx.EXPAND),
(wx.StaticText(self, -1, "PP Max:"), 0, wx.ALIGN_CENTER_VERTICAL),
(wx.TextCtrl(self, PP_MAX,
- self.master_dom.getAttribute('max1')), 0, wx.EXPAND),
+ self.xml.get('max1')), 0, wx.EXPAND),
(wx.StaticText(self, -1, "Current Free Talants per day:"),
0, wx.ALIGN_CENTER_VERTICAL),
(self.dyn3, 0, wx.EXPAND), #a 1.5015
# (wx.TextCtrl(self, PP_FRE,
-# self.master_dom.getAttribute('free')), 0, wx.EXPAND),#d 1.5015
+# self.xml.get('free')), 0, wx.EXPAND),#d 1.5015
(wx.StaticText(self, -1, "Max Free Talants per day:"),
0, wx.ALIGN_CENTER_VERTICAL),
(wx.TextCtrl(self, PP_MFRE,
- self.master_dom.getAttribute('maxfree')), 0, wx.EXPAND),
+ self.xml.get('maxfree')), 0, wx.EXPAND),
])
self.sizer.AddGrowableCol(1)
@@ -3455,13 +3373,13 @@
def on_text(self,evt):
id = evt.GetId()
if id == PP_CUR:
- self.master_dom.setAttribute('current1',evt.GetString())
+ self.xml.set('current1',evt.GetString())
elif id == PP_MAX:
- self.master_dom.setAttribute('max1',evt.GetString())
+ self.xml.set('max1',evt.GetString())
elif id == PP_FRE:
- self.master_dom.setAttribute('free',evt.GetString())
+ self.xml.set('free',evt.GetString())
elif id == PP_MFRE:
- self.master_dom.setAttribute('maxfree',evt.GetString())
+ self.xml.set('maxfree',evt.GetString())
def on_size(self,evt):
s = self.GetClientSizeTuple()
diff -r 174658f839c0 -r 8827271fbe1b orpg/main.py
--- a/orpg/main.py Sun Nov 01 01:12:50 2009 -0600
+++ b/orpg/main.py Sun Nov 01 11:36:14 2009 -0600
@@ -58,11 +58,10 @@
from orpg.tools.orpg_settings import settings
from orpg.tools.validate import validate
from orpg.tools.passtool import PassTool
-from orpg.tools.orpg_log import logger, crash
-from orpg.tools.decorators import debugging
+from orpg.tools.orpg_log import logger, crash, debug
from orpg.tools.metamenus import MenuBarEx
-from xml.etree.ElementTree import ElementTree, Element, iselement
+from xml.etree.ElementTree import ElementTree, Element, parse
from xml.etree.ElementTree import fromstring, tostring
from orpg.orpg_xml import xml #to be replaced by etree
@@ -73,7 +72,7 @@
class orpgFrame(wx.Frame):
- @debugging
+
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, wx.Point(100, 100), wx.Size(600,420), style=wx.DEFAULT_FRAME_STYLE)
self.validate = component.get("validate")
@@ -143,24 +142,24 @@
logger.debug("debugger window")
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
- @debugging
+
def post_show_init(self):
"""Some Actions need to be done after the main fram is drawn"""
self.players.size_cols()
- @debugging
+
def get_activeplugins(self):
try: tmp = self.pluginsFrame.get_activeplugins()
except: tmp = {}
return tmp
- @debugging
+
def get_startplugins(self):
try: tmp = self.pluginsFrame.get_startplugins()
except: tmp = {}
return tmp
- @debugging
+
def on_password_signal(self,signal,type,id,data):
try:
msg = ["DEBUG: password response= ",
@@ -182,7 +181,7 @@
else: pass
except: traceback.print_exc()
- @debugging
+
def build_menu(self):
menu = \
[[
@@ -300,7 +299,7 @@
## All Menu Events
#################################
#Tab Styles Menus
- @debugging
+
def SetTabStyles(self, *args, **kwargs):
tabtheme = settings.get('TabTheme') #This change is stable. TaS.
@@ -354,18 +353,18 @@
if textColor != None: wnd.SetNonActiveTabTextColour(textColor)
wnd.Refresh()
- @debugging
+
def OnMB_OpenRPGNewMap(self):
pass #Not Implemented yet!
- @debugging
+
def OnMB_OpenRPGTabStylesSlantedColorful(self):
if self.mainmenu.GetMenuState("OpenRPGTabStylesSlantedColorful"):
settings.change('TabTheme', 'slanted&colorful')
self.SetTabStyles("OpenRPGTabStylesSlantedColorful", FNB.FNB_VC8|FNB.FNB_COLORFUL_TABS)
else: self.mainmenu.SetMenuState("OpenRPGTabStylesSlantedColorful", True)
- @debugging
+
def OnMB_OpenRPGTabStylesSlantedBlackandWhite(self):
if self.mainmenu.GetMenuState("OpenRPGTabStylesSlantedBlackandWhite"):
settings.change('TabTheme', 'slanted&bw')
@@ -373,7 +372,7 @@
FNB.FNB_VC8, graidentTo=wx.WHITE, graidentFrom=wx.WHITE, textColor=wx.BLACK)
else: self.mainmenu.SetMenuState("OpenRPGTabStylesSlantedBlackandWhite", True)
- @debugging
+
def OnMB_OpenRPGTabStylesSlantedAqua(self):
if self.mainmenu.GetMenuState("OpenRPGTabStylesSlantedAqua"):
settings.change('TabTheme', 'slanted&aqua')
@@ -381,7 +380,7 @@
graidentTo=wx.Color(0, 128, 255), graidentFrom=wx.WHITE, textColor=wx.BLACK)
else: self.mainmenu.SetMenuState("OpenRPGTabStylesSlantedAqua", True)
- @debugging
+
def OnMB_OpenRPGTabStylesSlantedCustom(self):
if self.mainmenu.GetMenuState("OpenRPGTabStylesSlantedCustom"):
settings.change('TabTheme', 'customslant')
@@ -398,7 +397,7 @@
textColor=wx.Color(tred, tgreen, tblue))
else: self.mainmenu.SetMenuState("OpenRPGTabStylesSlantedCustom", True)
- @debugging
+
def OnMB_OpenRPGTabStylesFlatBlackandWhite(self):
if self.mainmenu.GetMenuState("OpenRPGTabStylesFlatBlackandWhite"):
settings.change('TabTheme', 'flat&bw')
@@ -406,7 +405,7 @@
graidentTo=wx.WHITE, graidentFrom=wx.WHITE, textColor=wx.BLACK)
else: self.mainmenu.SetMenuState("OpenRPGTabStylesFlatBlackandWhite", True)
- @debugging
+
def OnMB_OpenRPGTabStylesFlatAqua(self):
if self.mainmenu.GetMenuState("OpenRPGTabStylesFlatAqua"):
settings.change('TabTheme', 'flat&aqua')
@@ -414,7 +413,7 @@
graidentTo=wx.Color(0, 128, 255), graidentFrom=wx.WHITE, textColor=wx.BLACK)
else: self.mainmenu.SetMenuState("OpenRPGTabStylesFlatAqua", True)
- @debugging
+
def OnMB_OpenRPGTabStylesFlatCustom(self):
if self.mainmenu.GetMenuState("OpenRPGTabStylesFlatCustom"):
settings.change('TabTheme', 'customflat')
@@ -432,7 +431,7 @@
else: self.mainmenu.SetMenuState("OpenRPGTabStylesFlatCustom", True)
#Window Menu
- @debugging
+
def OnMB_WindowsMenu(self, event):
menuid = event.GetId()
name = self.mainwindows[menuid]
@@ -445,7 +444,7 @@
self._mgr.Update()
#OpenRPG Menu
- @debugging
+
def OnMB_OpenRPGSettings(self):
dlg = orpg.tools.orpg_settings.orpgSettingsWnd(self)
dlg.Centre()
@@ -455,18 +454,18 @@
self.OnCloseWindow(0)
#Game Server Menu
- @debugging
+
def OnMB_GameServerBrowseServers(self):
if self._mgr.GetPane("Browse Server Window").IsShown() == True: self._mgr.GetPane("Browse Server Window").Hide()
else: self._mgr.GetPane("Browse Server Window").Show()
self._mgr.Update()
- @debugging
+
def OnMB_GameServerServerHeartbeat(self):
if self.mainmenu.GetMenuState("GameServerServerHeartbeat"): settings.change('Heartbeat', '1')
else: settings.change('Heartbeat', '0')
- @debugging
+
def OnMB_GameServerStartServer(self):
start_dialog = wx.ProgressDialog( "Server Loading", "Server Loading, Please Wait...", 1, self )
# Spawn the new process and close the stdout handle from it
@@ -485,23 +484,23 @@
start_dialog.Destroy()
# Tools Menu
- @debugging
+
def OnMB_PluginControlPanel(self, evt):
if self.pluginsFrame.IsShown() == True: self.pluginsFrame.Hide()
else: self.pluginsFrame.Show()
- @debugging
+
def OnMB_UpdateManagerPanel(self, evt):
if self.updateMana.IsShown() == True: self.updateMana.Hide()
else: self.updateMana.Show()
- @debugging
+
def OnMB_DebugConsole(self, evt):
self.TraipseSuiteWarnCleanup('debug') ### Beta ###
if self.debugger.IsShown() == True: self.debugger.Hide()
else: self.debugger.Show()
- @debugging
+
def OnMB_ToolsLoggingLevelDebug(self):
lvl = logger.log_level
if self.mainmenu.GetMenuState("ToolsLoggingLevelDebug"): lvl |= ORPG_DEBUG
@@ -509,7 +508,7 @@
logger.log_level = lvl
settings.set('LoggingLevel', lvl)
- @debugging
+
def OnMB_ToolsLoggingLevelNote(self):
lvl = logger.log_level
if self.mainmenu.GetMenuState("ToolsLoggingLevelNote"): lvl |= ORPG_DEBUG
@@ -517,7 +516,7 @@
logger.log_level = lvl
settings.set('LoggingLevel', lvl)
- @debugging
+
def OnMB_ToolsLoggingLevelInfo(self):
lvl = logger.log_level
if self.mainmenu.GetMenuState("ToolsLoggingLevelInfo"): lvl |= ORPG_INFO
@@ -525,7 +524,7 @@
logger.log_level = lvl
settings.set('LoggingLevel', lvl)
- @debugging
+
def OnMB_ToolsLoggingLevelGeneral(self):
lvl = logger.log_level
if self.mainmenu.GetMenuState("ToolsLoggingLevelGeneral"): lvl |= ORPG_GENERAL
@@ -533,12 +532,12 @@
logger.log_level = lvl
settings.set('LoggingLevel', lvl)
- @debugging
+
def OnMB_ToolsPasswordManager(self):
if self.mainmenu.GetMenuState("ToolsPasswordManager"): self.password_manager.Enable()
else: self.password_manager.Disable()
- @debugging
+
def OnMB_ToolsStatusBar(self):
if self._mgr.GetPane("Status Window").IsShown() == True:
self.mainmenu.SetMenuState("ToolsStatusBar", False)
@@ -548,7 +547,7 @@
self._mgr.GetPane("Status Window").Show()
self._mgr.Update()
- @debugging
+
def OnMB_ToolsSoundToolbar(self):
if self._mgr.GetPane("Sound Control Toolbar").IsShown() == True:
self.mainmenu.SetMenuState("ToolsSoundToolbar", False)
@@ -558,7 +557,7 @@
self._mgr.GetPane("Sound Control Toolbar").Show()
self._mgr.Update()
- @debugging
+
def OnMB_ToolsDiceBar(self):
if self._mgr.GetPane("Dice Tool Bar").IsShown() == True:
self.mainmenu.SetMenuState("ToolsDiceBar", False)
@@ -568,7 +567,7 @@
self._mgr.GetPane("Dice Tool Bar").Show()
self._mgr.Update()
- @debugging
+
def OnMB_ToolsMapBar(self):
if self._mgr.GetPane("Map Tool Bar").IsShown() == True:
self.mainmenu.SetMenuState("ToolsMapBar", False)
@@ -579,22 +578,22 @@
self._mgr.Update()
#Help Menu #Needs a custom Dialog because it is ugly on Windows
- @debugging
+
def OnMB_HelpAbout(self):
if self.AboutORPG.IsShown() == True: self.AboutORPG.Hide()
else: self.AboutORPG.Show()
- @debugging
+
def OnMB_HelpOnlineUserGuide(self):
wb = webbrowser.get()
wb.open("http://www.assembla.com/wiki/show/traipse/User_Manual")
- @debugging
+
def OnMB_HelpChangeLog(self):
wb = webbrowser.get()
wb.open("http://www.assembla.com/spaces/milestones/index/traipse?spaces_tool_id=Milestones")
- @debugging
+
def OnMB_HelpReportaBug(self):
wb = webbrowser.get()
wb.open("http://www.assembla.com/spaces/tickets/index/traipse_dev?spaces_tool_id=Tickets")
@@ -603,24 +602,14 @@
#################################
## Build the GUI
#################################
- @debugging
+
def build_gui(self):
self.Freeze()
self.validate.config_file("layout.xml","default_layout.xml")
- filename = dir_struct["user"] + "layout.xml"
- temp_file = open(filename)
- txt = temp_file.read()
- xml_dom = xml.parseXml(txt)._get_documentElement()
- temp_file.close()
+ layout = parse(dir_struct["user"] + "layout.xml")
+ xml_dom = layout.getroot()
- """ Would a component work better?
- etree = ElementTree()
- with open(dir_struct['user'] + 'layout.xml') as f:
- etree.parse(f)
-
- base = etree.getroot()
- """
self.windowsmenu = wx.Menu()
self.mainwindows = {}
@@ -632,11 +621,11 @@
component.add("plugins", self.get_activeplugins())
component.add("startplugs", self.get_startplugins())
logger.debug("Menu Created")
- h = int(xml_dom.getAttribute("height"))
- w = int(xml_dom.getAttribute("width"))
- posx = int(xml_dom.getAttribute("posx"))
- posy = int(xml_dom.getAttribute("posy"))
- maximized = int(xml_dom.getAttribute("maximized"))
+ h = int(xml_dom.get("height"))
+ w = int(xml_dom.get("width"))
+ posx = int(xml_dom.get("posx"))
+ posy = int(xml_dom.get("posy"))
+ maximized = int(xml_dom.get("maximized"))
self.SetDimensions(posx, posy, w, h)
logger.debug("Dimensions Set")
@@ -645,22 +634,22 @@
self.updateMana = upmana.updatemana.updaterFrame(self,
"OpenRPG Update Manager Beta 0.8", component, self.manifest, True)
logger.debug("Menu Created")
- h = int(xml_dom.getAttribute("height"))
- w = int(xml_dom.getAttribute("width"))
- posx = int(xml_dom.getAttribute("posx"))
- posy = int(xml_dom.getAttribute("posy"))
- maximized = int(xml_dom.getAttribute("maximized"))
+ h = int(xml_dom.get("height"))
+ w = int(xml_dom.get("width"))
+ posx = int(xml_dom.get("posx"))
+ posy = int(xml_dom.get("posy"))
+ maximized = int(xml_dom.get("maximized"))
self.SetDimensions(posx, posy, w, h)
logger.debug("Dimensions Set")
# Debug Console
self.debugger = orpg.tools.orpg_log.DebugConsole(self)
logger.debug("Menu Created")
- h = int(xml_dom.getAttribute("height"))
- w = int(xml_dom.getAttribute("width"))
- posx = int(xml_dom.getAttribute("posx"))
- posy = int(xml_dom.getAttribute("posy"))
- maximized = int(xml_dom.getAttribute("maximized"))
+ h = int(xml_dom.get("height"))
+ w = int(xml_dom.get("width"))
+ posx = int(xml_dom.get("posx"))
+ posy = int(xml_dom.get("posy"))
+ maximized = int(xml_dom.get("maximized"))
self.SetDimensions(posx, posy, w, h)
logger.debug("Dimensions Set")
@@ -677,7 +666,7 @@
wndinfo.ToolbarPane()
wndinfo.Hide()
self._mgr.AddPane(self.sound_player, wndinfo)
- children = xml_dom._get_childNodes()
+ children = xml_dom.getchildren()
for c in children: self.build_window(c, self)
# status window
@@ -753,12 +742,11 @@
logger.debug("AUI Bindings Done")
#Load the layout if one exists
- layout = xml_dom.getElementsByTagName("DockLayout")
+ layout = xml_dom.findall("DockLayout")
try:
textnode = xml.safe_get_text_node(layout[0])
- self._mgr.LoadPerspective(textnode._get_nodeValue())
+ self._mgr.LoadPerspective(textnode.text)
except: pass
- xml_dom.unlink()
logger.debug("Perspective Loaded")
self._mgr.GetPane("Browse Server Window").Hide()
self._mgr.Update()
@@ -766,16 +754,16 @@
logger.debug("GUI is all created")
self.Thaw()
- @debugging
+
def do_tab_window(self,xml_dom,parent_wnd):
#def do_tab_window(self, etreeEl, parent_wnd):
# if container window loop through childern and do a recursive call
temp_wnd = orpgTabberWnd(parent_wnd, style=FNB.FNB_ALLOW_FOREIGN_DND)
- children = xml_dom._get_childNodes()
+ children = xml_dom.getchildren()
for c in children:
wnd = self.build_window(c,temp_wnd)
- name = c.getAttribute("name")
+ name = c.get("name")
temp_wnd.AddPage(wnd, name, False)
"""
@@ -785,17 +773,17 @@
"""
return temp_wnd
- @debugging
+
def build_window(self, xml_dom, parent_wnd):
- name = xml_dom._get_nodeName()
+ name = xml_dom.tag
if name == "DockLayout" or name == "dock": return
- dirc = xml_dom.getAttribute("direction") #should NOT use dir, it is a built in function.
- pos = xml_dom.getAttribute("pos")
- height = xml_dom.getAttribute("height")
- width = xml_dom.getAttribute("width")
- cap = xml_dom.getAttribute("caption")
- dockable = xml_dom.getAttribute("dockable")
- layer = xml_dom.getAttribute("layer")
+ dirc = xml_dom.get("direction") #should NOT use dir, it is a built in function.
+ pos = xml_dom.get("pos")
+ height = xml_dom.get("height")
+ width = xml_dom.get("width")
+ cap = xml_dom.get("caption")
+ dockable = xml_dom.get("dockable")
+ layer = xml_dom.get("layer")
try: layer = int(layer); dockable = int(dockable)
except: layer = 0; dockable = 1
@@ -859,7 +847,7 @@
self._mgr.AddPane(temp_wnd, wndinfo)
return temp_wnd
- @debugging
+
def onPaneClose(self, evt):
pane = evt.GetPane()
#Arbitrary If ELIF fix. Items had incorrect ID's set. Finding correct ID will fix it for the iteration.
@@ -875,42 +863,39 @@
evt.Skip()
self._mgr.Update()
- @debugging
+
def saveLayout(self):
- filename = dir_struct["user"] + "layout.xml"
- temp_file = open(filename)
- txt = temp_file.read()
- xml_dom = xml.parseXml(txt)._get_documentElement()
- temp_file.close()
+ layout = parse(dir_struct["user"] + "layout.xml")
+ xml_dom = layout.getroot()
(x_size,y_size) = self.GetClientSize()
(x_pos,y_pos) = self.GetPositionTuple()
if self.IsMaximized(): max = 1
else: max = 0
- xml_dom.setAttribute("height", str(y_size))
- xml_dom.setAttribute("width", str(x_size))
- xml_dom.setAttribute("posx", str(x_pos))
- xml_dom.setAttribute("posy", str(y_pos))
- xml_dom.setAttribute("maximized", str(max))
- layout = xml_dom.getElementsByTagName("DockLayout")
+ xml_dom.set("height", str(y_size))
+ xml_dom.set("width", str(x_size))
+ xml_dom.set("posx", str(x_pos))
+ xml_dom.set("posy", str(y_pos))
+ xml_dom.set("maximized", str(max))
+ layout = xml_dom.findall("DockLayout")
try:
textnode = xml.safe_get_text_node(layout[0])
textnode._set_nodeValue(str(self._mgr.SavePerspective()))
except:
elem = minidom.Element('DockLayout')
- elem.setAttribute("DO_NO_EDIT","True")
+ elem.set("DO_NO_EDIT","True")
textnode = xml.safe_get_text_node(elem)
textnode._set_nodeValue(str(self._mgr.SavePerspective()))
- xml_dom.appendChild(elem)
+ xml_dom.append(elem)
temp_file = open(filename, "w")
temp_file.write(xml_dom.toxml(1))
temp_file.close()
- @debugging
+
def build_hotkeys(self):
self.mainmenu.accel.xaccel.extend(self.chat.get_hot_keys())
self.mainmenu.accel.xaccel.extend(self.map.get_hot_keys())
- @debugging
+
def start_timer(self):
self.poll_timer.Start(100)
s = component.get('settings')
@@ -918,12 +903,12 @@
self.ping_timer.Start(1000*60)
logger.debug("starting heartbeat...", True)
- @debugging
+
def kill_mplay_session(self):
self.game_name = ""
self.session.start_disconnect()
- @debugging
+
def quit_game(self, evt):
dlg = wx.MessageDialog(self,"Exit gaming session?","Game Session",wx.YES_NO)
if dlg.ShowModal() == wx.ID_YES:
@@ -931,13 +916,13 @@
dlg.Destroy()
self.kill_mplay_session()
- @debugging
+
def on_status_event(self, evt):
id = evt.get_id()
status = evt.get_data()
if id == orpg.networking.mplay_client.STATUS_SET_URL: self.status.set_url(status)
- @debugging
+
def on_player_event(self, evt):
id = evt.get_id()
player = evt.get_data()
@@ -953,20 +938,20 @@
self.players.update_player(player)
self.players.Refresh()
- @debugging
+
def on_group_event(self, evt):
id = evt.get_id()
data = evt.get_data()
if id == orpg.networking.mplay_client.GROUP_NEW: self.gs.add_room(data)
elif id == orpg.networking.mplay_client.GROUP_DEL:
- self.password_manager.RemoveGroupData(data)
+ # self.password_manager.RemoveGroupData(data) #Removed for debugging.
self.gs.del_room(data)
elif id == orpg.networking.mplay_client.GROUP_UPDATE: self.gs.update_room(data)
- @debugging
+
def on_receive(self, data, player):
# see if we are ignoring this user
- (ignore_id,ignore_name) = self.session.get_ignore_list()
+ (ignore_id, ignore_name) = self.session.get_ignore_list()
for m in ignore_id:
if m == player[2]: logger.debug("ignoring message from player:" + player[0], True); return
@@ -992,7 +977,7 @@
wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
if dlg.ShowModal() == wx.ID_YES:
dlg.Destroy()
- self.tree.on_receive_data(data,player)
+ self.tree.on_receive_data(data, player)
self.chat.InfoPost(display_name + " has sent you a tree node...")
### Core ### to be milked in later.
#TODO: Fix game tree to accepts elements
@@ -1006,14 +991,14 @@
elif child.tag == 'chat':
msg = orpg.chat.chat_msg.chat_msg(data)
- self.chat.post_incoming_msg(msg,player)
+ self.chat.post_incoming_msg(msg, player)
### Core ### to be milked in later
#msg = orpg.chat.chat_msg.chat_msg()
#msg.takedom(child)
#self.chat.post_incoming_msg(msg, player)
- @debugging
+
def on_mplay_event(self, evt):
id = evt.get_id()
if id == orpg.networking.mplay_client.MPLAY_CONNECTED:
@@ -1040,21 +1025,20 @@
elif id == orpg.networking.mplay_client.MPLAY_GROUP_CHANGE:
group = evt.get_data()
- print 'main ', group
self.chat.InfoPost("Moving to room '"+group[1]+"'..")
if self.gs : self.gs.set_cur_room_text(group[1])
self.players.reset()
elif id == orpg.networking.mplay_client.MPLAY_GROUP_CHANGE_F:
self.chat.SystemPost("Room access denied!")
- @debugging
+
def OnCloseWindow(self, event):
dlg = wx.MessageDialog(self, "Quit OpenRPG?", "OpenRPG", wx.YES_NO)
if dlg.ShowModal() == wx.ID_YES:
dlg.Destroy()
self.closed_confirmed()
- @debugging
+
def closed_confirmed(self):
self.activeplugins = component.get('plugins')
self.aliaslib.OnMB_FileSave(None)
@@ -1183,7 +1167,7 @@
## Application class
########################################
class orpgSplashScreen(wx.SplashScreen):
- @debugging
+
def __init__(self, parent, bitmapfile, duration, callback):
wx.SplashScreen.__init__(self, wx.Bitmap(bitmapfile),
wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT, duration, None, -1)
@@ -1192,18 +1176,14 @@
self.Bind(wx.EVT_CLOSE, self.callback)
class orpgApp(wx.App):
- @debugging
+
def OnInit(self):
-
component.add('log', logger)
component.add('xml', xml)
component.add('settings', settings)
component.add('validate', validate)
component.add("tabbedWindows", [])
- logger._set_log_level = int(settings.get('LoggingLevel'))
- logger._set_log_to_console(False)
-
#Update Manager
self.manifest = manifest.ManifestChanges()
@@ -1215,13 +1195,13 @@
wx.Yield()
return True
- @debugging
+
def OnKeyPress(self, evt):
#Event handler
if evt.AltDown() and evt.CmdDown() and evt.KeyCode == ord('I'): self.ShowShell()
else: evt.Skip()
- @debugging
+
def ShowShell(self):
#Show the PyCrust window.
if not self._crust:
@@ -1231,7 +1211,7 @@
self._crust.shell.interp.locals['win'] = win
self._crust.Show()
- @debugging
+
def AfterSplash(self,evt):
if not self.called:
self.splash.Hide()
@@ -1246,7 +1226,7 @@
wx.CallAfter(self.splash.Close)
return True
- @debugging
+
def OnExit_CleanUp(self):
logger.debug("Preforming cleanup\n")
try: del os.environ["OPENRPG_BASE"]
@@ -1256,7 +1236,7 @@
try: os.remove(os.environ["OPENRPG_BASE"] + os.sep + 'orpg' + os.sep + 'dirpath' + os.sep + 'approot.pyc')
except: pass
- @debugging
+
def OnExit(self):
self.OnExit_CleanUp()
#Exit
diff -r 174658f839c0 -r 8827271fbe1b orpg/networking/gsclient.py
--- a/orpg/networking/gsclient.py Sun Nov 01 01:12:50 2009 -0600
+++ b/orpg/networking/gsclient.py Sun Nov 01 11:36:14 2009 -0600
@@ -29,15 +29,17 @@
from __future__ import with_statement
__version__ = "$Id: gsclient.py,v 1.53 2007/10/25 21:49:34 digitalxero Exp $"
+import meta_server_lib
+#import orpg.tools.orpg_settings
+import orpg.tools.rgbhex
+import traceback
+
from orpg.dirpath import dir_struct
from orpg.orpg_windows import *
-import meta_server_lib
-import orpg.tools.orpg_settings
+from orpg.tools.validate import validate
+from orpg.orpgCore import component
from orpg.tools.orpg_settings import settings
-import orpg.tools.rgbhex
-from orpg.orpgCore import component
-import traceback
-from orpg.tools.validate import validate
+from orpg.tools.orpg_log import debug
from xml.etree.ElementTree import ElementTree, Element
from xml.etree.ElementTree import fromstring, tostring
@@ -82,13 +84,13 @@
return 0
class game_server_panel(wx.Panel):
+ ##debug()
def __init__(self,parent):
wx.Panel.__init__(self, parent, -1)
self.parent = parent
self.password_manager = component.get('password_manager')
self.frame = component.get('frame')
self.session = component.get('session')
- #self.xml = component.get('xml') #Not used??
self.serverNameSet = 0
self.last_motd = ""
self.buttons = {}
@@ -97,7 +99,7 @@
self.build_ctrls()
self.bookmarks()
self.refresh_server_list()
- self.refresh_room_list()
+ self.refresh_room_list()
self.build_bookmark_menu()
def build_ctrls(self):
@@ -353,7 +355,8 @@
self.cur_server_index = -1
evt.Skip()
- def add_room(self,data):
+ def add_room(self, data):
+ #debug()
i = self.room_list.GetItemCount()
if (data[2]=="1") or (data[2]=="True"): pwd="yes"
else: pwd="no"
@@ -364,11 +367,12 @@
self.refresh_room_list()
def del_room(self, data):
+ #debug(data)
i = self.room_list.FindItemData(-1, int(data[0]))
self.room_list.DeleteItem(i)
self.refresh_room_list()
- def update_room(self,data):
+ def update_room(self, data):
i = self.room_list.FindItemData(-1,int(data[0]))
if data[2]=="1" : pwd="yes"
else: pwd="no"
@@ -377,15 +381,15 @@
self.room_list.SetStringItem(i,2,pwd)
self.refresh_room_list()
- def set_cur_room_text(self,name):
+ def set_cur_room_text(self, name):
pass
#self.texts["cur_room"].SetLabel(name)
#self.sizers["room"].Layout()
- def set_lobbybutton(self,allow):
+ def set_lobbybutton(self, allow):
self.buttons['gs_join_lobby'].Enable(allow)
- def set_connected(self,connected):
+ def set_connected(self, connected):
self.buttons['gs_connect'].Enable(not connected)
self.buttons['gs_disconnect'].Enable(connected)
self.buttons['gs_join_room'].Enable(connected)
@@ -435,7 +439,6 @@
def gs_close(self, evt):
self.parent.OnMB_GameServerBrowseServers()
-
def refresh_room_list(self):
self.room_list.DeleteAllItems()
address = self.texts["address"].GetValue()
@@ -483,7 +486,7 @@
part = 0
partLength = 1.0/length
for n in node_list:
- #if n.hasAttribute('id') and n.hasAttribute('name') and n.hasAttribute('num_users') and n.hasAttribute('address') and n.hasAttribute('port'):
+ #if n.get('id') and n.get('name') and n.get('num_users') and n.get('address') and n.get('port'):
self.svrList.append(server_instance(n.get('id'), n.get('name'),
n.get('num_users'), n.get('address'),
n.get('port')))
@@ -626,7 +629,7 @@
# [START] Snowdog: Updated Game Server Window 12/02
#---------------------------------------------------------
- def on_size(self,evt):
+ def on_size(self, evt):
# set column widths for room list
# set column widths for server list
pass
diff -r 174658f839c0 -r 8827271fbe1b orpg/networking/meta_server_lib.py
--- a/orpg/networking/meta_server_lib.py Sun Nov 01 01:12:50 2009 -0600
+++ b/orpg/networking/meta_server_lib.py Sun Nov 01 11:36:14 2009 -0600
@@ -37,22 +37,22 @@
from orpg.orpgCore import component
from orpg.tools.validate import validate
from orpg.dirpath import dir_struct
-import urllib
-import orpg.minidom
+
+import urllib, time, sys, traceback, re
+#import orpg.minidom
+
from threading import *
-import time
-import sys
-import random
-import traceback
-import re
+from random import uniform
+from urllib import urlopen, urlencode
+from orpg.tools.orpg_log import debug
from xml.etree.ElementTree import Element, fromstring
metacache_lock = RLock()
-def get_server_dom(data=None,path=None):
+def get_server_dom(data=None,path=None, string=False):
# post data at server and get the resulting DOM
-
+ #debug()
if path == None:
# get meta server URI
path = getMetaServerBaseURL()
@@ -64,7 +64,7 @@
print "=========================================="
print data
print
- file = urllib.urlopen(path, data)
+ file = urlopen(path, data)
data = file.read()
file.close()
@@ -81,15 +81,17 @@
print
# build dom
etreeEl = data
- return etreeEl
+ if not string: return fromstring(etreeEl)
+ else: return etreeEl
def post_server_data(name, realHostName=None):
- if realHostName: data = urllib.urlencode({"server_data[name]":name,
+ #debug()
+ if realHostName: data = urlencode({"server_data[name]":name,
"server_data[version]":PROTOCOL_VERSION,
"act":"new",
"REMOTE_ADDR": realHostName })
# print "Letting meta server decide the hostname to list..."
- else: data = urllib.urlencode({"server_data[name]":name,
+ else: data = urlencode({"server_data[name]":name,
"server_data[version]":PROTOCOL_VERSION,
"act":"new"})
path = component.get('settings').get('MetaServerBaseURL') #getMetaServerBaseURL()
@@ -97,16 +99,18 @@
return int(etreeEl.get('id'))
def post_failed_connection(id,meta=None,address=None,port=None):
+ #debug((meta, address, port))
# For now, turning this off. This needs to be re-vamped for
# handling multiple Metas.
return 0
- #data = urllib.urlencode({"id":id,"act":"failed"});
+ #data = urlencode({"id":id,"act":"failed"});
#xml_dom = get_server_dom(data)
#ret_val = int(xml_dom.getAttribute("return"))
#return ret_val
def remove_server(id):
- data = urllib.urlencode({"id":id,"act":"del"});
+ #debug(id)
+ data = urlencode({"id":id,"act":"del"});
etreeEl = get_server_dom(data)
return int(etreeEl.get("return"))
@@ -132,7 +136,7 @@
def get_server_list(versions = None, sort_by="start"):
- data = urllib.urlencode({"version":PROTOCOL_VERSION,"ports":"%"})
+ data = urlencode({"version":PROTOCOL_VERSION,"ports":"%"})
all_metas = getMetaServers(versions, 1) # get the list of metas
base_meta = getMetaServerBaseURL()
@@ -148,7 +152,7 @@
except: bad_meta = 1 #print "Trouble getting servers from " + meta + "..."
if bad_meta: continue
if base_meta == meta: updateMetaCache(xml_dom) #print "This is our base meta: " + meta
- node_list = fromstring(xml_dom).findall('server')
+ node_list = xml_dom.findall('server')
if len(node_list): # if there are entries in the node list
# otherwise, just loop to next meta
@@ -223,7 +227,7 @@
"""This code will allow for a list of metas to be created. Future developement will more integrate the list of metas"""
if path != None:
metas = []
- data = urllib.urlencode({"version":PROTOCOL_VERSION,"ports":"%"})
+ data = urlencode({"version":PROTOCOL_VERSION,"ports":"%"})
xml_dom = get_server_dom(data, path)
node_list = fromstring(xml_dom).findall('meta_server')
if len(node_list):
@@ -294,7 +298,7 @@
# if we have more than one and want a random one
elif pick_random:
if META_DEBUG: print "choosing random meta from: " + str(meta_names)
- i = int(random.uniform(0,len(meta_names)))
+ i = int(uniform(0,len(meta_names)))
#meta = meta_names[i]
meta_names = [meta_names[i]]
if META_DEBUG: print "using: " + str(meta_names)
@@ -470,7 +474,7 @@
if not self.isAlive(): # check to see if this thread is dead
return 1 # If so, return an error result
# Do the actual unregistering here
- data = urllib.urlencode( {"server_data[id]":self.id,
+ data = urlencode( {"server_data[id]":self.id,
"server_data[cookie]":self.cookie,
"server_data[version]":PROTOCOL_VERSION,
"act":"unregister"} )
@@ -493,6 +497,7 @@
finally: self.rlock.release()
def register(self, name=None, realHostName=None, num_users=None):
+ #debug((name, realHostName, num_users))
"""
Designed to handle the registration, both new and
repeated.
@@ -514,7 +519,7 @@
if realHostName: self.realHostName = realHostName
# build POST data
if self.realHostName:
- data = urllib.urlencode( {"server_data[id]":self.id,
+ data = urlencode( {"server_data[id]":self.id,
"server_data[cookie]":self.cookie,
"server_data[name]":self.name,
"server_data[port]":self.port,
@@ -524,7 +529,7 @@
"server_data[address]": self.realHostName } )
else:
if META_DEBUG: print "Letting meta server decide the hostname to list..."
- data = urllib.urlencode( {"server_data[id]":self.id,
+ data = urlencode( {"server_data[id]":self.id,
"server_data[cookie]":self.cookie,
"server_data[name]":self.name,
"server_data[port]":self.port,
@@ -532,7 +537,8 @@
"server_data[num_users]":self.num_users,
"act":"register"} )
try: # this POSTS the request and returns the result
- etreeEl = get_server_dom(data=data, path=self.path)
+ etreeEl = get_server_dom(data=data, path=self.path)
+ #debug(etreeEl)
except:
if META_DEBUG: print "Problem talking to server. Setting interval for retry ..."
if META_DEBUG: print data
@@ -554,6 +560,7 @@
# If there is a DOM returned ....
if etreeEl:
+ #debug(etreeEl)
# If there's an error, echo it to the console
if etreeEl.get("errmsg"):
print "Error durring registration: " + etreeEl.get("errmsg")
diff -r 174658f839c0 -r 8827271fbe1b orpg/networking/mplay_client.py
--- a/orpg/networking/mplay_client.py Sun Nov 01 01:12:50 2009 -0600
+++ b/orpg/networking/mplay_client.py Sun Nov 01 11:36:14 2009 -0600
@@ -31,26 +31,22 @@
### Alpha ###
##import orpg.minidom ## Deprecated. xml.parseXml calls minidom.parseString so it was superfluous and wasteful.
-import socket
-import Queue
-import thread
-import traceback
+import socket, Queue, thread, traceback, errno, os, time
+
from threading import Event, Lock
from xml.sax.saxutils import escape
from struct import pack, unpack, calcsize
from string import *
from orpg.orpg_version import CLIENT_STRING, PROTOCOL_VERSION, VERSION
-import errno
-import os
-import time
+
from orpg.orpgCore import component
from orpg.orpg_xml import xml
+from orpg.tools.orpg_log import debug
from xml.etree.ElementTree import ElementTree, Element, iselement
from xml.etree.ElementTree import fromstring, tostring
from xml.parsers.expat import ExpatError
-
try:
import bz2
cmpBZ2 = True
@@ -61,8 +57,7 @@
cmpZLIB = True
except: cmpZLIB = False
-
-# This should be configurable
+# Default, is configurable
OPENRPG_PORT = 9557
# We should be sending a length for each packet
@@ -97,7 +92,7 @@
return escape(data,{"\"":""})
class mplay_event:
- def __init__(self,id,data=None):
+ def __init__(self, id, data=None):
self.id = id
self.data = data
@@ -110,7 +105,6 @@
BOOT_MSG = "YoU ArE ThE WeAkEsT LiNk. GoOdByE."
class client_base:
-
# Player role definitions
def __init__(self):
self.outbox = Queue.Queue(0)
@@ -171,7 +165,6 @@
def recvThread( self, arg ):
"Receiving thread. This thread reads from the socket and writes to the data queue."
-
# Wait to be told it's okay to start running
self.startedEvent.wait()
@@ -201,7 +194,7 @@
def sendMsg( self, sock, msg ):
"""Very simple function that will properly encode and send a message to te
remote on the specified socket."""
-
+ #debug(log=False)
if self.useCompression and self.compressionType != None:
mpacket = self.compressionType.compress(msg)
lpacket = pack('!i', len(mpacket))
@@ -225,6 +218,7 @@
return sentm
def recvData( self, sock, readSize ):
+ #debug(log=False)
"""Simple socket receive method. This method will only return when the exact
byte count has been read from the connection, if remote terminates our
connection or we get some other socket exception."""
@@ -248,6 +242,7 @@
return data
def recvMsg(self, sock):
+ #debug()
"""This method now expects to receive a message having a 4-byte prefix length. It will ONLY read completed messages. In the event that the remote's connection is terminated, it will throw an exception which should allow for the caller to more gracefully handle this exception event.
Because we use strictly reading ONLY based on the length that is told to use, we no longer have to worry about partially adjusting for fragmented buffers starting somewhere within a buffer that we've read. Rather, it will get ONLY a whole message and nothing more. Everything else will remain buffered with the OS until we attempt to read the next complete message."""
@@ -265,6 +260,7 @@
return msgData
def initialize_threads(self):
+ #debug()
"Starts up our threads (2) and waits for them to make sure they are running!"
self.status = MPLAY_CONNECTED
self.sock.setblocking(1)
@@ -274,6 +270,7 @@
self.startedEvent.set()
def disconnect(self):
+ #debug()
self.set_status(MPLAY_DISCONNECTING)
self.log_msg("client stub " + self.ip +" disconnecting...")
self.log_msg("closing sockets...")
@@ -285,19 +282,20 @@
self.set_status(MPLAY_DISCONNECTED)
def reset(self,sock):
+ #debug()
self.disconnect()
self.sock = sock
self.initialize_threads()
def update_role(self,role):
+ #debug()
self.useroles = 1
self.role = role
def use_roles(self):
- if self.useroles:
- return 1
- else:
- return 0
+ #debug()
+ if self.useroles: return 1
+ else: return 0
def update_self_from_player(self, player):
try: (self.name, self.ip, self.id,
self.text_status, self.version,
@@ -309,9 +307,11 @@
client provided IP address to have much value. As such, we now label it as deprecated.
"""
def toxml(self, action):
+ #debug((myescape(self.name), self.name, self.role))
el = Element('player')
- el.set('name', myescape(self.name))
+ el.set('name', self.name)
el.set('action', action)
+ el.set('role', self.role)
el.set('id', self.id)
el.set('group_id', self.group_id)
el.set('ip', self.ip)
@@ -329,20 +329,22 @@
return tostring(el)
def log_msg(self,msg):
- if self.log_console:
- self.log_console(msg)
+ #debug(msg, log=False)
+ if self.log_console: self.log_console(msg)
def get_status(self):
+ #debug(log=False)
self.statLock.acquire()
status = self.status
self.statLock.release()
return status
def my_role(self):
- #Leaving this for testing.
+ #debug(self.role, log=False)
return self.role
def set_status(self,status):
+ #debug(status, log=False)
self.statLock.acquire()
self.status = status
self.statLock.release()
@@ -396,8 +398,10 @@
#
#========================================================================
class mplay_client(client_base):
+ #debug()
"mplay client"
def __init__(self,name,callbacks):
+ #debug(name)
client_base.__init__(self)
component.add('mp_client', self)
self.xml = component.get('xml')
@@ -427,13 +431,16 @@
return 0
def get_chat(self):
+ #debug()
return self.orpgFrame_callback.chat
def set_name(self,name):
+ #debug(name)
self.name = name
self.update()
def set_text_status(self, status):
+ #debug()
if self.text_status != status:
self.text_status = status
self.update()
@@ -596,6 +603,7 @@
self.outbox.put(tostring(el))
def get_role(self):
+ #debug((self.group_id, self.id, self.role))
el = Element('role')
el.set('action', 'get')
el.set('player', self.id)
@@ -603,7 +611,7 @@
self.outbox.put(tostring(el))
def set_role(self, player, role, pwd=""):
- print role; exit()
+ #debug(role)
el = Element('role')
el.set('action', 'set')
el.set('player', player)
@@ -646,7 +654,7 @@
el.set('from', self.id)
el.set('pwd', pwd)
el.set('group_id', str(group_id))
- print 'send join group ', str(group_id)
+
self.outbox.put(tostring(el))
def poll(self, evt=None):
@@ -737,7 +745,7 @@
def on_group(self, id, msg, etreeEl):
act = etreeEl.get("action")
group_data = (id, etreeEl.get("name"), etreeEl.get("pwd"), etreeEl.get("players"))
- if act == 'new' or 'update':
+ if act == ('new' or 'update'):
self.groups[id] = group_data
if act == 'update': self.on_group_event(mplay_event(GROUP_UPDATE, group_data))
elif act == 'new': self.on_group_event(mplay_event(GROUP_NEW, group_data))
diff -r 174658f839c0 -r 8827271fbe1b orpg/networking/mplay_groups.py
--- a/orpg/networking/mplay_groups.py Sun Nov 01 01:12:50 2009 -0600
+++ b/orpg/networking/mplay_groups.py Sun Nov 01 11:36:14 2009 -0600
@@ -1,4 +1,5 @@
from orpg.mapper.map_msg import *
+from orpg.tools.orpg_log import debug
class game_group:
def __init__( self, id, name, pwd, desc="",
diff -r 174658f839c0 -r 8827271fbe1b orpg/networking/mplay_server.py
--- a/orpg/networking/mplay_server.py Sun Nov 01 01:12:50 2009 -0600
+++ b/orpg/networking/mplay_server.py Sun Nov 01 11:36:14 2009 -0600
@@ -75,7 +75,6 @@
class game_group(object):
- debug()
def __init__(self, id, name, pwd, desc="", boot_pwd="",
minVersion="", mapFile=None, messageFile=None, persist=0):
self.id = id
@@ -104,40 +103,34 @@
self.game_map.init_from_xml(fromstring(tree))
def save_map(self):
- debug()
+ #debug(log=False)
if self.mapFile is not None and self.persistant == 1 and self.mapFile.find("default_map.xml") == -1:
f = open(self.mapFile, "w")
f.write(self.game_map.get_all_xml())
f.close()
def add_player(self,id):
- debug()
self.players.append(id)
def remove_player(self,id):
- debug()
if self.voice.has_key(id): del self.voice[id]
self.players.remove(id)
def get_num_players(self):
- debug()
num = len(self.players)
return num
def get_player_ids(self):
- debug()
tmp = self.players
return tmp
def check_pwd(self,pwd):
- debug()
return (pwd==self.pwd)
def check_boot_pwd(self,pwd):
return (pwd==self.boot_pwd)
def check_version(self,ver):
- debug()
if (self.minVersion == ""): return 1
minVersion=self.minVersion.split('.')
version=ver.split('.')
@@ -153,7 +146,6 @@
#depreciated - see send_group_list()
def toxml(self, act="new"):
- debug(self.name)
# Please don't add the boot_pwd to the xml, as this will give it away to players watching their console
el = Element('group')
el.set('id', self.id)
@@ -164,7 +156,6 @@
return tostring(el)
class client_stub(client_base):
- debug()
def __init__(self,inbox,sock,props,log):
client_base.__init__(self)
self.ip = props['ip']
@@ -196,7 +187,6 @@
else: return 0
def send(self, msg, player, group):
- debug()
if self.get_status() == MPLAY_CONNECTED:
#el = Element('msg')
#el.set('to', player)
@@ -206,7 +196,6 @@
self.outbox.put("" + msg)
def change_group(self, group_id, groups):
- debug()
old_group_id = str(self.group_id)
groups[group_id].add_player(self.id)
groups[old_group_id].remove_player(self.id)
@@ -236,7 +225,7 @@
"""
class mplay_server:
- debug()
+ #debug(log=False)
def __init__(self, log_console=None, name=None):
logger._set_log_level = 16
logger._set_log_to_console(True)
@@ -274,8 +263,8 @@
self.sendLobbySound = False
self.lobbySound = 'http://www.digitalxero.net/music/mus_tavern1.bmu' ##used?
- @debugging
def initServer(self, **kwargs):
+ #debug(log=False)
for atter, value in kwargs.iteritems(): setattr(self, atter, value)
validate.config_file( self.lobbyMapFile, "default_Lobby_map.xml" )
validate.config_file( self.lobbyMessageFile, "default_LobbyMessage.html" )
@@ -367,7 +356,9 @@
# This method reads in the server's configuration file and reconfigs the server
# as needed, over-riding any default values as requested.
+
def initServerConfig(self):
+ #debug(log=False)
self.log_msg("Processing Server Configuration File... " + self.userPath)
# make sure the server_ini.xml exists!
validate.config_file( "server_ini.xml", "default_server_ini.xml" )
@@ -666,20 +657,24 @@
return name
def registerRooms(self, args=None):
+ #debug()
rooms = ''
id = '0'
time.sleep(500)
+ #debug(self.groups)
for rnum in self.groups.keys():
rooms += urllib.urlencode( {"room_data[rooms][" + str(rnum) + "][name]":self.groups[rnum].name,
"room_data[rooms][" + str(rnum) + "][pwd]":str(self.groups[rnum].pwd != "")})+'&'
for pid in self.groups[rnum].players:
rooms += urllib.urlencode( {"room_data[rooms][" + str(rnum) + "][players]["+str(pid)+"]":self.players[pid].name,})+'&'
+ #debug(rooms)
for meta in self.metas.keys():
while id == '0':
id, cookie = self.metas[meta].getIdAndCookie()
data = urllib.urlencode( {"room_data[server_id]":id,
"act":'registerrooms'})
- get_server_dom(data+'&'+rooms, self.metas[meta].path)
+ #debug((data, rooms))
+ get_server_dom(data+'&'+rooms, self.metas[meta].path, string=True)
def register(self,name_given=None):
if name_given == None: name = self.name
@@ -912,7 +907,7 @@
print
def broadcast(self,msg):
- self.send_to_all("0","" + msg + "")
+ self.send_to_all("0","" + msg + "")
def console_log(self):
if self.log_to_console == 1:
@@ -972,6 +967,10 @@
elif self.players[id].protocol_version.find(patern)>-1: self.print_player_info(self.players[id])
elif self.players[id].client_string.find(patern)>-1: self.print_player_info(self.players[id])
+ def obtain_by_id(self, id, objects):
+ ### Alpha ### Basic way to obtain information for the Server GUI, currently reports the Client String only
+ return self.players[id].client_string
+
def print_player_info(self,player):
print player.id, player.name, player.ip, player.group_id, player.role, player.version, player.protocol_version, player.client_string
@@ -1257,7 +1256,7 @@
return 1
def SendLobbyMessage(self, socket, player_id):
- debug()
+ #debug(log=False)
"""
# Display the lobby message
# prepend this server's version string to the the lobby message
@@ -1329,7 +1328,7 @@
self.listen_event.set()
def acceptedNewConnectionThread( self, newsock, addr ):
- debug()
+ #debug(log=False)
"""Once a new connection comes in and is accepted, this thread starts up to handle it."""
# Initialize xml_dom
xml_dom = None
@@ -1390,12 +1389,12 @@
return #returning causes connection thread instance to terminate
# Again attempt to clean out DOM stuff
- try:
- if xml_dom: xml_dom.unlink()
+ """
+ try: if xml_dom: xml_dom.unlink()
except:
print "The following exception caught unlinking xml_dom:"
traceback.print_exc()
- return #returning causes connection thread instance to terminate
+ return #returning causes connection thread instance to terminate"""
"""
#========================================================
@@ -1410,7 +1409,7 @@
"""
def message_handler(self, arg):
- debug()
+ #debug(log=False)
xml_dom = None
self.log_msg( "message handler thread running..." )
while self.alive:
@@ -1436,7 +1435,6 @@
self.incoming_event.set()
def parse_incoming_dom(self,data):
- debug(data)
end = data.find(">") #locate end of first element of message
head = data[:end+1]
#self.log_msg(head)
@@ -1452,15 +1450,13 @@
print "Exception=" + str(e)
def message_action(self, xml_dom, data):
- debug()
- tag_name = xml_dom.tag; print 'message_action tag_name', tag_name
+ tag_name = xml_dom.tag
if self.svrcmds.has_key(tag_name): self.svrcmds[tag_name]['function'](xml_dom, data)
else: raise Exception, "Not a valid header!"
#Message Action thread expires and closes here.
return
def do_alter(self, xml_dom, data):
- debug()
target = xml_dom.get("key")
value = xml_dom.get("val")
player = xml_dom.get("plr")
@@ -1492,7 +1488,6 @@
self.players[player].outbox.put(msg)
def do_role(self, xml_dom, data):
- debug()
role = ""
boot_pwd = ""
act = xml_dom.get("action")
@@ -1507,7 +1502,6 @@
self.log_msg(("role", (player, role)))
def do_ping(self, xml_dom, data):
- debug()
player = xml_dom.get("player")
group_id = xml_dom.get("group_id")
sent_time = ""
@@ -1522,7 +1516,6 @@
#xml_dom.unlink()
def do_system(self, xml_dom, data):
- debug()
pass
def moderate_group(self,xml_dom,data):
@@ -1664,7 +1657,6 @@
def return_room_roles(self, from_id, group_id):
for m in self.players.keys():
if self.players[m].group_id == group_id:
- print 'return_room_roles', self.players[m].id, self.players[m].role, self.players[m]
try: msg = ""
except: exit()
self.players[from_id].outbox.put(msg)
@@ -1729,7 +1721,6 @@
thread.start_new_thread(self.registerRooms,(0,))
def create_group(self, xml_dom, data):
- debug((tostring(xml_dom), data))
#try:
from_id = xml_dom.get("from")
pwd = xml_dom.get("pwd")
@@ -1840,7 +1831,6 @@
self.log_msg("Explicit garbage collection shows %s undeletable items." % str(gc.collect()))
def incoming_player_handler(self, xml_dom, data):
- debug()
id = xml_dom.get("id")
act = xml_dom.get("action")
#group_id = xml_dom.get("group_id")
@@ -1858,8 +1848,6 @@
self.del_player(id,group_id)
self.check_group(id, group_id)
elif act=="update":
- debug(xml_dom)
- print xml_dom.get('name')
self.players[id].take_dom(xml_dom)
self.log_msg(("update", {"id": id,
"name": xml_dom.get("name"),
@@ -1892,7 +1880,6 @@
return False
def incoming_msg_handler(self,xml_dom,data):
- debug()
xml_dom, data = ServerPlugins.preParseIncoming(xml_dom, data)
###########################################################
to_id = xml_dom.get("to")
@@ -1942,7 +1929,6 @@
return
def sound_msg_handler(self, xml_dom, data):
- debug()
from_id = xml_dom.get("from")
group_id = xml_dom.get("group_id")
if group_id != 0: self.send_to_group(from_id, group_id, data)
@@ -2209,7 +2195,6 @@
def send_to_all(self,from_id,data):
try:
- print data
self.p_lock.acquire()
keys = self.players.keys()
self.p_lock.release()
diff -r 174658f839c0 -r 8827271fbe1b orpg/networking/mplay_server_gui.py
--- a/orpg/networking/mplay_server_gui.py Sun Nov 01 01:12:50 2009 -0600
+++ b/orpg/networking/mplay_server_gui.py Sun Nov 01 11:36:14 2009 -0600
@@ -22,6 +22,7 @@
from xml.dom import minidom
from orpg.orpgCore import component
from orpg.tools.orpg_log import debug
+from orpg.tools.orpg_settings import settings
from xml.etree.ElementTree import ElementTree, Element, iselement
from xml.etree.ElementTree import fromstring, tostring, parse
@@ -47,6 +48,7 @@
MENU_ADMIN_BAN = wx.NewId()
MENU_BAN_LIST = wx.NewId()
MENU_ADMIN_UNBAN = wx.NewId()
+PLAYER_SHOW_VERSION = wx.NewId()
#############
MENU_PLAYER_CREATE_ROOM = wx.NewId()
MENU_PLAYER_SEND_MESSAGE = wx.NewId()
@@ -93,13 +95,15 @@
# ServerConfig Object ############################
class ServerConfig:
- debug()
+ debug(log=False)
""" This class contains configuration
setting used to control the server."""
def __init__(self, owner ):
""" Loads default configuration settings."""
- validate.config_file("server_ini.xml", "default_server_ini.xml" )
+ validate.config_file("server_ini.xml", "default_server_ini.xml")
+ config_xml = parse(dir_struct['user'] + 'server_ini.xml')
+ debug(config_xml, log=False)
configDom = minidom.parse(dir_struct["user"] + 'server_ini.xml')
port = configDom.childNodes[0].childNodes[1].getAttribute('port')
OPENRPG_PORT = 6774 if port == '' else int(port) #Pretty ugly, but I couldn't find the tag any other way.
@@ -118,7 +122,7 @@
# Server Monitor #################################
class ServerMonitor(Thread):
- debug()
+ debug(log=False)
""" Monitor thread for GameServer. """
def __init__(self, cb, conf, name, pwd):
""" Setup the server. """
@@ -129,7 +133,7 @@
self.bootPwd = pwd
def log(self, mesg):
- debug()
+ debug(log=False)
if type(mesg) == types.TupleType:
func, msg = mesg
event = MessageFunctionEvent( func, msg )
@@ -138,7 +142,7 @@
del event
def run(self):
- debug()
+ debug(log=False)
""" Start the server. """
self.server = mplay_server(self.log, self.serverName )
self.server.initServer(bootPassword=self.bootPwd, reg="No")
@@ -146,7 +150,7 @@
while self.alive: time.sleep(3)
def stop(self):
- debug()
+ debug(log=False)
""" Stop the server. """
self.server.kill_server()
self.alive = 0
@@ -192,6 +196,7 @@
self.menu.SetTitle( "Player Menu" )
self.menu.Append( MENU_PLAYER_BOOT, "Boot Player" )
self.menu.Append( MENU_ADMIN_BAN, 'Ban Player' )
+ self.menu.Append( PLAYER_SHOW_VERSION, "Player Version" )
self.menu.AppendSeparator()
self.menu.Append( MENU_PLAYER_SEND_MESSAGE, "Send Player Message" )
self.menu.Append( MENU_PLAYER_SEND_ROOM_MESSAGE, "Send Room Message" )
@@ -204,6 +209,7 @@
self.Bind(wx.EVT_MENU, self.OnPopupMenuItem, id=MENU_PLAYER_SEND_MESSAGE)
self.Bind(wx.EVT_MENU, self.OnPopupMenuItem, id=MENU_PLAYER_SEND_ROOM_MESSAGE)
self.Bind(wx.EVT_MENU, self.OnPopupMenuItem, id=MENU_PLAYER_SEND_SERVER_MESSAGE)
+ self.Bind(wx.EVT_MENU, self.OnPopupMenuItem, id=PLAYER_SHOW_VERSION)
def add(self, player):
i = self.InsertImageStringItem( 0, player["id"], 0 )
@@ -211,11 +217,11 @@
self.SetStringItem(i, 2, "NEW")
self.SetStringItem(i, 3, self.roomList[0])
self.SetStringItem(i, 4, self.stripHtml(player["version"]))
- print self.stripHtml(player["role"])
- self.SetStringItem(i, 5, 'Lurker' if self.stripHtml(player["role"]) == '' else self.stripHtml(player["role"]))
+ self.SetStringItem(i, 5, 'Lurker' if player["role"] == None else self.stripHtml(player["role"]))
self.SetStringItem(i, 6, self.stripHtml(player["ip"]))
self.SetStringItem(i, 7, "PING")
self.SetItemData(i, int(player["id"]))
+ self.colorize_player_list(player)
self.AutoAjust()
def remove(self, id):
@@ -234,13 +240,35 @@
self.SetColumnWidth(7, -1)
self.Refresh()
+ def colorize_player_list(self, player):
+ debug(player, log=False)
+ if player == 0: return
+ for m in player.keys():
+ id = player['id']
+ item_list_location = self.FindItemData(-1, int(id))
+ if item_list_location == -1: continue
+ item = self.GetItem(item_list_location)
+ debug(item_list_location, log=False)
+ role = player['role']
+ debug(role, log=False)
+ try: #Players that turn up Blue are not passing the correct arguments.
+ try:
+ if player['group_id'] != "0": item.SetTextColour(settings.get_setting(role + "RoleColor"))
+ except KeyError: # Needed because group_id turns into group somewhere.
+ if player['group'] != "0": item.SetTextColour(settings.get_setting(role + "RoleColor"))
+ except:
+ item.SetTextColour('BLUE')
+ self.SetItem(item)
+
def update(self, player):
+ debug(player, log=False)
+ #try: int(player); i = self.FindItemData( -1, int(player) )
i = self.FindItemData( -1, int(player["id"]) )
if i > -1:
self.SetStringItem(i, 1, self.stripHtml(player["name"]))
self.SetStringItem(i, 2, self.stripHtml(player["status"]))
- print self.stripHtml(player["role"])
- self.SetStringItem(i, 5, 'Lurker' if self.stripHtml(player["role"]) == '' else self.stripHtml(player["role"]))
+ self.SetStringItem(i, 5, 'Lurker' if player["role"] == None else self.stripHtml(player["role"]))
+ self.colorize_player_list(player)
self.AutoAjust()
else: self.add(player)
@@ -249,11 +277,12 @@
i = self.FindItemData( -1, int(player) )
if player > 0: self.SetStringItem( i, 3, room )
self.AutoAjust()
+ #self.update(player) # player object doesn't send role object.
def setPlayerRole( self, id, role ):
i = self.FindItemData( -1, int(id) )
self.SetStringItem( i, 5, role )
- self.AutoAjust
+ self.AutoAjust()
def stripHtml( self, name ):
ret_string = ""
@@ -319,6 +348,10 @@
msg = self.GetMessageInput( "Broadcast Server Message" )
# If we got a message back, send it
if len(msg): self.main.server.server.broadcast( msg )
+ elif menuItem == PLAYER_SHOW_VERSION:
+ version_string = self.main.server.server.obtain_by_id(playerID, 'client_string')
+ if version_string: wx.MessageBox("Running client version " + version_string,"Version")
+ else: wx.MessageBox("No client version available for this player", "Version")
def GetMessageInput( self, title ):
prompt = "Please enter the message you wish to send:"
@@ -430,8 +463,8 @@
#Not sure why this is Remarked TaS - Sirebral
#nb.AddPage( self.conns, "Rooms" )
- #self.msgWindow = HTMLMessageWindow( nb )
- #nb.AddPage( self.msgWindow, "Messages" )
+ self.msgWindow = HTMLMessageWindow( nb )
+ nb.AddPage( self.msgWindow, "Messages" )
log = wx.TextCtrl(splitter, -1, style=wx.TE_MULTILINE | wx.TE_READONLY | wx.HSCROLL)
wx.Log.SetActiveTarget( wx.LogTextCtrl(log) )
@@ -468,7 +501,7 @@
# Event handler for out logging event
def OnFunctionMessage(self, event):
- debug()
+ debug(log=False)
self.callbacks[event.func]( event.message )
### Server Callbacks #####################################
diff -r 174658f839c0 -r 8827271fbe1b orpg/orpg_version.py
--- a/orpg/orpg_version.py Sun Nov 01 01:12:50 2009 -0600
+++ b/orpg/orpg_version.py Sun Nov 01 11:36:14 2009 -0600
@@ -4,7 +4,7 @@
#BUILD NUMBER FORMAT: "YYMMDD-##" where ## is the incremental daily build index (if needed)
DISTRO = "Traipse Alpha"
DIS_VER = "Ornery Orc"
-BUILD = "091001-00"
+BUILD = "091001-01"
# This version is for network capability.
PROTOCOL_VERSION = "1.2"
diff -r 174658f839c0 -r 8827271fbe1b orpg/tools/orpg_log.py
--- a/orpg/tools/orpg_log.py Sun Nov 01 01:12:50 2009 -0600
+++ b/orpg/tools/orpg_log.py Sun Nov 01 11:36:14 2009 -0600
@@ -62,12 +62,13 @@
def write(self, text):
#logger.stdout(text)
wx.Yield()
- #sys.__stdout__.write(text)
+ sys.__stdout__.write(text)
class TrueDebug(object):
### Alpha ###
- """A simple debugger. Add debug() to a function and it prints the function name and any objects included.
+ """A simple debugger. Add debug() to a function and it prints the function name and any objects included. Add an object or a group of objects in ()'s.
Adding True to locale prints the file name where the function is. Adding False to log turns the log off.
+ Adding True to parents will print out the parent functions, starting from TrueDebug.
This feature can be modified to trace deeper and find the bugs faster, ending the puzzle box."""
def __init__(self, objects=None, locale=False, log=True, parents=False):
if log == False: return
diff -r 174658f839c0 -r 8827271fbe1b rollback.py
--- a/rollback.py Sun Nov 01 01:12:50 2009 -0600
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,17 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import os
-
-HG = os.environ["HG"]
-
-os.system(HG + " rollback")
-os.system(HG + " revert --all")
-print "Since you reverted, I am guessing there are issues with the last update"
-print "PLEASE notify me on either the openrpg.com boards, or by email"
-print "digitalxero@gmail.com"
-print "You can continue using your rolled back version by launching openrpg from"
-print "the command line with the command: OpenRPG*.py -n"
-print "the -n tells the system not to update, it will still run the downloader"
-print "but it will not change your files"
-raw_input("press key to terminate program")
\ No newline at end of file
diff -r 174658f839c0 -r 8827271fbe1b start.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/start.py Sun Nov 01 11:36:14 2009 -0600
@@ -0,0 +1,20 @@
+#!/usr/bin/env python
+
+import pyver
+pyver.checkPyVersion()
+
+#Update Manager
+from orpg.orpg_wx import *
+import upmana.updatemana
+app = upmana.updatemana.updateApp(0)
+app.MainLoop()
+
+#Main Program
+from orpg.orpg_wx import *
+import orpg.main
+
+if WXLOADED:
+ mainapp = orpg.main.orpgApp(0)
+ mainapp.MainLoop()
+else:
+ print "You really really need wx!"
diff -r 174658f839c0 -r 8827271fbe1b start_developer.py
--- a/start_developer.py Sun Nov 01 01:12:50 2009 -0600
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
-#!/usr/bin/env python
-
-import pyver
-pyver.checkPyVersion()
-
-#Update Manager
-from orpg.orpg_wx import *
-import upmana.updatemana
-app = upmana.updatemana.updateApp(0)
-app.MainLoop()
-
-#Main Program
-from orpg.orpg_wx import *
-import orpg.main
-
-if WXLOADED:
- mainapp = orpg.main.orpgApp(0)
- mainapp.MainLoop()
-else:
- print "You really really need wx!"
diff -r 174658f839c0 -r 8827271fbe1b start_tester.py
--- a/start_tester.py Sun Nov 01 01:12:50 2009 -0600
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import os
-
-HG = os.environ["HG"]
-
-import pyver
-pyver.checkPyVersion()
-
-from orpg.orpg_wx import *
-import upmana.updatemana
-app = upmana.updatemana.updateApp(0)
-app.MainLoop()
-for key in sys.modules.keys():
- if 'orpg' in key:
- del sys.modules[key]
-
-from orpg.orpg_wx import *
-import orpg.main
-
-if WXLOADED:
- mainapp = orpg.main.orpgApp(0)
- mainapp.MainLoop()
-else:
- print "You really really need wx!"
|