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?
-
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.
-
@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 -
@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... -
@FrankenApps it is ok and then, when you tap the x, will_close is called, no?
-
Yes, but the Script is still running, even so the UI is closed
-
@FrankenApps understood, you have a thread still running...
You have to "warn" it to closeBut 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