classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view


Chris Norman

Hi all,

I'm happy to announce the first release of XMLUI: My quicker-and-dirty implementation of xrc.

The idea is you create structure in an XML file, then overlay that structure on an already-created wx.Frame or wx.Dialog instance.

Here's the xml for a login frame that's provided with the repo:

    <title>Test Frame</title>
    <sizer orient="vertical" name="main_sizer">
            <label style="st_ellipsize_end">&amp;Username</label>
            <text name="username" sizer_proportion="1" sizer_flag="grow" style="te_rich2">test</text>
            <label style="st_ellipsize_end">&amp;Password</label>
            <text name="password" sizer_proportion="1" sizer_flag="grow" style="te_password" bind="text_paste:on_paste,text_copy:on_copy"></text>
            <integer name="age" sizer_proportion="1" sizer_flag="grow" min="10">18</integer>
            <label>&amp;Height (in metres)</label>
            <float name="height" sizer_proportion="1" sizer_flag="grow" digits="2" min="0.5" max="2.5" increment="0.1">1.5</float>
            <slider style="sl_horizontal,sl_inverse" name="rating" min="0" max="5">3</slider>
            <checkbox name="agree" sizer_proportion="1" sizer_flag="grow" label="I &amp;Agree"></checkbox>
        <sizer sizer_proportion="1" sizer_flag="grow">
            <button name="login" label="&amp;Login" default="1" bind="button:on_login"></button>
            <button name="cancel" label="&amp;Cancel" bind="button:close"></button>

Here's the Python code that drives it:

"""Show a frame generated from an XML file."""

import wx
from xmlui.wx import WXXMLParser

class MyXMLParser(WXXMLParser):
    """Add event handlers."""

    def on_paste(self, event):
        """Pop up an alert."""
        return wx.MessageBox('You shouldn\'t copy and paste passwords.')

    def on_copy(self, event):
        """Pop up an alert."""
        return wx.MessageBox(
            'You probably won\'t get any useful text that way.'

    def on_login(self, event):
        frame = event.GetEventObject().GetParent().GetParent()
        username = frame.username.GetValue()
        password = frame.password.GetValue()
        return wx.MessageBox(
            'You clicked the Login button.\n\n'
            f'Username: {username}\n'
            f'Password: {password}'

    def close(self, event):

if __name__ == '__main__':
    a = wx.App()
    f = wx.Frame(None)
    xml.populate_from_file('frame.xml', f, None)

As you can see, you can bind multiple events for each control. Also, anything in there (apart from the root tag - which can be anything), with a name attribute will be added to the frame with that name.


Currently there is no work around for lines like:

frame.Bind(wx.EVT_MENU, handler, menu_item)

There is currently no documentation beyond docstrings. I'll add that at some point in the hopefully-not-too-distant future (hopefully tomorrow).

If I (or someone else) wants that functionality I could add it easily enough.

If anyone has any suggestions or whatever, please feel free to message me.

Github: Link

PyPi: Link

Complaints: [hidden email]

You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.