Как запустить код camera.py в файле homescreen.kv в киве - PullRequest
0 голосов
/ 18 февраля 2020

это мой файл camera.py

from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
import time
Builder.load_string('''
<CameraClick>:
   orientation: 'vertical'
   Camera:
       id: camera
       resolution: (640, 480)
       play: False
   ToggleButton:
       text: 'Play'
       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_{}.png".format(timestr))
       print("Captured")


class TestCamera(App):

   def build(self):
       return CameraClick()


TestCamera().run()

как я могу добавить этот файл камеры - python в качестве события к кнопке на главном экране? Может кто-нибудь помочь мне?

это мой файл homescreen.kv

#:import utils kivy.utils

<HomeScreen>:
    FloatLayout:
        canvas:
            Color:
                rgb: utils.get_color_from_hex("#f0eed1")
            Rectangle:
                source: "icons/blur.png"
                size: self.size
                pos: self.pos
        GridLayout:
            rows: 1
            pos_hint: {"top": 1, "left": 1}
            size_hint: 1, .1
            Image:
               source: "icons/search.png"
            Image:
                source: "icons/google.png"
        GridLayout:
            rows: 1
            pos_hint: {"top": .9,"left": 1}
            size_hint: 1, .2
            Image:
               source: "icons/003-sunset.png"
            Image:
                source: "icons/icon.png"
            Image:
                source: "icons/003-sunset.png"            
        Label:
            pos_hint: {"top": .7,"left": 1}
            size_hint: 1, .1
            text: "MediInfo"
            font_size: 30
            id: medi_label
            color: 1,1,1,1
        GridLayout:
            cols: 1
            pos_hint: {"top": .6,"left": 1}
            size_hint: 1, .4
        GridLayout:
            rows: 1
            pos_hint: {"top": .3,"left": 1}
            size_hint: 1, .1
            ImageButton:
                source: "icons/search.png"
                on_release:
                    app.change_screen("search_screen")
            ImageButton:
                source: "icons/camera.png"
                on_release:
                    # I want to run camera.py file on click of this button


        Label:
            pos_hint: {"top": .2,"left": 0}
            size_hint: 1, .07
            text: "upload file"
            id: medi_label
            color: 1,1,1,1

Я хочу запустить камеру после нажатия кнопки камеры на главном экране этого приложения, но не понимаю, как это сделать? Спасибо.

...