Strange Issue with Wx_Sugar and xml.load

Hi everyone,

I’m having a strange issue and I’m trying to wrap my head around it and
unfortunately, I’m not having much luck.

Let me simplify my directory structure and show you what’s happening:

\lib
– app.rb
– main.rb
– xrc_source.rb
– xrc_source.xrc


app.rb just contains some standard requires:

$:.unshift File.dirname(FILE)

require ‘wx’
require ‘pp’
require “xrc_source”
require “main”

Wx::App.run do
GuiMain.new.show
end


When the xrc_source.rb is required, inside of xrc_source.rb is the
following line:

xml.load(‘xrc_source’)

… which is automatically generated by running the xrcise command:

xrcise -o xrc_source.rb xrc_source.xrc

So Sugar is creating the load line. Now, so far so good. When I try to
run my app out of the lib directory using ruby app.rb it launches and
the gui is working just fine.

If I try to package this using ocra and type ocra app.rb it
automatically creates an app.exe executable file. If I double-click the
exe file, it launches and everything is good. Again, so far so good.

Now, if I move this new executable file anywhere else, and launch it, I
receive the following error:

Cannot load resources from file ‘xrc_source.xrc’.

========

So, does this mean that if I use wx_sugar, I won’t be able to create a
stand-a-lone GUI app with ocra? Notice, I’m not receiving any errors
concerning any other loads or requires from my other files. The only
error is occurring from the xml.load method inside of the file that was
created via xrcise.

I’m sure there must be a way around this.

Please advise.

Thanks.

Just for clarification:

xml.load(‘xrc_source’)

is actually xml.load(‘xrc_source.xrc’)

I believe the problem is probably more related to something ocra is
doing during compile so I added a bug report to the ocra home project
page. If anyone else is using ocra with wxruby, and you are able to
move the exe to another part of your system and launch it, please let me
know what I’m doing wrong in terms of the xrc source load from sugar…

After reading Ocra’s website, it looks as though, if you want the
xrc_source.xrc to be included, you need to add it to the ocra command
line
execution, EG:

ocra app.rb xrc_source.xrc

This will add xrc_source.xrc to the executable, and when it extracts it,
it’ll be placed into the same directory as your app.rb, so it should
work
then.

hth,

Mario

Mario S. wrote:

After reading Ocra’s website, it looks as though, if you want the
xrc_source.xrc to be included, you need to add it to the ocra command
line
execution, EG:

ocra app.rb xrc_source.xrc

This will add xrc_source.xrc to the executable, and when it extracts it,
it’ll be placed into the same directory as your app.rb, so it should
work
then.

hth,

Mario

Hey Mario,

I’m not sure how I missed that. I tried what you said and with the
packager what happens is when I open the file on another part of the
system, I receive the same error.

However, instead of closing the app and allowing it to fully close, I go
to the temp directory within appdata and I personally checked out
everything. There’s a src folder that shows that it is indeed pulling
the xrc source and placing it in the same directory.

So, perhaps it has something to do with how it’s being required in the
xml.load?

Should I be placing some other relative path? Again, a very strange
thing as all of the files are there but it refuses to load the xrc
source. The error usually happens when the path is not correct. But,
I’m not sure why that is…

Okay, I figured it out, but it’s a really weird issue.

I decided to put the following in the generated ruby file that xrcise
generates:

begin
xml.load(“ui/ui.xrc”)
rescue
xml.load(Dir.getwd + “/ui/ui.xrc”)
end

When I built the app and ran the app from my desktop:

Cannot load resources from C:/users/joel/desktop/ui/ui.xrc.

So, I created a folder called ui on my desktop and placed the xrc source
in there and it works. I went back to the generated ruby file, removed
the rescue statement completely and left it just as:

xml.load(“ui/ui.xrc”)

And rebuilt the app and tried again from my desktop. It worked, because
there was a ui/ui.xrc file on my desktop.

This is very strange because when using xml.load it appears it’s looking
in the current working directory and not the temp directory that ocra
unpacks everything into. So, I’m not sure how to change the working
directory to the temp directory that ocra creates when you launch the
executable.

Is this a bug with xml.load? Or a bug with Ocra?

Reported this in a bug ticket:

http://rubyforge.org/tracker/index.php?func=detail&aid=27762&group_id=35&atid=218

Ticket # 27762

In order to fix the issue, I had to replace the xml.load with:

xml.load(File.join(File.dirname(FILE),“ui.xrc”))

… which while fixable, means that anytime I want to port an application
using xrcise, I have to hack the generated file. I wonder if they
realize that load is not like require and that it generally should be
used with absolute paths?