# Xrcise question

**URL:** <https://www.ruby-forum.com/t/xrcise-question/153312>\
**Category:** wxRuby\
**Created:** [November 14, 2008, 7:07pm UTC](https://www.ruby-forum.com/t/xrcise-question/153312 "2008-11-14T19:07:04Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![heinrich1208](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ed655f/32.png) [@heinrich1208](https://www.ruby-forum.com/u/heinrich1208)\
**Post date:** [November 14, 2008, 7:07pm UTC](https://www.ruby-forum.com/t/xrcise-question/153312/1 "2008-11-14T19:07:04Z")

</div>

Hi all,

where can I find a tutorial like “How to use wxFormbuilder with ruby”?

I want to transform xrcise code into ruby code and don’t know how to do  
this.

Thanks!

bye  
Henry

---

<div class="post-metadata">

**Author:** ![heinrich1208](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ed655f/32.png) [@heinrich1208](https://www.ruby-forum.com/u/heinrich1208)\
**Post date:** [November 14, 2008, 7:14pm UTC](https://www.ruby-forum.com/t/xrcise-question/153312/2 "2008-11-14T19:14:01Z")

</div>

Heinrich P. wrote:

> where can I find a tutorial like “How to use wxFormbuilder with ruby”?
> 
> I want to transform xrcise code into ruby code and don’t know how to do  
> this.

[http://wxruby.rubyforge.org/wiki/wiki.pl?UsingXRCise](http://wxruby.rubyforge.org/wiki/wiki.pl?UsingXRCise)

Note that XRCise doesn’t generate ruby code for the layout - but it  
writes all the boring code that loads your layout from XML. This means  
your handwritten classes can concentrate on event handling without  
having to write heaps of layout code.

Any probs, feel free to ask  
alex

---

<div class="post-metadata">

**Author:** ![heinrich1208](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ed655f/32.png) [@heinrich1208](https://www.ruby-forum.com/u/heinrich1208)\
**Post date:** [November 14, 2008, 7:39pm UTC](https://www.ruby-forum.com/t/xrcise-question/153312/3 "2008-11-14T19:39:41Z")

</div>

Alex F. wrote:

> Heinrich P. wrote:
> 
> > where can I find a tutorial like “How to use wxFormbuilder with ruby”?
> > 
> > I want to transform xrcise code into ruby code and don’t know how to do  
> > this.
> 
> [http://wxruby.rubyforge.org/wiki/wiki.pl?UsingXRCise](http://wxruby.rubyforge.org/wiki/wiki.pl?UsingXRCise)
> 
> Note that XRCise doesn’t generate ruby code for the layout - but it  
> writes all the boring code that loads your layout from XML. This means  
> your handwritten classes can concentrate on event handling without  
> having to write heaps of layout code.
> 
> Any probs, feel free to ask  
> alex

Hi Alex,

thanks!

I prepared everything and started a test but it didn’t work.  
I created a xrc file and no used xrcise -o test.rm nonam.xrc and get the  
following error message:  
Cannot create wrapper for class without ‘subclass’ attribute

Here the xrc xml:

\<?xml version="1.0" encoding="UTF-8" standalone="yes" ?\> wxDEFAULT\_FRAME\_STYLE|wxTAB\_TRAVERSAL 554,553 500 3 0 0 wxST\_SIZEGRIP 1 wxTB\_HORIZONTAL 1 5 enter ticker 0 -1,-1 Start 0 Stop 0

---

<div class="post-metadata">

**Author:** ![heinrich1208](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ed655f/32.png) [@heinrich1208](https://www.ruby-forum.com/u/heinrich1208)\
**Post date:** [November 14, 2008, 8:08pm UTC](https://www.ruby-forum.com/t/xrcise-question/153312/4 "2008-11-14T20:08:46Z")

</div>

Mario S. wrote:

> Hello Heinrich,
> 
> What you will need to do, is goto your main Window form, and scroll down  
> on  
> the properties page, you will see a field that says Subclass, and have a  
> semi-colon in it, with a + next to the field name. You need to click  
> that  
> plus, and put what name you want your ruby class to be named as.
> 
> EG:  
> MyFrame
> 
> This will tell XRCise when it generates the wrapper, that the class to  
> use,  
> will be MyFrame.
> 
> hth,
> 
> Mario

Great! Thanks Mario!

bye  
Henry

---

<div class="post-metadata">

**Author:** ![heinrich1208](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ed655f/32.png) [@heinrich1208](https://www.ruby-forum.com/u/heinrich1208)\
**Post date:** [November 14, 2008, 7:53pm UTC](https://www.ruby-forum.com/t/xrcise-question/153312/5 "2008-11-14T19:53:58Z")

</div>

Hello Heinrich,

What you will need to do, is goto your main Window form, and scroll down  
on  
the properties page, you will see a field that says Subclass, and have a  
semi-colon in it, with a + next to the field name. You need to click  
that  
plus, and put what name you want your ruby class to be named as.

EG:  
MyFrame

This will tell XRCise when it generates the wrapper, that the class to  
use,  
will be MyFrame.

hth,

Mario

---

<div class="post-metadata">

**Author:** ![heinrich1208](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ed655f/32.png) [@heinrich1208](https://www.ruby-forum.com/u/heinrich1208)\
**Post date:** [November 14, 2008, 8:40pm UTC](https://www.ruby-forum.com/t/xrcise-question/153312/6 "2008-11-14T20:40:02Z")

</div>

Heinrich P. wrote:

> Mario S. wrote:
> 
> > Hello Heinrich,
> > 
> > What you will need to do, is goto your main Window form, and scroll down  
> > on  
> > the properties page, you will see a field that says Subclass, and have a  
> > semi-colon in it, with a + next to the field name. You need to click  
> > that  
> > plus, and put what name you want your ruby class to be named as.
> > 
> > EG:  
> > MyFrame
> > 
> > This will tell XRCise when it generates the wrapper, that the class to  
> > use,  
> > will be MyFrame.
> > 
> > hth,
> > 
> > Mario
> 
> Great! Thanks Mario!
> 
> bye  
> Henry

Hi all,

one more question popped up:

14:37:40: Error: Cannot load resources from file  
‘file:/C%3A/ruby/ruby\_scripts/wxFormBuilder/nonam.xrc’.  
c:/ruby/lib/ruby/gems/1.8/gems/wxruby-1.9.9-x86-mswin32-60/lib/wx/classes/xmlresource.rb:31:in  
`load': Failed to load XRC from 'nonam.xrc'; check the file exists and is valid XML (RuntimeError) from test.rb:20:in `initialize’  
from test.rb:47:in `new' from test.rb:47:in `initialize’  
from test.rb:50:in `new’  
from test.rb:50

The file is in that directory.

bye  
Henry

---

<div class="post-metadata">

**Author:** ![heinrich1208](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ed655f/32.png) [@heinrich1208](https://www.ruby-forum.com/u/heinrich1208)\
**Post date:** [November 14, 2008, 9:55pm UTC](https://www.ruby-forum.com/t/xrcise-question/153312/7 "2008-11-14T21:55:22Z")

</div>

Heinrich P. wrote:

> one more question popped up:
> 
> 14:37:40: Error: Cannot load resources from file  
> ‘file:/C%3A/ruby/ruby\_scripts/wxFormBuilder/nonam.xrc’.  
> c:/ruby/lib/ruby/gems/1.8/gems/wxruby-1.9.9-x86-mswin32-60/lib/wx/classes/xmlresource.rb:31:in  
> `load’: Failed to load XRC from ‘nonam.xrc’; check the file exists and  
> is valid XML (RuntimeError)  
> The filename looks a bit suspicious to me. I would expect it to be a  
> valid path rather than a mangled-looking URL. Hard to know where this  
> came from without knowing more about your project layout.

I would check that you call xrcise with a relative path, in a typical  
project structure. Eg I have

app.rb  
lib/_._/rb  
share/xrc.xrc

I call “xrcise share/xrc.xrc” from the base directory and that means  
that the paths resolve fine.

a

---

<div class="post-metadata">

**Author:** ![heinrich1208](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ed655f/32.png) [@heinrich1208](https://www.ruby-forum.com/u/heinrich1208)\
**Post date:** [November 15, 2008, 10:11pm UTC](https://www.ruby-forum.com/t/xrcise-question/153312/8 "2008-11-15T22:11:55Z")

</div>

Alex F. wrote:

> Heinrich P. wrote:
> 
> > one more question popped up:
> > 
> > 14:37:40: Error: Cannot load resources from file  
> > ‘file:/C%3A/ruby/ruby\_scripts/wxFormBuilder/nonam.xrc’.  
> > c:/ruby/lib/ruby/gems/1.8/gems/wxruby-1.9.9-x86-mswin32-60/lib/wx/classes/xmlresource.rb:31:in  
> > `load’: Failed to load XRC from ‘nonam.xrc’; check the file exists and  
> > is valid XML (RuntimeError)  
> > The filename looks a bit suspicious to me. I would expect it to be a  
> > valid path rather than a mangled-looking URL. Hard to know where this  
> > came from without knowing more about your project layout.
> 
> I would check that you call xrcise with a relative path, in a typical  
> project structure. Eg I have
> 
> app.rb  
> lib/_._/rb  
> share/xrc.xrc
> 
> I call “xrcise share/xrc.xrc” from the base directory and that means  
> that the paths resolve fine.
> 
> a

Hello,

here is my code. Is still can’t get it to work.

# This class was automatically generated from XRC source. It is not

# recommended that this file is edited directly; instead, inherit from

# this class and extend its behaviour there.

# 

# Source file: wxFormBuilder\nonam.xrc

# Generated at: Fri Nov 14 17:16:34 -0500 2008

require ‘wx’  
include Wx

class CometApplication \< Wx::Frame

attr\_reader :m\_statusbar1, :m\_toolbar1, :m\_textctrl1, :m\_button2,  
:m\_button3

def initialize(parent = nil)  
super()  
xml = Wx::XmlResource.get  
xml.flags = 2 # Wx::XRC\_NO\_SUBCLASSING  
xml.init\_all\_handlers  
xml.load(“wxFormBuilder\nonam.xrc”)  
xml.load\_frame\_subclass(self, parent, “MyFrame1”)

```
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

@m_statusbar1 = finder.call("m_statusBar1")
@m_toolbar1 = finder.call("m_toolBar1")
@m_textctrl1 = finder.call("m_textCtrl1")
@m_button2 = finder.call("m_button2")
@m_button3 = finder.call("m_button3")
if self.class.method_defined? "on_init"
  self.on_init()
end

```

end  
end

class MyApp \< App  
def initialize()  
CometApplication.new  
end  
end  
MyApp.new.main\_loop()

I start the code from C:\ruby\ruby\_scripts\test.rb and the xrc file is  
in C:\ruby\ruby\_scripts\wxFormBuilder\nonam.xrc

---

<div class="post-metadata">

**Author:** ![heinrich1208](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ed655f/32.png) [@heinrich1208](https://www.ruby-forum.com/u/heinrich1208)\
**Post date:** [November 16, 2008, 4:36pm UTC](https://www.ruby-forum.com/t/xrcise-question/153312/9 "2008-11-16T16:36:35Z")

</div>

Mario S. wrote:

> Try changing the line for the loading of the XML resource file from:
> 
> xml.load(“wxFormBuilder\noname.xrc”)
> 
> To:
> 
> xml.load(“wxFormBuilder/noname.xrc”)
> 
> Thankfully, to Ruby and wxWidgets, it doesn’t really need you to use the  
>   
> slash to access a file path.
> 
> Often times, it’s better to run xrcise as such:
> 
> xrcise -o noname.rb wxFormBuilder/noname.xrc
> 
> This way, doesn’t matter if it’s on Windows, or Linux, it will be able  
> to  
> find the resources just fine.

Hi Mario,

changed it but still get this message.

10:33:15: Error: Cannot load resources from file  
‘file:/C%3A/ruby/ruby\_scripts/wxFormBuilder/nonam.xrc’.  
c:/ruby/lib/ruby/gems/1.8/gems/wxruby-1.9.9-x86-mswin32-60/lib/wx/classes/xmlresource.rb:31:in  
`load': Failed to load XRC from 'wxFormBuilder/nonam.xrc'; check the file exists and is valid XML (RuntimeError) from test.rb:23:in `initialize’  
from test.rb:51:in `new' from test.rb:51:in `initialize’  
from test.rb:54:in `new’  
from test.rb:54

Thanks!

bye  
Henry

---

<div class="post-metadata">

**Author:** ![heinrich1208](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ed655f/32.png) [@heinrich1208](https://www.ruby-forum.com/u/heinrich1208)\
**Post date:** [November 17, 2008, 3:24am UTC](https://www.ruby-forum.com/t/xrcise-question/153312/10 "2008-11-17T03:24:34Z")

</div>

Heinrich P. wrote:

> Mario S. wrote:
> 
> > Try changing the line for the loading of the XML resource file from:
> > 
> > xml.load(“wxFormBuilder\noname.xrc”)
> > 
> > To:
> > 
> > xml.load(“wxFormBuilder/noname.xrc”)
> > 
> > Thankfully, to Ruby and wxWidgets, it doesn’t really need you to use the  
> >   
> > slash to access a file path.
> > 
> > Often times, it’s better to run xrcise as such:
> > 
> > xrcise -o noname.rb wxFormBuilder/noname.xrc
> > 
> > This way, doesn’t matter if it’s on Windows, or Linux, it will be able  
> > to  
> > find the resources just fine.
> 
> Hi Mario,
> 
> changed it but still get this message.
> 
> 10:33:15: Error: Cannot load resources from file  
> ‘file:/C%3A/ruby/ruby\_scripts/wxFormBuilder/nonam.xrc’.  
> c:/ruby/lib/ruby/gems/1.8/gems/wxruby-1.9.9-x86-mswin32-60/lib/wx/classes/xmlresource.rb:31:in  
> `load': Failed to load XRC from 'wxFormBuilder/nonam.xrc'; check the file exists and is valid XML (RuntimeError) from test.rb:23:in `initialize’  
> from test.rb:51:in `new' from test.rb:51:in `initialize’  
> from test.rb:54:in `new’  
> from test.rb:54
> 
> Thanks!
> 
> bye  
> Henry

Hi all,

could the above errors be caused by a bug?

bye  
Henry

---

<div class="post-metadata">

**Author:** ![heinrich1208](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ed655f/32.png) [@heinrich1208](https://www.ruby-forum.com/u/heinrich1208)\
**Post date:** [November 16, 2008, 5:59am UTC](https://www.ruby-forum.com/t/xrcise-question/153312/11 "2008-11-16T05:59:11Z")

</div>

Try changing the line for the loading of the XML resource file from:

xml.load(“wxFormBuilder\noname.xrc”)

To:

xml.load(“wxFormBuilder/noname.xrc”)

Thankfully, to Ruby and wxWidgets, it doesn’t really need you to use the  
  
slash to access a file path.

Often times, it’s better to run xrcise as such:

xrcise -o noname.rb wxFormBuilder/noname.xrc

This way, doesn’t matter if it’s on Windows, or Linux, it will be able  
to  
find the resources just fine.

---

<div class="post-metadata">

**Author:** ![heinrich1208](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ed655f/32.png) [@heinrich1208](https://www.ruby-forum.com/u/heinrich1208)\
**Post date:** [November 17, 2008, 1:59pm UTC](https://www.ruby-forum.com/t/xrcise-question/153312/12 "2008-11-17T13:59:28Z")

</div>

Alex F. wrote:

> Heinrich P. wrote:
> 
> > > > xml.load(“wxFormBuilder/noname.xrc”)  
> > > > file exists and is valid XML (RuntimeError)
> > 
> > could the above errors be caused by a bug?
> 
> It’s possible, but I can’t tell without seeing the XRC file as well as  
> the generated code. Please could you post your own script, the  
> XRC-generated ruby file and the XML source file in a zip attachment, or  
> file it as a bug with attachments on the website bug tracker.
> 
> thanks  
> alex

Hi Alex,

I have attached the file in zip format.

noname.zip

---

<div class="post-metadata">

**Author:** ![heinrich1208](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ed655f/32.png) [@heinrich1208](https://www.ruby-forum.com/u/heinrich1208)\
**Post date:** [November 17, 2008, 10:52am UTC](https://www.ruby-forum.com/t/xrcise-question/153312/13 "2008-11-17T10:52:11Z")

</div>

Heinrich P. wrote:

> > > xml.load(“wxFormBuilder/noname.xrc”)  
> > > file exists and is valid XML (RuntimeError)
> 
> could the above errors be caused by a bug?

It’s possible, but I can’t tell without seeing the XRC file as well as  
the generated code. Please could you post your own script, the  
XRC-generated ruby file and the XML source file in a zip attachment, or  
file it as a bug with attachments on the website bug tracker.

thanks  
alex

---

<div class="post-metadata">

**Author:** ![heinrich1208](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ed655f/32.png) [@heinrich1208](https://www.ruby-forum.com/u/heinrich1208)\
**Post date:** [November 18, 2008, 4:37pm UTC](https://www.ruby-forum.com/t/xrcise-question/153312/14 "2008-11-18T16:37:36Z")

</div>

Heinrich P. wrote:

> Alex F. wrote:
> 
> > Heinrich P. wrote:
> > 
> > > > > xml.load(“wxFormBuilder/noname.xrc”)  
> > > > > file exists and is valid XML (RuntimeError)
> > > 
> > > could the above errors be caused by a bug?
> > 
> > It’s possible, but I can’t tell without seeing the XRC file as well as  
> > the generated code. Please could you post your own script, the  
> > XRC-generated ruby file and the XML source file in a zip attachment, or  
> > file it as a bug with attachments on the website bug tracker.
> > 
> > thanks  
> > alex
> 
> Hi Alex,
> 
> I have attached the file in zip format.
> 
> noname.zip

Hi all,

I was able to solve the issue my self. It was a code issue in  
class MyApp

this is how it should look:

class MyApp \< Wx::App  
def on\_init()  
Test.new.show()  
end  
end

MyApp.new.main\_loop()

Thanks to all!

bye  
Henry
