Xrcise question

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

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

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

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

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

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

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

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:ininitialize’
from test.rb:47:in new' from test.rb:47:ininitialize’
from test.rb:50:in `new’
from test.rb:50

The file is in that directory.

bye
Henry

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

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

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:ininitialize’
from test.rb:51:in new' from test.rb:51:ininitialize’
from test.rb:54:in `new’
from test.rb:54

Thanks!

bye
Henry

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:ininitialize’
from test.rb:51:in new' from test.rb:51:ininitialize’
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

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.

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

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

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