sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #07715
Re: [Question #182604]: Using a common resource folder for Sikuli Images with the IDE
Question #182604 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/182604
Status: Open => Answered
RaiMan proposed the following answer:
--- IDE image thumbnails
These are only refreshed when a script is opened in the IDE.
--- IDE does not know image path
The IDE itself (e.g. Preview) does not use the image path. It only looks into the script folder. So if you move an image from the current tabs .sikuli folder elsewhere, while the script is opened in the IDE, the thumbnail will remain, but Preview fails, since the image is no longer in the .sikuli folder. When reopening the script, the image name will no longer be replaced by its thumbnail, since the image is not found in the .sikuli folder.
Currently, there is no way to to overcome this inconvenience.
So when using image path to centralize images, you cannot use Preview
for these images.
--- what to do
You already have a "imagelibrary.sikuli" in your concept. So just open this in parallel in the IDE and manage your images there.
Save this before running your main script, when you have made changes.
e.g.
"myImage.png" # the image name for convenience (myImage here)
since the images are shown as thumbnails and you have to hover to get
the filename tooltip.
You might even switch to import and leave the image path handling to
Sikuli:
your revised intro:
use os.path.join, to avoid backslash handling (which otherwise have to
be doubled (escaped) or you have to use raw strings (r"\lib”)
# get the directory containing your running .sikuli
import os
scriptLocation = os.path.dirname(getBundlePath())
libPath = os.path.join(scriptLocation, "lib")
if not scriptLocation in sys.path: sys.path.append(scriptLocation)
if not libPath in sys.path: sys.path.append(libPath)
import imagelibrary
# this adds image library.sikuli to image path internally
If you want to stick with image path handling, you have to revise your
code this way:
import os
scriptLocation = os.path.dirname(getBundlePath())
libPath = os.path.join(scriptLocation, "lib")
if not scriptLocation in sys.path: sys.path.append(scriptLocation)
if not libPath in sys.path: sys.path.append(libPath)
imagePath = os.path.join(scriptLocation, "imagelibrary.sikuli")
if not [e for e in getImagePath() if imagePath in e]: # see comment
addImagePath(imagePath)
comment: the simple
if not imagePath in getImagePath(): addImagePath(imagepath)
does not seem to work (Jython / Java problem ??), so you have to check
the entries individually in a loop (to be compact, I use a list
comprehension in this case).
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.