IDE changes png file paths

Asked by mike

I wanted to share some image files between a few sikuli tests.
So in the IDE I deleted the image and typed in
   click("../images/test001c.png")
The test ran successfully.
I closed that tab in the IDE,

I then opened it again in the IDE.
The IDE seems to read the .png file and display the image.
Placing the mouse over the image, the tooltip showed the filename without the path.
I saved the test fileand closed the tab again.

I then opened it again in the IDE.
The IDE now shows this
    click("test001c.png")
It has lost the filename path that I typed in.

I guess I can have multiple copies of the files inecah sikuli job.
Is there something I'm missing here?

Regards,
Mike

Question information

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

--1.
if you want to use path's for images, you have to use absolute paths.

--2.
if you want to refer a directory in the same directory as your script:
import os
imageDir = os.path.join(os.path.dirname(getBundlePath()), "images")
...
click(os.path.join(imageDir), "test001c.png"))

--3.
the most elegant and flexible solution is to have all images in one images.sikuli and just import this.
This allows to use variables for images (with a naming convention) or sets of images in lists or dictionaries.
look: http://sikuli.org/docx/globals.html#importing-other-sikuli-scripts-reuse-code-and-images

images.sikuli:
img1 = "some-image.png"
# more images

main.sikuli
import os
dir = os.path.dirname(getBundlePath())
if not dir in sys.path: path.append(dir)
from images import *
click(img1)

Can you help with this problem?

Provide an answer of your own, or ask mike for more information if necessary.

To post a message you must log in.