Image Dictionary Help

Asked by Garsk

In the script that I am currently working on, I am trying to reference an image dictionary where I am going to store all my images.

The image dictionary folder is in the same directory as the script that I am writing. I have used the " from sikuli import * " to try to import the images. When the script is running it is failing at the first image that is in the dictionary. The log message that it giving me is;

FindFailed: can not find image on the screen.

any help would be great, my knowledge/experience with Sikuli is limited. I have only started to use Sikuli and Python in the past two months.

Matthew

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

As far as I understand, you seem to have the following:

# image dictionary
# someName.sikuli
from sikuli import *
img1 = "someImage1.png"
# … and more of these

all the captures you make, are stored into this script with some naming convention.

now you have a main script, where you want to use the images from someName.sikuli

2 possibilities:

1. using the variable names
# content of main script
from someName import * # makes all variable names like img1 known in main
click(img1) # uses the image

2. using the filenames
# content of main script
import someName.sikuli # makes the image files in folder someName.sikuli available on the image path
click("someImage1.png") # image is found on image path and used

-- Questions:
- what version of Sikuli do you use?
- what exactly is your implementation (be more specific, paste code)?

Revision history for this message
Garsk (m-garskey) said :
#2

The version of code I am using right now is 1.0rc3 (r905). I named my image dictionary as 'puttydictionary.sikuli'

so far my code looks as such;

from sikuli import *
openApp ('C:\Users\carrier\Documents\putty.exe')
find (['ipaddress'])
click (['ipaddress'])
FGTIP = input('what is the IP address of the FGT? ')
type ('172.25.188.188')
find (['Open'])
click (['Open'])

once it gets to the first find option it give me the error in question.

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

ok, seems to be really a dictionary, that you have in puttydictionary.sikuli

1. you have to name the dictionary, that you want to read from:

someDict['ipaddress']

this returns the value (I guess image file name) in dictionary someDict that is defined in puttydictionary.sikuli

2. you have to import your puttydictionary.sikuli to get access to the contained elements

import puttydictionary
images = puttydictionary. someDict # see comment
openApp ('C:\Users\carrier\Documents\putty.exe')
# find (['ipaddress']) # not needed see comment
click (images['ipaddress'])
FGTIP = input('what is the IP address of the FGT? ')
type ('172.25.188.188')
# find (['Open'])
click (images['Open'])

comments:
--- in the main script
from sikuli import *
is not needed (done internally anyways)

but it is mandatory in imported scripts (putty dictionary.sikuli)

--- puttydictionary. someDict
since I do not know your puttydictionary. sikuli, I do not know the name of the dictionary.

--- # find (['Open'])
not needed, since the following click internally does a find anyway

One more thing:
for what you are doing, using a dictionary is far beyond the need.
Try to understand the concept In my comment #1.

Revision history for this message
Garsk (m-garskey) said :
#4

I am going the route of a image dictionary because later on I am going to have various scripts referencing the dictionary, so I figured it would be easier to have one location for the images and the rest of the scripts referencing it.

As for the changes that you suggested, when running the script for the first time, it failed on the first line with the error message;

[error] Stopped
[error] An error occurs at line 1
[error] Error message: Traceback (most recent call last):
 File "C:\Users\carrier\AppData\Local\Temp\sikuli-tmp1365089574905954334.py", line 1, in
 import PuttyDictionary
 File "C:\Program Files (x86)\Sikuli X\sikuli-script.jar\Lib\sikuli\SikuliImporter.py", line 45, in load_module
 File "C:\Program Files (x86)\Sikuli X\sikuli-script.jar\Lib\sikuli\SikuliImporter.py", line 29, in _load_module
ImportError: Errors in loading sikuli module: PuttyDictionary
name 'Pattern' is not defined
 - HOW TO FIX? Try adding "from sikuli import *" in the module.

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

sometimes it is really frustrating answering questions here, because I get the feeling, that people do not read carefully enough what I write - sorry, but from time to time I need to say that.

in comment #3:
-- in the main script
from sikuli import *
is not needed (done internally anyways)

but it is mandatory in imported scripts (putty dictionary.sikuli)

... and in the error message:
 - HOW TO FIX? Try adding "from sikuli import *" in the module.

... now try to get the solution ;-)

--- you say:
I am going the route of a image dictionary because later on I am going to have various scripts referencing the dictionary, so I figured it would be easier to have one location for the images and the rest of the scripts referencing it.

... not the dictionary is what implements the DRY pattern (don't repeat yourself), but it is the image module, that is then imported in various other modules to get access to the images.

the easiest implementation: see comment #1

Can you help with this problem?

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

To post a message you must log in.