File: orientation.py

package info (click to toggle)
python-plyer 2.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,808 kB
  • sloc: python: 13,395; sh: 217; makefile: 177
file content (81 lines) | stat: -rw-r--r-- 1,878 bytes parent folder | download | duplicates (2)
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
'''
Orientation
==========

The :class:`Orientation` provides access to public methods to set orientation
of your device.

.. note::
    These settings are generally guidelines, the operating
    system may choose to ignore them, or they may be overridden by
    other system components.

.. versionadded:: 1.2.4

Simple Examples
---------------

To set landscape::

    >>> from plyer import orientation
    >>> orientation.set_landscape()

To set portrait::

    >>> orientation.set_portrait()

To set sensor::

    >>> orientation.set_sensor()

Supported Platforms
-------------------
Android, Linux

'''


class Orientation:
    '''
    Orientation facade.
    '''

    def set_landscape(self, reverse=False):
        '''
        Rotate the app to a landscape orientation.

        :param reverse: If True, uses the opposite of the natural
                        orientation.
        '''
        self._set_landscape(reverse=reverse)

    def set_portrait(self, reverse=False):
        '''
        Rotate the app to a portrait orientation.

        :param reverse: If True, uses the opposite of the natural
                        orientation.
        '''
        self._set_portrait(reverse=reverse)

    def set_sensor(self, mode='any'):
        '''
        Rotate freely following sensor information from the device.

        :param mode: The rotation mode, should be one of 'any' (rotate
                     to any orientation), 'landscape' (choose nearest
                     landscape mode) or 'portrait' (choose nearest
                     portrait mode). Defaults to 'any'.
        '''
        self._set_sensor(mode=mode)

    # private

    def _set_landscape(self, **kwargs):
        raise NotImplementedError()

    def _set_portrait(self, **kwargs):
        raise NotImplementedError()

    def _set_sensor(self, **kwargs):
        raise NotImplementedError()