XRC-Problem: How to replace an object from the xrc-tree after creation

Josh English wrote:

There's a way in XRC to accept custom elements in the xml file, so you
dont' have to replace it. I'd point you to a page on the wiki, but the
wxpyhton site seems to be down.

Josh

Here is, what I want to do:
1.) I have written a custom Widget "Grating" inherited from wxPanel which works fine when loaded into a programm not using xrc.
2.) I'd like to replace an empty wxPanel which I put into the XRC-layout as a place holder by my custom widget.

If going the route of the custom handler doesn't work for you then an easy workaround is to make your Grating widget be a child of the placeholder panel, and use a sizer such that the grating widget completely fills the placeholder.

···

On Wed, Jul 16, 2008 at 8:11 AM, Christian Weickhmann > <christian.weickhmann@gmx.de> wrote:

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

Hi,

If going the route of the custom handler doesn't work for you then an
easy workaround is to make your Grating widget be a child of the
placeholder panel, and use a sizer such that the grating widget
completely fills the placeholder.

that is _exactly_ what I'm looking for. But how do I do this?

I've tried:
  in XRC:

  ...
   <object class="unknown" name="g_Grating">
                <size>400,-1</size>
                <flag>wxEXPAND|wxALL</flag>
         </object>
  ...

  in python file:

  ...
  self.G = xrc.XRCCTRL(self.panel, "g_Grating")
  box = wx.BoxSizer(wx.HORIZONTAL)
  box.Add(Grating(self.panel, 0))
  self.G.SetSizer(box)
  ...

But then he says: self.G.SetSizer(box)
AttributeError: 'NoneType' object has no attribute 'SetSizer'

Cheers,
Christian

···

--
Christian Weickhmann
Schaafgasse 7
D-64347 Griesheim

Tel: +49 (0) 6155 799185
Handy: +49 (0) 172 9542058

--
A classic is something that everyone wants to have read
and nobody wants to read.
    -- Mark Twain, "The Disappearance of Literature"

Christian Weickhmann wrote:

Hi,

If going the route of the custom handler doesn't work for you then an
easy workaround is to make your Grating widget be a child of the
placeholder panel, and use a sizer such that the grating widget
completely fills the placeholder.

that is _exactly_ what I'm looking for. But how do I do this?

I've tried:
  in XRC:

  ...
   <object class="unknown" name="g_Grating">
                <size>400,-1</size>
                <flag>wxEXPAND|wxALL</flag>
         </object>
  ...

  in python file:

  ...
  self.G = xrc.XRCCTRL(self.panel, "g_Grating")
  box = wx.BoxSizer(wx.HORIZONTAL)
  box.Add(Grating(self.panel, 0))
  self.G.SetSizer(box)
  ...

But then he says: self.G.SetSizer(box)
AttributeError: 'NoneType' object has no attribute 'SetSizer'

Try this: use class="wxPanel" and then this code:

    self.G = xrc.XRCCTRL(self.panel, "g_Grating")
    box = wx.BoxSizer(wx.HORIZONTAL)
    box.Add(Grating(self.G, 0))
    self.G.SetSizer(box)

This is essentially the same as using XRC's unknown control functionality, except it does some magic behind the scenes.

···

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