view plugins/xxstdnamespace.py @ 34:1fb663829ef6 ornery-orc

Traipse 'OpenRPG' {100504-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) http://traipse.assembla.com/wiki/show/traipse/Patch-2 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 Namespace 2.0 documentation in the User Manual New Namespace plugin, Allows Traipse users to use the Standard syntax !@ :: @! New Mini Library with minis from Devin Knight 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 Lib 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 Warhammer PC Sheet 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 Update to how display names are acquired Update to Server, added some 'Pious' technology Update to features 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 Fix to Server GUI's broadcast, room, player messaging
author sirebral
date Tue, 04 May 2010 10:43:29 -0500
parents fc48380f0c9f
children d02e9197c066
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.NameSpaceE = Parse.NameSpaceE
        self.parseMethods = {'Traipse': self.NameSpaceE, 'Standard': self.NameSpaceS}

    def NameSpaceS(self, s): ## Re define NameSpace External
        reg1 = re.compile("(!@(.*?)@!)") ## Include 'Standard' method
        reg2 = re.compile("(!&(.*?)&!)")
        ## Before anyone rags on me about how this is a useless plugin, or that two methods are confusing,
        ## consider that this will be fully integrated later. Then consider that you can now create a reference
        ## with a reference. !@ :: !& :: &! :: @!
        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 = self.NameSpaceS(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 = Parse.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