Forum Archive

A problem with ui.in_background and console.alert - help need asap :) [FIXED]

JadedTuna

GitRepo with the app is here: https://github.com/Vik2015/appbug

When you click some zip file in the TableView, it asks you if you are sure you want to unzip this file. But looks like ui is not waiting for the function to finish and just returns None from it. Any ideas why and how to fix it? Thanks

omz

When you decorate a function with @ui.in_background, it will always return None. This is by design – the entire point of ui.in_background is basically to return immediately, without blocking, and when it returns, the result of the actual function call is not yet known.

In your case, I would recommend moving the ask_unzip action into the App class (don't forget the additional self parameter), and then calling some kind of do_unzip method if the alert comes back with a confirmation. So basically, you'd split the unzip method in two, one that just shows the alert, and the other one that does the actual unzipping, and which you call separately when the alert returns in the background. I hope that makes sense.

JadedTuna

@omz, if I understand you right, I should have like three methods, do_unzip, unzip and ask_unzip. do_unzip will execute ask_unzip and if user presses "Yes" it will call unzip?

JadedTuna

Okay, I think I finally got it. do_unzip should have decorator @ui.in_background and other functions should not. Now it runs just fine. Thanks :)