X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/628c7f79d4f177b18349c9c10d49db6c9c4bc56c..7728856b75c201016a30145673bc8a85be96fdfe:/wxPython/contrib/xrc/_xrcextras.py?ds=inline diff --git a/wxPython/contrib/xrc/_xrcextras.py b/wxPython/contrib/xrc/_xrcextras.py index e4cd16f562..9562aea2eb 100644 --- a/wxPython/contrib/xrc/_xrcextras.py +++ b/wxPython/contrib/xrc/_xrcextras.py @@ -4,3 +4,35 @@ wxTheXmlResource = wxXmlResource_Get() wx.wxXmlNodePtr = wxXmlNodePtr + + + + +#---------------------------------------------------------------------- +# Create a factory for handling the subclass property of the object tag. + + +def _my_import(name): + mod = __import__(name) + components = name.split('.') + for comp in components[1:]: + mod = getattr(mod, comp) + return mod + + +class wxXmlSubclassFactory_Python(wxXmlSubclassFactory): + def __init__(self): + wxXmlSubclassFactory.__init__(self) + + def Create(self, className): + assert className.find('.') != -1, "Module name must be specified!" + mname = className[:className.rfind('.')] + cname = className[className.rfind('.')+1:] + module = _my_import(mname) + klass = getattr(module, cname) + inst = klass() + return inst + + +wxXmlResource_AddSubclassFactory(wxXmlSubclassFactory_Python()) +