# A very simple wxRuby loading a xrc file

**URL:** <https://www.ruby-forum.com/t/a-very-simple-wxruby-loading-a-xrc-file/162002>\
**Category:** wxRuby\
**Created:** [March 4, 2009, 6:19pm UTC](https://www.ruby-forum.com/t/a-very-simple-wxruby-loading-a-xrc-file/162002 "2009-03-04T18:19:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zignus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/77aa72/32.png) [@zignus](https://www.ruby-forum.com/u/zignus)\
**Post date:** [March 4, 2009, 6:19pm UTC](https://www.ruby-forum.com/t/a-very-simple-wxruby-loading-a-xrc-file/162002/1 "2009-03-04T18:19:10Z")

</div>

Greetings,  
I am trying to get a very simple .xrc file to load with no  
interaction. This does run, but it will not exit cleanly. Can someone  
please help me? I have been making progress, but I just cannot seem to  
get that last bit. I am very new to wxruby.

Thanks,  
Zignus

samples.xrc

\<?xml version="1.0" encoding="ISO-8859-1"?\> wxCAPTION|wxRESIZE\_BORDER|wxSYSTEM\_MENU 400,300 Sample 1 wxHORIZONTAL wxALIGN\_CENTER\_VERTICAL|wxALL 5 wxVERTICAL wxALIGN\_CENTER\_HORIZONTAL|wxALL 5 Ok wxALIGN\_CENTER\_HORIZONTAL|wxALL 5 Cancel wxALIGN\_CENTER\_HORIZONTAL|wxALL 5 Message... wxALIGN\_CENTER\_HORIZONTAL|wxALL 5 zignus was here 

zignus.sample.rbw

require ‘wxruby’

# 

# Application class.

# 

class XrcApp \< Wx::App

def on\_init  
Wx::init\_all\_image\_handlers() # Initializes handlers for all  
supported controls/windows. In wxRuby versions 1.9.6 and later, this is  
called automatically for you, so there is no need to call this method  
xml = Wx::XmlResource.get() #Loads resources from the XML file  
file. If this file does not exist, or contains invalid XML, an exception  
will be raised; if successful, the loaded file name will be returneed.  
xml.init\_all\_handlers() #Initializes handlers for all supported  
controls/windows. In wxRuby versions 1.9.6 and later, this is called  
automatically for you, so there is no need to call this method  
xml.load(“samples.xrc”) #Loads resources from the XML file file.  
If this file does not exist, or contains invalid XML, an exception will  
be raised; if successful, the loaded file name will be returneed.  
#  
# Show the main frame.  
#  
frame = Wx::Frame.new(nil, -1, “Sample” ) #create the window  
frame.set\_client\_size(Wx::Size.new(200,200)) #sets the size of  
the window  
#sizer = Wx::BoxSizer.new(Wx::VERTICAL)  
xml.load\_dialog\_subclass(frame, nil, ‘SAMPLE\_DIALOG’) #loads in  
the .xrc into the window! Yea!!  
#frame.set\_sizer(sizer)  
frame.show()  
end

end

=begin  
=end

XrcApp.new().main\_loop() #Create a new object with no name from  
‘XrcApp’ class and places in a loop.

---

<div class="post-metadata">

**Author:** ![zignus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/77aa72/32.png) [@zignus](https://www.ruby-forum.com/u/zignus)\
**Post date:** [March 5, 2009, 5:07pm UTC](https://www.ruby-forum.com/t/a-very-simple-wxruby-loading-a-xrc-file/162002/2 "2009-03-05T17:07:37Z")

</div>

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"?\> wxTAB\_TRAVERSAL Simple 1 wxVERTICAL wxALIGN\_CENTER\_HORIZONTAL|wxALL 5 Static text wxALIGN\_CENTER\_HORIZONTAL|wxALL 5 Static text wxALIGN\_CENTER\_HORIZONTAL|wxALL 5 Static text wxALIGN\_CENTER\_HORIZONTAL|wxALL 5 Static text 

There it is.

Thanks,  
Zignus

---

<div class="post-metadata">

**Author:** ![zignus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/77aa72/32.png) [@zignus](https://www.ruby-forum.com/u/zignus)\
**Post date:** [March 5, 2009, 5:53pm UTC](https://www.ruby-forum.com/t/a-very-simple-wxruby-loading-a-xrc-file/162002/3 "2009-03-05T17:53:49Z")

</div>

Zignus Arcanniss wrote:

> I figured some things out.  
> You should use at the top of your Ruby code:  
> require ‘wxruby’  
> What version of wxRuby are you using? require ‘wxruby’ was used for the  
> very old version 0.6.0. I strongly recommend that you use version 2.0.0.  
> The old version is very buggy, has lots of missing features etc.

a
