~thomir-deactivatedaccount/autopilot/trunk-make-click-call-more-pedantic

« back to all changes in this revision

Viewing changes to autopilot/display/_upa.py

  • Committer: Thomi Richards
  • Date: 2014-02-26 19:13:39 UTC
  • mfrom: (406.2.39 autopilot)
  • Revision ID: thomi.richards@canonical.com-20140226191339-689x4coi2bchzhy4
Merged trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import logging
22
22
 
23
23
from autopilot.display import Display as DisplayBase
24
 
from subprocess import check_output
25
 
 
26
 
try:
27
 
    DEVICE = check_output(
28
 
        ["/usr/bin/getprop", "ro.product.device"]).decode().strip()
29
 
except OSError:
30
 
    DEVICE = ''
31
 
 
32
 
RESOLUTIONS = {
33
 
    "generic": (480, 800),
34
 
    "mako": (768, 1280),
35
 
    "maguro": (720, 1280),
36
 
    "manta": (2560, 1600),
37
 
    "grouper": (800, 1280),
38
 
}
39
 
 
40
 
if DEVICE not in RESOLUTIONS:
41
 
    raise NotImplementedError(
42
 
        'Device "{}" is not supported by Autopilot.'.format(DEVICE))
43
 
 
44
 
X, Y = RESOLUTIONS[DEVICE]
 
24
from autopilot.platform import image_codename
 
25
import subprocess
 
26
 
 
27
 
 
28
def query_resolution():
 
29
    try:
 
30
        return _get_fbset_resolution()
 
31
    except Exception:
 
32
        return _get_hardcoded_resolution()
 
33
 
 
34
 
 
35
def _get_fbset_resolution():
 
36
    """Return the resolution, as determined by fbset, or None."""
 
37
    fbset_output = _get_fbset_output()
 
38
    for line in fbset_output.split('\n'):
 
39
        line = line.strip()
 
40
        if line.startswith('Mode'):
 
41
            quoted_resolution = line.split()[1]
 
42
            resolution_string = quoted_resolution.strip('"')
 
43
            return tuple(int(piece) for piece in resolution_string.split('x'))
 
44
    raise RuntimeError("No modes found from fbset output")
 
45
 
 
46
 
 
47
def _get_fbset_output():
 
48
    return subprocess.check_output(["fbset", "-s", "-x"]).decode().strip()
 
49
 
 
50
 
 
51
def _get_hardcoded_resolution():
 
52
    name = image_codename()
 
53
 
 
54
    resolutions = {
 
55
        "generic": (480, 800),
 
56
        "mako": (768, 1280),
 
57
        "maguro": (720, 1280),
 
58
        "manta": (2560, 1600),
 
59
        "grouper": (800, 1280),
 
60
    }
 
61
 
 
62
    if name not in resolutions:
 
63
        raise NotImplementedError(
 
64
            'Device "{}" is not supported by Autopilot.'.format(name))
 
65
 
 
66
    return resolutions[name]
 
67
 
45
68
 
46
69
logger = logging.getLogger(__name__)
47
70
 
49
72
class Display(DisplayBase):
50
73
    """The base class/inteface for the display devices"""
51
74
 
 
75
    def __init__(self):
 
76
        super(Display, self).__init__()
 
77
        self._X, self._Y = query_resolution()
 
78
 
52
79
    def get_num_screens(self):
53
80
        """Get the number of screens attached to the PC."""
54
81
        return 1
58
85
        return 0
59
86
 
60
87
    def get_screen_width(self):
61
 
        return X
 
88
        return self._X
62
89
 
63
90
    def get_screen_height(self):
64
 
        return Y
 
91
        return self._Y
65
92
 
66
93
    def get_screen_geometry(self, screen_number):
67
94
        """Get the geometry for a particular screen.
69
96
        :return: Tuple containing (x, y, width, height).
70
97
 
71
98
        """
72
 
        return (0, 0, X, Y)
 
99
        return (0, 0, self._X, self._Y)