mirror of https://github.com/kivy/kivy.git
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:
parent
5b5129a921
commit
63eefb7ea5
|
@ -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('''
|
||||
<CameraClick>:
|
||||
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()
|
||||
|
|
Loading…
Reference in New Issue