annotate plugins/xxstdnamespace.py @ 227:81d0bfd5e800 alpha

Traipse Alpha 'OpenRPG' {100612-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 (Preparing to close updates) New Features: New to Map, can re-order Grid, Miniatures, and Whiteboard layer draw order Fixes: Fix to InterParse that was causing an Infernal Loop with Namespace Internal Fix to XML data, removed old Minidom and switched to Element Tree Fix to Server that was causing eternal attempt to find a Server ID, in Register Rooms thread Fix to metaservers.xml file not being created
author sirebral
date Sat, 12 Jun 2010 03:50:37 -0500
parents
children
rev   line source
227
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
1 import os, wx, re
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
2 import orpg.pluginhandler
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
3 from orpg.tools.InterParse import Parse
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
4 from orpg.orpgCore import component
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
5 from xml.etree.ElementTree import iselement
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
6
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
7 class Plugin(orpg.pluginhandler.PluginHandler):
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
8 # Initialization subroutine.
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
9 #
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
10 # !self : instance of self
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
11 # !openrpg : instance of the the base openrpg control
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
12 def __init__(self, plugindb, parent):
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
13 orpg.pluginhandler.PluginHandler.__init__(self, plugindb, parent)
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
14
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
15 # The Following code should be edited to contain the proper information
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
16 self.name = 'Standard Namespace'
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
17 self.author = 'Prof. Ebral'
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
18 self.help = 'The Standard Namespace plugin allows for users of Traipse to use '
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
19 self.help += 'the Standard Namespace syntax of !@ :: @!\n\n'
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
20 self.help += 'This plugin modifies the External method, so context sensivity\n'
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
21 self.help += 'is not calculated when using the Standard syntax. References must '
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
22 self.help += 'have a unique name.'
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
23
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
24 self.NameSpaceE = Parse.NameSpaceE
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
25 self.parseMethods = {'Traipse': self.NameSpaceE, 'Standard': self.NameSpaceS}
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
26
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
27 def NameSpaceS(self, s): ## Re define NameSpace External
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
28 reg1 = re.compile("(!@(.*?)@!)") ## Include 'Standard' method
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
29 reg2 = re.compile("(!&(.*?)&!)")
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
30 ## Before anyone rags on me about how this is a useless plugin, or that two methods are confusing,
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
31 ## consider that this will be fully integrated later. Then consider that you can now create a reference
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
32 ## with a reference. !@ :: !& :: &! :: @!
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
33 matches = reg1.findall(s) + reg2.findall(s)
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
34 newstr = False
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
35 nodeable = ['rpg_grid_handler', 'container_handler',
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
36 'group_handler', 'tabber_handler',
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
37 'splitter_handler', 'form_handler', 'textctrl_handler']
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
38 for i in xrange(0,len(matches)):
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
39 find = matches[i][1].split('::')
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
40 node = component.get('tree').xml_root
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
41 if not iselement(node):
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
42 s = s.replace(matches[i][0], 'Invalid Reference!', 1);
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
43 s = self.NameSpaceS(s)
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
44 return s
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
45 for x in xrange(0, len(find)):
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
46 namespace = node.getiterator('nodehandler')
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
47 for node in namespace:
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
48 if find[x] == node.get('name'):
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
49 if node.get('class') not in nodeable: continue
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
50 if node.get('class') == 'rpg_grid_handler':
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
51 try: newstr = Parse.NameSpaceGrid(find[x+1], node); break
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
52 except: newstr = 'Invalid Grid Reference!'
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
53 try:
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
54 if Parse.FutureCheck(node, find[x+1]): break
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
55 else: continue
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
56 except:
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
57 if x == len(find)-1:
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
58 if node.find('text') != None: newstr = str(node.find('text').text)
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
59 else: newstr = 'Invalid Reference!'
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
60 break
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
61 else: break
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
62 if not newstr: newstr = 'Invalid Reference!'
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
63 s = s.replace(matches[i][0], newstr, 1)
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
64 s = Parse.ParseLogic(s, node)
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
65 return s
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
66
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
67 def plugin_menu(self):
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
68 ## This is a standardized Menu item. It connects to plugin_toggle where you can set events.
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
69 self.menu = wx.Menu()
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
70 self.toggle = self.menu.AppendCheckItem(wx.ID_ANY, 'On')
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
71 self.topframe.Bind(wx.EVT_MENU, self.plugin_toggle, self.toggle)
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
72 self.toggle.Check(True)
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
73
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
74 def plugin_toggle(self, evt):
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
75 if self.toggle.IsChecked() == True:
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
76 Parse.NameSpaceE = self.parseMethods['Standard']
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
77 self.plugindb.SetString('xxstdnamespace', 'Standard', 'True')
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
78 if self.toggle.IsChecked() == False:
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
79 Parse.NameSpaceE = self.parseMethods['Traipse']
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
80 self.plugindb.SetString('xxstdnamespace', 'Standard', 'False')
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
81 pass
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
82
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
83 def plugin_enabled(self):
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
84 self.onoroff = self.plugindb.GetString('xxstdnamespace', 'Standard', '') or 'False'
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
85 self.toggle.Check(True) if self.onoroff == 'True' else self.toggle.Check(False)
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
86 Parse.NameSpaceE = self.parseMethods['Standard'] if self.onoroff == 'True' else self.parseMethods['Traipse']
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
87 pass
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
88
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
89 def plugin_disabled(self):
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
90 Parse.NameSpaceE = self.parseMethods['Traipse']
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
91
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
92 def pre_parse(self, text):
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
93 return text
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
94
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
95 def send_msg(self, text, send):
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
96 return text, send
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
97
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
98 def plugin_incoming_msg(self, text, type, name, player):
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
99 return text, type, name
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
100
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
101 def post_msg(self, text, myself):
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
102 return text
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
103
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
104 def refresh_counter(self):
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents:
diff changeset
105 pass