def wait_for_one_of(self, images, timeout=15, zone=None):
     # wait_for_one_of_images(images, timeout, step, zone) -> bool
     # images - list of (image, threshold, bool)
     #     image - PIL image
     #     threshold - threshold for image
     #     bool - True for wait for show, False for wait for hide
     
     assert len(images) > 0, "You are trying to wait for empty list of images. Really?"
     
     timeout = float(timeout)
     start_time = datetime.datetime.now()
     
     while True:
         screen_img = self._screenshot(zone)
         for image_info in images:
             # todo: optimize
             result = self._find_image_result(image_info[0], screen_img, float(image_info[1]))
             if result.found == utils.to_bool(image_info[2]):
                 return result
         
         utils.sleep(0)
         if (datetime.datetime.now() - start_time).seconds > timeout:
             break
     
     images_info = []
     for index, image in enumerate(images):
         images_info.append(("image_{}_threshold_{}".format(index, image[1]), image[0]))
     
     images_info.append(("screen", screen_img))
     self.error_handler.report_warning("Waiting for one of the images was unsuccessful", *images_info)
     return result
 def _find_image(self, image, threshold=0.99, cache=False, zone=None, screen=None):
     # _find_image(image, threshold, cache, zone) -> FindResult
     threshold = float(threshold)
     cache = utils.to_bool(cache)
     
     assert threshold > 0 and threshold <= 1, "Threshold must be between (0, 1)"
     screen_img = self._get_screen(cache, zone, screen)
     img = self.load_image(image)
     return self._find_image_result(img, screen_img, threshold)
 def find_multiple_images(self, image, threshold=0.99, cache=False, zone=None, screen=None):
     # _find_image(image, threshold, cache, zone) -> list(FindResult)
     
     
     threshold = float(threshold)
     cache = utils.to_bool(cache)
     
     screen_img = self._get_screen(cache, zone, screen)
     img = self.load_image(image)
     
     poses = OpenCV().find_multiple_templates(img, screen_img, threshold)
     
     result = []
     for pos in poses:
         result.append(FindResult(*pos, image=img, screen=screen_img, found=True))
     
     return result
Esempio n. 4
0
    def find_image(self,
                   image,
                   threshold=0.99,
                   cache=False,
                   zone=None,
                   screen=None):
        """S.find_image(image, threshold, cache, zone) -> FindResult"""
        threshold = float(threshold)
        cache = utils.to_bool(cache)

        assert 0 < threshold <= 1, "Threshold must be in (0, 1)"

        #get the screenshot to search on
        screen_img = self._get_screen(cache, zone, screen)
        #load the template image
        img = self.load_image(image)
        #locate the image with threshold and return result
        return self.find_image_result(img, screen_img, threshold)
Esempio n. 5
0
    def wait_for_one_of(self, images, timeout=15, zone=None):
        """wait_for_one_of_images(images, timeout, step, zone) -> bool
            images - list of (image, threshold, bool)
                image - PIL image
                threshold - threshold for image
                bool - True for wait for show, False for wait for hide
        """
        assert len(
            images
        ) > 0, "You are trying to wait for empty list of images. Really?"

        timeout = float(timeout)
        start_time = datetime.datetime.now()

        #loops through images in list and locates image on screen. Returns search results.
        #if not timeout repeats taking new screenshots and searching images on it.
        #ends loop on timeout
        while True:
            screen_img = self._get_screen(False, zone)
            for image_info in images:
                #todo: optimize
                result = self.find_image_result(image_info[0], screen_img,
                                                float(image_info[1]))
                if result.found == utils.to_bool(image_info[2]):
                    return result

            utils.sleep(0)
            if (datetime.datetime.now() - start_time).seconds > timeout:
                break

        images_info = []
        for index, image in enumerate(images):
            images_info.append(
                ("image_{}_threshold_{}".format(index, image[1]), image[0]))

        images_info.append(("screen", screen_img))
        self.error_handler.report_warning(
            "Waiting for one of the images was unsuccessful", *images_info)
        return result
Esempio n. 6
0
 def iterate_all_values(self, reverse=False):
     reverse = utils.to_bool(reverse)
     print(*iter(self.values))
     return ValuesIterator(
         iter(self.values) if not reverse else reversed(self.values),
         len(self.values))