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 (52 lines) | stat: -rw-r--r-- 1,349 bytes parent folder | download | duplicates (2)
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
from os import remove
from plyer.facades import Camera

from plyer.utils import reify


class iOSCamera(Camera):

    @reify
    def photos(self):
        # pyPhotoLibrary is a ios recipe/module that
        # interacts with the gallery and the camera on ios.
        from photolibrary import PhotosLibrary
        return PhotosLibrary()

    def _take_picture(self, on_complete, filename=None):
        assert on_complete is not None
        self.on_complete = on_complete
        self.filename = filename
        photos = self.photos

        if not photos.isCameraAvailable():
            # no camera hardware
            return False

        photos.bind(on_image_captured=self.capture_callback)
        self._capture_filename = filename
        photos.capture_image(filename)
        return True

    def capture_callback(self, photolibrary):
        # Image was chosen

        # unbind
        self.photos.unbind(on_image_captured=self.capture_callback)

        if self.on_complete(self.filename):
            self._remove(self.filename)

    def _take_video(self, on_complete, filename=None):
        assert on_complete is not None
        raise NotImplementedError

    def _remove(self, fn):
        try:
            remove(fn)
        except OSError:
            print('Could not remove photo!')


def instance():
    return iOSCamera()