| 1 |
''' |
| 2 |
Vibrator |
| 3 |
======= |
| 4 |
|
| 5 |
The :class:`Vibrator` provides access to public methods to use vibrator of your |
| 6 |
device. |
| 7 |
|
| 8 |
.. note:: |
| 9 |
On Android your app needs the VIBRATE permission to |
| 10 |
access the vibrator. |
| 11 |
|
| 12 |
Simple Examples |
| 13 |
--------------- |
| 14 |
|
| 15 |
To vibrate your device:: |
| 16 |
|
| 17 |
>>> from plyer import vibrator |
| 18 |
>>> time=2 |
| 19 |
>>> vibrator.vibrate(time=time) |
| 20 |
|
| 21 |
To set a pattern:: |
| 22 |
|
| 23 |
>>> vibrator.pattern(pattern=pattern, repeat=repeat) |
| 24 |
|
| 25 |
To know whether vibrator exists or not:: |
| 26 |
|
| 27 |
>>> vibrator.exists() |
| 28 |
|
| 29 |
To cancel vibration:: |
| 30 |
|
| 31 |
>>> vibrator.cancel() |
| 32 |
|
| 33 |
Supported Platforms |
| 34 |
------------------- |
| 35 |
Android, iOS |
| 36 |
|
| 37 |
|
| 38 |
''' |
| 39 |
|
| 40 |
|
| 41 |
class Vibrator: |
| 42 |
''' |
| 43 |
Vibration facade. |
| 44 |
''' |
| 45 |
|
| 46 |
def vibrate(self, time=1): |
| 47 |
''' |
| 48 |
Ask the vibrator to vibrate for the given period. |
| 49 |
|
| 50 |
:param time: Time to vibrate for, in seconds. Default is 1. |
| 51 |
''' |
| 52 |
self._vibrate(time=time) |
| 53 |
|
| 54 |
def pattern(self, pattern=(0, 1), repeat=-1): |
| 55 |
''' |
| 56 |
Ask the vibrator to vibrate with the given pattern, with an |
| 57 |
optional repeat. |
| 58 |
|
| 59 |
:param pattern: Pattern to vibrate with. Should be a list of |
| 60 |
times in seconds. The first number is how long to wait |
| 61 |
before vibrating, and subsequent numbers are times to |
| 62 |
vibrate and not vibrate alternately. |
| 63 |
Defaults to ``[0, 1]``. |
| 64 |
|
| 65 |
:param repeat: Index at which to repeat the pattern. When the |
| 66 |
vibration pattern reaches this index, it will start again |
| 67 |
from the beginning. Defaults to ``-1``, which means no |
| 68 |
repeat. |
| 69 |
''' |
| 70 |
self._pattern(pattern=pattern, repeat=repeat) |
| 71 |
|
| 72 |
def exists(self): |
| 73 |
''' |
| 74 |
Check if the device has a vibrator. Returns True or |
| 75 |
False. |
| 76 |
''' |
| 77 |
return self._exists() |
| 78 |
|
| 79 |
def cancel(self): |
| 80 |
''' |
| 81 |
Cancels any current vibration, and stops the vibrator. |
| 82 |
''' |
| 83 |
self._cancel() |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
def _vibrate(self, **kwargs): |
| 88 |
raise NotImplementedError() |
| 89 |
|
| 90 |
def _pattern(self, **kwargs): |
| 91 |
raise NotImplementedError() |
| 92 |
|
| 93 |
def _exists(self, **kwargs): |
| 94 |
raise NotImplementedError() |
| 95 |
|
| 96 |
def _cancel(self, **kwargs): |
| 97 |
raise NotImplementedError() |