How can i show lottie json animation in My Popup?

104 views
Skip to first unread message

MECRA YAVCIN

unread,
Feb 24, 2024, 8:14:14 AM2/24/24
to Kivy users support
Hi @ElliotG
I hope you are doin well. You helped me so much thanks for all.
I am not so good at Python and also KIvy.
I have a PopUP structure that works well.
Can you please help to modify it show lottie json animation?

KV FILE:
<PopupBox>:
    pop_up_text: _pop_up_text
    background_color: '#38B6FF'
    background: 'white'
    size_hint: 1, 1
    auto_dismiss: True
    title: 'FOOTBALL PREDICTOR'
    title_size: '15dp'
    title_font: 'fonts/Bungee-Regular.ttf'
    BoxLayout:
        orientation: "vertical"
        Label:
            id: _pop_up_text
            text: ''
            font_name: 'fonts/Bungee-Regular.ttf'
            font_size: '30dp'
            color: 1, 0.4, 0.769, 1 

Python File Example:

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.uix.image import Image
from kivy.metrics import dp
from kivy.clock import mainthread
from kivy.uix.popup import Popup
from kivy.factory import Factory
from kivy.properties import ObjectProperty
from kivy.utils import platform
if platform == 'android':
    from kivmob_mod import KivMob
from time import sleep
from unidecode import unidecode
from bs4 import BeautifulSoup
import aiohttp
import asyncio
import requests
import threading
import re
import ssl


class PopupBox(Popup):

    pop_up_text = ObjectProperty()
    def update_pop_up_text(self, p_message):
        self.pop_up_text.text = p_message



class Predictor(BoxLayout):
   
    def __init__(self, **kwargs):
        super(Predictor, self).__init__(**kwargs)
 
        self.status = True

    @mainthread
    def on_size_calculate(self, *args):
        self.ids.sv_calculate.scroll_y = 1
        print('Scroll 1')
        self.pop_up.dismiss()
        print('Popup Dismiss')    


    @mainthread
    def on_size_guide_eng(self, *args):
        self.ids.sv_guide_eng.scroll_y = 1
        print('Scroll 3')
        self.pop_up.dismiss()
        print('Popup Dismiss')

    @mainthread
    def on_size_guide_tr(self, *args):
        self.ids.sv_guide_tr.scroll_y = 1
        print('Scroll 4')
        self.pop_up.dismiss()
        print('Popup Dismiss')          
               

    def homepage(self, s_image, screenmanager):        
       
        screenmanager.current = 'homepage_screen'

    def league(self, s_image, screenmanager):        
       
        screenmanager.current = 'league_screen'    
   
    def show_popup(self):
       
        self.pop_up = Factory.PopupBox()
        self.pop_up.update_pop_up_text('''Please Wait...\n...Be Patient''')
        self.pop_up.open()
       
    @mainthread
    def clear_widgets(self, *args):

        if self.ids.gridsonuc.children:            
            for child in [child for child in self.ids.gridsonuc.children]:            
                self.ids.gridsonuc.remove_widget(child)
            print('Screen Cleared')

        if self.ids.guidesonuc_eng.children:            
            for child in [child for child in self.ids.guidesonuc_eng.children]:            
                self.ids.guidesonuc_eng.remove_widget(child)
            print('Screen Cleared')

        if self.ids.guidesonuc_tr.children:            
            for child in [child for child in self.ids.guidesonuc_tr.children]:            
                self.ids.guidesonuc_tr.remove_widget(child)
            print('Screen Cleared')                      

    def calculate_screen(self, s_image, screenmanager, lig):
       
        screenmanager.current = 'calculate_screen'
        self.show_popup()
        mythread = threading.Thread(target=self.clear_widgets)
        mythread.start()
        mythread3 = threading.Thread(target=self.calculate(lig))
        mythread3.start()
        mythread4 = threading.Thread(target=self.on_size_calculate)
        mythread4.start()    

    @mainthread
    def calculate(self, lig, *args):
       
        calculations:::::::::::::::::::::

class FootballpredictorApp(App):

    def build(self):
        return Predictor()

if __name__ == '__main__':
    FootballpredictorApp().run()


In this structure there are buttons in  league_screen when i click them it sends me  calculate_screen and popup opens. I used dismis in  self.on_size_calculate. Works perfect but i need to show lottie json animation. For example i have a test.json in images/test.json how can i show it?

Thanks very much for your help.
 

elli...@cox.net

unread,
Feb 24, 2024, 10:32:07 AM2/24/24
to Kivy users support
There is no direct support for Lottie in kivy at this time.  You could convert your animation to a gif and display it in a AsyncImage or Image widget.  

From: kivy-...@googlegroups.com <kivy-...@googlegroups.com> on behalf of MECRA YAVCIN <mecra...@gmail.com>
Sent: Saturday, February 24, 2024 5:14 AM
To: Kivy users support <kivy-...@googlegroups.com>
Subject: [kivy-users] How can i show lottie json animation in My Popup?
 
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/fbb352ea-9f10-4a9e-90a8-5f36aec458d4n%40googlegroups.com.

MECRA YAVCIN

unread,
Feb 24, 2024, 10:37:09 AM2/24/24
to Kivy users support
Thanks

my new KV file code is:


<PopupBox>:
    pop_up_text: _pop_up_text
    background_color: '#38B6FF'
    background: 'white'
    size_hint: 1, 1
    auto_dismiss: True
    title: 'FOOTBALL PREDICTOR'
    title_size: '15dp'
    title_font: 'fonts/Bungee-Regular.ttf'
    BoxLayout:
        orientation: "vertical"
        Label:
            id: _pop_up_text
            text: ''
            font_name: 'fonts/Bungee-Regular.ttf'
            font_size: '30dp'
            color: 1, 0.4, 0.769, 1
        AsyncImage:
            source: 'wait.gif'
            anim_delay: 1/30 

only added this lines

Screenshot 2024-02-24 183537.png

now showing

original gif is 
Screenshot 2024-02-24 183625.png
Message has been deleted

MECRA YAVCIN

unread,
Feb 24, 2024, 12:32:50 PM2/24/24
to Kivy users support
UPDATE:

I used this below method not worked 

class PopupBox(Popup):
    pop_up_text = ObjectProperty()
    pop_up_image = ObjectProperty()

    def update_pop_up_text(self, p_message):
        self.pop_up_text.text = p_message

    def update_pop_up_image(self, image_url):
        self.pop_up_image.source = image_url
class Predictor(BoxLayout):
def show_popup(self):
        self.pop_up = PopupBox()
        self.pop_up.update_pop_up_text('''Please Wait...\n...Be Patient''')
        self.pop_up.update_pop_up_image('images/tur.png')
        self.pop_up.open()
KV file: <PopupBox>:
    pop_up_text: _pop_up_text
    pop_up_image: _pop_up_image

    background_color: '#38B6FF'
    background: 'white'
    size_hint: 1, 1
    auto_dismiss: True
    title: 'FOOTBALL PREDICTOR'
    title_size: '15dp'
    title_font: 'fonts/Bungee-Regular.ttf'
    BoxLayout:
        orientation: "vertical"
        Label:
            id: _pop_up_text
            text: ''
            font_name: 'fonts/Bungee-Regular.ttf'
            font_size: '30dp'
            color: 1, 0.4, 0.769, 1
        AsyncImage:
            id: _pop_up_image
            source: ''


same did not worked

Screenshot 2024-02-24 183537.png

MECRA YAVCIN

unread,
Feb 24, 2024, 1:37:49 PM2/24/24
to Kivy users support

**UPDATE: A CLUE **

I run this app in Vscode and in terminal when the popup closes i get this error:

    Scroll 1
    Popup Dismiss
    Unknown <gif> type, no loader found.

elli...@cox.net

unread,
Feb 24, 2024, 7:25:11 PM2/24/24
to kivy-...@googlegroups.com
Interesting... Share your gif, I'll try to load it and see what happens.  Perhaps try a different mechanism for creating the gif.


Sent: Saturday, February 24, 2024 10:37 AM

To: Kivy users support <kivy-...@googlegroups.com>
Subject: Re: [kivy-users] How can i show lottie json animation in My Popup?
 

MECRA YAVCIN

unread,
Feb 25, 2024, 5:10:54 AM2/25/24
to Kivy users support
https://giphy.com/gifs/reaction-mood-stephen-colbert-1XdfVRTyn5d31Q1lG0 you can save it with right click and save.
i tied this. In giphy site nthere are many gifs.
It is too strange that i tried a png and jpg file also but same error :D

for example i can see that image in this example. below code works. I found it in Stackoverflow. But i could not success to show it in my popup
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.popup import Popup
from kivy.uix.gridlayout import GridLayout
from kivy.clock import Clock
kv = """
<Test@AnchorLayout>:
    AsyncImage:
        source: 'giphy.gif'
        anim_delay: 0.1
Test:"""



class TestApp(App):

    def build(self):
        layout = GridLayout(cols=1, padding=10)
        anim = Builder.load_string(kv)
        layout.add_widget(anim)
        popup = Popup(content=layout)
        popup.open()
        print('Hello world')
        Clock.schedule_once(App().get_running_app().stop,10)

if __name__ == '__main__':
    TestApp().run()

elli...@cox.net

unread,
Feb 25, 2024, 11:20:25 AM2/25/24
to Kivy users support
It looks like the problem is the way you are using the kivy properties.  

Your code:
self.pop_up.update_pop_up_text('''Please Wait...\n...Be Patient''')
should be:
self.pop_up.update_pop_up_text = 'your text'

Here is a simple example:
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.popup import Popup
from kivy.properties import StringProperty

kv =
"""
<GifPop>:
   title: 'Test the Popup'
   size_hint: .9, .9
   BoxLayout:
       orientation: 'vertical'
       Label:
           text: root.text
           size_hint_y: None
           height: dp(30)
       Image:
           source: root.source
           anim_delay: 0.1
           fit_mode: 'contain'
       Button:
           size_hint_y: None
           height: dp(48)
           text: 'Close'
           on_release: root.dismiss()

AnchorLayout:
   Button:
       size_hint: None, None
       size: dp(200), dp(48)
       text: 'Pop'
       on_release: app.pop.open()
"""

class GifPop(Popup):
   source = StringProperty()
   text = StringProperty()

class PopApp(App):
   
def build(self):
       
return Builder.load_string(kv)

   
def on_start(self):
       
self.pop = GifPop(source='giphy.gif', text='Test the gif')

PopApp().run()



Sent: Sunday, February 25, 2024 2:10 AM
Reply all
Reply to author
Forward
0 new messages