~jocave/checkbox/hybrid-amd-gpu-mods

« back to all changes in this revision

Viewing changes to checkbox-old/scripts/rotation_test

  • Committer: Tarmac
  • Author(s): Brendan Donegan
  • Date: 2013-06-03 11:12:58 UTC
  • mfrom: (2154.2.1 bug1185759)
  • Revision ID: tarmac-20130603111258-1b3m5ydvkf1accts
"[r=zkrynicki][bug=1185759][author=brendan-donegan] automatic merge by tarmac"

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python3
 
2
# -*- coding: utf-8 -*-
 
3
#
 
4
#  rotation_test
 
5
#
 
6
# This file is part of Checkbox.
 
7
#
 
8
# Copyright 2012 Canonical Ltd.
 
9
#
 
10
# Authors: Alberto Milone <alberto.milone@canonical.com>
 
11
#
 
12
# Checkbox is free software: you can redistribute it and/or modify
 
13
# it under the terms of the GNU General Public License as published by
 
14
# the Free Software Foundation, either version 3 of the License, or
 
15
# (at your option) any later version.
 
16
#
 
17
# Checkbox is distributed in the hope that it will be useful,
 
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
20
# GNU General Public License for more details.
 
21
#
 
22
# You should have received a copy of the GNU General Public License
 
23
# along with Checkbox.  If not, see <http://www.gnu.org/licenses/>.
 
24
 
 
25
import time
 
26
import sys
 
27
 
 
28
from checkbox.contrib import xrandr
 
29
 
 
30
 
 
31
def rotate_screen(rotation):
 
32
    # Refresh the screen. Required by NVIDIA
 
33
    screen = xrandr.get_current_screen()
 
34
    screen.set_rotation(rotation)
 
35
    return screen.apply_config()
 
36
 
 
37
def main():
 
38
    screen = xrandr.get_current_screen()
 
39
    rotations = {'normal': xrandr.RR_ROTATE_0,
 
40
                 'right': xrandr.RR_ROTATE_90,
 
41
                 'inverted': xrandr.RR_ROTATE_180,
 
42
                 'left': xrandr.RR_ROTATE_270}
 
43
    rots_statuses = {}
 
44
 
 
45
    for rot in rotations:
 
46
        try:
 
47
            status = rotate_screen(rotations[rot])
 
48
        except(xrandr.RRError, xrandr.UnsupportedRRError) as error:
 
49
            status = 1
 
50
        else:
 
51
            error = 'N/A'
 
52
        # Collect the status and the error message
 
53
        rots_statuses[rot] = (status, error)
 
54
        time.sleep(4)
 
55
 
 
56
    # Try to set the screen back to normal
 
57
    try:
 
58
        rotate_screen(xrandr.RR_ROTATE_0)
 
59
    except(xrandr.RRError, xrandr.UnsupportedRRError) as error:
 
60
        print(error)
 
61
 
 
62
    result = 0
 
63
    for elem in rots_statuses:
 
64
        status = rots_statuses.get(elem)[0]
 
65
        error = rots_statuses.get(elem)[1]
 
66
        if status != 0:
 
67
            print('Error: rotation "%s" failed with status %d: %s.' %
 
68
                  (elem, status, error), file=sys.stderr)
 
69
            result = 1
 
70
    return result
 
71
 
 
72
if __name__ == '__main__':
 
73
    exit(main())