Displaying something in kivy while a process is running background

╄→гoц情女王★ 提交于 2021-02-11 12:38:20

问题


I'm trying to generate a graph when i'm leaving my kivy app using matplotlib. The process time to generate these graphs is about 20 seconds and i would like to warn the user during this time. I tried to use a Kivy pop up, and it didn't work. I tried to add a label, but it doesn't seems to work either. That's why I really need help !

My code :

    def fermerBanc(self):  

        list_argument_graph=[]
        list_argument_graph.append(passerelle.graph1.y_low_min)
        list_argument_graph.append(passerelle.graph1.y_low_max)
        list_argument_graph.append(passerelle.graph1.y_high_min)
        list_argument_graph.append(passerelle.graph1.y_high_max)
        list_argument_graph.append(passerelle.graph1.setTaille)

        list_argument_graph_1=list(list_argument_graph)
        list_argument_graph_1.insert(0, chemin1)

        list_argument_graph_2=list(list_argument_graph)
        list_argument_graph_2.insert(0, chemin2)

        list_argument_graph_3=list(list_argument_graph)
        list_argument_graph_3.insert(0, chemin3)

        list_argument_graph_4=list(list_argument_graph)
        list_argument_graph_4.insert(0, chemin4)

        if(passerelle.graph1.flagGraph):

            p1 = Process(target=process_graph, args=(list_argument_graph_1,))
            p2 = Process(target=process_graph, args=(list_argument_graph_2,))
            p3 = Process(target=process_graph, args=(list_argument_graph_3,))
            p4 = Process(target=process_graph, args=(list_argument_graph_4,))

            try:
                p1.start()
            except AttributeError:
                Logger.warning('fermerBanc: impossible de generer un graph 1, fichier vide')

            try:
                p2.start()  
                pass
            except AttributeError:
                Logger.warning('fermerBanc: impossible de generer un graph 2, fichier vide')

            try:
                p3.start()
                pass
            except AttributeError:
                Logger.warning('fermerBanc: impossible de generer un graph 3, fichier vide')

            try:
                p4.start()
                pass              
            except AttributeError:
                Logger.warning('fermerBanc: impossible de generer un graph 4, fichier vide')

            self.msgWarning = Label(text="Merci de patienter...", font_size='55sp', size=(100, 50), pos_hint={'center_x': .5, 'center_y':.5})
            self.add_widget(self.msgWarning)

            p1.join()
            p2.join()
            p3.join()
            p4.join()

        exit()

Edit : If I comment the several processand the exit() command my Label is displaying normally


回答1:


Just found the solution thanks to this thread

you have to use the kivy Clock.schedule_once() method : kivy clock doc

I my case, I just create a function fermerbanc_schedule in charge of :

  • Displaying the waiting message on the screen
  • called the fermerBanc function via schedule_once

    def fermerBanc_schedule(self, *args): self.msgWarning = Label(text="Merci de patienter...", font_size='55sp', size=(100, 50), pos_hint={'center_x': .5, 'center_y':.5}) self.add_widget(self.msgWarning) Clock.schedule_once(lambda dt: self.fermerBanc(self, *args), 0)



来源:https://stackoverflow.com/questions/55238034/displaying-something-in-kivy-while-a-process-is-running-background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!