How to include resource files to maked executable?

New to Gambas? Post your questions here. No question is too silly or too simple.
JumpyVB
Posts: 75
Joined: Friday 11th September 2020 9:09am

How to include resource files to maked executable?

Post by JumpyVB »

I have several *.svg glyph icons inside my gambas project directory that I would like to embed with the *.gambas executable. Is that possible and how? I access these files while debugging like this:
ToolButton_Left.Picture = Picture.Load(Application.Path &/ "glyphs/pan-start-symbolic.svg")
My executable will crash with error: "Unable to load picture".
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: How to include resource files to maked executable?

Post by BruceSteers »

make a folder in your projects main dir called .public

place your files in there.

access like


ToolButton_Left.Picture = Picture["./.public/glyphs/pan-start-symbolic.svg"]



a .public folder gets compiled with the archive and it's contents available at runtime. do not use Application.Path just use ./

Note: using Picture.Load() will load from disk each time
using Picture["/path/to/pic.jpg"] loads using cache if already loaded once before using the same method.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
thatbruce
Posts: 161
Joined: Saturday 4th September 2021 11:29pm

Re: How to include resource files to maked executable?

Post by thatbruce »

(smacks grasshopper a big one on the back of his head!)

All files inside your project, as long as they are not in the .hidden directory WILL be included automatically in your "executable" (which is an archive accessed by gbr3/gbx3 and not an executable btw).

Your problem is not understanding how to refer to files inside that archive. The answer lies in the way the runtime accesses "relative paths". See https://gambaswiki.org/wiki/lang/path
In particular, it is usual to just put your images in the "Data" "folder" in the project, then they are accessible easily as

Code: Select all

 Picture["./pic.jpg"]
b
p.s. you can also use subdirs inside "Data" as well if you want to keep things even more tidy. e.g.

Code: Select all

Picture["./images/pic.jpg"
Have you ever noticed that software is never advertised using the adjective "spreadable".
JumpyVB
Posts: 75
Joined: Friday 11th September 2020 9:09am

Re: How to include resource files to maked executable?

Post by JumpyVB »

BruceSteers wrote: Sunday 30th April 2023 8:03am Make a folder in your projects main dir called .public and place your files in there.
The .public folder gets compiled with the archive and it's contents available at runtime.
Do not use Application.Path just use ./
Thank you. It's working.
JumpyVB
Posts: 75
Joined: Friday 11th September 2020 9:09am

Re: How to include resource files to maked executable?

Post by JumpyVB »

thatbruce wrote: Sunday 30th April 2023 8:41am Your problem is understanding how to refer to files inside that archive. The answer lies in the way the runtime accesses "relative paths". See https://gambaswiki.org/wiki/lang/path
In particular, it is usual to just put your images in the "Data" "folder" in the project, then they are accessible easily as

Code: Select all

 Picture["./pic.jpg"]
b
p.s. you can also use subdirs inside "Data" as well if you want to keep things even more tidy. e.g.

Code: Select all

Picture["./images/pic.jpg"
So my files were included with my .gambas file all along. And I did not need that .public folder. Thank you for this clarification. This way of accessing my svg files is working splendidly.
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: How to include resource files to maked executable?

Post by BruceSteers »

I've always had problems with included files that were not in a .public folder when using the executable outside the project dir.

Good luck.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
thatbruce
Posts: 161
Joined: Saturday 4th September 2021 11:29pm

Re: How to include resource files to maked executable?

Post by thatbruce »

Well, my lumbago ridden left toe does remind me that there is a possible source of confusion.
IIRC "./" refers to the actual executable archive and if that is a library or a component then it is not the running project. In that case one has to refer to "../" - a fine point but a trap that did cause me some confusion when I was younger.
b
Have you ever noticed that software is never advertised using the adjective "spreadable".
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: How to include resource files to maked executable?

Post by BruceSteers »

I discovered that my problems seem to have been with using hidden folders starting with a full stop.

Ie. the .public folder is hidden and packs contents into archive okay.

a folder called .images that is hidden does not seem to work
a folder called images does.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
thatbruce
Posts: 161
Joined: Saturday 4th September 2021 11:29pm

Re: How to include resource files to maked executable?

Post by thatbruce »

That's interesting!
Some years ago I wrote a wiki page about just what is in a Gambas project directory and in particular what happens to the contents when the executable archive is created. I can't find it anymore which is sad (it did take a fair bit of work to figure it all out at the time). IIRC!.. I thought that generally speaking, everything relevant except ".hidden" and its contents were included (of course the compiler and translator work files and directories were excluded :? )
Your comment makes me wonder now whether there are other "dot" files and directories that are excluded that we don't know about. So ".public" is but ".images" isn't. Strange, weird even.
bests
b
Have you ever noticed that software is never advertised using the adjective "spreadable".
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: How to include resource files to maked executable?

Post by BruceSteers »

Yes it seem all hidden folders and files are excluded
i put 2 files, one named icon.png the other .icon.png in a folder called img and also in a folder called .img. this was the result from ls -aR, then gba3 -l on the compiled executable ...


bonus@bonus-G33M-DS2R:~/Desktop/_aa$ ls -aR
.:
.   _aa.gambas  content.txt  .gambas     .hidden    .img  .lang     .settings  .startup
..  .action     .directory   .gitignore  .icon.png  img   .project  .src
./.action:
.  ..
./.gambas:
.  ..  FORM1
./.hidden:
.  ..
./.img:
.  ..  .icon.png  icon.png
./img:
.  ..  .icon.png  icon.png
./.lang:
.  ..
./.src:
.  ..  Form1.class  Form1.class~  Form1.form  Form1.form~

bonus@bonus-G33M-DS2R:~/Desktop/_aa$ gba3 -l ./_aa.gambas
.startup
.project
.action
.gambas
.lang
content.txt
img
.gambas/FORM1
img/icon.png



the only icon in the archive is the non-hidden img/icon.png
no .icon.png and no .img folder

Respects
If at first you don't succeed , try doing something differently.
BruceS
Post Reply