← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #177997]: image matching different at Preview and at runtime

 

Question #177997 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/177997

RaiMan proposed the following answer:
Had a look at your code, you sent me.

You have a submodule, that is imported and contains captured images
(your key pictures), that are not referenced with their filenames in the
code. If you edit this script in the IDE, and save it, all these images
are deleted.

Since you used try:/except: for the find operation using these images,
you did not realize that Sikuli complains, that the image file cannot be
found.

I always use exists() in these situations and when I am sure, that the
image should be found and not found is a fatal error, then I use
exists(image, 0), which makes only one search and instantly comes back
(does not wait the 3 seconds standard waiting time).

*** So what can you do?

In the current shape of the IDE, you have to reference the images with it's filenames in the script, to secure them from being purged.
I usually use:
name = "some-image.png"

for each image.

In your case (this was what I have done with your stuff), I would do all
images into one separate images.sikuli with a script just containing the
filename strings (visible as thumbnails in the IDE).

so you would have:

*** main.sikuli
import sub
reload sub
from sub import * # preferable with a naming convention, no need to qualify
# your code

*** sub.sikuli
from sikuli import *
import images # to get the images in the image path

*** images.sikuli
"a_key_qwertykeyboard.png"
"b_key_qwertykeyboard.png"
# .... and all other images needed in main or sub

If you want to add images to images.sikuli, just open in IDE, capture
the image,  save and close.

Only when you decide, to put supporting code (functions, classes) in
images.sikuli (what I do not recommend) you would need:

*** sub.sikuli
from sikuli import *
import images
reload(images)
from images import *

and may be a from sikuli import * in images.sikuli.

As in this case, where all *.sikuli are in the same folder as
main.sikuli, there is no need to append sys.path, since import x.sikuli
finds x, if in same folder as the importing script.

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.