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.
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.
My code:
v = ui.load_view('umswi')
v.present()
os._exit(EX_OK)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_modal
in order to stop execution until the user closes the view --present
does 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
View
class 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).The
will_close
method 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:
@ui.in.background
def button_camera(sender):
if len(pics) == 4:
pics.pop(0)
pic = photos.capture_image()
if pic:
pics[len(pics):] = [pic]
showpics(sender)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.