How to enable NSUserNotificationCenter in py2app

I am making an application in python 2.7 on mac osx 10.8.5 I want to show the number of notifications using NSUserNotificationCenter. Notifications are triggered when you run eclipse code. But the problem is: when I made app using py2app, Notifications are not coming. Moreover, the default error page of the open console and Terminate appears. Please suggest some way to enable notification in dist created by py2app so that it works on any other machine. My setup.py is

from setuptools import setup

APP=['CC4Box.py']
DATA_FILES= [('',['config.cfg'])]
OPTIONS={'iconfile':'cc.icns','argv_emulation': True,'plist':{'CFBundleShortVersionString':'1.0'}}

setup(
    app=APP,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app']
    ) 

My notification code:

def notify(title, subtitle, info_text, delay=0, sound=False, userInfo={}):
    NSUserNotification = objc.lookUpClass('NSUserNotification')
    NSUserNotificationCenter = objc.lookUpClass('NSUserNotificationCenter')
    notification = NSUserNotification.alloc().init()
    notification.setTitle_(title)
    notification.setSubtitle_(subtitle)
    notification.setInformativeText_(info_text)
    notification.setUserInfo_(userInfo)
    if sound:
        notification.setSoundName_("NSUserNotificationDefaultSoundName")
    notification.setDeliveryDate_(Foundation.NSDate.dateWithTimeInterval_sinceDate_(delay, Foundation.NSDate.date()))
    NSUserNotificationCenter.defaultUserNotificationCenter().scheduleNotification_(notification)


def notificationBalloon(title,msg):
    notify(title1, msg1,"", sound=False) 

In eclipse, notifications arrive as expected, however an import error is generated in the lines:

NSUserNotification = objc.lookUpClass('NSUserNotification')
 NSUserNotificationCenter = objc.lookUpClass('NSUserNotificationCenter') 

but in the terminal these lines are well executed.

+4
source share
2 answers

, .lookUpClass() . , py2app. , .

, , objc . , virtualenv, py2app. python -m pydoc objc , , python setup.py py2app.

0

, python. Wx python - . :

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

: Apple , . . , , , python :

import subprocess

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

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

, . , , , . , :

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

0

All Articles