]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_xrc_ex.py
reswigged
[wxWidgets.git] / wxPython / src / _xrc_ex.py
CommitLineData
d14a1e28 1#----------------------------------------------------------------------------
ce914f73
RD
2# The global was removed in favor of static accessor functions. This is for
3# backwards compatibility:
1e4a197e 4
d14a1e28 5TheXmlResource = XmlResource_Get()
1e4a197e
RD
6
7
d14a1e28 8#----------------------------------------------------------------------------
1e4a197e
RD
9# Create a factory for handling the subclass property of the object tag.
10
11
12def _my_import(name):
846b1185
RD
13 try:
14 mod = __import__(name)
15 except ImportError:
16 import traceback
17 print traceback.format_exc()
18 raise
1e4a197e
RD
19 components = name.split('.')
20 for comp in components[1:]:
21 mod = getattr(mod, comp)
22 return mod
23
24
d14a1e28 25class XmlSubclassFactory_Python(XmlSubclassFactory):
1e4a197e 26 def __init__(self):
d14a1e28 27 XmlSubclassFactory.__init__(self)
1e4a197e
RD
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
d14a1e28 39XmlResource_AddSubclassFactory(XmlSubclassFactory_Python())
1e4a197e 40
d14a1e28 41#----------------------------------------------------------------------------