[wxruby-users] a very simple wxRuby loading a xrc file
Zignus Arcanniss
lists at ruby-forum.com
Wed Mar 4 12:19:10 EST 2009
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"?>
<resource version="2.3.0.1" xmlns="http://www.wxwidgets.org/wxxrc">
<object class="wxDialog" name="SAMPLE_DIALOG">
<style>wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU</style>
<size>400,300</size>
<title>Sample</title>
<centered>1</centered>
<object class="wxBoxSizer">
<orient>wxHORIZONTAL</orient>
<object class="sizeritem">
<flag>wxALIGN_CENTER_VERTICAL|wxALL</flag>
<border>5</border>
<object class="wxBoxSizer">
<orient>wxVERTICAL</orient>
<object class="sizeritem">
<flag>wxALIGN_CENTER_HORIZONTAL|wxALL</flag>
<border>5</border>
<object class="wxButton" name="wxID_OK">
<label>Ok</label>
</object>
</object>
<object class="sizeritem">
<flag>wxALIGN_CENTER_HORIZONTAL|wxALL</flag>
<border>5</border>
<object class="wxButton" name="wxID_CANCEL">
<label>Cancel</label>
</object>
</object>
<object class="sizeritem">
<flag>wxALIGN_CENTER_HORIZONTAL|wxALL</flag>
<border>5</border>
<object class="wxButton" name="SAMPLE_MESSAGE">
<label>Message...</label>
</object>
</object>
<object class="sizeritem">
<flag>wxALIGN_CENTER_HORIZONTAL|wxALL</flag>
<border>5</border>
<object class="wxStaticText" name="wxID_STATIC">
<label>zignus was here</label>
</object>
</object>
</object>
</object>
</object>
</object>
</resource>
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.
--
Posted via http://www.ruby-forum.com/.
More information about the wxruby-users
mailing list