2
# -*- coding: utf-8 -*-
6
# This file is part of Checkbox.
8
# Copyright 2012 Canonical Ltd.
10
# Authors: Alberto Milone <alberto.milone@canonical.com>
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.
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.
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/>.
28
from checkbox.contrib import xrandr
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()
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}
47
status = rotate_screen(rotations[rot])
48
except(xrandr.RRError, xrandr.UnsupportedRRError) as error:
52
# Collect the status and the error message
53
rots_statuses[rot] = (status, error)
56
# Try to set the screen back to normal
58
rotate_screen(xrandr.RR_ROTATE_0)
59
except(xrandr.RRError, xrandr.UnsupportedRRError) as error:
63
for elem in rots_statuses:
64
status = rots_statuses.get(elem)[0]
65
error = rots_statuses.get(elem)[1]
67
print('Error: rotation "%s" failed with status %d: %s.' %
68
(elem, status, error), file=sys.stderr)
72
if __name__ == '__main__':