コード例 #1
0
def zoom_with_mouse_wheel(nr_of_times=1, zoom_type=None):
    """Zoom in/Zoom out using the mouse wheel.

    :param nr_of_times: Number of times the 'zoom in'/'zoom out' action should
    take place.
    :param zoom_type: Type of the zoom action('zoom in'/'zoom out') intended to
    be performed.
    :return: None.
    """

    # MAC needs doubled number of mouse wheels to zoom in correctly.
    if OSHelper.is_mac():
        nr_of_times *= 2

    # Move focus in the middle of the page to be able to use the scroll.

    Mouse().move(Location(Screen.SCREEN_WIDTH // 4, Screen.SCREEN_HEIGHT // 2))

    for i in range(nr_of_times):
        if OSHelper.is_mac():
            key_down("command")

        else:
            key_down("ctrl")

        Mouse().scroll(dy=zoom_type, dx=0)
        if OSHelper.is_mac():
            key_up("command")

        else:
            key_up("ctrl")

        time.sleep(Settings.DEFAULT_UI_DELAY)
    Mouse().move(Location(0, 0))
コード例 #2
0
def maximize_window():
    """Maximize the browser window to fill the screen.

    This is NOT Full Screen mode.
    """
    if OSHelper.is_mac():
        # There is no keyboard shortcut for this on Mac. We'll do it the old fashioned way.
        # This image is of the three window control buttons at top left of the window.
        # We have to resize the window to ensure maximize works properly in all cases.
        window_controls_pattern = Pattern('window_controls.png')
        controls_location = find(window_controls_pattern)
        xcoord = controls_location.x
        ycoord = controls_location.y
        width, height = window_controls_pattern.get_size()
        drag_start = Location(xcoord + 70, ycoord + 5)
        drag_end = Location(xcoord + 75, ycoord + 5)
        Mouse().drag_and_drop(drag_start, drag_end, duration=0.1)

        # Alt key changes maximize button from full screen to maximize window.
        maximize_button = window_controls_pattern.target_offset(width / 2 - 3, 0)
        key_down(Key.ALT)
        click(maximize_button)
        key_up(Key.ALT)

    elif OSHelper.is_windows():
        type(text=Key.UP, modifier=KeyModifier.WIN)
    else:
        type(text=Key.UP, modifier=[KeyModifier.CTRL, KeyModifier.META])
    time.sleep(Settings.DEFAULT_UI_DELAY)
コード例 #3
0
def restore_window_from_taskbar(option=None):
    """Restore firefox from task bar."""
    if OSHelper.is_mac():
        try:
            click(Pattern("main_menu_window.png"))
            if option == "browser_console":
                click(Pattern("window_browser_console.png"))
            else:
                click(Pattern("window_firefox.png"))
        except FindError:
            raise APIHelperError("Restore window from taskbar unsuccessful.")
    elif OSHelper.get_os_version() == "win7":
        try:
            click(Pattern("firefox_start_bar.png"))
            if option == "library_menu":
                click(Pattern("firefox_start_bar_library.png"))
            if option == "browser_console":
                click(Pattern("firefox_start_bar_browser_console.png"))
        except FindError:
            raise APIHelperError("Restore window from taskbar unsuccessful.")

    else:
        type(text=Key.TAB, modifier=KeyModifier.ALT)
        if OSHelper.is_linux():
            Mouse().move(Location(0, 50))
    time.sleep(Settings.DEFAULT_UI_DELAY)
コード例 #4
0
def find_window_controls(window_type):
    """Find window controls for main and auxiliary windows.

    :param window_type: Controls for a specific window type.
    :return: None.
    """
    if window_type == "auxiliary":
        Mouse().move(Location(1, 300))
        if OSHelper.is_mac():
            try:
                wait(AuxiliaryWindow.RED_BUTTON_PATTERN.similar(0.9), 5)
                logger.debug("Auxiliary window control found.")
            except FindError:
                raise APIHelperError(
                    "Can't find the auxiliary window controls, aborting.")
        else:
            if OSHelper.is_linux():
                Mouse().move(Location(80, 0))
            try:
                wait(AuxiliaryWindow.CLOSE_BUTTON, 5)
                logger.debug("Auxiliary window control found.")
            except FindError:
                raise APIHelperError(
                    "Can't find the auxiliary window controls, aborting.")

    elif window_type == "main":
        if OSHelper.is_mac():
            try:
                wait(MainWindow.MAIN_WINDOW_CONTROLS.similar(0.9), 5)
                logger.debug("Main window controls found.")
            except FindError:
                raise APIHelperError(
                    "Can't find the Main window controls, aborting.")
        else:
            try:
                if OSHelper.is_linux():
                    reset_mouse()
                wait(MainWindow.CLOSE_BUTTON, 5)
                logger.debug("Main window control found.")
            except FindError:
                raise APIHelperError(
                    "Can't find the Main window controls, aborting.")
    else:
        raise APIHelperError("Window Type not supported.")
コード例 #5
0
def reset_mouse():
    """Reset mouse position to location (0, 0)."""
    Mouse().move(Location(0, 0))