问题
I have a kivy app, in which when a button is pressed, it starts communicating with the server and based on information obtained, it creates and fills the screen with widgets. Some actions are almost instant, some take considerable time in seconds. I want to implement a loading popup that is shown while the screen loads. I would also like to do it so that when loading takes less time than some configured time period, lets call it MIN_TIME, the popup does not show at all. Moreover, if the loading time is longer than MIN_TIME, I want to show loading popup for at least some other configured time, lets call it TIME_INT. Both of these conditions are to prevent it from showing the popup and immediately closing it if the loading is too fast.
So basically:
- If loading time < MIN_TIME : don't show loading popup at all
- If MIN_TIME < loading time < MIN_TIME + TIME_INT : show loading popup after MIN_TIME seconds for TIME_INT seconds
- If loading time > MIN_TIME + TIME_INT : show loading popup after MIN_TIME seconds and close it as soon as loading is complete.
I tried various approaches but nothing works as I want it. I suspect I need threading or multiprocessing to do this. If I understand it correctly, loading must be done in main thread, because I update GUI elements, but showing the popup is also done in main thread, and it cant show popup while it processes some time intensive action. Is it even possible to do this the way I want it?
来源:https://stackoverflow.com/questions/56058099/correct-way-to-implement-loading-popup-in-kivy-app