_xrc_ex.py
Go to the documentation of this file.
00001 #----------------------------------------------------------------------------
00002 # The global was removed  in favor of static accessor functions.  This is for
00003 # backwards compatibility:
00004 
00005 TheXmlResource = XmlResource_Get()
00006 
00007 
00008 #----------------------------------------------------------------------------
00009 #  Create a factory for handling the subclass property of the object tag.
00010 
00011 
00012 def _my_import(name):
00013     try:
00014         mod = __import__(name)
00015     except ImportError:
00016         import traceback
00017         print traceback.format_exc()
00018         raise
00019     components = name.split('.')
00020     for comp in components[1:]:
00021         mod = getattr(mod, comp)
00022     return mod
00023 
00024 
00025 class XmlSubclassFactory_Python(XmlSubclassFactory):
00026     def __init__(self):
00027         XmlSubclassFactory.__init__(self)
00028 
00029     def Create(self, className):
00030         assert className.find('.') != -1, "Module name must be specified!"
00031         mname = className[:className.rfind('.')]
00032         cname = className[className.rfind('.')+1:]
00033         module = _my_import(mname)
00034         klass = getattr(module, cname)
00035         inst = klass()
00036         return inst
00037 
00038 
00039 XmlResource_AddSubclassFactory(XmlSubclassFactory_Python())
00040 
00041 #----------------------------------------------------------------------------


wxPython_swig_interface
Author(s): Many
autogenerated on Mon Jan 6 2014 11:44:26