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
|
"""
Basic camera example
Default picture is saved as
/sdcard/org.test.cameraexample/enter_file_name_here.jpg
"""
from os import getcwd
from os.path import exists
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.popup import Popup
import kivy
from plyer import camera
kivy.require('1.8.0')
class CameraDemo(FloatLayout):
def __init__(self):
super().__init__()
self.cwd = getcwd() + "/"
self.ids.path_label.text = self.cwd
def do_capture(self):
filepath = self.cwd + self.ids.filename_text.text
if exists(filepath):
popup = MsgPopup("Picture with this name already exists!")
popup.open()
return False
try:
camera.take_picture(filename=filepath,
on_complete=self.camera_callback)
except NotImplementedError:
popup = MsgPopup(
"This feature has not yet been implemented for this platform.")
popup.open()
def camera_callback(self, filepath):
if exists(filepath):
popup = MsgPopup("Picture saved!")
popup.open()
else:
popup = MsgPopup("Could not save your picture!")
popup.open()
class CameraDemoApp(App):
def __init__(self):
super().__init__()
self.demo = None
def build(self):
self.demo = CameraDemo()
return self.demo
def on_pause(self):
return True
def on_resume(self):
pass
class MsgPopup(Popup):
def __init__(self, msg):
super().__init__()
self.ids.message_label.text = msg
if __name__ == '__main__':
CameraDemoApp().run()
|