Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If you add in self.setStopFunction(f), the program will not end unless f() contains some form of sys.exit(0) #521

Closed
robertmlinden opened this issue Aug 15, 2018 · 7 comments
Labels

Comments

@robertmlinden
Copy link

See subj. line

@robertmlinden
Copy link
Author

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

@robertmlinden
Copy link
Author

And calling app.stop() within this stop function obviously causes infinite recursion.

@jarvisteach
Copy link
Owner

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)

@jarvisteach
Copy link
Owner

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

@jarvisteach
Copy link
Owner

jarvisteach commented Aug 15, 2018

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

@robertmlinden
Copy link
Author

Thank you! Return true, got it.

jarvisteach added a commit that referenced this issue Aug 15, 2018
jarvisteach added a commit that referenced this issue Aug 15, 2018
@jarvisteach
Copy link
Owner

I've updated the docs :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants