31
|
1 import os, wx, re
|
|
2 import orpg.pluginhandler
|
|
3 from orpg.tools.InterParse import Parse
|
|
4 from orpg.orpgCore import component
|
|
5 from xml.etree.ElementTree import iselement
|
|
6
|
|
7 class Plugin(orpg.pluginhandler.PluginHandler):
|
|
8 # Initialization subroutine.
|
|
9 #
|
|
10 # !self : instance of self
|
|
11 # !openrpg : instance of the the base openrpg control
|
|
12 def __init__(self, plugindb, parent):
|
|
13 orpg.pluginhandler.PluginHandler.__init__(self, plugindb, parent)
|
|
14
|
|
15 # The Following code should be edited to contain the proper information
|
|
16 self.name = 'Standard Namespace'
|
|
17 self.author = 'Prof. Ebral'
|
|
18 self.help = 'The Standard Namespace plugin allows for users of Traipse to use '
|
|
19 self.help += 'the Standard Namespace syntax of !@ :: @!\n\n'
|
|
20 self.help += 'This plugin modifies the External method, so context sensivity\n'
|
|
21 self.help += 'is not calculated when using the Standard syntax. References must '
|
|
22 self.help += 'have a unique name.'
|
|
23
|
36
|
24 self.parseMethods = {'Traipse': Parse.NameSpaceE, 'Standard': self.NameSpaceS}
|
31
|
25
|
|
26 def NameSpaceS(self, s): ## Re define NameSpace External
|
36
|
27 reg1 = re.compile("(!@(.*?)@!)") ## Inlcude 'Standard' method
|
31
|
28 reg2 = re.compile("(!&(.*?)&!)")
|
|
29 matches = reg1.findall(s) + reg2.findall(s)
|
|
30 newstr = False
|
|
31 nodeable = ['rpg_grid_handler', 'container_handler',
|
|
32 'group_handler', 'tabber_handler',
|
|
33 'splitter_handler', 'form_handler', 'textctrl_handler']
|
|
34 for i in xrange(0,len(matches)):
|
|
35 find = matches[i][1].split('::')
|
|
36 node = component.get('tree').xml_root
|
|
37 if not iselement(node):
|
|
38 s = s.replace(matches[i][0], 'Invalid Reference!', 1);
|
36
|
39 s = Parse.NameSpaceE(s)
|
31
|
40 return s
|
|
41 for x in xrange(0, len(find)):
|
|
42 namespace = node.getiterator('nodehandler')
|
|
43 for node in namespace:
|
|
44 if find[x] == node.get('name'):
|
|
45 if node.get('class') not in nodeable: continue
|
|
46 if node.get('class') == 'rpg_grid_handler':
|
36
|
47 try: newstr = self.NameSpaceGrid(find[x+1], node); break
|
31
|
48 except: newstr = 'Invalid Grid Reference!'
|
|
49 try:
|
|
50 if Parse.FutureCheck(node, find[x+1]): break
|
|
51 else: continue
|
|
52 except:
|
|
53 if x == len(find)-1:
|
|
54 if node.find('text') != None: newstr = str(node.find('text').text)
|
|
55 else: newstr = 'Invalid Reference!'
|
|
56 break
|
|
57 else: break
|
|
58 if not newstr: newstr = 'Invalid Reference!'
|
|
59 s = s.replace(matches[i][0], newstr, 1)
|
|
60 s = Parse.ParseLogic(s, node)
|
|
61 return s
|
|
62
|
|
63 def plugin_menu(self):
|
|
64 ## This is a standardized Menu item. It connects to plugin_toggle where you can set events.
|
|
65 self.menu = wx.Menu()
|
|
66 self.toggle = self.menu.AppendCheckItem(wx.ID_ANY, 'On')
|
|
67 self.topframe.Bind(wx.EVT_MENU, self.plugin_toggle, self.toggle)
|
|
68 self.toggle.Check(True)
|
|
69
|
|
70 def plugin_toggle(self, evt):
|
|
71 if self.toggle.IsChecked() == True:
|
34
|
72 Parse.NameSpaceE = self.parseMethods['Standard']
|
31
|
73 self.plugindb.SetString('xxstdnamespace', 'Standard', 'True')
|
|
74 if self.toggle.IsChecked() == False:
|
34
|
75 Parse.NameSpaceE = self.parseMethods['Traipse']
|
31
|
76 self.plugindb.SetString('xxstdnamespace', 'Standard', 'False')
|
|
77 pass
|
|
78
|
|
79 def plugin_enabled(self):
|
|
80 self.onoroff = self.plugindb.GetString('xxstdnamespace', 'Standard', '') or 'False'
|
|
81 self.toggle.Check(True) if self.onoroff == 'True' else self.toggle.Check(False)
|
|
82 Parse.NameSpaceE = self.parseMethods['Standard'] if self.onoroff == 'True' else self.parseMethods['Traipse']
|
|
83 pass
|
|
84
|
|
85 def plugin_disabled(self):
|
|
86 Parse.NameSpaceE = self.parseMethods['Traipse']
|
|
87
|
|
88 def pre_parse(self, text):
|
|
89 return text
|
|
90
|
|
91 def send_msg(self, text, send):
|
|
92 return text, send
|
|
93
|
|
94 def plugin_incoming_msg(self, text, type, name, player):
|
|
95 return text, type, name
|
|
96
|
|
97 def post_msg(self, text, myself):
|
|
98 return text
|
|
99
|
|
100 def refresh_counter(self):
|
|
101 pass
|