os._exit() after present() exits right away
I'm sure I'm missing something obvious.
I added os.exit(EX_OK) after the v.present() line in my code, and when I run my app, Pythonista exists right away.
v = ui.load_view('umswi')
If I remove the os._exit(EX_OK), my app runs until I press the "X" in the upper left-hand corner. If I put the os._exit(EX_OK) back in, my app starts and immediately exits.
If a user presses "X" in the upper left-hand corner, I want Pythonista to close. But I don't want it to close until someone presses that "X".
What am I doing wrong?
you want a
wait_modalin order to stop execution until the user closes the view --
presentdoes not block. The ui operates on a different thread effectively from the main script.
I added a wait_model() line after the present() line, but it seems to block access to the camera.
Any tips there?
@cgallery Here's something you can try: Define a custom
Viewclass like this:
class ExitingView (ui.View): def will_close(self): os._exit(0)
Then, in your pyui file, enter
ExitingView(or whatever class name you chose) in "Custom View Class" for the main view (show the inspector with nothing selected).
will_closemethod will be called automatically when the "X" is tapped.
Thank you I will try that.
Huh, that also blocks the camera.
I have @ui.in.background before the line that takes the picture with the built-in camera. So that code looks like this:
if len(pics) == 4:
pic = photos.capture_image()
pics[len(pics):] = [pic]
So in my ui, I have a button with an action set to button_camera.
@cgallery Hmm, I think this may actually be a bug in
photos.capture_image. I'll look into it, but I can't think of a workaround right now.
Well I can change my code and add an Exit button or something, I'll figure out some way to work around this.
Thanks for all your help.