← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #272118]: Check if image file exist in getImagePath()

 

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

Brad requested more information:
Thanks for that workaround, I am using that but is there a way to stop the
[error] Image: could not be loaded: files:/C:/Some Path/Some Image.png
from printing to screen.  Preferably with a global switch I can turn off then back on instead of Try:  ?

I tried using try: and except: nesting but it made no change, but it
could have been because where I'm searching for existence of file is
already heavily nested and I didn't do it right.

In my script, I'm searching for a match of 2 possibilities... 00001X.png where X can be T or F.
So using the solution above, I have 

def TorFMatch(number,localDebug=False):                         #Checks if the #####T.png or #####F.png file already exists, 
    slowdown=1                                                                                # returns filename if it does or "Not Found" if it doesn't
    if localDebug: print "TorFMatch( number= "+str(number)+", localDebug=",localDebug,")"
    fn="TorF\\"+str(number).rjust(5,'0')                                    #Pad the number to 5 digits
    if localDebug: 
        print "Filename="+str(fn)
        wait(slowdown)
    if Image.create(fn+"T.png").isValid():                                  #Check for the True file match and return the filename if it exists
        if localDebug: 
            print "-True file found"
            wait(slowdown)
        return fn+"T.png"
    elif Image.create(fn+"F.png").isValid():                              #Check for the False file match and return the filename if it exists
        if localDebug: 
            print "-False file found"
            wait(slowdown)
        return fn+"F.png"
    else:                                                                                                #If neither the True or False match are found, return "Not Found"
        if localDebug: 
            print "-Neither file found"
            wait(slowdown)
        return "Not Found"

Outside of that function I have a loop from 1 to a possible 100000
which, if the file exists, searches for a match on screen and responds
differently if it was a T or F result, or else captures a region of the
screen, then figures out if that new result should be a T or F and saves
that to the first available position where there is no existing "T" or
"F" version of the file.  In this way, the longer the script runs, the
more it learns from screen, and the more matches it does in subsequent
runs.

It works, but I get a lot of the
[error] Image: could not be loaded: files:/C:/Some Path/Some Image.png
prompts written to output and that's all I'm trying to remove

P.S.  Please don't mock me too badly for my bad debugging, I couldn't
get my head around using the logging properly, so I code it all manually
in a way I can turn on and off when testing my functions :S

-- 
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.