annotate plugins/xxstdnamespace.py @ 221:e4a4429c5f85 alpha

Traipse Alpha 'OpenRPG' {100502-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) Moved to Beta!! 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 New to Mini Lin node, change title in design mode New to Game Tree, never lose a node, appends a number to the end of corrupted trees New to Server GUI, Traipse Suite's Debug Console New Namespace plugin, Allows Traipse users to use the Standard syntax !@ :: @! Updates: Update to White Board layer, uses a pencil image for color button Update to Grid Layer, uses a grid image for color button Update to Chat Window, size of drop down menus Update to default lobby message Update to template Text node Update to 4e PC Sheet node 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 Fix to Mini Lib node that was preventing use Fix to plugins that parce dice but did not call InterParse Fix to nodes for name changing by double click Fix to Game Tree, node ordering on drag and drop corrected Fix to Game Tree, corrupted error message was not showing Fix to Update Manager, checks for internet connection Fix to Update Manager, Auto Update corrections
author sirebral
date Sun, 02 May 2010 16:19:29 -0500
parents
children d5ff505a2a16
rev   line source
221
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
1 import os, wx, re
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
2 import orpg.pluginhandler
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
3 from orpg.tools.InterParse import Parse
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
4 from orpg.orpgCore import component
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
5 from xml.etree.ElementTree import iselement
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
6
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
7 class Plugin(orpg.pluginhandler.PluginHandler):
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
8 # Initialization subroutine.
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
9 #
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
10 # !self : instance of self
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
11 # !openrpg : instance of the the base openrpg control
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
12 def __init__(self, plugindb, parent):
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
13 orpg.pluginhandler.PluginHandler.__init__(self, plugindb, parent)
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
14
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
15 # The Following code should be edited to contain the proper information
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
16 self.name = 'Standard Namespace'
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
17 self.author = 'Prof. Ebral'
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
18 self.help = 'The Standard Namespace plugin allows for users of Traipse to use '
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
19 self.help += 'the Standard Namespace syntax of !@ :: @!\n\n'
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
20 self.help += 'This plugin modifies the External method, so context sensivity\n'
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
21 self.help += 'is not calculted when using the Standard syntax. References must\n'
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
22 self.help += 'a unique name.'
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
23
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
24 self.parseMethods = {'Traipse': Parse.NameSpaceE, 'Standard': self.NameSpaceS}
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
25
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
26 def NameSpaceS(self, s): ## Re define NameSpace External
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
27 reg1 = re.compile("(!@(.*?)@!)") ## Inlcude 'Standard' method
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
28 reg2 = re.compile("(!&(.*?)&!)")
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
29 matches = reg1.findall(s) + reg2.findall(s)
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
30 newstr = False
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
31 nodeable = ['rpg_grid_handler', 'container_handler',
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
32 'group_handler', 'tabber_handler',
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
33 'splitter_handler', 'form_handler', 'textctrl_handler']
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
34 for i in xrange(0,len(matches)):
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
35 find = matches[i][1].split('::')
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
36 node = component.get('tree').xml_root
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
37 if not iselement(node):
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
38 s = s.replace(matches[i][0], 'Invalid Reference!', 1);
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
39 s = Parse.NameSpaceE(s)
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
40 return s
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
41 for x in xrange(0, len(find)):
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
42 namespace = node.getiterator('nodehandler')
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
43 for node in namespace:
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
44 if find[x] == node.get('name'):
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
45 if node.get('class') not in nodeable: continue
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
46 if node.get('class') == 'rpg_grid_handler':
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
47 try: newstr = self.NameSpaceGrid(find[x+1], node); break
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
48 except: newstr = 'Invalid Grid Reference!'
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
49 try:
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
50 if Parse.FutureCheck(node, find[x+1]): break
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
51 else: continue
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
52 except:
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
53 if x == len(find)-1:
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
54 if node.find('text') != None: newstr = str(node.find('text').text)
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
55 else: newstr = 'Invalid Reference!'
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
56 break
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
57 else: break
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
58 if not newstr: newstr = 'Invalid Reference!'
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
59 s = s.replace(matches[i][0], newstr, 1)
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
60 s = Parse.ParseLogic(s, node)
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
61 return s
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
62
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
63 def plugin_menu(self):
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
64 ## This is a standardized Menu item. It connects to plugin_toggle where you can set events.
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
65 self.menu = wx.Menu()
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
66 self.toggle = self.menu.AppendCheckItem(wx.ID_ANY, 'On')
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
67 self.topframe.Bind(wx.EVT_MENU, self.plugin_toggle, self.toggle)
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
68 self.toggle.Check(True)
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
69
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
70 def plugin_toggle(self, evt):
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
71 if self.toggle.IsChecked() == True:
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
72 Parse.NameSpaceI = self.parseMethods['Standard']
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
73 self.plugindb.SetString('xxstdnamespace', 'Standard', 'True')
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
74 if self.toggle.IsChecked() == False:
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
75 Parse.NameSpaceI = self.parseMethods['Traipse']
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
76 self.plugindb.SetString('xxstdnamespace', 'Standard', 'False')
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
77 pass
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
78
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
79 def plugin_enabled(self):
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
80 self.onoroff = self.plugindb.GetString('xxstdnamespace', 'Standard', '') or 'False'
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
81 self.toggle.Check(True) if self.onoroff == 'True' else self.toggle.Check(False)
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
82 Parse.NameSpaceE = self.parseMethods['Standard'] if self.onoroff == 'True' else self.parseMethods['Traipse']
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
83 pass
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
84
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
85 def plugin_disabled(self):
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
86 Parse.NameSpaceE = self.parseMethods['Traipse']
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
87
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
88 def pre_parse(self, text):
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
89 return text
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
90
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
91 def send_msg(self, text, send):
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
92 return text, send
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
93
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
94 def plugin_incoming_msg(self, text, type, name, player):
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
95 return text, type, name
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
96
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
97 def post_msg(self, text, myself):
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
98 return text
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
99
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
100 def refresh_counter(self):
e4a4429c5f85 Traipse Alpha 'OpenRPG' {100502-00}
sirebral
parents:
diff changeset
101 pass