Updating Kivy GUI using clock object?

781 views Asked by At

I asked in a previous question about updating a popup to say something like 'running' after a run button in the popup has been pressed. The issue is that the gui doesn't actually update until after the process has finished running, by which point updating the popup is pointless.

I have tried running my process using a separate thread, but this introduced all sorts of issues, and based on my research this may not be worth pursuing due to threading issues in Kivy.

What I want to know is if I can achieve a similar effect using a clock object to schedule the popup to update '.1' seconds after the 'run' button has been clicked.

Will this actually work, or will this clock object not actually be created until after my other process has finished, again making it useless.

My program works great from a functionality prospective, but I don't want users to be stuck with a spinning wheel without knowing that a process is running. I would love to have a progress bar, but that is an entirely different challenge as the functions I am running are using an external console based application that does not indicate progress.

As you can probably tell from this question, I am both new to Kivy and to GUI development in general. Any help would be greatly appreciated.

1

There are 1 answers

1
inclement On BEST ANSWER

Open the popup, then schedule the function that runs your long task.

SomePopupClass().open()
Clock.schedule_once(your_long_running_function, 0)

By scheduling the long running function for the next frame (this is the effect of the 0 argument), you give kivy time to run its normal gui update loop so you'll see the popup appear before the ui is blocked.

You'll need to use a thread for your long task if you want the gui to remain responsive while it runs. There's no major issue doing this with kivy.