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/.
Zignus Arcanniss
2009-Mar-05 16:07 UTC
[wxruby-users] a very simple wxRuby loading a xrc file
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/.
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