From 63eefb7ea5c493db3bb60c6ac9b87fd1cb2a5404 Mon Sep 17 00:00:00 2001 From: Yash Jain Date: Sat, 31 Dec 2016 06:05:15 +0530 Subject: [PATCH] picture saving added to camera example (#4842) * camera click_pic added * date formate corrected * function name changed * func name changed * pep8 fixes * pep8 fix --- examples/camera/main.py | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/examples/camera/main.py b/examples/camera/main.py index 505abec3d..f7671e92e 100644 --- a/examples/camera/main.py +++ b/examples/camera/main.py @@ -16,9 +16,10 @@ throw an exception during the kv language processing. from kivy.app import App from kivy.lang import Builder - -kv = ''' -BoxLayout: +from kivy.uix.boxlayout import BoxLayout +import time +Builder.load_string(''' +: orientation: 'vertical' Camera: id: camera @@ -29,12 +30,30 @@ BoxLayout: on_press: camera.play = not camera.play size_hint_y: None height: '48dp' -''' + Button: + text: 'Capture' + size_hint_y: None + height: '48dp' + on_press: root.capture() +''') + + +class CameraClick(BoxLayout): + def capture(self): + ''' + Function to capture the images and give them the names + according to their captured time and date. + ''' + camera = self.ids['camera'] + timestr = time.strftime("%Y%m%d_%H%M%S") + camera.export_to_png("IMG_" + timestr) + print("Captured") class TestCamera(App): + def build(self): - return Builder.load_string(kv) + return CameraClick() TestCamera().run()