Debian Codegraph @

examples/camera/basic/main.py

raw symbols SCIP
1 """
2 Basic camera example
3 Default picture is saved as
4 /sdcard/org.test.cameraexample/enter_file_name_here.jpg
5 """
6
7 from os import getcwd
8 from os.path import exists
9
10 from kivy.app import App
11 from kivy.uix.floatlayout import FloatLayout
12 from kivy.uix.popup import Popup
13 import kivy
14
15 from plyer import camera
16
17 kivy.require('1.8.0')
18
19
20 class CameraDemo(FloatLayout):
21 def __init__(self):
22 super().__init__()
23 self.cwd = getcwd() + "/"
24 self.ids.path_label.text = self.cwd
25
26 def do_capture(self):
27 filepath = self.cwd + self.ids.filename_text.text
28
29 if exists(filepath):
30 popup = MsgPopup("Picture with this name already exists!")
31 popup.open()
32 return False
33
34 try:
35 camera.take_picture(filename=filepath,
36 on_complete=self.camera_callback)
37 except NotImplementedError:
38 popup = MsgPopup(
39 "This feature has not yet been implemented for this platform.")
40 popup.open()
41
42 def camera_callback(self, filepath):
43 if exists(filepath):
44 popup = MsgPopup("Picture saved!")
45 popup.open()
46 else:
47 popup = MsgPopup("Could not save your picture!")
48 popup.open()
49
50
51 class CameraDemoApp(App):
52 def __init__(self):
53 super().__init__()
54 self.demo = None
55
56 def build(self):
57 self.demo = CameraDemo()
58 return self.demo
59
60 def on_pause(self):
61 return True
62
63 def on_resume(self):
64 pass
65
66
67 class MsgPopup(Popup):
68 def __init__(self, msg):
69 super().__init__()
70 self.ids.message_label.text = msg
71
72
73 if __name__ == '__main__':
74 CameraDemoApp().run()