Debian Codegraph @

plyer/facades/camera.py

raw symbols SCIP
1 '''
2 Camera
3 ======
4
5 The :class:`Camera` is to capture pictures and make videos.
6
7 .. note::
8 - On Android the `CAMERA` , `WRITE_EXTERNAL_STORAGE`,
9 `READ_EXTERNAL_STORAGE` permissions are needed.
10
11 Simple Examples
12 ---------------
13
14 Setup callback function.
15
16 >>> from os.path import exists, join
17 >>> from plyer import camera
18 >>> def camera_callback(filepath):
19 >>> if(exists(filepath)):
20 >>> print "saved"
21 >>> else:
22 >>> print "unable to save."
23 >>> filepath = 'path/to/your/file'
24 >>> # e.g: filepath = join(App.get_running_app().user_data_dir, file_name)
25
26 To take picture::
27
28 >>> file_name = "test.jpg"
29 >>> camera.take_picture(filename=file_name,
30 >>> on_complete=camera_callback)
31
32 Ta take a video::
33
34 >>> file_name = "test.mp4"
35 >>> camera.take_video(filename=file_name,
36 >>> on_complete=camera_callback)
37
38 Supported Platforms
39 -------------------
40 Android, iOS
41
42 '''
43
44
45 class Camera:
46 '''
47 Camera facade.
48 '''
49
50 def take_picture(self, filename, on_complete):
51 '''Ask the OS to capture a picture, and store it at filename.
52
53 When the capture is done, on_complete will be called with the filename
54 as an argument. If the callback returns True, the filename will be
55 unlinked.
56
57 :param filename: Name of the image file
58 :param on_complete: Callback that will be called when the operation is
59 done
60
61 :type filename: str
62 :type on_complete: callable
63 '''
64 self._take_picture(filename=filename, on_complete=on_complete)
65
66 def take_video(self, filename, on_complete):
67 '''Ask the OS to capture a video, and store it at filename.
68
69 When the capture is done, on_complete will be called with the filename
70 as an argument. If the callback returns True, the filename will be
71 unlinked.
72
73 :param filename: Name of the video file
74 :param on_complete: Callback that will be called when the operation is
75 done
76
77 :type filename: str
78 :type on_complete: callable
79 '''
80 self._take_video(filename=filename, on_complete=on_complete)
81
82 # private
83
84 def _take_picture(self, **kwargs):
85 raise NotImplementedError()
86
87 def _take_video(self, **kwargs):
88 raise NotImplementedError()