Hi,
I’m trying to load a gui with a xrcise/.xrc combo. I’ve tried both with
this trivial .xrc - which is just a frame with nothing in it - and a few
more advanced which worked great when compiled to c++.
I’ve tried both win xp sp2 and vista, ruby 1.8.6 from the one-click
installer and 1.8.7, wxRuby (1.9.7) and wx_sugar (0.1.20) installed with
gems.
C:\Users\magnuss\workspace\TestProject>ruby main.rb
10:55:50: Error: Cannot load resources from file
‘file:/C%3A/Users/magnuss/workspace/TestProject/noname.xrc’.
c:/ruby/lib/ruby/gems/1.8/gems/wxruby-1.9.7-x86-mswin32/lib/wx/classes/xmlresource.rb:31:in
load': Failed to load XRC from 'noname.xrc'; check the file exists and is valid XML (RuntimeError) from ./forms.rb:16:in
initialize’
from main.rb:10:in `new’
from main.rb:10
The .xrc file is in the same directory as my main.rb, and does indeed
exist
Any ideas or tips would be greatly appreciated
best regards,
Magnus Sjöstrand
=====================================================
main.rb
require “wx”
require “forms”
include Wx
class MainWindow < MainWindowBase
end
MainWindow.new.main_loop
noname.xrc
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL
500,300
forms.rb
class MainWindowBase < Wx::Frame
def initialize(parent = nil)
super()
xml = Wx::XmlResource.get
xml.flags = 2 # Wx::XRC_NO_SUBCLASSING
xml.init_all_handlers
xml.load(“noname.xrc”)
xml.load_frame_subclass(self, parent, “MainFrame”)
finder = lambda do | x |
int_id = Wx::xrcid(x)
begin
Wx::Window.find_window_by_id(int_id, self) || int_id
# Temporary hack to work around regression in 1.9.2; remove
# begin/rescue clause in later versions
rescue RuntimeError
int_id
end
end
if self.class.method_defined? "on_init"
self.on_init()
end
end
end