Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
A problem with ui.in_background and console.alert - help need asap :) [FIXED]
-
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
-
When you decorate a function with
@ui.in_background
, it will always returnNone
. This is by design – the entire point ofui.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 theApp
class (don't forget the additionalself
parameter), and then calling some kind ofdo_unzip
method if the alert comes back with a confirmation. So basically, you'd split theunzip
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. -
@omz, if I understand you right, I should have like three methods,
do_unzip
,unzip
andask_unzip
.do_unzip
will executeask_unzip
and if user presses "Yes" it will callunzip
? -
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 :)