Esempio n. 1
0
'''
Esempio n. 2
0
'''
Esempio 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))
Esempio 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))
Esempio n. 5
0
'''
Esempio n. 6
0
'''