Subclassed sizers and XRC

Hello,

I created a new type of sizer that is
a subclass of wx.GridBagSizer. I need to be able to load a layout using
this sizer from an XRC resource definition. I have created an XmlResourceHandler
that correctly loads the sizer, but when I call LoadObject to load the
sizer, it returns a wx.GridBagSizer, and not an instance of my subclassed
sizer. Anyone have any ideas on how to get around this? A simple code sample
is included:

resourceText = r’’’<?xml version="1.0"?>

    <object

class=“SubclassedGBSizer” name=“sizer”>

    </object>

‘’’

import wx

import wx.xrc as xrc

class SubclassedGBSizer(wx.GridBagSizer):

    def

init(self):

  wx.GridBagSizer.__init__(self)

class SubclassedGBSizerXmlHandler(xrc.XmlResourceHandler):

    def

init(self):

  xrc.XmlResourceHandler.__init__(self)

    def

CanHandle(self, node):

  return self.IsOfClass(node, "SubclassedGBSizer")

    def

DoCreateResource(self):

  sizer = SubclassedGBSizer()

     
  return sizer

res = xrc.EmptyXmlResource()

res.InsertHandler(SubclassedGBSizerXmlHandler())

res.LoadFromString(resourceText)

sizer = res.LoadObject(None, “sizer”,
“SubclassedGBSizer”)

print sizer #Note
that the object is of type wx.GridBagSizer, not SubclassedGBSizer

Thanks!

–Matt Harriger

MATTHEW J HARRIGER wrote:

Hello,

I created a new type of sizer that is a subclass of wx.GridBagSizer. I need to be able to load a layout using this sizer from an XRC resource definition. I have created an XmlResourceHandler that correctly loads the sizer, but when I call LoadObject to load the sizer, it returns a wx.GridBagSizer, and not an instance of my subclassed sizer. Anyone have any ideas on how to get around this? A simple code sample is included:

It's a bug, the typemap for wxObject* (the return value of LoadObject) isn't doing the OOR check for wxSizer. I'll get it fixed today. For a workaround you can get an instance of one of the windows managed by the sizer with XRCCTRL and then call it's GetContainingSizer method.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!