Closed robertmlinden closed 6 years ago
I would like a way to run statements after app.launch(), specifically restart the app. If you have any suggestions regarding this process (considering that I can't exit cleanly with a stop function...).
And calling app.stop()
within this stop function obviously causes infinite recursion.
The purpose of .setStopFunction()
is to allow you to confirm the user really wants to exit - the stop function should return True
to confirm exit, or `False to prevent exit. It's common to show some kind of popup to get this confirmation.
Have you tried the code here: http://appjar.info/pythonEvents/#stopping-the-gui
I've just given it a quick test, and it seems to be working.
app.stop()
is a way of quitting the GUI, it should be linked to a button, or called from within a function. If a stopFunction
has been set, then app.stop()
will still run the stopFunction
to confirm the user wants to exit.
Here's the code I used:
from appJar import gui
def checkStop():
return app.yesNoBox("Confirm Exit", "Are you sure you want to exit the application?")
with gui('Stop test') as app:
app.label('Stop Test')
app.stopFunction = checkStop
app.button('quit', app.stop)
As to your question about running functions where the GUI starts, there is a corresponding startFunction
: http://appjar.info/pythonEvents/#starting-the-gui
You use this in the same way, registering a function that will be called once the GUI has started...
And, getting the program to run again once it's closed, you could try putting it in a infinite loop, although I'm not sure how that will work out...
Alternatively, just have the stopFunction
always return False
, that'll prevent the user from exiting...
Thank you! Return true, got it.
I've updated the docs :)
See subj. line