Exemplo n.º 1
0
def set_primary_monitor(monitor):
    """Set *monitor* to be the primary monitor.

    :param int monitor: Must be between 0 and the number of configured
     monitors.
    :raises: **ValueError** if an invalid monitor is specified.
    :raises: **BlacklistedDriverError** if your video driver does not
     support this.

    """
    try:
        glxinfo_out = subprocess.check_output("glxinfo")
    except OSError as e:
        raise OSError("Failed to run glxinfo: %s. (do you have mesa-utils installed?)" % e)

    for dri in _blacklisted_drivers:
        if dri in glxinfo_out:
            raise Display.BlacklistedDriverError('Impossible change the primary monitor for the given driver')

    num_monitors = Display.create().get_num_screens()
    if monitor < 0 or monitor >= num_monitors:
        raise ValueError('Monitor %d is not in valid range of 0 <= monitor < %d.' % (num_monitors))

    default_screen = Gdk.Screen.get_default()
    monitor_name = default_screen.get_monitor_plug_name(monitor)

    if not monitor_name:
        raise ValueError('Could not get monitor name from monitor number %d.' % (monitor))

    ret = os.spawnlp(os.P_WAIT, "xrandr", "xrandr", "--output", monitor_name, "--primary")

    if ret != 0:
        raise RuntimeError('Xrandr can\'t set the primary monitor. error code: %d' % (ret))
Exemplo n.º 2
0
    def test_input_backends_default_order(self, pick_backend):
        d = Display()
        d.create()

        backends = list(pick_backend.call_args[0][0].items())
        self.assertTrue(backends[0][0] == 'X11')
        self.assertTrue(backends[1][0] == 'UPA')
    def test_window_geometry(self):
        """Window.geometry property

        Check that all Window geometry properties work and have a plausible
        range.
        """
        # ensure we have at least one open app window
        self.start_mock_app(EmulatorBase)

        display = Display.create()
        top = left = right = bottom = None
        # for multi-monitor setups, make sure we examine the full desktop
        # space:
        for monitor in range(display.get_num_screens()):
            sx, sy, swidth, sheight = Display.create().get_screen_geometry(
                monitor
            )
            logger.info(
                "Monitor %d geometry is (%d, %d, %d, %d)",
                monitor,
                sx,
                sy,
                swidth,
                sheight,
            )
            if left is None or sx < left:
                left = sx
            if top is None or sy < top:
                top = sy
            if right is None or sx + swidth >= right:
                right = sx + swidth
            if bottom is None or sy + sheight >= bottom:
                bottom = sy + sheight

        logger.info(
            "Total desktop geometry is (%d, %d), (%d, %d)",
            left,
            top,
            right,
            bottom,
        )
        for win in self.process_manager.get_open_windows():
            logger.info("Win '%r' geometry is %r", win, win.geometry)
            geom = win.geometry
            self.assertThat(len(geom), Equals(4))
            self.assertThat(geom[0], GreaterThan(left - 1))  # no GreaterEquals
            self.assertThat(geom[1], GreaterThan(top - 1))
            self.assertThat(geom[2], LessThan(right))
            self.assertThat(geom[3], LessThan(bottom))
Exemplo n.º 4
0
def drag_window_to_screen(window, screen):
    """Drags *window* to *screen*

    :param autopilot.process.Window window: The window to drag
    :param integer screen: The screen to drag the *window* to
    :raises: **TypeError** if *window* is not a autopilot.process.Window

    """
    if not isinstance(window, Window):
        raise TypeError("Window must be a autopilot.process.Window")

    if window.monitor == screen:
        logger.debug("Window %r is already on screen %d." % (window.x_id, screen))
        return

    assert(not window.is_maximized)
    (win_x, win_y, win_w, win_h) = window.geometry
    (mx, my, mw, mh) = Display.create().get_screen_geometry(screen)

    logger.debug("Dragging window %r to screen %d." % (window.x_id, screen))

    mouse = Mouse.create()
    keyboard = Keyboard.create()
    mouse.move(win_x + win_w/2, win_y + win_h/2)
    keyboard.press("Alt")
    mouse.press()
    keyboard.release("Alt")

    # We do the movements in two steps, to reduce the risk of being
    # blocked by the pointer barrier
    target_x = mx + mw/2
    target_y = my + mh/2
    mouse.move(win_x, target_y, rate=20, time_between_events=0.005)
    mouse.move(target_x, target_y, rate=20, time_between_events=0.005)
    mouse.release()
Exemplo n.º 5
0
    def test_check_for_offline_message(self):
        display = Display.create()
        screenWidth = display.get_screen_width()
        screenHeight = display.get_screen_height()

        #Pull menu from top
        self.main_view.pointing_device.drag(screenWidth - 202, 0,
                                            screenWidth - 202, screenHeight)
        #Tap Flight Mode switch
        self.main_view.pointing_device.move(screenWidth - 130, 150)
        self.main_view.pointing_device.click()
        #Close menu
        self.main_view.pointing_device.drag(0, screenHeight, 0, 0)

        account_page = self.main_view.account_page

        # if account_page.get_default_header().title in ('Telegram', 'Connecting...'):
        # 	print("WARNING - Please turn ON Airplane Mode")

        self.assertThat(account_page.get_default_header().title,
                        Eventually(Equals("Waiting for network...")))

        #Pull menu from top
        self.main_view.pointing_device.drag(screenWidth - 180, 0,
                                            screenWidth - 180, screenHeight)
        #Tap Flight Mode switch
        self.main_view.pointing_device.move(screenWidth - 130, 150)
        self.main_view.pointing_device.click()
        #Close menu
        self.main_view.pointing_device.drag(0, screenHeight, 0, 0)

        # Check header no longer says offline message
        self.assertThat(account_page.get_default_header().title,
                        Eventually(Equals("Telegram")))
Exemplo n.º 6
0
def drag_window_to_screen(window, screen):
    """Drags *window* to *screen*

    :param autopilot.process.Window window: The window to drag
    :param integer screen: The screen to drag the *window* to
    :raises: **TypeError** if *window* is not a autopilot.process.Window

    """
    if not isinstance(window, Window):
        raise TypeError("Window must be a autopilot.process.Window")

    if window.monitor == screen:
        logger.debug("Window %r is already on screen %d." % (window.x_id, screen))
        return

    assert(not window.is_maximized)
    (win_x, win_y, win_w, win_h) = window.geometry
    (mx, my, mw, mh) = Display.create().get_screen_geometry(screen)

    logger.debug("Dragging window %r to screen %d." % (window.x_id, screen))

    mouse = Mouse.create()
    keyboard = Keyboard.create()
    mouse.move(win_x + win_w/2, win_y + win_h/2)
    keyboard.press("Alt")
    mouse.press()
    keyboard.release("Alt")

    # We do the movements in two steps, to reduce the risk of being
    # blocked by the pointer barrier
    target_x = mx + mw/2
    target_y = my + mh/2
    mouse.move(win_x, target_y, rate=20, time_between_events=0.005)
    mouse.move(target_x, target_y, rate=20, time_between_events=0.005)
    mouse.release()
Exemplo n.º 7
0
 def _geo_larger_than_display(self, width, height):
     should_scale = getattr(self, 'scale_geo', True)
     if should_scale:
         screen = Display.create()
         screen_width = screen.get_screen_width()
         screen_height = screen.get_screen_height()
         return (width > screen_width) or (height > screen_height)
     else:
         return False
Exemplo n.º 8
0
 def _geo_larger_than_display(self, width, height):
     should_scale = getattr(self, 'scale_geo', True)
     if should_scale:
         screen = Display.create()
         screen_width = screen.get_screen_width()
         screen_height = screen.get_screen_height()
         return (width > screen_width) or (height > screen_height)
     else:
         return False
Exemplo n.º 9
0
    def __init__(self, *args, **kwargs):
        super(Launcher, self).__init__(*args, **kwargs)

        self.show_timeout = 1
        self.hide_timeout = 1
        self.in_keynav_mode = False
        self.in_switcher_mode = False

        self._mouse = Mouse.create()
        self._display = Display.create()
Exemplo n.º 10
0
    def __init__(self, *args, **kwargs):
        super(Launcher, self).__init__(*args, **kwargs)

        self.show_timeout = 1
        self.hide_timeout = 1
        self.in_keynav_mode = False
        self.in_switcher_mode = False

        self._mouse = Mouse.create()
        self._display = Display.create()
Exemplo n.º 11
0
def _make_monitor_scenarios():
    num_monitors = Display.create().get_num_screens()
    scenarios = []

    if num_monitors == 1:
        scenarios = [('Single Monitor', {'hud_monitor': 0})]
    else:
        for i in range(num_monitors):
            scenarios += [('Monitor %d' % (i), {'hud_monitor': i})]

    return scenarios
Exemplo n.º 12
0
    def test_move_to_nonint_point(self):
        """Test mouse does not get stuck when we move to a non-integer point.

        LP bug #1195499.

        """
        device = Mouse.create()
        screen_geometry = Display.create().get_screen_geometry(0)
        target_x = screen_geometry[0] + 10
        target_y = screen_geometry[1] + 10.6
        device.move(target_x, target_y)
        self.assertEqual(device.position(), (target_x, int(target_y)))
Exemplo n.º 13
0
def _make_scenarios():
    """Make scenarios for launcher test cases based on the number of configured
    monitors.
    """
    num_monitors = Display.create().get_num_screens()

    # it doesn't make sense to set only_primary when we're running in a single-monitor setup.
    if num_monitors == 1:
        return [('Single Monitor', {'launcher_monitor': 0, 'only_primary': False})]

    monitor_scenarios = [('Monitor %d' % (i), {'launcher_monitor': i}) for i in range(num_monitors)]
    launcher_mode_scenarios = [('launcher_on_primary', {'only_primary': True}),
                                ('launcher on all', {'only_primary': False})]
    return multiply_scenarios(monitor_scenarios, launcher_mode_scenarios)
Exemplo n.º 14
0
    def refresh_workspace_information(self):
        """Re-read information about available workspaces from compiz and X11."""
        self._viewport_width = 0
        self._viewport_height = 0

        self._workspaces_wide = get_compiz_option("core", "hsize")
        self._workspaces_high = get_compiz_option("core", "vsize")

        display = Display.create()
        num_screens = display.get_num_screens()

        for screen in range(num_screens):
            _, _, width, height = display.get_screen_geometry(screen)
            self._viewport_width += width
            self._viewport_height += height
Exemplo n.º 15
0
def _get_system_resolution():
    from autopilot.display import Display
    display = Display.create()
    # TODO: This calculation needs to become part of the display module:
    l = r = t = b = 0
    for screen in range(display.get_num_screens()):
        geometry = display.get_screen_geometry(screen)
        if geometry[0] < l:
            l = geometry[0]
        if geometry[1] < t:
            t = geometry[1]
        if geometry[0] + geometry[2] > r:
            r = geometry[0] + geometry[2]
        if geometry[1] + geometry[3] > b:
            b = geometry[1] + geometry[3]
    res_x = r - l
    res_y = b - t
    return res_x, res_y
Exemplo n.º 16
0
def _get_screenshot_mir():
    """Capture screenshot from Mir display.

    :raises FileNotFoundError: If the mirscreencast utility is not found.
    :raises CalledProcessError: If the mirscreencast utility errors while
      taking a screenshot.
    :raises ValueError: If the PNG conversion step fails.

    """
    from autopilot.display import Display
    display_resolution = Display.create().get_screen_geometry(0)[2:]
    screenshot_filepath = _take_mirscreencast_screenshot()
    try:
        png_data_file = _get_png_from_rgba_file(
            screenshot_filepath,
            display_resolution
        )
    finally:
        os.remove(screenshot_filepath)

    return png_data_file
Exemplo n.º 17
0
def _make_scenarios():
    """Make scenarios for launcher test cases based on the number of configured
    monitors.
    """
    num_monitors = Display.create().get_num_screens()

    # it doesn't make sense to set only_primary when we're running in a single-monitor setup.
    if num_monitors == 1:
        return [('Single Monitor', {
            'launcher_monitor': 0,
            'only_primary': False
        })]

    monitor_scenarios = [('Monitor %d' % (i), {
        'launcher_monitor': i
    }) for i in range(num_monitors)]
    launcher_mode_scenarios = [('launcher_on_primary', {
        'only_primary': True
    }), ('launcher on all', {
        'only_primary': False
    })]
    return multiply_scenarios(monitor_scenarios, launcher_mode_scenarios)
Exemplo n.º 18
0
     monitors.
    :raises: **ValueError** if an invalid monitor is specified.
    :raises: **BlacklistedDriverError** if your video driver does not
     support this.

    """
    try:
        glxinfo_out = subprocess.check_output("glxinfo")
    except OSError, e:
        raise OSError("Failed to run glxinfo: %s. (do you have mesa-utils installed?)" % e)

    for dri in _blacklisted_drivers:
        if dri in glxinfo_out:
            raise Display.BlacklistedDriverError('Impossible change the primary monitor for the given driver')

    num_monitors = Display.create().get_num_screens()
    if monitor < 0 or monitor >= num_monitors:
        raise ValueError('Monitor %d is not in valid range of 0 <= monitor < %d.' % (num_monitors))

    default_screen = Gdk.Screen.get_default()
    monitor_name = default_screen.get_monitor_plug_name(monitor)

    if not monitor_name:
        raise ValueError('Could not get monitor name from monitor number %d.' % (monitor))

    ret = os.spawnlp(os.P_WAIT, "xrandr", "xrandr", "--output", monitor_name, "--primary")

    if ret != 0:
        raise RuntimeError('Xrandr can\'t set the primary monitor. error code: %d' % (ret))

def reset_display():
Exemplo n.º 19
0
     monitors.
    :raises: **ValueError** if an invalid monitor is specified.
    :raises: **BlacklistedDriverError** if your video driver does not
     support this.

    """
    try:
        glxinfo_out = subprocess.check_output("glxinfo")
    except OSError, e:
        raise OSError(
            "Failed to run glxinfo: %s. (do you have mesa-utils installed?)" %
            e)

    for dri in _blacklisted_drivers:
        if dri in glxinfo_out:
            raise Display.BlacklistedDriverError(
                'Impossible change the primary monitor for the given driver')

    num_monitors = Display.create().get_num_screens()
    if monitor < 0 or monitor >= num_monitors:
        raise ValueError(
            'Monitor %d is not in valid range of 0 <= monitor < %d.' %
            (num_monitors))

    default_screen = Gdk.Screen.get_default()
    monitor_name = default_screen.get_monitor_plug_name(monitor)

    if not monitor_name:
        raise ValueError('Could not get monitor name from monitor number %d.' %
                         (monitor))

    ret = os.spawnlp(os.P_WAIT, "xrandr", "xrandr", "--output", monitor_name,
Exemplo n.º 20
0
    def test_SecretMessage(self):

        # Note the number of dialogs in the dialog list at the start of the test
        account_page = self.main_view.account_page
        dialog_list_page = account_page.get_dialog_list_page()
        count = dialog_list_page.dialog_count

        # Open the account panel by tapping the navigation menu icon
        account_panel = account_page.open_account_panel()
        self.assertThat(account_panel.opened, Eventually(Equals(True)))

        # Select the secret chat option
        account_panel.select_secret_chat()

        # Select an online contact
        apl = self.main_view.apl
        contacts_page = apl.contacts_page
        recipient = contacts_page.select_first_online_contact()
        self.main_view.pointing_device.click_object(recipient)

        # Create a new secret chat
        self.assertThat(count, Eventually(Equals(count + 1)))
        dialog_list_page.select_dialog_at_index(0)
        dialog_page = apl.dialog_page

        # Check that only system message is being displayed
        message_list = dialog_page.account_message_list
        initial_count = message_list.messages.count
        self.assertThat(initial_count, Equals(1))

        status_received = message_received_image
        status_read = message_read_image

        if "textMessage" in self.input or self.input == "photoMessageReceive":
            # Send the first message

            ts = time.time()
            timestamp = datetime.datetime.fromtimestamp(ts).strftime(
                '%y:%m:%d,%H:%M:%S')
            message_to_send = "Autopilot:" + timestamp
            if self.input == "textMessageSend":
                message_to_send = message_to_send + " DO NOT REPLY"
            elif self.input == "photoMessageReceive":
                message_to_send = message_to_send + " SEND IMAGE"

            dialog_page.enter_message(message_to_send)
            dialog_page.message_area.select_attach_or_send()

        elif self.input == "photoMessageSend":

            if platform.model() == "Desktop":
                return

            dialog_page.message_area.select_attach_or_send()
            dialog_page.message_area.select_attach_photo_option()
            self.main_view.select_content_hub_app("Camera")

            # Allow time to open the app
            sleep(5)

            display = Display.create()
            screen_width = display.get_screen_width()
            screen_height = display.get_screen_height()
            button_x_pos = screen_width / 2.0
            button_y_pos = screen_height - 100.0

            # Click on the take photo button
            self.main_view.pointing_device.move(button_x_pos, button_y_pos)
            self.main_view.pointing_device.click()

            # Allow time to take the photo
            sleep(5)

            # Tap the tick to return to Telegram
            self.main_view.pointing_device.move(button_x_pos, button_y_pos)
            self.main_view.pointing_device.click()

            status_received = media_received_image
            status_read = media_read_image

            # Allow time for photo to be sent
            sleep(30)

        # Check that sent message appears in the dialog content
        self.assertThat(message_list.messages.count,
                        Eventually(Equals(initial_count + 1)))

        # Check that the message received image is displayed for the sent message
        index_of_sent_message = 0
        message = message_list.get_message_at_index(index_of_sent_message)
        status_image = message.message_status_image

        if self.input != "photoMessageSend":
            self.assertThat(status_image.source,
                            Eventually(Equals(status_received)))

        if "Receive" in self.input:

            index_of_sent_message = index_of_sent_message + 1

            # Check for reply
            self.assertThat(message_list.messages.count,
                            Eventually(Equals(initial_count + 2)))

        # Check that the message read image is displayed for the sent message
        message = message_list.get_message_at_index(index_of_sent_message)
        status_image = message.message_status_image

        if self.input == "photoMessageSend" and platform.model() != "Desktop":
            status_image = message.account_message_media.media_message_status_image

        self.assertThat(status_image.source, Eventually(Equals(status_read)))