Thumbnails not shown when using setBundlePath()

Asked by Tom Edmond

Like many others, I'm new to Java and Sikuli so forgive please if I am asking silly questions.

My problem is about 99% of problem 138597 - although not using my script as part of larger script.

This is a simple example I've now go to work, using setBundlePath() and uses the Windows Start button for now :-

#
setBundlePath("D:\documents and Settings\sesa121526\My Documents\images")

exists("start.png")
click(Pattern("start-1.png").targetOffset(20,100))
wait(2)
m=getLastMatch()
x=m.right(120).above(100)
x.highlight(2)
wait(2)
#

Previous versions of the script had the full pathname spec'd in the exists() and click(Pattern( )) statements
and although the IDE found the images and showed the thumbnails, when it came to run the script, it failed
stating the image file not found - hovering over the image showed just the filename and not the full path.

The above script loads into the IDE but it doesn't show the images as captured, only the image file name.

Is there another, more elegant solution that will allow the images to be viewed in the IDE and the script to run ?

I've read up on further questions and come across references to addImagePath and creating functions but I'm not
sure where this code needs to go ?

Regards

Tom

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Tom Edmond
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

--- If an image is not found in the your-script.sikuli folder, when the script is loaded, only the file name is shown
--- when capturing an image in the IDE, the image is always stored in the your-script.sikuli folder, no matter what image path settings you have in your script (addImagePath or setBundlePath, these are only evaluated at script run)
--- if you use setBundlePath() to get access to images stored somewhere else, you can no longer use the IDE Preview feature. Have a look at http://sikuli.org/docx/globals.html#importing-other-sikuli-scripts-reuse-code-and-images for possible solutions.

So in your case, thumbnails will never be shown, supposing the images are actually stored at
D:\documents and Settings\sesa121526\My Documents\images

which means in the WindowsExplorer you should see the images
start.png
start-1.png

BTW: always avoid, to capture the same images twice. The easiest way is to use image variables:

#exists("start.png") # this does nothing but searching the image, so it is cruft
imgStartButton = "start.png"
click(Pattern(imgStartButton).targetOffset(20,100))
wait(2)
m=getLastMatch()
x=m.right(120).above(100)
x.highlight(2)
wait(2)

Revision history for this message
Tom Edmond (tom-edmond) said :
#2

RaiMan,

Thanks for the prompt response.

Just a quick comment on the first line of your reply, before I close my question off.

I found that if the script didn't have the setBundlePath() call and I used the full pathname to the images in the
image directory in the exists() and click(Pattern(...)) calls, the thumbnails were shown in the IDE but the script
failed to run cause it couldn't find the actual images - it still showed them as thumbnails, though they were no
longer in the .sikuli directory as I had moved them to my images area.

However, I can live with just seeing the file names for now - until I take your advice and look at the scripts
reuse-code-and-images link for enhanced solution(s) - when time permits.

BTW: Thanks for the tip on using image variables

Great tool with great possibilities !!

Thanks for the support.

Regards

Tom

Revision history for this message
RaiMan (raimund-hocke) said :
#3

Thanks for your feedback and insisting on your observations ;-)

I confirm your findings, but they are simply bugs ;-)

--- showing thumbnails when giving absolute path
- if you add an image filename with absolute path to the script, you see the filename (no thumbnail)
- after saving and reopening the script, a thumbnail is shown and the path is stripped from the image filename. Saving the script again and reopen it, you will find, that the image filename is shown with the path stripped (but no thumbnail), so on run you get an image file not found error(and a FindFailed, since Sikuli tries to search for the image filename text now)
- clicking on such a corrupted thumbnail, gives an error in the IDE, because the image file cannot be found (no Preview started)

workaround:
divide the path string into 2 concatenated substrings:
"absolute-path-to-image-folder"+"some-image.png"

This will not be touched by the thumbnail logic on script open.

I will look wether this is already bug reported or even solved in r930.

You found another workaround:
Setting the image path to the image folder lets Sikuli find the image despite having this stripped, corrupted file name.