XRC and wxPanel subclass loaded from XRC

Hi all.

Perhaps this question is dumb, but I am very new to XRC. I have a class
deriving from wxPanel. I would like to have such panels on several of
the dialogs of my application. So, I went the "XRC and subclassing" way.
However, the contents of the panel are loaded from XRC, too.

The constructors of subclasses must take no other arguments but self.
LoadOnPanel requires a parent. What could I do?

Here is a code snippet. I have commented out the old constructor, before
XRC subclassing. There is a 'parent' argument at thAt the 2nd line of
the constructor, which curently generates an exception, because it does
not exist.

class PersonSelPanel(wx.Panel):
  #def __init__(self, parent, id, pos, size, style, name):
  def __init__(self):
    self.Pre = wx.PrePanel()
    xrc.XmlResource.Get().LoadOnPanel(self.Pre, parent, "ID_PN_PERSONSEL")
    self.PostCreate(self.Pre)

    self.BtFind = xrc.XRCCTRL(self, "ID_BT_FIND")

    self.Bind(wx.EVT_BUTTON, self.onBtFind, self.BtFind)
    return

Thank you very much.

Stavros

Tsolakos Stavros wrote:

Hi all.

Perhaps this question is dumb, but I am very new to XRC. I have a class
deriving from wxPanel. I would like to have such panels on several of
the dialogs of my application. So, I went the "XRC and subclassing" way.
However, the contents of the panel are loaded from XRC, too.

The constructors of subclasses must take no other arguments but self.
LoadOnPanel requires a parent. What could I do?

You don't need to load the contents of the panel yourself, XRC will do it for you, that's what it is there for. All your subclass needs to do is create the instance and XRC will do the rest.

If you want to be able to do something after XRC is finished loading (like binding event handlers for child widgets as in your example) then you can use wx.CallAfter, or people will sometimes do it in a EVT_CREATE_WINDOW handler, the first EVT_SIZE event, or etc. See the sample in the demo.

···

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