[wxruby-users] a very simple wxRuby loading a xrc file

Zignus Arcanniss lists at ruby-forum.com
Thu Mar 5 11:07:37 EST 2009


I figured some things out.
You should use at the top of your Ruby code:
require 'wxruby'
include Wx

Here is my code that works:

require 'wxruby'
include Wx
# Application class.
#
class XrcApp < Wx::App

  def on_init
    Wx::init_all_image_handlers()
    xml = Wx::XmlResource.get()
    xml.init_all_handlers()
    xml.load("SimplePanel.xrc")
    #
    # Show the main frame.
    #
        frame = Wx::Frame.new( nil, -1, 'Simple' )
        frame.set_client_size( Wx::Size.new( 200, 200))
        xml.load_panel( frame, 'ID_WXPANEL')
        frame.show()
  end

end

XrcApp.new().main_loop()

and I created new .xrc file to go with it.
SimplePanel.xrc

<?xml version="1.0" encoding="UTF-8"?>
<resource version="2.3.0.1" xmlns="http://www.wxwidgets.org/wxxrc">
    <object class="wxPanel" name="ID_WXPANEL">
        <style>wxTAB_TRAVERSAL</style>
        <title>Simple</title>
        <centered>1</centered>
        <object class="wxBoxSizer">
            <orient>wxVERTICAL</orient>
            <object class="sizeritem">
                <flag>wxALIGN_CENTER_HORIZONTAL|wxALL</flag>
                <border>5</border>
                <object class="wxStaticText" name="wxID_STATIC">
                    <label>Static text</label>
                </object>
            </object>
            <object class="sizeritem">
                <flag>wxALIGN_CENTER_HORIZONTAL|wxALL</flag>
                <border>5</border>
                <object class="wxStaticText" name="wxID_STATIC">
                    <label>Static text</label>
                </object>
            </object>
            <object class="sizeritem">
                <flag>wxALIGN_CENTER_HORIZONTAL|wxALL</flag>
                <border>5</border>
                <object class="wxStaticText" name="wxID_STATIC">
                    <label>Static text</label>
                </object>
            </object>
            <object class="sizeritem">
                <flag>wxALIGN_CENTER_HORIZONTAL|wxALL</flag>
                <border>5</border>
                <object class="wxStaticText" name="wxID_STATIC">
                    <label>Static text</label>
                </object>
            </object>
        </object>
    </object>
</resource>



There it is.

Thanks,
Zignus
-- 
Posted via http://www.ruby-forum.com/.


More information about the wxruby-users mailing list