Kivy stop Video and show photo - python

I'm working on a kivy framework (v1.10). I'm trying to create a simple photo booth software that runs a video loop and stops the video when someone clicks on the screen. After that the camera takes a picture and the program displays it on the monitor together with two buttons yes or no. they will allow you to repeat the photo. I am developing this application for Raspberry PI. My question is how do I stop the video and make something else.
ok, so if I want to add another movie between the first movie and the buttons, do I have to add a new screen or maybe change the video source in this funtion self.bind (on_touch_down = self.on_stop)? I would like to add a video with a countdown time and let him release the camera by taking pictures. then display this photo once with the buttons: repeat and continue.
from kivy.app import App
from kivy.logger import Logger
from kivy.uix.videoplayer import Video
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
class Player(Video):
def __init__(self, **kwargs):
super(Player, self).__init__(**kwargs)
self.source = './START.mp4'
self.state='play'
self.options={'eos': 'loop'}
self.bind(on_touch_down = self.on_stop)
self.get_set_current_video_state = self.get_set_current_video_state()
def check(self):
Logger.info("film position:" + str(self.position))
def on_stop(self, *args):
print ('I have been clicked')
Player.state='stop'
#App.get_running_app().stop()
#self.get_set_current_video_state = ('pause')
return MyWindowApp().run()
class VideoPlayerApp(App):
def build(self):
return Player()
class MyWindowApp(App):
def __init__(self):
super(MyWindowApp, self).__init__()
self.btn = Button(text='Push Me!')
self.lbl = Label(text='Read Me!')

Instead of trying to use two Apps, just use two Screens. Here is a modification of your code using Screens:
from kivy.app import App
from kivy.logger import Logger
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.video import Video
from kivy.uix.label import Label
from kivy.uix.button import Button
class Player(Video):
def __init__(self, **kwargs):
super(Player, self).__init__(**kwargs)
self.source = './START.mp4'
self.state='play'
self.options={'eos': 'loop'}
self.bind(on_touch_down = self.on_stop)
def check(self):
Logger.info("film position:" + str(self.position))
def on_stop(self, *args):
print ('I have been clicked')
self.state='stop' # stop the video
sm.current = 'WindowApp' # switch to the other Screen
class MyWindowApp(Screen):
def __init__(self, **kwargs):
super(MyWindowApp, self).__init__(**kwargs)
self.btn = Button(text='Push Me!', pos_hint={'center_x': 0.5, 'center_y': 0.75}, size_hint=(0.2, 0.2))
self.lbl = Label(text='Read Me!', pos_hint={'center_x': 0.5, 'center_y': 0.25})
self.add_widget(self.btn)
self.add_widget(self.lbl)
sm = ScreenManager()
screen1 = Screen(name='video')
screen1.add_widget(Player())
sm.add_widget(screen1)
screen2 = MyWindowApp(name='WindowApp')
sm.add_widget(screen2)
class VideoPlayerApp(App):
def build(self):
return sm
VideoPlayerApp().run()
I corrected your import to from kivy.uix.video import Video

Related

I want change the Label inserted in one class, by pressing the button in another class. Without using Kv language. Help me

I'm learning to program with Python and Kivy.
I'm trying to change the text of a Label inserted in one class, by pressing the button which is in another
class. Without using Kv language
I tried them all, the text does not change. Help me!!!!
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.app import App
class Gestione(BoxLayout):
def __init__(self, **kwargs):
super(Gestione, self).__init__(**kwargs)
self.w1 = Windows()
self.w2 = Windows2()
self.add_widget(self.w1)
self.add_widget(self.w2)
class Windows(BoxLayout):
def __init__(self, **kwargs):
super(Windows,self).__init__(**kwargs)
self.label = Label()
self.label.text = "Label to change in Window1"
self.add_widget(self.label)
class Windows2(BoxLayout):
def __init__(self, **kwargs):
super(Windows2, self).__init__(**kwargs)
self.link = Windows()
bottone = Button(text="button Class2", on_press=self.changetext)
self.add_widget(bottone)
def changetext(self, *args, **kwargs):
self.link.label.text = "Text changed"
class Gestioneapp(App):
def build(self):
return Gestione()
Gestioneapp().run()

Not able to print the text taken from kivy.uix.textinput.TextInput in KIVY Python

What I want to do is take input from kivy.uix.textinput.TextInput() and show it on the screen.
I am new to gui Programming and I think it is an easy task.
import kivy
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.textinput import TextInput
class MyWindowApp(App):
def __init__(self):
super(MyWindowApp, self).__init__()
self.lbl = Label(text='Read Me!')
self.inp = TextInput(multiline=False,
size_hint =(1, 0.05),
pos_hint = {"x":0, "y":0.05})
def build(self):
self.inp.bind(on_text_validate=self.on_enter)
#self.bt1.bind(on_press=self.clk)
layout = FloatLayout()
layout.orientation = 'vertical'
layout.add_widget(self.lbl)
layout.add_widget(self.inp)
return layout
def on_enter(self,value):
print(value)
def clk(self, obj):
print ('input')
x = input()
self.lbl.text = x
window = MyWindowApp()
window.run()
when i run the code, I get the regular output output.
when I type say "hello world" in the textbox, this is the output:
<kivy.uix.textinput.TextInput object at 0x03F5AE30>
I do not get what I typed.
please suggest what should I do
Modify the following ...
def on_enter(self, value):
print(value.text)

How to change Image created in a for loop with on_press in kivy

I have created a group of images in a for loop in kivy and those images have the attribute of 'buttonbehavior' making them clickable. I am trying to change the image at a particular index to another image when clicked but it is not working.
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.image import Image
from kivy.uix.button import Button
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
class ScreenManagement(ScreenManager):
def __init__(self, **kwargs):
super(ScreenManagement, self).__init__(**kwargs)
class Screen2(Screen):
def __init__(self, **kwargs):
super(Screen2, self).__init__(**kwargs)
Pass
class ImageButton(ButtonBehavior,Image):
pass
class Screen1(Screen, ButtonBehavior,Image):
def __init__(self, **kwargs):
super(Screen1,self).__init__(**kwargs)
for i in range(6):
self.btn= ImageButton(source='put_any.png', size_hint=(.3, .2),
pos_hint={'center_x': .5, 'center_y': .32})
self.add_widget(self.btn)
If i==0:
self.btn.bind(on_press=self.change_image)
def change_image(self,*args)
self.source='put_any.png'
class Application(App):
def build(self):
sm = ScreenManagement(transition=FadeTransition())
sm.add_widget(Screen1(name='screen1'))
sm.add_widget(Screen2(name='screen2'))
return sm
if __name__ == "__main__":
Application().run()
I want the image at index 0 in the for loop to change to another image when it is pressed, but it is not working please what am I doing wrong.
If you refer self.source it means Screen.source that wont affect anything.
Change the func like this:
def change_image(self, btn)
btn.source='put_any.png'

Play video inside kivy canvas

I have put the video inside kivy canvas, first 3 sec showing image afterthat will be play video. But only show all time image only.
Any suggestion.
Thanks
import kivy
from kivymd.app import MDApp
from kivy.uix.widget import Widget
from kivy.graphics import Rectangle ,Color
from kivy.core.video import Video as CoreVideo
from kivy.clock import Clock
class Mycanvas(Widget):
def __init__(self,**kw):
super(Mycanvas,self).__init__(**kw)
with self.canvas:
self.bg = Rectangle(source='Flower.jpg', pos=self.pos, size=self.size)
self.video = CoreVideo()
self.video.bind(on_frame=self.set_bg_texture)
self.video.filename = 'Garden.mp4'
Clock.schedule_once(self.start_vid, 3)
self.start_vid(3)
def start_vid(self, dt):
self.video.play()
def set_bg_texture(self, *args):
self.bg.texture = self.video.texture
class mainapp(MDApp):
def build(self):
return Mycanvas()
mainapp().run()

Kivy Dynamic selection image according to button

I want to place image on button. Button's size depends on size of screen. I want to select ideal image's size according to button's size. Buttons are defined in class ButtonTools. With my knowledges I cann obtain size only in fuction of class ButtonTools. How do I obtain size of screen?
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.image import Image
class Paint(Widget):
pass
class ButtonTools(BoxLayout):
def __init__(self, **kwargs):
super(ButtonTools, self).__init__(**kwargs)
self.size_hint = (1, None)
self.height = 50
but = Button(on_press = self.DrawAbscissa)
but.background_normal = 'abscissa.png'
self.add_widget(but)
but = Button( on_press = self.DrawCurve)
but.background_normal ='curve.png'
self.add_widget(but)
def DrawAbscissa(self, obj):
size = self.parent.size
p=1
pass
def DrawCurve(self, obj):
pass
class WorkShop(BoxLayout):
def __init__(self, **kwargs):
super(WorkShop, self).__init__(**kwargs)
self.orientation = "vertical"
self.paint = Paint()
self.tools = ButtonTools()
self.add_widget(self.paint)
self.add_widget(self.tools)
class MyPaintApp(App):
def build(self):
return WorkShop()
if __name__ == '__main__':
MyPaintApp().run()
You can obtain the screen size using the following:
from kivy.core.window import Window
...
print("Window.size={}".format(Window.size))
print("Window.height={}".format(Window.height))
print("Window.width={}".format(Window.width))

Categories