/usr/lib/python2.7/dist-packages/autopilot/display/__init__.py is in python-autopilot 1.4.1+17.04.20170305-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
#
# Autopilot Functional Test Tool
# Copyright (C) 2012-2013 Canonical
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
"""The display module contaions support for getting screen information."""
from collections import OrderedDict
from autopilot.utilities import _pick_backend
from autopilot.input import Mouse
def is_rect_on_screen(screen_number, rect):
"""Return True if *rect* is **entirely** on the specified screen, with no
overlap."""
(x, y, w, h) = rect
(mx, my, mw, mh) = Display.create().get_screen_geometry(screen_number)
return (x >= mx and x + w <= mx + mw and y >= my and y + h <= my + mh)
def is_point_on_screen(screen_number, point):
"""Return True if *point* is on the specified screen.
*point* must be an iterable type with two elements: (x, y)
"""
x, y = point
(mx, my, mw, mh) = Display.create().get_screen_geometry(screen_number)
return (x >= mx and x < mx + mw and y >= my and y < my + mh)
def is_point_on_any_screen(point):
"""Return true if *point* is on any currently configured screen."""
return any([is_point_on_screen(m, point) for m in
range(Display.create().get_num_screens())])
def move_mouse_to_screen(screen_number):
"""Move the mouse to the center of the specified screen."""
geo = Display.create().get_screen_geometry(screen_number)
x = geo[0] + (geo[2] / 2)
y = geo[1] + (geo[3] / 2)
#dont animate this or it might not get there due to barriers
Mouse.create().move(x, y, False)
# veebers TODO: Write this so it's usable.
# def drag_window_to_screen(self, window, screen):
# """Drags *window* to *screen*
# :param BamfWindow window: The window to drag
# :param integer screen: The screen to drag the *window* to
# :raises: **TypeError** if *window* is not a BamfWindow
# """
# if not isinstance(window, BamfWindow):
# raise TypeError("Window must be a BamfWindow")
# 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) = self.get_screen_geometry(screen)
# logger.debug("Dragging window %r to screen %d." % (window.x_id, screen))
# mouse = Mouse()
# keyboard = Keyboard()
# 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()
class Display(object):
"""The base class/inteface for the display devices."""
@staticmethod
def create(preferred_backend=''):
"""Get an instance of the Display class.
For more infomration on picking specific backends, see
:ref:`tut-picking-backends`
:param preferred_backend: A string containing a hint as to which
backend you would like.
possible backends are:
* ``X11`` - Get display information from X11.
* ``UPA`` - Get display information from the ubuntu platform API.
:raises: RuntimeError if autopilot cannot instantate any of the
possible backends.
:raises: RuntimeError if the preferred_backend is specified and is not
one of the possible backends for this device class.
:raises: :class:`~autopilot.BackendException` if the preferred_backend
is set, but that backend could not be instantiated.
:returns: Instance of Display with appropriate backend.
"""
def get_x11_display():
from autopilot.display._X11 import Display
return Display()
def get_upa_display():
from autopilot.display._upa import Display
return Display()
backends = OrderedDict()
backends['X11'] = get_x11_display
backends['UPA'] = get_upa_display
return _pick_backend(backends, preferred_backend)
class BlacklistedDriverError(RuntimeError):
"""Cannot set primary monitor when running drivers listed in the
driver blacklist."""
def get_num_screens(self):
"""Get the number of screens attached to the PC."""
raise NotImplementedError("You cannot use this class directly.")
def get_primary_screen(self):
raise NotImplementedError("You cannot use this class directly.")
def get_screen_width(self, screen_number=0):
raise NotImplementedError("You cannot use this class directly.")
def get_screen_height(self, screen_number=0):
raise NotImplementedError("You cannot use this class directly.")
def get_screen_geometry(self, monitor_number):
"""Get the geometry for a particular monitor.
:return: Tuple containing (x, y, width, height).
"""
raise NotImplementedError("You cannot use this class directly.")
|