Handling XRC files
Prev | Chapter 2. Exploring wxGlade | Next

## Handling XRC files

wxGlade is able to save projects as XRC files and to convert XRC files into wxGlade projects.

One way for converting XRC files is the usage of the Python script xrc2wxg.py at command line. The script is part of wxGlade.

Example 2.6. Converting a XRC file into a wxGlade project

    # ./xrc2wxg.py FontColour.xrc

    # ls -l FontColour.*
    -rw-r--r-- 1 carsten carsten 5554 Dez  4 20:36 FontColour.wxg
    -rw-r--r-- 1 carsten carsten 4992 Dez  4 20:13 FontColour.xrc

The “File” menu provides a menu item “Import from XRC...” to import and open a XRC file directly.

The following example shows how to load and show the frame “Main” from XRC file `test.xrc`.

Example 2.7. wxPython code to load and show a XRC resource

    #!/usr/bin/env python2

    import wx
    from wx import xrc

    GUI_FILENAME = "test.xrc"
    GUI_MAINFRAME_NAME = "Main"

    class MyApp(wx.App):
        def OnInit(self):
            self.res = xrc.XmlResource(GUI_FILENAME)
            self.frame = self.res.LoadFrame(None, GUI_MAINFRAME_NAME)
            self.frame.Show()
            return True

    if __name__ == '__main__':
        app = MyApp()
        app.MainLoop()

Prev | Up | Next
Using the source code | Home | Chapter 3. wxGlade User Interface