diff orpg/tools/aliaslib.py @ 195:b633f4c64aae alpha

Traipse Alpha 'OpenRPG' {100219-00} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user. Update Summary (Patch-2) New Features: New Namespace method with two new syntaxes Fixes: Fix to Server GUI startup errors Fix to Server GUI Rooms tab updating Fix to Chat and Settings if non existant die roller is picked Fix to Dieroller and .open() used with .vs(). Successes are correctly calculated Fix to Alias Lib's Export to Tree, Open, Save features Fix to alias node, now works properly Fix to Splitter node, minor GUI cleanup
author sirebral
date Sat, 24 Apr 2010 08:37:20 -0500
parents f38df4bf9715
children
line wrap: on
line diff
--- a/orpg/tools/aliaslib.py	Fri Jan 15 22:45:51 2010 -0600
+++ b/orpg/tools/aliaslib.py	Sat Apr 24 08:37:20 2010 -0500
@@ -21,12 +21,12 @@
 # Author: Dj Gilcrease
 # Maintainer:
 # Version:
-#   $Id: aliaslib.py,v 1.20 2007/08/09 05:23:21 digitalxero Exp $
+#   $Id: aliaslib.py,v Traipse 'Ornery-Orc' prof.ebral Exp $
 #
 # Description: nodehandler for alias.
 #
 
-__version__ = "$Id: aliaslib.py,v 1.20 2007/08/09 05:23:21 digitalxero Exp $"
+__version__ = "$Id: aliaslib.py,v Traipse 'Ornery-Orc' prof.ebral Exp $"
 
 from orpg.orpg_wx import *
 from orpg.orpgCore import component
@@ -35,6 +35,7 @@
 from orpg.dirpath import dir_struct
 from orpg.tools.validate import validate
 from orpg.tools.orpg_settings import settings
+from xml.etree.ElementTree import tostring, parse
 import re
 
 class AliasLib(wx.Frame):
@@ -174,7 +175,6 @@
         f.close()
 
     def OnMB_FileExportToTree(self, event):
-        #tree = component.get("tree")
         xml = '<nodehandler class="voxchat_handler" '
         xml += 'icon="player" '
         xml += 'module="voxchat" '
@@ -459,36 +459,30 @@
         self.Fit()
 
     def loadFile(self):
-        f = open(dir_struct["user"] + self.filename, "r")
-        data = f.read()
-        f.close()
-        self.alias = -1
-        self.filter = -1
-        xml_dom = component.get('xml').parseXml(data)
-        del data
-        aliases = xml_dom.getElementsByTagName("alias")
+        data = parse(dir_struct["user"] + self.filename)
+        xml_dom = data.getroot()
+        aliases = xml_dom.findall("alias")
         alist = []
         for alias in aliases:
-            if alias.hasAttribute("color"): color = alias.getAttribute("color")
+            if alias.get("color"): color = alias.get("color")
             else: color = 'Default'
-            aname = self.MakeSafeHTML(alias.getAttribute("name"))
+            aname = self.MakeSafeHTML(alias.get("name"))
             alist.append([aname, color])
         alist.sort()
         self.aliasList = alist
-        filters = xml_dom.getElementsByTagName("filter")
+        filters = xml_dom.findall("filter")
         flist = []
         self.regExList = []
         for filter in filters:
-            flist.append(filter.getAttribute("name"))
-            rules = filter.getElementsByTagName("rule")
+            flist.append(filter.get("name"))
+            rules = filter.findall("rule")
             sub = []
-            for rule in rules: sub.append([self.MakeSafeHTML(rule.getAttribute("match")), 
-                                        self.MakeSafeHTML(rule.getAttribute("sub"))])
+            for rule in rules: sub.append([self.MakeSafeHTML(rule.get("match")), 
+                                        self.MakeSafeHTML(rule.get("sub"))])
             self.regExList.append(sub)
         self.filterList = flist
-        xml_dom.unlink()
-        self.alias = -1
-        self.filter = -1
+        self.alias = 0
+        self.filter = 0
 
     def MakeSafeHTML(self, str):
         return str.replace("&amp;", "&").replace("&lt;", "<").replace("&quot;", '"').replace("&gt;", ">").replace("&#39;", "'")
@@ -496,7 +490,7 @@
         return str.replace("&", "&amp;").replace("<", "&lt;").replace('"', "&quot;").replace(">", "&gt;").replace("'", "&#39;")
     def ImportFromTree(self, xml_dom):
         oldfilename = self.filename
-        if xml_dom.getAttribute('name') == 'Alias Library':
+        if xml_dom.get('name') == 'Alias Library':
             dlg = wx.TextEntryDialog(self, "Please Name This Alias Lib", "New Alias Lib")
             if dlg.ShowModal() == wx.ID_OK:
                 self.filename = dlg.GetValue() + '.alias'
@@ -504,11 +498,11 @@
             else:
                 dlg.Destroy()
                 return
-        else: self.filename = xml_dom.getAttribute('name') + '.alias'
+        else: self.filename = xml_dom.get('name') + '.alias'
         settings.set_setting('aliasfile', self.filename[:-6])
         if oldfilename != self.filename: self.OnMB_FileSave(None, oldfilename)
         f = open(dir_struct["user"] + self.filename, "w")
-        f.write(xml_dom.toxml().replace('nodehandler', 'aliaslib').replace('voxchat.', ''))
+        f.write(tostring(xml_dom).replace('nodehandler', 'aliaslib').replace('voxchat.', ''))
         f.close()
         wx.CallAfter(self.loadFile)
 
@@ -689,8 +683,6 @@
         self.regExList[self.filterIdx] = list
 
     def FormatText(self, event):
-        #self.textColorBtn = wx.Button(self, wx.ID_ANY, "Color")
-        #self.textColorBtn.SetForegroundColour(wx.BLACK)
         id = event.GetId()
         txt = self.textWnd.GetValue()
         (beg, end) = self.textWnd.GetSelection()