keyerror message when running automation script

Asked by mohammed ahmed on 2019-08-06

from sikuli.Sikuli import *
import os
myPath = os.path.dirname(getBundlePath())
if not myPath in sys.path: sys.path.append(myPath)
from imagerepository import *
from imageclick import *
#from util import *
#from regionDictionary import *

class PSWTest():

            def openpsw():
            #def __init__(self):
                myImages = imagerepository()

****image repository*****
from sikuli.Sikuli import *
myPath = os.path.dirname(getBundlePath())
if not myPath in sys.path: sys.path.append(myPath)

class imagerepository():

    imgDict = {}
    def __init__(self):
        self.imgDict = {}
        self.addImage("ok servername","1564497875916.png")

    def addImage(self, name, img):
  self.imgDict[name] = img

    def getImage1(self, name):
  return self.imgDict[name]

[error] script [ PSWTest ] stopped with error at line --unknown--
[error] Error caused by: Traceback (most recent call last): File "C:\Users\mahmed\Documents\sikuli images\PSWTest.sikuli\", line 11, in <module> class PSWTest(): File "C:\Users\mahmed\Documents\sikuli images\PSWTest.sikuli\", line 22, in PSWTest openpsw() File "C:\Users\mahmed\Documents\sikuli images\PSWTest.sikuli\", line 20, in openpsw click(myImages.getImage("open")) File "C:\Users\mahmed\Documents\sikuli images\imagerepository.sikuli\", line 22, in getImage return self.imgDict[name] KeyError: open

Question information

English Edit question
Sikuli Edit question
No assignee Edit question
Last query:
Last reply:
RaiMan (raimund-hocke) said : #1

not a SikuliX problem, since it is self-made Jython code.

mohammed ahmed (md-ahmd) said : #2

Apologies, to come back to this question.
I think I know what is happening, Every time I add an image to image dictionary.
I need to restart IDE for the image to be identified by other scripts.

I have "from imagerepository import *" in all the scripts that use the images.
Not sure if it is repeated question. Also I am using SikulixIDE 1.1.3.

Please let me know if you need more information to help me with this.

mohammed ahmed (md-ahmd) said : #3

Can someone help me with this. It might be a trivial issue for experts to solve but I have reached a bottleneck.

RaiMan (raimund-hocke) said : #4

Your overall concept is not dynamic:
If you change a script's content, that was imported before in the IDE, it has to be reloaded at the next run, to reflect the changes.

So if you add an image in the script with class imagerepository, it is not reflected by the already imported script (the IDE is one continous Jython session).

A solution is to run your main script from command line, which starts a new session with every run and make your changes in parallel in the IDE.

Another solution is to rely on the image path feature:
instead of importing the imagerepository script, put it on the image path

Can you help with this problem?

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

To post a message you must log in.