XML ressource and subclass

Hi,

could someone explain how the xml ressource subclassing works ?
I have a xrc file with

< .... class="wxBitmapButton" subclass="myClass" >

For the one it throws an error on load about the module not specified (from
the xrc source it's probably meant to be < ... subclass="whatever.myClass" >
, whatever sense that makes)

Problem is to write a custom XmlRessourceHandler for it. The subclass is
handled in some Factory which does the Create by itself. No Parameters are
passed to the subclass. How is this supposed to work ?

I need to have a custom xml ressource handler that can catch the subclass and
instanciate my derived class instead of the main class. How ? No docs
anywhere and the source doesn't really provide a good clue.

Thanks

  UC

- --
Open Source Solutions 4U, LLC 2570 Fleetwood Drive
Phone: +1 650 872 2425 San Bruno, CA 94066
Cell: +1 650 302 2405 United States
Fax: +1 650 872 2417

Uwe C. Schroeder wrote:

could someone explain how the xml ressource subclassing works ?

Sorry, I thought I had a sample for it in the demo but I guess not.

I have a xrc file with

< .... class="wxBitmapButton" subclass="myClass" >

For the one it throws an error on load about the module not specified (from the xrc source it's probably meant to be < ... subclass="whatever.myClass" > , whatever sense that makes)

It should be "moduleName.ClassName".

Problem is to write a custom XmlRessourceHandler for it.

You shouldn't need to, the current handlers are used. The only thing that is different is that the factory is used to create the instance of the class. For example, let's say you have a class called MyPanel derived from wxPanel. If you specify class="wxPanel" subclass="myModule.MyPanel" then the wxXmlResourceHandler for wxPanel will still be used but the wxXmlSubclassFactory_Python instance will get first crack at creating an instance for it. All it does is create the instance. wxPanel::Create will still be called to create the actual window. So the only requirement to use it is that your class can be instantiated with no parameters, and only creates the instance in __init__, not the window. (IOW, it uses 2-phase create.)

I need to have a custom xml ressource handler that can catch the subclass and instanciate my derived class instead of the main class. How ? No docs anywhere and the source doesn't really provide a good clue.

Attached is a sample for the demo.

wxXmlResourceSubclass.py (3.01 KB)

···

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

Ahh, that makes sense. Thanks a lot.

Uwe C. Schroeder wrote:
> could someone explain how the xml ressource subclassing works ?

Sorry, I thought I had a sample for it in the demo but I guess not.

> I have a xrc file with
>
> < .... class="wxBitmapButton" subclass="myClass" >
>
> For the one it throws an error on load about the module not specified
> (from the xrc source it's probably meant to be < ...
> subclass="whatever.myClass" > , whatever sense that makes)

It should be "moduleName.ClassName".

> Problem is to write a custom XmlRessourceHandler for it.

You shouldn't need to, the current handlers are used. The only thing
that is different is that the factory is used to create the instance of
the class. For example, let's say you have a class called MyPanel
derived from wxPanel. If you specify class="wxPanel"
subclass="myModule.MyPanel" then the wxXmlResourceHandler for wxPanel
will still be used but the wxXmlSubclassFactory_Python instance will get
first crack at creating an instance for it. All it does is create the
instance. wxPanel::Create will still be called to create the actual
window. So the only requirement to use it is that your class can be
instantiated with no parameters, and only creates the instance in
__init__, not the window. (IOW, it uses 2-phase create.)

> I need to have a custom xml ressource handler that can catch the subclass
> and instanciate my derived class instead of the main class. How ? No docs
> anywhere and the source doesn't really provide a good clue.

Attached is a sample for the demo.

- --
  UC

- --
Open Source Solutions 4U, LLC 2570 Fleetwood Drive
Phone: +1 650 872 2425 San Bruno, CA 94066
Cell: +1 650 302 2405 United States
Fax: +1 650 872 2417

···

On Monday 20 October 2003 05:53 pm, Robin Dunn wrote: