Example #1
0
def get_areas(area_map):
    """Возвращает координаты квадрата для заданой сетки"""
    if len(area_map) == 0:
        return 0, 0, 0, 0

    xdo = Xdo()
    size = xdo.get_window_size(xdo.get_active_window())
    locations = xdo.get_window_location(xdo.get_active_window())
    wnd_w = int(size.width / len(area_map[0]))
    wnd_h = int(size.height / len(area_map))
    result = []

    for row_n in range(len(area_map)):
        for cell_n in range(len(area_map[row_n])):
            if area_map[row_n][cell_n] == 1:
                result.append(
                    (wnd_w * cell_n + locations.x,
                     wnd_h * row_n + locations.y,
                     wnd_w * cell_n + wnd_w + locations.x,
                     wnd_h * row_n + wnd_h + locations.y)
                )
    return result
Example #2
0
def start_ns(url):

    # First, create the copy of the hard drive
    if DEBUG:
        print "creating the HD"

    # kill any previous binaries
    for proc in psutil.process_iter():
        if proc.name() == "previous":
            proc.kill()

    tar = tarfile.open(PRISTINE_HARD_DISK, 'r:gz')
    tar.extractall(ACTUAL_HARD_DISK_DIR)

    if DEBUG:
        print "done creating the HD"

    with pyvirtualdisplay.smartdisplay.SmartDisplay(visible=0,
                                                    size=(1300,
                                                          900)) as v_display:
        if DEBUG:
            print v_display
            print v_display.display

        with easyprocess.EasyProcess(PREVIOUS_BINARY) as previous:

            time.sleep(.50)
            xdo = Xdo()

            done = False
            while not done:
                wins = xdo.search_windows('Previous')
                # check if alive
                if not previous.is_alive():
                    print "Error, couldn't boot emulator"
                    return
                if wins:
                    done = True
                    window = wins[0]
                else:
                    time.sleep(.50)

            # Get the relative X and Y for the window
            loc = xdo.get_window_location(window)

            print "Booting up"

            # wait until we get to the login screen
            wait_until_login_screen(xdo, loc, window, v_display)

            print "Finally booted"

            current_image = v_display.waitgrab()
            send_screen_shot(current_image)

            log_into_ns(xdo, window)

            print "Waiting to log in"

            # wait for the screen to load
            wait_until_login_desktop(xdo, loc, window, v_display)

            print "Logged in"

            current_image = v_display.waitgrab()
            send_screen_shot(current_image)

            # Send the data
            send_url_to_ns(url)

            send_copy_command(xdo, window)

            time.sleep(.50)

            current_image = v_display.waitgrab()
            send_screen_shot(current_image)

            print "Starting the old dog"

            send_start_www_command(xdo, window)

            # Wait until WWW is ready
            wait_until_www_ready(xdo, loc, window, v_display)

            print "That old dog is ready"

            current_image = v_display.waitgrab()
            send_screen_shot(current_image)

            # Close out the terminal
            # Command-q is the keyboard shortcut to quit
            xdo.send_keysequence_window(window, "Super_L+q")
            time.sleep(.50)
            select_open_document(xdo, loc, window)

            # Wait until Document Inspector is open
            print "Sending your input"
            wait_until_document_inspector_open(xdo, loc, window, v_display)

            current_image = v_display.waitgrab()
            send_screen_shot(current_image)

            move_to_address_field(xdo, loc, v_display)
            time.sleep(.50)
            xdo.click_window(window, 1)

            current_image = v_display.waitgrab()
            send_screen_shot(current_image)

            # Paste that shit!
            # Command-v is the keyboard shortcut
            xdo.send_keysequence_window(window, "Super_L+v")
            time.sleep(.50)

            current_image = v_display.waitgrab()
            send_screen_shot(current_image)

            print "That old dog can still visit URLs!"

            # if DEBUG:
            #     input("Wait for debugging")

            # Open it!
            xdo.send_keysequence_window(window, "Return")

            print "tbl would be proud"

            # Wait for 5 seconds, taking screenshots
            for i in xrange(5):
                time.sleep(1)
                current_image = v_display.waitgrab()
                send_screen_shot(current_image)

        # Crazy hack b/c something is sending an error message:
        # "XIO:  fatal IO error 0 (Success) on X server ":1001""
        # Which is freaking crazy, doesn't make any
        devnull = open(os.devnull, 'w')
        os.dup2(devnull.fileno(), 2)