def _init_static_elements(self, screen=None): """Init position of static elements of window. Assumes that window is on screen or error will be raised """ #init buttons for button in self.buttons.values(): button.find_on_screen(screen) screen = ImageProcessor().get_screenshot() if screen is None else screen #check window if "check" in self.config: images_to_check = [] if isinstance(self.config["check"], list): for img_name in self.config["check"]: images_to_check.append(get_image_from_config(img_name)) if type(images_to_check[0]) == list: for image in images_to_check[0]: res = ImageProcessor().is_image_on_screen(image, screen=screen) if not res: msg = "Image {} was not found at screen".format(image) ErrorHandler().report_error(msg) raise RuntimeError(msg) elif type(images_to_check) == list: for image in images_to_check: try: ImageProcessor().image_should_be_on_screen(image[0], image[1], screen=screen) except RuntimeError as e: pass else: images_to_check.append(get_image_from_config(self.config["check"])) for image in images_to_check: ImageProcessor().image_should_be_on_screen(image[0], image[1], screen=screen)
def check_if_section(config, screen_img): out = [] res = [] if isinstance(config, list): result = False for subnode in config: if isinstance(subnode, list): subresult = True for image_entry in subnode: image = get_image_from_config(image_entry) midresult = ImageProcessor().is_image_on_screen(image[0], image[1], screen=screen_img) subresult &= ImageProcessor().is_image_on_screen(image[0], image[1], screen=screen_img) if midresult is False: out.append(image_entry) result |= subresult else: image = get_image_from_config(subnode) midresult = ImageProcessor().is_image_on_screen(image[0], image[1], screen=screen_img) result |= ImageProcessor().is_image_on_screen(image[0], image[1], screen=screen_img) if midresult is False: out.append(subnode) else: image = get_image_from_config(config) midresult = ImageProcessor().is_image_on_screen(image[0], image[1], screen=screen_img) result = ImageProcessor().is_image_on_screen(image[0], image[1], screen=screen_img) if midresult is False: out.append(config) res.append(result) res.append(out) return res
def __init__(self, name, config): self.name = name self.images = None #if there are multiple images self.image = None #if this is one image if isinstance(config, list): self.images = [] for entry in config: self.images.append(get_image_from_config(entry)) else: self.image = get_image_from_config(config)
def wait_for_window_to_stop(self, timeout=15, move_threshold=0.99, step=0.1): if not "exist" in self.config or not "if" in self.config["exist"]: raise AssertionError('Section "exist":"if" must be defined in config') node = self.config["exist"]["if"] while isinstance(node, list): node = node[0] image_info = get_image_from_config(node) return ImageProcessor().wait_for_image_to_stop(image_info[0], image_info[1], timeout=timeout, move_threshold=move_threshold, step=step)
def __init__(self, name, config): super(DynamicMultipleButton, self).__init__(name) self.image_info = get_image_from_config(config) self.buttons = None if "direction" not in config or config["direction"] == "horizontal": self.direction = 0 elif config["direction"] == "vertical": self.direction = 1 else: raise errors.ConfigError( "Unknown direction, only horizontal and vertical are supported, {} recieved" .format(config["direction"]))
def __init__(self, name, config): if not isinstance(config, list): raise AssertionError( 'Config corrupted for complex template {}: must be list of filenames, {} actually' .format(name, config)) self.name = name self.images = [] if isinstance(config, list): for entry in config: self.images.append(get_image_from_config(entry)) else: raise AssertionError( "Complex template must contain list of images")