omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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

    Pythonista
    3
    9
    4618
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • cgallery
      cgallery last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • JonB
        JonB last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • cgallery
          cgallery last edited by

          I added a wait_model() line after the present() line, but it seems to block access to the camera.

          Any tips there?

          1 Reply Last reply Reply Quote 0
          • omz
            omz last edited by omz

            @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.

            1 Reply Last reply Reply Quote 0
            • cgallery
              cgallery last edited by

              Thank you I will try that.

              1 Reply Last reply Reply Quote 0
              • cgallery
                cgallery last edited by

                Huh, that also blocks the camera.

                1 Reply Last reply Reply Quote 0
                • cgallery
                  cgallery last edited by

                  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.

                  1 Reply Last reply Reply Quote 0
                  • omz
                    omz last edited by

                    @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.

                    1 Reply Last reply Reply Quote 0
                    • cgallery
                      cgallery last edited by

                      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.

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post
                      Powered by NodeBB Forums | Contributors