Ejemplo n.º 1
0
    def parametrize(self, ignorable_areas):
        '''
        For the given node we need to mark as dynamic the changing areas
        and ensure recognition of it will go smooth
        FIXME: should check sanity validate on tab images
        '''
        if self.file_name is None:
            raise Exception("Node file name must be set before parametrize!")

        if len(self.reference_images) == 0:
            raise Exception("No reference images available to parametrize")

        dialog = self.reference_images[0].image
        color = (237, 28, 36, 0)
        for edge in self.edges:
            if edge.location:
                elem_rect = expand_rect(edge.location, (1, 1))
                dialog.paste(color, elem_rect)

        LOGGER.debug("Parametrizing with %s ignorable areas" %
                     len(ignorable_areas))
        for area in ignorable_areas:
            elem_rect = expand_rect(area, (1, 1))
            dialog.paste(color, elem_rect)

        dialog = Image2(image=dialog,
                        color_mask=0xed1c2400,
                        tolerance=self.graph.image_tolerance)
        self.screenshots.append(dialog)
Ejemplo n.º 2
0
    def parametrize(self, ignorable_areas):
        '''
        For the given node we need to mark as dynamic the changing areas
        and ensure recognition of it will go smooth
        FIXME: should check sanity validate on tab images
        '''
        if self.file_name is None:
            raise Exception("Node file name must be set before parametrize!")

        if len(self.reference_images) == 0:
            raise Exception("No reference images available to parametrize")
            
        dialog = self.reference_images[0].image
        color = (237, 28, 36, 0)
        for edge in self.edges:
            if edge.location:
                elem_rect = expand_rect(edge.location, (1, 1))
                dialog.paste(color, elem_rect)
            
        LOGGER.debug("Parametrizing with %s ignorable areas" % 
                     len(ignorable_areas))
        for area in ignorable_areas:
            elem_rect = expand_rect(area, (1, 1))
            dialog.paste(color, elem_rect)
            
        dialog = Image2(image=dialog,
                        color_mask=0xed1c2400,
                        tolerance=self.graph.image_tolerance)
        self.screenshots.append(dialog)
Ejemplo n.º 3
0
def scrap_state(node, world, scraper_hints, node_hints):
    '''
    Scraps the ui into the given node for the given world state
    '''
    node_index = node.graph.nodes.index(node)
    node.name = 'Node %s' % node_index
    node.file_name = 'node_%s' % str(node_index).zfill(2)

    screen_image = world.machine.automation.grab_screen()
    screen = Image2(image=screen_image)

    LOGGER.debug("Node hints for scrapper, node %s are %s" % (node_index,
                                                            str(scraper_hints)))
    is_desktop = False
    if scraper_hints.get('windowless', False):
        #rect is difference between world.last_screen and screen
        no_taskbar = world.last_screen
        no_taskbar = world.last_screen.crop((0,
                                             0,
                                             no_taskbar.size[0],
                                             no_taskbar.size[1] -
                                                  TASKBAR_HEIGHT))
        window_rect = Image2(image=no_taskbar).difference(screen)
        window_rect = automation_helpers.refine_window_rect(screen_image,
                                                            window_rect)
    else:
        is_desktop, window_rect = solve_active_window_rect(world, screen_image)
        
    window_image = Image2(image=screen_image.crop(window_rect))
    node.reference_images.append(window_image)
    
    node.last_location = window_rect
    #Don't scrap the desktop!
    print "Screen size %s, window_rect %s" % (str(screen_image.size),
                                              str(window_rect))
    
    if is_desktop == "Screen":
        LOGGER.info("Disabling outfocus method as window rect is the whole screen")
        scraper_hints['outfocus method'] = False
        is_desktop = False
        
    if not is_desktop:
        scraper = Scraper(world.machine.automation, crop_taskbar=True)
        if 'defined by hover points' in scraper_hints:
            LOGGER.debug("Node defined by hover points")
            elements = scraper.get_elements_by_hover_points((window_rect[0],
                                                             window_rect[1]),
                                       scraper_hints['defined by hover points'])
        else:
            elements = scraper.get_elements(scraper_hints,
                                            (window_rect[0], window_rect[1]))
    else:
        #FIXME: could search for new icons...
        elements = []
        
    LOGGER.debug("Found elements: %s" % str(elements))

    LOGGER.debug("Node hints for node %s are %s" % (node_index,
                                                    str(node_hints)))
    ignorable_areas = node_hints.get('ignorable', [])
    for element in elements:
        element_rect = move_rect(element['coords'],
                                 (window_rect[0], window_rect[1]))

        if not is_rect_inside(element_rect, ignorable_areas):
            edge_name = 'Element %s' % len(node.edges)
            edge = node.create_edge(edge_name)
            edge.location = element_rect
            edge.absolute_location = element['coords']
            edge.ui_type = element['type']
            elem_rect = expand_rect(element['coords'], (1, 1))
            screenshot = Image2(image=screen.image.crop(elem_rect))
            edge.screenshots.append(screenshot)
            if edge.ui_type == 'text':
                edge.head = node
        else:
            LOGGER.debug(("Ignoring element at %s as it is inside ignorable" +
                          " area") % str(element_rect))
Ejemplo n.º 4
0
def scrap_state(node, world, scraper_hints, node_hints):
    '''
    Scraps the ui into the given node for the given world state
    '''
    node_index = node.graph.nodes.index(node)
    node.name = 'Node %s' % node_index
    node.file_name = 'node_%s' % str(node_index).zfill(2)

    screen_image = world.machine.automation.grab_screen()
    screen = Image2(image=screen_image)

    LOGGER.debug("Node hints for scrapper, node %s are %s" %
                 (node_index, str(scraper_hints)))
    is_desktop = False
    if scraper_hints.get('windowless', False):
        #rect is difference between world.last_screen and screen
        no_taskbar = world.last_screen
        no_taskbar = world.last_screen.crop(
            (0, 0, no_taskbar.size[0], no_taskbar.size[1] - TASKBAR_HEIGHT))
        window_rect = Image2(image=no_taskbar).difference(screen)
        window_rect = automation_helpers.refine_window_rect(
            screen_image, window_rect)
    else:
        is_desktop, window_rect = solve_active_window_rect(world, screen_image)

    window_image = Image2(image=screen_image.crop(window_rect))
    node.reference_images.append(window_image)

    node.last_location = window_rect
    #Don't scrap the desktop!
    print "Screen size %s, window_rect %s" % (str(
        screen_image.size), str(window_rect))

    if is_desktop == "Screen":
        LOGGER.info(
            "Disabling outfocus method as window rect is the whole screen")
        scraper_hints['outfocus method'] = False
        is_desktop = False

    if not is_desktop:
        scraper = Scraper(world.machine.automation, crop_taskbar=True)
        if 'defined by hover points' in scraper_hints:
            LOGGER.debug("Node defined by hover points")
            elements = scraper.get_elements_by_hover_points(
                (window_rect[0], window_rect[1]),
                scraper_hints['defined by hover points'])
        else:
            elements = scraper.get_elements(scraper_hints,
                                            (window_rect[0], window_rect[1]))
    else:
        #FIXME: could search for new icons...
        elements = []

    LOGGER.debug("Found elements: %s" % str(elements))

    LOGGER.debug("Node hints for node %s are %s" %
                 (node_index, str(node_hints)))
    ignorable_areas = node_hints.get('ignorable', [])
    for element in elements:
        element_rect = move_rect(element['coords'],
                                 (window_rect[0], window_rect[1]))

        if not is_rect_inside(element_rect, ignorable_areas):
            edge_name = 'Element %s' % len(node.edges)
            edge = node.create_edge(edge_name)
            edge.location = element_rect
            edge.absolute_location = element['coords']
            edge.ui_type = element['type']
            elem_rect = expand_rect(element['coords'], (1, 1))
            screenshot = Image2(image=screen.image.crop(elem_rect))
            edge.screenshots.append(screenshot)
            if edge.ui_type == 'text':
                edge.head = node
        else:
            LOGGER.debug(
                ("Ignoring element at %s as it is inside ignorable" + " area")
                % str(element_rect))