[wxruby-users] Problems loading .xrc file

Magnus Engström magnus at aoeu.info
Wed Jul 23 05:39:00 EDT 2008


Hi Magnus,

I'm using XRC on both Windows and Linux, and I'm usually building 
applications the same way, so I wrote a template to have a quick 
starting point. It should work fine on Windows too I think.
Make sure to start it from the right directory though (double-clicking 
on wxtemplate should work), currently it looks for ui/ui.xrc relative to 
starting directory.

/Magnus

Magnus Sjöstrand wrote:
> 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" ?>
> <resource xmlns="http://www.wxwindows.org/wxxrc" version="2.3.0.1">
>   <object class="wxFrame" name="MainFrame" subclass="MainWindowBase">
>     <style>wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL</style>
>     <size>500,300</size>
>     <title></title>
>   </object>
> </resource>
> =====================================================
> 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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: wxtemplate.zip
Type: application/octet-stream
Size: 4355 bytes
Desc: not available
URL: <http://rubyforge.org/pipermail/wxruby-users/attachments/20080723/e258326f/attachment.obj>


More information about the wxruby-users mailing list