덮어 쓰기 - (하지만 파이썬 & PyObjC에서이 작업을 수행하는 방법에 대한 답변을 찾는 사람들이있을 수 있습니다 나는 여기에 올바른 구문을 게시 할 예정입니다 그것은 최고의 Google 검색 결과 중 하나입니다.) imp의 주석에 대해서는 언급 할 수 없기 때문에 이것을 다른 답변으로 게시 할 것입니다.
그것은 pyobjc 파이썬에서이 방법으로 동일한 작업을 수행하는 것이 가능하다 :
def userNotificationCenter_shouldPresentNotification_(self, center, notification):
return True
이
전체 클래스는 다음과 같이 보일 것이다 :
from Cocoa import NSObject
import objc
class MountainLionNotification(NSObject):
""" MacOS Notifications """
# Based on http://stackoverflow.com/questions/12202983/working-with-mountain-lions-notification-center-using-pyobjc
def userNotificationCenter_shouldPresentNotification_(self, center, notification):
return True
def init(self):
self = super(MountainLionNotification, self).init()
if self is None: return None
# Get objc references to the classes we need.
self.NSUserNotification = objc.lookUpClass('NSUserNotification')
self.NSUserNotificationCenter = objc.lookUpClass('NSUserNotificationCenter')
return self
def clearNotifications(self):
"""Clear any displayed alerts we have posted. Requires Mavericks."""
NSUserNotificationCenter = objc.lookUpClass('NSUserNotificationCenter')
NSUserNotificationCenter.defaultUserNotificationCenter().removeAllDeliveredNotifications()
def notify(self, title="", subtitle="", text="", url=""):
"""Create a user notification and display it."""
notification = self.NSUserNotification.alloc().init()
notification.setTitle_(str(title))
notification.setSubtitle_(str(subtitle))
notification.setInformativeText_(str(text))
# notification.setSoundName_("NSUserNotificationDefaultSoundName")
notification.setHasActionButton_(False)
notification.setActionButtonTitle_("View")
# notification.setUserInfo_({"action":"open_url", "value": url})
self.NSUserNotificationCenter.defaultUserNotificationCenter().setDelegate_(self)
self.NSUserNotificationCenter.defaultUserNotificationCenter().scheduleNotification_(notification)
# Note that the notification center saves a *copy* of our object.
return notification
당신이 전체 샘플을 추가 할 수 있습니다를, 난을 잘 모르겠어요 그 줄을 어디에 둘 것인지 이해하십시오. –
큰 감사드립니다. 흥미로운 것은 대리자를 설정하지 않고이 메서드를 구현하면 알림 센터에 알림이 표시되지만 표시되지 않는다는 것입니다. – Ants
@Ants Python에서 델리게이트를 설정하는 방법 – imp