Skip to content Skip to sidebar Skip to footer

How To Include Nsusernotificationcenter In Py2app

I am making an app in python 2.7 on mac osx 10.8.5 I want to show notification number of times, therefore using NSUserNotificationCenter. Notifications are coming while running cod

Solution 1:

My guess is, .lookUpClass() should be resolved at runtime. Thus you don't actually want to include that class in your py2app. Unless you wrote this class yourself that it.

What you do want to include is objc and related libraries. Make sure it's in your virtualenv when you call py2app. If python -m pydoc objc works, so should python setup.py py2app.

Solution 2:

If you are trying to create a pop-up window to notify the user of certain information, there are plenty of python modules for this purpose. Wx python is a good choice. Here is the documentation for pop-up windows:

http://wxpython.org/docs/api/wx.PopupWindow-class.html

EDIT: That won't get an apple notification in the way you want. Try this code. It uses a downloadable command line tool called terminal-notifier to make notifications, accessed through python via sub process:

import subprocess

defnotification(title, subtitle, message):
    subprocess.Popen(['terminal-notifier','-message',message,'-title',title,'-subtitle',subtitle])

notification(title = 'notification title', subtitle = 'subtitle', message  = 'Hello World')

This should get the results you want, although to install it automatically you need to run a build in ruby. You could also get it to play sounds, change some ID parameters, and even tell it to run a shell command when you click on it. For more information go here, this is where you can get the source and the docs:

https://github.com/julienXX/terminal-notifier

Post a Comment for "How To Include Nsusernotificationcenter In Py2app"