bitmaptogglebutton and xrc

Paul Sijben wrote:

When I specify a wx.lib.buttons.bitmaptogglebutton in XRC I get the
error that the init() of the bitmagtogglebutton requires more parameters.

Now I have been looking at XmlResourceSubclass but it does not make much
sense to me. The parameters that in that example a Panel needs seems to
be nowhere.

Is there a place where this is explained a little more?

XRC relies on the ability to use a two-phase creation method of the widgets it creates and manages. In other words, instead of creating both the class instance and the UI widget in one step like you usually do, in a two-phase create you first create the class instance without the UI widget, and then later the UI widget can be created in a separate step after some other initialization has been done. In the case of XRC it allows the class instance to be created outside of XRC (such as with the subclass factory) and then XRC will be the one to call the Create method once it has gathered everything it needs from the xrc document.

There is some more info about this here: TwoStageCreation - wxPyWiki and elsewhere in the wiki.

The Python XRC subclass factory expects that the class named in in the xrc document can be created by passing no parameters to the constructor, since that is the normal pattern with two-phase create. It is also required that the widget's parent class' Create method can be called by XRC and that the RightThing will be done when that happens. Obviously the generic button classes in wx.lib.buttons don't fit this pattern, so you'll need to make your own subclass that does.

···

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

thanks will try!

Robin Dunn wrote:

···

Paul Sijben wrote:

When I specify a wx.lib.buttons.bitmaptogglebutton in XRC I get the
error that the init() of the bitmagtogglebutton requires more parameters.

Now I have been looking at XmlResourceSubclass but it does not make much
sense to me. The parameters that in that example a Panel needs seems to
be nowhere.

Is there a place where this is explained a little more?

XRC relies on the ability to use a two-phase creation method of the widgets it creates and manages. In other words, instead of creating both the class instance and the UI widget in one step like you usually do, in a two-phase create you first create the class instance without the UI widget, and then later the UI widget can be created in a separate step after some other initialization has been done. In the case of XRC it allows the class instance to be created outside of XRC (such as with the subclass factory) and then XRC will be the one to call the Create method once it has gathered everything it needs from the xrc document.

There is some more info about this here: http://wiki.wxpython.org/TwoStageCreation and elsewhere in the wiki.

The Python XRC subclass factory expects that the class named in in the xrc document can be created by passing no parameters to the constructor, since that is the normal pattern with two-phase create. It is also required that the widget's parent class' Create method can be called by XRC and that the RightThing will be done when that happens. Obviously the generic button classes in wx.lib.buttons don't fit this pattern, so you'll need to make your own subclass that does.

--
Paul Sijben tel: +31334566488
Eemvalley Technology fax: +31334557523
the Netherlands http://eemvalley.com