picture saving added to camera example (#4842)

* camera click_pic added

* date formate corrected

* function name changed

* func name changed

* pep8 fixes

* pep8 fix
This commit is contained in:
Yash Jain 2016-12-31 06:05:15 +05:30 committed by dessant
parent 5b5129a921
commit 63eefb7ea5
1 changed files with 24 additions and 5 deletions

View File

@ -16,9 +16,10 @@ throw an exception during the kv language processing.
from kivy.app import App from kivy.app import App
from kivy.lang import Builder from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
kv = ''' import time
BoxLayout: Builder.load_string('''
<CameraClick>:
orientation: 'vertical' orientation: 'vertical'
Camera: Camera:
id: camera id: camera
@ -29,12 +30,30 @@ BoxLayout:
on_press: camera.play = not camera.play on_press: camera.play = not camera.play
size_hint_y: None size_hint_y: None
height: '48dp' 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): class TestCamera(App):
def build(self): def build(self):
return Builder.load_string(kv) return CameraClick()
TestCamera().run() TestCamera().run()