rumps icon indicating copy to clipboard operation
rumps copied to clipboard

Customizing application startup and termination, defining custom delegates

Open romix opened this issue 12 years ago • 1 comments

I like rumps as it meets my needs for creating a simple menu bar app.

But I don't quite understand how I can customize actions to be performed when my application starts or terminates. I think I have to define a delegate that would listen to the corresponding events, but I'm not sure how and if this can be done with rumps.

I also would like to customize the menu in such a way, that I define my own "Quit" menu item. Eventually, I'd like to give it a different name or place it in a sub-menu. But this seems to be impossible, as rumps automatically defines this menu item.

Another question: How can I terminate rumps application programmatically? Can you give an example of the code to be used? Most likely I have to send a "terminate:" event, but how can I do it?

Thanks, Leo

romix avatar Dec 06 '13 23:12 romix

Hi Leo,

Sorry for the late response. I believe the newest version allows for all of the features you were interested in.

If you just want to change the name of the quit menu item, provide a value for quit_button in App. If you want to put it inside a sub-menu, disable the default quit menu item by setting quit_button to None and define your own MenuItem that calls quit_application function.

Having a callable python function that quits the application allows you to do clean up by simply including it after,

@rumps.clicked('Clean Quit')
def clean_up_before_quit(_):
    print 'execute clean up code'  # maybe close open files / connections
    rumps.quit_application()

app = rumps.App('Hallo Thar', menu=['Clean Quit'], quit_button=None)
app.run()

As for customizing start up, it would seem that this would only be needed if there were options you couldn't customize before calling App.run. Something that relied on the code inside run being executed first. The only thing that I could think of that worked this way was the default quit button and that is now changed.

If you could provide an example of its benefit, I would add the feature.

Thanks, Jared

jaredks avatar Aug 09 '14 22:08 jaredks