pubsubconf.py :  » GUI » wxPython » wxPython-src-2.8.11.0 » wxPython » wx » lib » pubsub » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » GUI » wxPython 
wxPython » wxPython src 2.8.11.0 » wxPython » wx » lib » pubsub » pubsubconf.py
"""
Configuration of pubsub API to use either the *arg1* or *kwargs*
messaging protocol in API, or to help transition from the former to the
latter. This should be used only internally by pubsub. 

:copyright: Copyright 2006-2009 by Oliver Schoenborn, all rights reserved.
:license: BSD, see LICENSE.txt for details.
     
"""


pubModuleInfo = None


def setVersion(id):
    pubModuleInfo.setVersion(id)


class _PubModuleInfo:
    '''Used to keep track of which pub module is loaded, based on version
    selected. '''

    DEFAULT_VERSION = 3

    def __init__(self, moduleSearchPaths, moduleDict):
        self.__searchPaths = moduleSearchPaths
        self.__pubsubDict  = moduleDict
        self.__version = self.DEFAULT_VERSION
        # nothing else to do for default version

    def setVersion(self, versionID):
        if versionID == self.__version:
            return

        modulePath = self.__searchPaths

        # cleanup first if necessary:

        if self.__version == self.DEFAULT_VERSION:
            # nothing to cleanup
            pass

        else:
            # remove the now obsolete path element
            assert len(modulePath) > 1
            del modulePath[0]

            if self.__version == 1:
                self.__unsetupV1()

        assert len(modulePath) == 1

        # now add path if necessary:
        if versionID == self.DEFAULT_VERSION:
            # path is '.', ie modulePath[-1]
            pass

        else:
            # just prepend the path:
            ourInitpyPath = modulePath[-1]
            paths = {1: 'pubsub1', 2: 'pubsub2', self.DEFAULT_VERSION: None}
            import os
            path = os.path.join(ourInitpyPath, paths[versionID])
            modulePath.insert(0, path)

        assert versionID != self.__version
        self.__version = versionID

        if self.__version == 1:
            self.__setupForV1()


    def __setupForV1(self):
        '''Add the pub module and Publisher singleton to the given map
        (pubsubInitGlobals), assumed to be pubsub.__init__'s global dict.
        The pub module will provide the legacy "version 1" API for pubsub,
        and Publisher will be the singleton stored in that module.'''
        import pub
        from pub import Publisher

        self.__pubsubDict['Publisher'] = Publisher
        self.__pubsubDict['pub'] = pub


    def __unsetupV1(self):
        '''This should be called by pubsub.setup!* modules in case setupv1 was used.'''
        self.__removePubModule()
        del self.__pubsubDict['pub']
        del self.__pubsubDict['Publisher']


    def __removePubModule(self):
        '''Remove the given module object from the sys.modules map.'''
        pubsub1 = self.__pubsubDict['pub']
        import sys
        for (modName, modObj) in sys.modules.iteritems():
            if modObj is pubsub1:
                del sys.modules[modName]
                break


def setPubsubInfo(moduleSearchPath, moduleDict):
    '''This gets called by pubsub's __init__.py so that setupv1 will be
    able to add the pub and Publisher instances to pubsub module, and so
    that setupkwargs and setuparg1 can clean things up if they are
    imported after setupv1 was used. '''
    global pubModuleInfo
    assert pubModuleInfo is None
    pubModuleInfo = _PubModuleInfo(moduleSearchPath, moduleDict)


def pubModuleLoaded():
    '''This gets called by pub once loaded. Helps avoid circular refs.'''
    #global pubModuleInfo
    #pubModuleInfo = None

    
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.