← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #250984]: How convert org.sikuli.script.Pattern in string?

 

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

    Status: Answered => Open

gregory is still having a problem:
Yes me too I can get it working without an error:

the map is declarer in file that contains only map of images.

Then I am doing a check_icons on Icons Class:

    ## Find corresponding snapshot in list
    ## @param map_id is the map name
    ## @param timeout is time to wait in seconde before exit in case of error (default: 10 secondes)
    ## @param pExistDef set to True in case exist is done and so no need to create html error
    def check_icons(self, map_id, timeout=1,pExistDef=False):
        map_name = map_id.keys()[0]
        #print "KEYS"
        #print map_name
        map_values = map_id.values()[0][self.os_name]
        #print "VALUES"
        #print map_values
        # Check if there is more than 1 value in map
        #try:
        #    test_iterable_map = iter(map_id.values()[0][self.os_name])
        #    iterable_map = 1
            #print "object iterable"
        #except:
            #print "object non iterable"
        #    iterable_map = 0
        if timeout > 0 and timeout < 600:
            tout=timeout
        else:
            tout=self.tout
        #self.msg.debug("Timeout: ")
        #print tout
        #self.msg.debug("cache:")
        #print self.cache
        delta=0
        # Before found image, check if there are several match with list images and map contains more than 1 value.
        if(self.check_dup==1):
            self.check_duplicated_icons(map_name,map_values)
        while delta<tout:
            # Get start time before check image map
            #start_time = time.time()
            # check cache:
            if map_name in self.cache:
                if exists(self.cache[map_name]):
                    self.msg.debug(toString(delta)+") Icon found in cache - list: " + map_name)
                    return(self.cache[map_name])
            # check all icons
            for i in map_values:
                if exists(i) :
                    self.msg.debug(toString(delta)+") Icon found (" + toString(i) + ") added to cache - list: " + map_name)
                    #hover(i) # only for debug
                    self.cache[map_name]=i
                    return(i)
           # OK not found, let's wait and retry
           # let's try every 3 sec, until timeout is expired
            #print time.time() - start_time, "seconds"
            #end_time=time.time() - start_time
            sleep(0.5)
            delta=delta+0.5
        # In case check_icons failed we need to generate html file for help to understand what is going on
        if pExistDef == False:
            self.msg.create_html_error(map_id.values()[0][self.os_name])  <--- DEF WHERE I get error
        self.msg.debug("No match for any icons in list: " + map_name)
        raise Exception("No match for any icons in list: " + map_name)

Then I want to write an html page with getting image name and copy them
in dedicated directory, and we are now in Output Class

    def create_html_error(self,pImageMap):
        #try:
        ####### Take screenshot for copy it
        self.take_screen_shot()
        ####### Coutner -1 to get screenshot taken
        my_coutner = int(self.mCounter) - 1
        matches=[]
        if not os.path.exists(self.DstPath):
            os.makedirs(self.DstPath)

        print "sikuli map image path: " + self.ImagePath
        for x in pImageMap:
            print "My map: " + x
            image_parse = re.search('\((.*)\)',x)
            print "image parsed: " + image_parse
            for root, dirnames, filenames in os.walk(self.ImagePath):
                for filename in fnmatch.filter(filenames, '*.png'):
                    #print "filename: " + filename
                    if str(x) == filename:
                        print "match: " + str(x) + " and " + filename
                        matches.append(os.path.join(root, filename))

I hope this will help you :)

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