comparison orpg/tools/aliaslib.py @ 212:13054be69834 beta

Traipse Beta 'OpenRPG' {100428-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 New Namespace Internal is context sensitive, always! New Namespace External is 'as narrow as you make it' New Namespace FutureCheck helps ensure you don't receive an incorrect node New PluginDB access for URL2Link plugin New to Forms, they now show their content in Design Mode New to Update Manager, checks Repo for updates on software start 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 Fix to Backgrounds not loading through remote loader Fix to Node name errors Fix to rolling dice in chat Whispers Fix to Splitters Sizing issues Fix to URL2Link plugin, modified regex compilation should remove memory leak Fix to mapy.py, a roll back due to zoomed grid issues Fix to whiteboard_handler, Circles work by you clicking the center of the circle Fix to Servers parse_incoming_dom which was outdated and did not respect XML Fix to a broken link in the server welcome message Fix to InterParse and logger requiring traceback Fix to Update Manager Status Bar Fix to failed image and erroneous pop up
author sirebral
date Wed, 28 Apr 2010 08:08:09 -0500
parents dcae32e219f1
children 682032381be8
comparison
equal deleted inserted replaced
194:44ef45e77880 212:13054be69834
33 from orpg.orpg_windows import createMaskedButton, orpgMultiCheckBoxDlg 33 from orpg.orpg_windows import createMaskedButton, orpgMultiCheckBoxDlg
34 from orpg.tools.rgbhex import RGBHex 34 from orpg.tools.rgbhex import RGBHex
35 from orpg.dirpath import dir_struct 35 from orpg.dirpath import dir_struct
36 from orpg.tools.validate import validate 36 from orpg.tools.validate import validate
37 from orpg.tools.orpg_settings import settings 37 from orpg.tools.orpg_settings import settings
38 from xml.etree.ElementTree import tostring, parse
38 import re 39 import re
39 40
40 class AliasLib(wx.Frame): 41 class AliasLib(wx.Frame):
41 def __init__(self): 42 def __init__(self):
42 self.orpgframe = component.get('frame') 43 self.orpgframe = component.get('frame')
456 self.SetSizer(self.sizer) 457 self.SetSizer(self.sizer)
457 self.SetAutoLayout(True) 458 self.SetAutoLayout(True)
458 self.Fit() 459 self.Fit()
459 460
460 def loadFile(self): 461 def loadFile(self):
461 f = open(dir_struct["user"] + self.filename, "r") 462 data = parse(dir_struct["user"] + self.filename)
462 data = f.read() 463 xml_dom = data.getroot()
463 f.close() 464 aliases = xml_dom.findall("alias")
464 self.alias = -1
465 self.filter = -1
466 xml_dom = component.get('xml').parseXml(data)
467 del data
468 aliases = xml_dom.getElementsByTagName("alias")
469 alist = [] 465 alist = []
470 for alias in aliases: 466 for alias in aliases:
471 if alias.hasAttribute("color"): color = alias.getAttribute("color") 467 if alias.get("color"): color = alias.get("color")
472 else: color = 'Default' 468 else: color = 'Default'
473 aname = self.MakeSafeHTML(alias.getAttribute("name")) 469 aname = self.MakeSafeHTML(alias.get("name"))
474 alist.append([aname, color]) 470 alist.append([aname, color])
475 alist.sort() 471 alist.sort()
476 self.aliasList = alist 472 self.aliasList = alist
477 filters = xml_dom.getElementsByTagName("filter") 473 filters = xml_dom.findall("filter")
478 flist = [] 474 flist = []
479 self.regExList = [] 475 self.regExList = []
480 for filter in filters: 476 for filter in filters:
481 flist.append(filter.getAttribute("name")) 477 flist.append(filter.get("name"))
482 rules = filter.getElementsByTagName("rule") 478 rules = filter.findall("rule")
483 sub = [] 479 sub = []
484 for rule in rules: sub.append([self.MakeSafeHTML(rule.getAttribute("match")), 480 for rule in rules: sub.append([self.MakeSafeHTML(rule.get("match")),
485 self.MakeSafeHTML(rule.getAttribute("sub"))]) 481 self.MakeSafeHTML(rule.get("sub"))])
486 self.regExList.append(sub) 482 self.regExList.append(sub)
487 self.filterList = flist 483 self.filterList = flist
488 xml_dom.unlink() 484 self.alias = 0
489 self.alias = -1 485 self.filter = 0
490 self.filter = -1
491 486
492 def MakeSafeHTML(self, str): 487 def MakeSafeHTML(self, str):
493 return str.replace("&amp;", "&").replace("&lt;", "<").replace("&quot;", '"').replace("&gt;", ">").replace("&#39;", "'") 488 return str.replace("&amp;", "&").replace("&lt;", "<").replace("&quot;", '"').replace("&gt;", ">").replace("&#39;", "'")
494 def MakeHTMLSafe(self, str): 489 def MakeHTMLSafe(self, str):
495 return str.replace("&", "&amp;").replace("<", "&lt;").replace('"', "&quot;").replace(">", "&gt;").replace("'", "&#39;") 490 return str.replace("&", "&amp;").replace("<", "&lt;").replace('"', "&quot;").replace(">", "&gt;").replace("'", "&#39;")
496 def ImportFromTree(self, xml_dom): 491 def ImportFromTree(self, xml_dom):
497 oldfilename = self.filename 492 oldfilename = self.filename
498 if xml_dom.getAttribute('name') == 'Alias Library': 493 if xml_dom.get('name') == 'Alias Library':
499 dlg = wx.TextEntryDialog(self, "Please Name This Alias Lib", "New Alias Lib") 494 dlg = wx.TextEntryDialog(self, "Please Name This Alias Lib", "New Alias Lib")
500 if dlg.ShowModal() == wx.ID_OK: 495 if dlg.ShowModal() == wx.ID_OK:
501 self.filename = dlg.GetValue() + '.alias' 496 self.filename = dlg.GetValue() + '.alias'
502 dlg.Destroy() 497 dlg.Destroy()
503 else: 498 else:
504 dlg.Destroy() 499 dlg.Destroy()
505 return 500 return
506 else: self.filename = xml_dom.getAttribute('name') + '.alias' 501 else: self.filename = xml_dom.get('name') + '.alias'
507 settings.set_setting('aliasfile', self.filename[:-6]) 502 settings.set_setting('aliasfile', self.filename[:-6])
508 if oldfilename != self.filename: self.OnMB_FileSave(None, oldfilename) 503 if oldfilename != self.filename: self.OnMB_FileSave(None, oldfilename)
509 f = open(dir_struct["user"] + self.filename, "w") 504 f = open(dir_struct["user"] + self.filename, "w")
510 f.write(xml_dom.toxml().replace('nodehandler', 'aliaslib').replace('voxchat.', '')) 505 f.write(tostring(xml_dom).replace('nodehandler', 'aliaslib').replace('voxchat.', ''))
511 f.close() 506 f.close()
512 wx.CallAfter(self.loadFile) 507 wx.CallAfter(self.loadFile)
513 508
514 def NewAliasSelection(self, event): 509 def NewAliasSelection(self, event):
515 self.alias = event.GetIndex() 510 self.alias = event.GetIndex()