NSUserNotification无法使用wx.app.MainLoop()方法

时间:2013-05-08 14:18:56

标签: python wxpython pyobjc

以下是使用PyObjC界面显示桌面通知的简单代码。当我在没有wx.app.MainLoop()的情况下调用notify方法时,它工作正常,但是没有wx.app.MainLoop()。

import Foundation, objc

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

def notify(title, subtitle, info_text, delay=0, sound=False, userInfo={}):

  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)


if __name__ == '__main__':
    app = wx.App()
    notify("Notify Tittle", "Notify Subtitle", "Notify body")
    app.MainLoop()    # commenting this line shows the desktop notification

0 个答案:

没有答案