File: camera.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 (88 lines) | stat: -rw-r--r-- 2,376 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
'''
Camera
======

The :class:`Camera` is to capture pictures and make videos.

.. note::
        - On Android the `CAMERA` , `WRITE_EXTERNAL_STORAGE`,
          `READ_EXTERNAL_STORAGE` permissions are needed.

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

Setup callback function.

    >>> from os.path import exists, join
    >>> from plyer import camera
    >>> def camera_callback(filepath):
    >>>     if(exists(filepath)):
    >>>         print "saved"
    >>>     else:
    >>>         print "unable to save."
    >>> filepath = 'path/to/your/file'
    >>> # e.g: filepath = join(App.get_running_app().user_data_dir, file_name)

To take picture::

    >>> file_name = "test.jpg"
    >>> camera.take_picture(filename=file_name,
    >>>                     on_complete=camera_callback)

Ta take a video::

    >>> file_name = "test.mp4"
    >>> camera.take_video(filename=file_name,
    >>>                   on_complete=camera_callback)

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

'''


class Camera:
    '''
    Camera facade.
    '''

    def take_picture(self, filename, on_complete):
        '''Ask the OS to capture a picture, and store it at filename.

        When the capture is done, on_complete will be called with the filename
        as an argument. If the callback returns True, the filename will be
        unlinked.

        :param filename: Name of the image file
        :param on_complete: Callback that will be called when the operation is
            done

        :type filename: str
        :type on_complete: callable
        '''
        self._take_picture(filename=filename, on_complete=on_complete)

    def take_video(self, filename, on_complete):
        '''Ask the OS to capture a video, and store it at filename.

        When the capture is done, on_complete will be called with the filename
        as an argument. If the callback returns True, the filename will be
        unlinked.

        :param filename: Name of the video file
        :param on_complete: Callback that will be called when the operation is
            done

        :type filename: str
        :type on_complete: callable
        '''
        self._take_video(filename=filename, on_complete=on_complete)

    # private

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

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