]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_xrc_ex.py
wxPathList cleanup by Francesco (patch 1521481)
[wxWidgets.git] / wxPython / src / _xrc_ex.py
1 #----------------------------------------------------------------------------
2 # The global was removed in favor of static accessor functions. This is for
3 # backwards compatibility:
4
5 TheXmlResource = XmlResource_Get()
6
7
8 #----------------------------------------------------------------------------
9 # Create a factory for handling the subclass property of the object tag.
10
11
12 def _my_import(name):
13 try:
14 mod = __import__(name)
15 except ImportError:
16 import traceback
17 print traceback.format_exc()
18 raise
19 components = name.split('.')
20 for comp in components[1:]:
21 mod = getattr(mod, comp)
22 return mod
23
24
25 class XmlSubclassFactory_Python(XmlSubclassFactory):
26 def __init__(self):
27 XmlSubclassFactory.__init__(self)
28
29 def Create(self, className):
30 assert className.find('.') != -1, "Module name must be specified!"
31 mname = className[:className.rfind('.')]
32 cname = className[className.rfind('.')+1:]
33 module = _my_import(mname)
34 klass = getattr(module, cname)
35 inst = klass()
36 return inst
37
38
39 XmlResource_AddSubclassFactory(XmlSubclassFactory_Python())
40
41 #----------------------------------------------------------------------------