Forum: wxRuby xrcise question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
8b15b7fd17545663d3a4f4727f81a72a?d=identicon&s=25 Heinrich Piard (heinrich1208)
on 2008-11-14 19:07
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
06f6780c99d4a8dd71f2b474082ea9ce?d=identicon&s=25 Alex Fenton (Guest)
on 2008-11-14 19:14
(Received via mailing list)
Heinrich Piard 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
8b15b7fd17545663d3a4f4727f81a72a?d=identicon&s=25 Heinrich Piard (heinrich1208)
on 2008-11-14 19:39
Alex Fenton wrote:
> Heinrich Piard 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" ?>
<resource xmlns="http://www.wxwindows.org/wxxrc" version="2.3.0.1">
  <object class="wxFrame" name="MyFrame1">
    <style>wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL</style>
    <size>554,553</size>
    <title></title>
    <object class="wxGridSizer">
      <rows>500</rows>
      <cols>3</cols>
      <vgap>0</vgap>
      <hgap>0</hgap>
    </object>
    <object class="wxStatusBar" name="m_statusBar1">
      <style>wxST_SIZEGRIP</style>
      <fields>1</fields>
    </object>
    <object class="wxToolBar" name="m_toolBar1">
      <style>wxTB_HORIZONTAL</style>
      <bitmapsize></bitmapsize>
      <margins></margins>
      <packing>1</packing>
      <separation>5</separation>
      <object class="wxTextCtrl" name="m_textCtrl1">
        <value>enter ticker</value>
        <maxlength>0</maxlength>
      </object>
      <object class="wxButton" name="m_button2">
        <pos>-1,-1</pos>
        <label>Start</label>
        <default>0</default>
      </object>
      <object class="wxButton" name="m_button3">
        <label>Stop</label>
        <default>0</default>
      </object>
    </object>
  </object>
</resource>
3396e4a3df8a840faec520af8555a400?d=identicon&s=25 Mario Steele (Guest)
on 2008-11-14 19:53
(Received via mailing list)
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
8b15b7fd17545663d3a4f4727f81a72a?d=identicon&s=25 Heinrich Piard (heinrich1208)
on 2008-11-14 20:08
Mario Steele 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
8b15b7fd17545663d3a4f4727f81a72a?d=identicon&s=25 Heinrich Piard (heinrich1208)
on 2008-11-14 20:40
Heinrich Piard wrote:
> Mario Steele 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
06f6780c99d4a8dd71f2b474082ea9ce?d=identicon&s=25 Alex Fenton (Guest)
on 2008-11-14 21:55
(Received via mailing list)
Heinrich Piard 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
8b15b7fd17545663d3a4f4727f81a72a?d=identicon&s=25 Heinrich Piard (heinrich1208)
on 2008-11-15 22:11
Alex Fenton wrote:
> Heinrich Piard 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
3396e4a3df8a840faec520af8555a400?d=identicon&s=25 Mario Steele (Guest)
on 2008-11-16 05:59
(Received via mailing list)
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.
8b15b7fd17545663d3a4f4727f81a72a?d=identicon&s=25 Heinrich Piard (heinrich1208)
on 2008-11-16 16:36
Mario Steele 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
8b15b7fd17545663d3a4f4727f81a72a?d=identicon&s=25 Heinrich Piard (heinrich1208)
on 2008-11-17 03:24
Heinrich Piard wrote:
> Mario Steele 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
06f6780c99d4a8dd71f2b474082ea9ce?d=identicon&s=25 Alex Fenton (Guest)
on 2008-11-17 10:52
(Received via mailing list)
Heinrich Piard 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
8b15b7fd17545663d3a4f4727f81a72a?d=identicon&s=25 Heinrich Piard (heinrich1208)
on 2008-11-17 13:59
Attachment: noname.zip (1 KB)
Alex Fenton wrote:
> Heinrich Piard 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
8b15b7fd17545663d3a4f4727f81a72a?d=identicon&s=25 Heinrich Piard (heinrich1208)
on 2008-11-18 16:37
Heinrich Piard wrote:
> Alex Fenton wrote:
>> Heinrich Piard 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
This topic is locked and can not be replied to.