Pop up Kivy displaying while a process is running in background

孤街醉人 提交于 2020-08-09 09:09:33

问题


In my kivy project, I have a button allowing me to generate a matplotlib graph in .png format. Generating this image takes time (around 20 seconds), and I would like to display a pop-up window to warn the user.

What i tried :

<MyPopup@Popup>:
    auto_dismiss: False
    Button:
        text: 'This could take time, please wait :)  '
        on_release: root.dismiss()

and :

ActionButton:
                        text: 'generate graph'
                        on_release: Factory.MyPopup().open()
                        #on_release: root.generate_graph() 

Unfortunately, if I uncomment the second "on_release", the pop_up window never appears?

Do you have any guess?

Thank you in advance!


回答1:


You were overwriting the on_release method.

ActionButton:
    text: 'generate graph'
    on_release: 
        Factory.MyPopup().open()
        root.generate_graph() 



回答2:


To display a popup while a method is running I use threads. When the popup fires up, the method runs in a thread.

CODE:

def popupThread(self):          
    
    #set the popup structure
    self.popup = ActivityBox(self)
    self.popup.open()
    
    # run the method in threads
    t1 = threading.Thread(target = self.someMethod)
    t1.start()

The popup is defined in the Builder.load_string():

def build(self):
        sm = Builder.load_string("""    
<ActivityBox>:
    size_hint: 1, .7
    auto_dismiss: False
    title: 'some activity' 
    title_align: "center"
    title_size: 30
    BoxLayout:
        orientation: "vertical"
        Label:
            font_size: '30sp'
            text: 'work in progress'
        BoxLayout:
            orientation: "horizontal"
            spacing: 10
            size_hint: 1, .5
""")


来源:https://stackoverflow.com/questions/54924125/pop-up-kivy-displaying-while-a-process-is-running-in-background

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