File: vibrator.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 (97 lines) | stat: -rw-r--r-- 2,197 bytes parent folder | download | duplicates (3)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
'''
Vibrator
=======

The :class:`Vibrator` provides access to public methods to use vibrator of your
device.

.. note::
    On Android your app needs the VIBRATE permission to
    access the vibrator.

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

To vibrate your device::

    >>> from plyer import vibrator
    >>> time=2
    >>> vibrator.vibrate(time=time)

To set a pattern::

    >>> vibrator.pattern(pattern=pattern, repeat=repeat)

To know whether vibrator exists or not::

    >>> vibrator.exists()

To cancel vibration::

    >>> vibrator.cancel()

Supported Platforms
-------------------
Android, iOS


'''


class Vibrator:
    '''
    Vibration facade.
    '''

    def vibrate(self, time=1):
        '''
        Ask the vibrator to vibrate for the given period.

        :param time: Time to vibrate for, in seconds. Default is 1.
        '''
        self._vibrate(time=time)

    def pattern(self, pattern=(0, 1), repeat=-1):
        '''
        Ask the vibrator to vibrate with the given pattern, with an
        optional repeat.

        :param pattern: Pattern to vibrate with. Should be a list of
            times in seconds. The first number is how long to wait
            before vibrating, and subsequent numbers are times to
            vibrate and not vibrate alternately.
            Defaults to ``[0, 1]``.

        :param repeat: Index at which to repeat the pattern. When the
            vibration pattern reaches this index, it will start again
            from the beginning. Defaults to ``-1``, which means no
            repeat.
        '''
        self._pattern(pattern=pattern, repeat=repeat)

    def exists(self):
        '''
        Check if the device has a vibrator. Returns True or
        False.
        '''
        return self._exists()

    def cancel(self):
        '''
        Cancels any current vibration, and stops the vibrator.
        '''
        self._cancel()

    # private

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

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

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

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