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.
Capturing the view close "x"
-
So, can you capture the event of the "x" in the upper left hand corner of a presented ui.view being touched to allow for a cleanup before the whole script stops? I tried the obvious "finally", but that didn't fire, only the console upper right hand X did that.
-
Two techniques to look at:
while View.on_screen:
andView.wait_modal()
. -
I assume this is a custom view, in which case, did you try
def will_close(self): # This will be called when a presented view is about to be dismissed. # You might want to save data here. pass
However, I vaguely recall this working for some types of presentation modes (say, popover), but not others, but I could be wrong about that.
Another alternative to the blocking options that ccc suggests would be a
threading.Thread
orTimer
that polls theon_screen
at some reasonably slow interval (few seconds).One other option... hide the title bar and provide your own "X". Doesn't protect against two finger swipes, but most people don't know about that anyway.