[1.1.1] Image taken at runtime isn't updated in Sikuli --- HowTo force the update

Asked by Maurice Richard

--- How to force the update:

*** to permanently switch off image caching use:
Settings.setImageCache(0)
... from that time on every image will be loaded from its file whenever used

*** to force the reload of an image after having changed its file content during runtime of the script while image caching is not switched of:
(only works with version 1.1.1 after 2017-02-25)
Image.reload(image)
... where image is the same string that is used to define the image - example
img = "someImage.png"
find(img) # old version used
# do something to change the content of the image file
Image.reload(img) # or
Image.reload("someImage.png")
find(img) # new version used

------------------------------------------------------------------------------------------------
My sikuli application takes a snapshot of a user selection in a dropdown list.
It then does various actions with this screenshot, and finishes its execution.
This works brilliantly.

When the user runs the script again, it overwrites the image file with the new dropdown selection. (as it should)
But for some reason, the second time, it continues looking for the original screenshot.
If I close & reopen Sikuli, it then registers the updated screenshot and works fine.

It seems like the original image is cached, despite it being overwritten by Sikuli.
So I've tried using: Image.reload(filename.png)
I've also tried using: Settings.setImageCache(0)

Despite that, it works the first execution, fails on the second. But works if Sikuli is restarted.

Any help would be very appreciated!

Question information

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

version 1.1.1?

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

just checked with version 1.1.1:

using
Image.reset()

after having changed the filecontent programatically resets the cache and the new image content is used from now on.

I will check, why the other 2 options you used (both are valid) did not work.

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

... and if you say at the beginning of your script
Settings.setImageCache(0)

... then image caching is completely switched of

Revision history for this message
Maurice Richard (flashfires) said :
#4

Hmm. None of these are working for me.

I'm on 1.1.0 ... isn't that the stable version?
Should I switch to the nightly build? (1.1.1)

Revision history for this message
Maurice Richard (flashfires) said :
#5

I've tried turning off image caching as you've suggested, but it's not working.
I'll post a code sample below in case I'm doing something wrong.

#Remove file caching
Settings.setImageCache(0)

def ProcessRateBuild():
    #Loop using screen capture to save multiple versions of the selected rate code
    x=0
        while x<9:
                x = x + 1

                click("dropdown.png")
                type(Key.PAGE_DOWN)
                click("ImgSelectedRatePlan.png")
                click("BAR1.png")
                click("Save.png")

def GetSelectedRatePlan():
    #This sub takes a screenshot of the dropdown list value, saves it in the project directory

    #Get the selected dropdown value
    captured_screen = capture(332,449,180,13)

    #variable for the file name
    varTempImage = "ImgSelectedRatePlan.png"

    #create a new file path
    NewFileName = os.path.join(getBundlePath(), varTempImage)

    #Copy file to the project directory
    shutil.move (captured_screen, NewFileName)

#Main Program - Saves selected rate code, then saves data based on that
GetSelectedRatePlan()
ProcessRateBuild()

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

Ok, I am testing and fixing in 1.1.1

might not work with 1.1.0

I guess you have to try with nightly 1.1.1 (anyways pre-final ;-)

Revision history for this message
Maurice Richard (flashfires) said :
#7

I tried v1.1.1 this morning, and my code worked like a charm!
So thanks RaiMan, that was driving me crazy.

The only downside is, compared to the previous build (1.1.0), this one is noticeably slower.
It's not the end of the world, but if you have any tips for speeding it up, that would be appreciated!

Thanks again!

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

--- this one is noticeably slower
... should not be.

please tell me what you finally did with 1.1.1, to fix your problem and give me more information where you see a slowdown.

Revision history for this message
Maurice Richard (flashfires) said :
#9

Disregard, the slowness was caused by my code. Thanks!

Revision history for this message
Maurice Richard (flashfires) said :
#10

Thanks RaiMan, that solved my question.