view plugins/xxstdnamespace.py @ 245:682032381be8 beta

Traipse Beta 'OpenRPG' {101130-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 (Closing/Closed) New Features: New to Map, can re-order Grid, Miniatures, and Whiteboard layer draw order New to Server GUI, can now clear log New Earthdawn Dieroller New IronClaw roller, sheet, and image Updates: Update to Warhammer PC Sheet. Rollers set as macros. Should work with little maintanence. Update to Browser Server window. Display rooms with ' " & cleaner Update to Server. Handles ' " & cleaner Update to Dieroller. Cleaner, more effecient expression system Update to Hidden Die plugin, allows for non standard dice rolls 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 Fix to Single and Double quotes in Whiteboard text Fix to Background images not showing when using the Image Server Fix to Duplicate chat names appearing Fix to Server GUI's logging output Fix to FNB.COLORFUL_TABS bug Fix to Gametree for XSLT Sheets Fix to Gametree for locating gametree files Fix to Send to Chat from Gametree Fix to Gametree, renaming and remapping operates correctly Fix to aliaslib, prevents error caused when SafeHTML is sent None
author sirebral
date Tue, 30 Nov 2010 02:34:58 -0600
parents 56c1f2729413
children
line wrap: on
line source

import os, wx, re
import orpg.pluginhandler
from orpg.tools.InterParse import Parse
from orpg.orpgCore import component
from xml.etree.ElementTree import iselement

class Plugin(orpg.pluginhandler.PluginHandler):
    # Initialization subroutine.
    #
    # !self : instance of self
    # !openrpg : instance of the the base openrpg control
    def __init__(self, plugindb, parent):
        orpg.pluginhandler.PluginHandler.__init__(self, plugindb, parent)

        # The Following code should be edited to contain the proper information
        self.name = 'Standard Namespace'
        self.author = 'Prof. Ebral'
        self.help = 'The Standard Namespace plugin allows for users of Traipse to use '
        self.help += 'the Standard Namespace syntax of !@ :: @!\n\n'
        self.help += 'This plugin modifies the External method, so context sensivity\n'
        self.help += 'is not calculated when using the Standard syntax. References must '
        self.help += 'have a unique name.'

        self.parseMethods = {'Traipse': Parse.NameSpaceE, 'Standard': self.NameSpaceS}

    def NameSpaceS(self, s): ## Re define NameSpace External
        reg1 = re.compile("(!@(.*?)@!)") ## Inlcude 'Standard' method
        reg2 = re.compile("(!&(.*?)&!)")
        matches = reg1.findall(s) + reg2.findall(s)
        newstr = False
        nodeable = ['rpg_grid_handler', 'container_handler', 
                    'group_handler', 'tabber_handler', 
                    'splitter_handler', 'form_handler', 'textctrl_handler']
        for i in xrange(0,len(matches)):
            find = matches[i][1].split('::')
            node = component.get('tree').xml_root
            if not iselement(node): 
                s = s.replace(matches[i][0], 'Invalid Reference!', 1); 
                s = Parse.NameSpaceE(s)
                return s
            for x in xrange(0, len(find)):
                namespace = node.getiterator('nodehandler')
                for node in namespace:
                    if find[x] == node.get('name'):
                        if node.get('class') not in nodeable: continue
                        if node.get('class') == 'rpg_grid_handler':
                            try: newstr = self.NameSpaceGrid(find[x+1], node); break
                            except: newstr = 'Invalid Grid Reference!'
                        try:
                            if Parse.FutureCheck(node, find[x+1]): break
                            else: continue
                        except:
                            if x == len(find)-1:
                                if node.find('text') != None: newstr = str(node.find('text').text) 
                                else: newstr = 'Invalid Reference!'
                                break
                            else: break
            if not newstr: newstr = 'Invalid Reference!'
            s = s.replace(matches[i][0], newstr, 1)
            s = Parse.ParseLogic(s, node)
        return s

    def plugin_menu(self):
        ## This is a standardized Menu item.  It connects to plugin_toggle where you can set events.
        self.menu = wx.Menu()
        self.toggle = self.menu.AppendCheckItem(wx.ID_ANY, 'On')
        self.topframe.Bind(wx.EVT_MENU, self.plugin_toggle, self.toggle)
        self.toggle.Check(True)

    def plugin_toggle(self, evt):
        if self.toggle.IsChecked() == True: 
            Parse.NameSpaceE = self.parseMethods['Standard']
            self.plugindb.SetString('xxstdnamespace', 'Standard', 'True')
        if self.toggle.IsChecked() == False: 
            Parse.NameSpaceE = self.parseMethods['Traipse']
            self.plugindb.SetString('xxstdnamespace', 'Standard', 'False')
        pass

    def plugin_enabled(self):
        self.onoroff = self.plugindb.GetString('xxstdnamespace', 'Standard', '') or 'False'
        self.toggle.Check(True) if self.onoroff == 'True' else self.toggle.Check(False)
        Parse.NameSpaceE = self.parseMethods['Standard'] if self.onoroff == 'True' else self.parseMethods['Traipse']
        pass

    def plugin_disabled(self):
        Parse.NameSpaceE = self.parseMethods['Traipse']

    def pre_parse(self, text):
        return text

    def send_msg(self, text, send):
        return text, send

    def plugin_incoming_msg(self, text, type, name, player):
        return text, type, name

    def post_msg(self, text, myself):
        return text

    def refresh_counter(self):
        pass