Search code examples
pythonwxpythonwxwidgetswxruby

How to use AddSubclassFactory from wxPython?


I cant find any examples online on how to use this method. I think that It may be something that I will use. Can someone provide me an example on how to use this method?

http://wxpython.org/docs/api/wx.xrc.XmlResource-class.html


Solution

  • Based on the source code, I believe this is how you would do it.

    Source Code: http://wxwidgets2.8.sourcearchive.com/documentation/2.8.7.1/classxrc_1_1XmlResource_4a0466d7ef7ac98ef7a9b8135a0c9339.html

    def AddSubclassFactory(*args, **kwargs):
        """AddSubclassFactory(XmlSubclassFactory factory)"""
        return _xrc.XmlResource_AddSubclassFactory(*args, **kwargs)
    

    So you can see that it is looking for an object of type XmlSubclassFactory. From the documentation (http://wxpython.org/docs/api/wx.xrc.XmlSubclassFactory-class.html) we find...

    XmlSubclassFactory  __init__(self)
    

    We can see that the constructor for XmlSubClassFactory takes no arguments. So we create an object of XmlSubclassFactory and create a resource to add the SubClassFactory to.

    import wx
    from wx import xrc
    
    scf = xrc.XmlSubClassFactory()
    resource = xrc.XmlResource("resource.xrc")
    resource.AddSubclassFactory(scf)
    

    I, unfortunately, could not find a Python example. However, I think the Perl analog is pretty close. From http://permalink.gmane.org/gmane.comp.lang.perl.wxperl/477

    Wx::XmlResource::AddSubclassFactory( MyFactory->new ); // perl
    

    This is pretty similar to what we are doing. So between reading the source code and that example, I believe the snippet is a good place to start. Good luck!