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.


    How to send 'CTRL-C' to console, when close button in ui is tapped?

    Pythonista
    2
    6
    3488
    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.
    • FrankenApps
      FrankenApps last edited by FrankenApps

      button in Pythonista.

      Is there a way to send 'CTRL-C' via the UI close button in the title bar?

      I want to call

      except KeyboardInterrupt:
        cb.reset()
      

      when the close button in the title bar is tapped.

      I have tried making the main View a customView and then using

      class MainView(ui.View):
       def will_close(self):
         print('Closing')
         cb.reset()
         sys.exit(0)
      

      button in order to stop the script execution.

      Only to be clear: I do not want to close Pythonista, I only want to stop the script from running, when I hit the close button in the UI and return to the console/editor.

      cvp 1 Reply Last reply Reply Quote 0
      • cvp
        cvp @FrankenApps last edited by cvp

        @FrankenApps How do you present your view? Normally, if you present with hide_title_bar=False, the x button at top left is the standard close button, thus your ui.View closes.
        Don't call sys.exit

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

          @cvp I do it with:

          v=ui.loadView()
          v.present(style=full_screen, orientations= ['portrait'])
          

          the title bar is shown by default, isn't it?
          I can post the whole code later if necessary...

          cvp 1 Reply Last reply Reply Quote 0
          • cvp
            cvp @FrankenApps last edited by

            @FrankenApps it is ok and then, when you tap the x, will_close is called, no?

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

              Yes, but the Script is still running, even so the UI is closed

              cvp 1 Reply Last reply Reply Quote 0
              • cvp
                cvp @FrankenApps last edited by cvp

                @FrankenApps understood, you have a thread still running...
                You have to "warn" it to close

                see here

                But you have to set, in will_close, a global checked by your thread to see that close has been asked and then leave the thread run by a return

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