How to get a .exe packaged Ruby Shoes app to reference resources outside the package? - ruby

I'm trying to make a standalone .exe packaged Ruby Shoes app that uses images dynamically, meaning whichever images is found in the folder of the .exe file.
Shoes.app() {
background "bg.jpg"
}
This code works if the image is in the same folder when the .exe is packaged, and the image seems to be packaged into the .exe since it's not needed in the same folder as the .exe for it to display when running the exe. But when you want it to load the file in the same folder as the .exe, packaging the app without the image, it does not show. I've tried different ways at finding absolute path to the current directory where the .exe is launched from, but they all seem to point to some temporary directory under AppData and not where the .exe file is located.

Edit: my first answer was incomplete. Windows is a little odd in Shoes for packaged apps. Write a little test script.
Shoes.app do
stack do
para "DIR: #{DIR}"
para "LIB_DIR: #{LIB_DIR}"
cdir = Dir.getwd
para "CWD: #{cdir}"
end
end
Dir.getwd is probably what you want.

Calling pwd should get you what you want
Nope, Ok sorry get it now !:-)
Shoes is opening your exe/shy into AppData/temp so working directory and __FILE__ both point there !
Someone, some time ago proposed this : Trying to access the "current dir" in a packaged Shoes app
must be a better way !
EDIT:
you probably want custom packager (check "i want advanced install options")
check "Expand shy in users directory"
Do as you done for regular packaging.
Now when launching the exe, it will ask you( or the user) to choose where to install your app, proceed, note the directory.
Now before launching the installed app feed the noted directory with your resources and you should be ok
Some references : https://github.com/Shoes3/shoes3/wiki/Custom-Install-Scripts
(there's a lot more to it)
https://github.com/Shoes3/shoes3/issues/247#issuecomment-213919829

Related

Application doesn't launch from ZeroBrane Studio

I'm having a lot of problems with ZeroBraneStudio!
I enjoyed using it to write my first application on Windows, but now I fail to make it working on MacBook Air and even on WIndows after reinstalling Solar2D and ZeroBrane!
If I launch my app opening Corona Simulator everythings works well, but ZeroBrane doesn't work. The errors on MacBook and on Windows are similar.
On MacBook:
Program starting as '"/Applications/Corona-3664/Native/Corona/mac/bin/lua" -e "io.stdout:setvbuf('no')" "/var/folders/4w/hn6pxl5s20v31f0q2n9msjs40000gn/T/.bO0D1R"'.
Program 'lua' started in '/Applications/Corona-3664' (pid: 1638).
Debugging session started in '/Applications/Corona-3664/'.
SampleCode/Interface/Composer/main.lua:18: module 'composer' not found:
no field package.preload['composer']
no file './composer.lua'
no file '/usr/local/share/lua/5.1/composer.lua'
no file '/usr/local/share/lua/5.1/composer/init.lua'
no file '/usr/local/lib/lua/5.1/composer.lua'
no file '/usr/local/lib/lua/5.1/composer/init.lua'
no file './composer.lua'
no file './composer/init.lua'
no file './lua/composer.lua'
no file './lua/composer/init.lua'
no file '/Applications/ZeroBraneStudio.app/Contents/ZeroBraneStudio/lualibs/composer/composer.lua'
no file '/Applications/ZeroBraneStudio.app/Contents/ZeroBraneStudio/lualibs/composer.lua'
no file '/Applications/ZeroBraneStudio.app/Contents/ZeroBraneStudio/lualibs/composer/composer/init.lua'
no file '/Applications/ZeroBraneStudio.app/Contents/ZeroBraneStudio/lualibs/composer/init.lua'
no file './composer.so'
no file '/usr/local/lib/lua/5.1/composer.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
no file '/Applications/ZeroBraneStudio.app/Contents/ZeroBraneStudio/bin/clibs/composer.dylib'
no file '/Applications/ZeroBraneStudio.app/Contents/ZeroBraneStudio/bin/clibs/libcomposer.dylib'
stack traceback:
[C]: in function 'require'
SampleCode/Interface/Composer/main.lua:18: in ma etc.
Please help me to understand what is going wrong!
Thanks
It looks like your project points to /Applications/Corona-3664/ folder, but it needs to point to the location of your project files, such that the require statement for your project modules work from that location (or you need to adjust package.path values so that Lua interpreter can find the modules you are loading).
In this particular case it looks like the application expects the composer.lua to be in the same folder as main.lua, so try setting your project folder to /Applications/Corona-3664/SampleCode/Interface/Composer/ (although it's better to keep it outside of Applications/ folder).

How to package a Kivy app with Pyinstaller

I have a lot of troubles following the instructions form the Kivy website, many steps aren't explained like what should I answer to the warning.
WARNING: The output directory "..." and ALL ITS CONTENTS will be REMOVED! Continue? (y/n)
Even if I choose y, the folder isn't removed.
Also should I always add these lines:
from kivy.deps import sdl2, glew
Tree('C:\\Users\\<username>\\Desktop\\MyApp\\'),
*[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)]
in the .spec file? Why are they necessary?
Not many info is available for Kivy.
Because I spent a lot of time understanding how I should package my app, here are some instructions that would have really helped me.
Some info are available at http://pythonhosted.org/PyInstaller/
Python 3.6 as of march 2017
Because packaging my app gave me the error IndexError: tuple index out of range, I had to install the developement version of PyInstaller:
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip
Step 1:
I moved all the files of MyApp in a folder "C:\Users\<username>\Desktop\MyApp": the .py, the .kv and the images and I created an icon.ico.
I created another folder C:\Users\<username>\Desktop\MyPackagedApp. In this folder I press Shift+right click and select open command window here.
Then I pasted this:
python -m PyInstaller --name MyApp --icon "C:\Users\<username>\Desktop\MyApp\icon.ico" "C:\Users\<username>\Desktop\MyApp\myapp.py"
This creates two folders, build and dist, and a .spec file. In dist/MyApp, I can find a .exe. Apparently, if my app is really simple (just one label), the packaged app can works without the Step 2.
Step 2:
The second step involves editing the .spec file. Here is an exemple of mine.
(cf Step 3, for the explanations about my_hidden_modules)
I go back to the cmd, and enter
python -m MyApp myapp.spec
I then got this warning:
WARNING: The output directory "..." and ALL ITS CONTENTS will be REMOVED! Continue? (y/n)
I enter y and then press enter.
Because I choosed y, I was surpised that the folder build was still there and that the dist/MyApp was still containing many files. But this is normal. PyInstaller can output a single file .exe or a single folder which contains all the script’s dependencies and an executable file. But the default output is a single folder with multiple files.
Step 3: adding hidden modules
When I click on the myapp.exe in dist/MyApp, the app crashed. In the log C:\Users\.kivy\logs\ I could find 2 errors: ModuleNotFoundError: No module named 'win32timezone' and SystemError: <class '_frozen_importlib._ModuleLockManager'>.
Because of this I had to edit the .spec file and add these lines:
my_hidden_modules = [
( 'C:\\Users\\<username>\\AppData\\Local\\Programs\\Python\\Python36\\Lib\\site-packages\\win32\\lib\\win32timezone.py', '.' )
]
in a = Analysis I changed datas = [] to datas = my_hidden_modules,
Apparently this is because I used a FileChooser widget.
So, the line:
ALL ITS CONTENTS will be REMOVED!
yes, it will be removed AND replaced later with new files. Check the date. I think it prints permission denied if it can't do such a thin both for files and the whole folder, so you'd notice it. It's important though, because you need to add additional files into your folder.
Those additional files of two types:
kivy dependencies
application data
Dependencies are just binaries (+/- loaders, licenses, or so), you get them through the *[Tree(p) ...] piece of code, which is just a command for "get all files from that folder". Without them Kivy won't even start.
Similarly to that, the second Tree(<app folder>) does the same, but for your own files such as .py files, .kv files, images, music, databases, basically whatever you create.
Obviously if you remove the deps, app won't start and if you remove app data, you'll get some path errors and most likely crash. You don't want any of that :P
It also works if in the 'a = Analysis...' block in the spec file one substitutes
hiddenimports=[]
for
hiddenimports=['win32file', 'win32timezone']
for win32file, win32timezone or for whatever files are missing

"The selected directory is not valid home for Lua SDK"?

I'm new here so I apologize if this question is breaking some rule or something. But this is becoming a problem for me. I downloaded Intellij and downloaded the lua plugin for it. Well, now I'm trying to configure lua sdk but everytime I put in the location for it, it says "The selected directory is not valid home for Lua SDK"
What is the valid home? What am I doing wrong?
The problem might be that your lua.exe file is actually named luaXX.exe where XX is the version.
In my case it was lua53.exe. I renamed just the lua53.exe file to lua.exe; I didn't rename the rest.
So at first I had:
lua53.dll
lua53.exe
luac53.exe
wlua53.exe
After renaming the file I have:
lua53.dll
lua.exe
luac53.exe
wlua53.exe
With this changed, the Intellij plugin detected the folder as a valid home.

Ruby Shoes App packaged for Windows doesn't display images

When I package my Shoes App for Windows images doesn't work. I have this very simple app (min_test.rb):
Shoes.app()
{
background "bg.jpg"
}
Which works fine if I run it through Shoes, but when I package it with Shoes so that I get a standalone .exe file the images doesn't load. Inside the folder these are the contents:
min_test.rb
bg.jpg
min_test.exe (after packaging)
If Shoes3.3.1, indeed, on linux too.
console (alt-/) saying "couldn't find tmp.....bg.jpg" ?
(background or image)
could you file a bug report, please : https://github.com/Shoes3/shoes3/issues
EDIT: Sorry, wait
if Shoes3.3.1 !
you have to first make a shy then an exe and the resulting exe will be outside of the directory where your script and image is.
follow this : https://github.com/Shoes3/shoes3/wiki/Packaging
(note: tested on linux and on Windows)

Images Disappear in Running Status on Qt

Original design :
Setting in property :
When the program is running :
All the image inside the project folder "QuickRecorder/Images/MainWindow".
How to solve this problem?
Thank you for your help.
In cases like this the reason almost always is: You use relative path to the image, and the working directory is different when you run the application, and image is not found by the relative path.
To debug, add this to your main to print current working directory:
qDebug() << QDir::currentPath();
A few solutions:
Use absolute paths (preferably so that you construct them at runtime, for example using QCoreApplication::applicationDirPath(), instead of hard-coding).
Put images to Qt resources, so they are embedded to the executable.
Change working directory after application starts (might have unintended consequences if you for example launch child processes, or with file open/save dialogs).
Untested, moved from comment to answer: To automatically copy files from the source dir to the build dir, you could add a build step "Custom Process Step" in the Qt Creator project settings. The command you might want to use for the case of this question might be (again, untested):
cp -rv %{sourceDir}/QuickRecorder %{buildDir}

Resources