| 1 |
''' |
| 2 |
Orientation |
| 3 |
========== |
| 4 |
|
| 5 |
The :class:`Orientation` provides access to public methods to set orientation |
| 6 |
of your device. |
| 7 |
|
| 8 |
.. note:: |
| 9 |
These settings are generally guidelines, the operating |
| 10 |
system may choose to ignore them, or they may be overridden by |
| 11 |
other system components. |
| 12 |
|
| 13 |
.. versionadded:: 1.2.4 |
| 14 |
|
| 15 |
Simple Examples |
| 16 |
--------------- |
| 17 |
|
| 18 |
To set landscape:: |
| 19 |
|
| 20 |
>>> from plyer import orientation |
| 21 |
>>> orientation.set_landscape() |
| 22 |
|
| 23 |
To set portrait:: |
| 24 |
|
| 25 |
>>> orientation.set_portrait() |
| 26 |
|
| 27 |
To set sensor:: |
| 28 |
|
| 29 |
>>> orientation.set_sensor() |
| 30 |
|
| 31 |
Supported Platforms |
| 32 |
------------------- |
| 33 |
Android, Linux |
| 34 |
|
| 35 |
''' |
| 36 |
|
| 37 |
|
| 38 |
class Orientation: |
| 39 |
''' |
| 40 |
Orientation facade. |
| 41 |
''' |
| 42 |
|
| 43 |
def set_landscape(self, reverse=False): |
| 44 |
''' |
| 45 |
Rotate the app to a landscape orientation. |
| 46 |
|
| 47 |
:param reverse: If True, uses the opposite of the natural |
| 48 |
orientation. |
| 49 |
''' |
| 50 |
self._set_landscape(reverse=reverse) |
| 51 |
|
| 52 |
def set_portrait(self, reverse=False): |
| 53 |
''' |
| 54 |
Rotate the app to a portrait orientation. |
| 55 |
|
| 56 |
:param reverse: If True, uses the opposite of the natural |
| 57 |
orientation. |
| 58 |
''' |
| 59 |
self._set_portrait(reverse=reverse) |
| 60 |
|
| 61 |
def set_sensor(self, mode='any'): |
| 62 |
''' |
| 63 |
Rotate freely following sensor information from the device. |
| 64 |
|
| 65 |
:param mode: The rotation mode, should be one of 'any' (rotate |
| 66 |
to any orientation), 'landscape' (choose nearest |
| 67 |
landscape mode) or 'portrait' (choose nearest |
| 68 |
portrait mode). Defaults to 'any'. |
| 69 |
''' |
| 70 |
self._set_sensor(mode=mode) |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
def _set_landscape(self, **kwargs): |
| 75 |
raise NotImplementedError() |
| 76 |
|
| 77 |
def _set_portrait(self, **kwargs): |
| 78 |
raise NotImplementedError() |
| 79 |
|
| 80 |
def _set_sensor(self, **kwargs): |
| 81 |
raise NotImplementedError() |