-
Notifications
You must be signed in to change notification settings - Fork 1
/
photolibrary.pyx
70 lines (52 loc) · 1.77 KB
/
photolibrary.pyx
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
"""
iOS Photo Library Python wrapper
=================================
"""
__all__ = ("PhotosLibrary", )
from kivy.utils import platform, reify
from kivy.event import EventDispatcher
from kivy.properties import StringProperty
from pyobjus import autoclass, protocol, objc_str
from pyobjus.protocols import protocols
protocols["PyPhotoDelegate"] = {
'imageCaptured': ('v8@0:4', 'v16@0:8'),
'captureCancelled': ('v8@0:4', 'v16@0:8')}
class PhotosLibrary(EventDispatcher):
__events__ = (
"on_image_captured",
"on_capture_cancelled")
def __init__(self):
self.controller = None
super(PhotosLibrary, self).__init__()
@reify
def pyPhotos(self):
return autoclass('PyPhotos').alloc().init()
def on_image_captured(self):
''' Default implenentation of the event.
'''
pass
def on_capture_cancelled(self):
''' Default implementation of the event.
'''
pass
def chooseFromGallery(self, filename, type='imges'):
''' Choose images/videos from gallery.
'''
if not self.pyPhotos.delegate:
self.pyPhotos.delegate = self
if type == 'image':
return self.pyPhotos.chooseImageFromGallery_(filename)
def isCameraAvailable(self):
return self.pyPhotos.isCameraAvailable()
def capture_image(self, filename):
"""Open Camera interface, capture image save it to filename.
"""
if not self.pyPhotos.delegate:
self.pyPhotos.delegate = self
return self.pyPhotos.captureImage_(filename)
@protocol("PyPhotoDelegate")
def imageCaptured(self):
self.dispatch('on_image_captured')
@protocol("PyPhotoDelegate")
def captureCancelled(self):
self.dispatch('on_capture_cancelled')