Debian Codegraph @

plyer/platforms/ios/flash.py

raw symbols SCIP
1 # coding=utf-8
2 """
3 Flash
4 -----
5 """
6 from plyer.facades import Flash
7 from pyobjus import autoclass
8
9 NSString = autoclass("NSString")
10 AVCaptureDevice = autoclass("AVCaptureDevice")
11 AVMediaTypeVideo = NSString.alloc().initWithUTF8String_("vide")
12 AVCaptureTorchModeOff = 0
13 AVCaptureTorchModeOn = 1
14
15
16 class IosFlash(Flash):
17 _camera = None
18
19 def _on(self):
20 if self._camera is None:
21 self._camera_open()
22 if not self._camera:
23 return
24 self._camera.lockForConfiguration_(None)
25 try:
26 self._camera.setTorchMode(AVCaptureTorchModeOn)
27 finally:
28 self._camera.unlockForConfiguration()
29
30 def _off(self):
31 if not self._camera:
32 return
33 self._camera.lockForConfiguration_(None)
34 try:
35 self._camera.setTorchMode(AVCaptureTorchModeOff)
36 finally:
37 self._camera.unlockForConfiguration()
38
39 def _release(self):
40 pass
41
42 def _camera_open(self):
43 device = AVCaptureDevice.defaultDeviceWithMediaType_(AVMediaTypeVideo)
44 if not device:
45 return
46 self._camera = device
47
48
49 def instance():
50 return IosFlash()