在python中,NSUserNotificationCenter.defaultUserNotificationCenter()不返回任何值

在python中,NSUserNotificationCenter.defaultUserNotificationCenter()不返回任何值,python,osx-mountain-lion,nsnotificationcenter,pyobjc,nsusernotificationcenter,Python,Osx Mountain Lion,Nsnotificationcenter,Pyobjc,Nsusernotificationcenter,我正在尝试通过python连接到山狮通知中心。我已经安装了pyobjc,并按照说明和。另见: 这是我的密码: import Foundation, objc import AppKit import sys NSUserNotification = objc.lookUpClass('NSUserNotification') NSUserNotificationCenter = objc.lookUpClass('NSUserNotificationCenter') def notify(t

我正在尝试通过python连接到山狮通知中心。我已经安装了pyobjc,并按照说明和。另见:

这是我的密码:

import Foundation, objc
import AppKit
import sys

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

def notify(title, subtitle, info_text, delay=0, sound=False, userInfo={}):
    """ Python method to show a desktop notification on Mountain Lion. Where:
        title: Title of notification
        subtitle: Subtitle of notification
        info_text: Informative text of notification
        delay: Delay (in seconds) before showing the notification
        sound: Play the default notification sound
        userInfo: a dictionary that can be used to handle clicks in your
                  app's applicationDidFinishLaunching:aNotification method
    """
    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)
当我使用参数调用notify函数时,我得到一个属性错误:

AttributeError:“非类型”对象没有属性“scheduleNotification”


我不明白为什么
NSUserNotificationCenter.defaultUserNotificationCenter()
返回一个非类型对象。我无法在互联网上查询任何关于这件事的信息

因此,使用Ned关于使用默认python的建议,这一点很好。当我在32位Enthound发行版上安装pyobjc时,它也起到了作用。在我看来,pyobjc只能在32位python发行版上工作(我无法确认这一点,但到目前为止似乎是这样)


(注意:当我发布这个问题时,我已经在64位Enthound发行版上安装了pyobjc)

你不能用三行代码(
import objc;NSUserNotificationCenter=objc.lookUpClass('NSUserNotificationCenter');print NSUserNotificationCenter.defaultUserNotificationCenter()
)而不是整个函数来复制这个吗?啊!我想我本可以的!FWIW,三行测试在我使用当前的MacPorts
python27
(@2.7.3_1)和
py27 pyobjc
(@2.5.1_0)时有效:它返回一个
\NSConcreteUserNotificationCenter
的实例。因此,三行测试在我使用当前苹果提供的系统Python2.7.2时也有效(
/usr/bin/python2.7
)在OS X 10.8.3中,Apple随系统Pythons提供了一个PyObjC版本。谢谢Ned!我注意到它在使用默认python 2.7.2时也适用于我。但是,当我在64位的Enthude python安装上使用easy_install安装PyObjC时,上面提到的问题就出现了。目前我想我将继续使用系统默认pythonn。但是,许多Apple框架无法正常工作,除非二进制文件在捆绑包(应用程序或插件)中。Enthught是安装框架还是只安装普通的unix发行版?这对我来说适用于使用pyobjc的本机安装和自定义的64位python安装。