227
|
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
|
|
24 self.NameSpaceE = Parse.NameSpaceE
|
|
25 self.parseMethods = {'Traipse': self.NameSpaceE, 'Standard': self.NameSpaceS}
|
|
26
|
|
27 def NameSpaceS(self, s): ## Re define NameSpace External
|
|
28 reg1 = re.compile("(!@(.*?)@!)") ## Include 'Standard' method
|
|
29 reg2 = re.compile("(!&(.*?)&!)")
|
|
30 ## Before anyone rags on me about how this is a useless plugin, or that two methods are confusing,
|
|
31 ## consider that this will be fully integrated later. Then consider that you can now create a reference
|
|
32 ## with a reference. !@ :: !& :: &! :: @!
|
|
33 matches = reg1.findall(s) + reg2.findall(s)
|
|
34 newstr = False
|
|
35 nodeable = ['rpg_grid_handler', 'container_handler',
|
|
36 'group_handler', 'tabber_handler',
|
|
37 'splitter_handler', 'form_handler', 'textctrl_handler']
|
|
38 for i in xrange(0,len(matches)):
|
|
39 find = matches[i][1].split('::')
|
|
40 node = component.get('tree').xml_root
|
|
41 if not iselement(node):
|
|
42 s = s.replace(matches[i][0], 'Invalid Reference!', 1);
|
|
43 s = self.NameSpaceS(s)
|
|
44 return s
|
|
45 for x in xrange(0, len(find)):
|
|
46 namespace = node.getiterator('nodehandler')
|
|
47 for node in namespace:
|
|
48 if find[x] == node.get('name'):
|
|
49 if node.get('class') not in nodeable: continue
|
|
50 if node.get('class') == 'rpg_grid_handler':
|
|
51 try: newstr = Parse.NameSpaceGrid(find[x+1], node); break
|
|
52 except: newstr = 'Invalid Grid Reference!'
|
|
53 try:
|
|
54 if Parse.FutureCheck(node, find[x+1]): break
|
|
55 else: continue
|
|
56 except:
|
|
57 if x == len(find)-1:
|
|
58 if node.find('text') != None: newstr = str(node.find('text').text)
|
|
59 else: newstr = 'Invalid Reference!'
|
|
60 break
|
|
61 else: break
|
|
62 if not newstr: newstr = 'Invalid Reference!'
|
|
63 s = s.replace(matches[i][0], newstr, 1)
|
|
64 s = Parse.ParseLogic(s, node)
|
|
65 return s
|
|
66
|
|
67 def plugin_menu(self):
|
|
68 ## This is a standardized Menu item. It connects to plugin_toggle where you can set events.
|
|
69 self.menu = wx.Menu()
|
|
70 self.toggle = self.menu.AppendCheckItem(wx.ID_ANY, 'On')
|
|
71 self.topframe.Bind(wx.EVT_MENU, self.plugin_toggle, self.toggle)
|
|
72 self.toggle.Check(True)
|
|
73
|
|
74 def plugin_toggle(self, evt):
|
|
75 if self.toggle.IsChecked() == True:
|
|
76 Parse.NameSpaceE = self.parseMethods['Standard']
|
|
77 self.plugindb.SetString('xxstdnamespace', 'Standard', 'True')
|
|
78 if self.toggle.IsChecked() == False:
|
|
79 Parse.NameSpaceE = self.parseMethods['Traipse']
|
|
80 self.plugindb.SetString('xxstdnamespace', 'Standard', 'False')
|
|
81 pass
|
|
82
|
|
83 def plugin_enabled(self):
|
|
84 self.onoroff = self.plugindb.GetString('xxstdnamespace', 'Standard', '') or 'False'
|
|
85 self.toggle.Check(True) if self.onoroff == 'True' else self.toggle.Check(False)
|
|
86 Parse.NameSpaceE = self.parseMethods['Standard'] if self.onoroff == 'True' else self.parseMethods['Traipse']
|
|
87 pass
|
|
88
|
|
89 def plugin_disabled(self):
|
|
90 Parse.NameSpaceE = self.parseMethods['Traipse']
|
|
91
|
|
92 def pre_parse(self, text):
|
|
93 return text
|
|
94
|
|
95 def send_msg(self, text, send):
|
|
96 return text, send
|
|
97
|
|
98 def plugin_incoming_msg(self, text, type, name, player):
|
|
99 return text, type, name
|
|
100
|
|
101 def post_msg(self, text, myself):
|
|
102 return text
|
|
103
|
|
104 def refresh_counter(self):
|
|
105 pass
|