PyObjC インターフェイスを使用してデスクトップ通知を表示する簡単なコードを次に示します。wx.app.MainLoop() なしで通知メソッドを呼び出すと正常に動作しますが、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