[wxPython] wxDesigner wxr XML file support outside of wxDesigner?

Robin,
could you let us know the current state of resource files and wxPython?

wxDesigner can import and export XML for layout info. I've included the
output from the minimal sample below. In addition, Roman Rolinsky posted
about XRCed back in August

http://aspn.activestate.com/ASPN/Mail/Message/757596

and it looks like XRCed is now included in the tools directory for wxPython.

XRCed home page
http://www.mema.ucl.ac.be/~rolinsky/xrced/

What I was wondering is whether this is the new standard for resources in
wxWindows/wxPython? If so, does it support menus, the output below didn't
include the menu definitions. Finally, do you have any code snippets or are
there new handlers in the latest wxPython beta to load and create windows,
frames, controls, etc. from the XML resource definitions? wxDesigner appears
to be generating code for layout (like Boa) and the XML is just for
import/export.

Riaan if your reading this, do you have any plans for supporting the XML xrc
files?

ka

···

---
<?xml version="1.0"?>
<!-- XML resource generated by wxDesigner from file: minimal.wdr -->
<!-- Do not modify this file, all changes will be lost! -->

<resource>

<object class="wxPanel" name="MyDialogFunc">
    <object class="wxBoxSizer">
        <orient>wxVERTICAL</orient>
        <object class="sizeritem">
            <flag>wxGROW|wxALIGN_CENTER_VERTICAL|wxALL</flag>
            <border>5</border>
            <object class="wxStaticBoxSizer">
                <orient>wxVERTICAL</orient>
                <label>Copyright</label>
                <object class="sizeritem">
                    <flag>wxALIGN_CENTRE|wxALL</flag>
                    <border>5</border>
                    <object class="wxStaticText" name="ID_TEXT">
                        <fg>#0000FF</fg>
                        <label>Minimal app
(C)opyright 2000 Robert Roebling</label>
                    </object>
                </object>
            </object>
        </object>
        <object class="sizeritem">
            <flag>wxGROW|wxALIGN_CENTER_VERTICAL|wxALL</flag>
            <border>5</border>
            <object class="wxStaticLine" name="ID_LINE">
                <size>20,-1</size>
                <style>wxLI_HORIZONTAL</style>
            </object>
        </object>
        <object class="sizeritem">
            <flag>wxALIGN_CENTRE|wxALL</flag>
            <border>5</border>
            <object class="wxButton" name="wxID_OK">
                <label>OK</label>
            </object>
        </object>
    </object>
</object>

</resource>

Robin,
could you let us know the current state of resource files and wxPython?

wxDesigner can import and export XML for layout info.

It can also be one of the targeted output formats (so instead of generating
Python or C++ you can just have it generate an xrc file.)

In addition, Roman Rolinsky posted
about XRCed back in August

This is still in progressa as far as I know. I'm waiting for new code from
Roman.

What I was wondering is whether this is the new standard for resources in
wxWindows/wxPython?

More or less. It's still in wxWindows contrib, not in the core, but it is
the accepted standard.

If so, does it support menus,

Yes.

Finally, do you have any code snippets or are
there new handlers in the latest wxPython beta to load and create windows,
frames, controls, etc. from the XML resource definitions?

Yes, it's in the 2.3.1 demo.

···

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

From: Robin Dunn

More or less. It's still in wxWindows contrib, not in the core, but it is
the accepted standard.

> If so, does it support menus,

Yes.

> Finally, do you have any code snippets or are
> there new handlers in the latest wxPython beta to load and
create windows,
> frames, controls, etc. from the XML resource definitions?

Yes, it's in the 2.3.1 demo.

Okay, my bad for not paying attention to this earlier. I have a sample
working with LoadPanel. I have not been able to get LoadFrame to work
because I can't figure out the argument list. I found xmlres.py, so I can
see the various methods. My next dumb question is where are these methods
documented? I at least need to see the expected args and the expected arg
order.

Also, since it appears there are separate methods for Panel, Frame, Dialog
can you still use the resource files for loading even if you've make a
subclass on wxPanel, wxFrame, etc.? Does it support the existing wxWindows
window types? If not, then the loading needs to be made more generic. How
are LoadOnPanel and LoadOnDialog different from LoadPanel and LoadDialog?
Should we discuss this over on wx-dev?

ka

Okay, my bad for not paying attention to this earlier. I have a sample
working with LoadPanel. I have not been able to get LoadFrame to work
because I can't figure out the argument list. I found xmlres.py, so I can
see the various methods. My next dumb question is where are these methods
documented? I at least need to see the expected args and the expected arg
order.

http://cvs.wxwindows.org/cgi-bin/viewcvs.cgi/wxPython/contrib/xrc/xrc.i?rev=
1.1&content-type=text/vnd.viewcvs-markup

Also, since it appears there are separate methods for Panel, Frame, Dialog
can you still use the resource files for loading even if you've make a
subclass on wxPanel, wxFrame, etc.? Does it support the existing wxWindows
window types? If not, then the loading needs to be made more generic. How
are LoadOnPanel and LoadOnDialog different from LoadPanel and LoadDialog?

The answer to your first question is your last question. <wink>

I havn't actually tried it yet but the LoadOn* versions of the methods are
for loading a resource onto an existing window. There is a trick to it
however. The LoadOn* methods expect the window to not have been created
yet, because it will call the Create method itself. (Vaclav please correct
me if I have this wrong.)

In C++ this means that the window has been constructed with only the default
constructor (for example, wxPanel()) not the one we usually use in wxPython
(for example, wxPanel(parent, ID, pos, size, style)).

In the 2.3.2 beta you'll find a note in CHANGES.txt that there are some new
functions to help simulate this in wxPython. All the window classes now
have a helper functoin with a "Pre" in the name that creates an instance of
the class with the default constructor and returns it. The trick is that
since it's not a class you can't derive from it, but something like the
following would probably work:

class MyPanel(wxPanel):
    def __init__(self, parent):
        # instead of calling wxPanel.__init__ do this:
        p = wxPrePanel()
        self.this = p.this
        self.thisown = 1
        self._setOORInfo(self)

        # load resources or whatever you need to customize this class
        blah, blah, blah

Hmmm... I just noticed a bug in the wxPre** functions so don't try this
until the next beta.

···

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