当前位置: 首页>>代码示例>>Python>>正文


Python Foundation.NSUserNotification类代码示例

本文整理汇总了Python中Foundation.NSUserNotification的典型用法代码示例。如果您正苦于以下问题:Python NSUserNotification类的具体用法?Python NSUserNotification怎么用?Python NSUserNotification使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了NSUserNotification类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _pyobjc_notify

            def _pyobjc_notify(message, title=None, subtitle=None, appIcon=None, contentImage=None, open_URL=None, delay=0, sound=False):

                swizzle(objc.lookUpClass('NSBundle'),
                        b'bundleIdentifier',
                        swizzled_bundleIdentifier)
                notification = NSUserNotification.alloc().init()
                notification.setInformativeText_(message)
                if title:
                    notification.setTitle_(title)
                if subtitle:
                    notification.setSubtitle_(subtitle)
                if appIcon:
                    url = NSURL.alloc().initWithString_(appIcon)
                    image = NSImage.alloc().initWithContentsOfURL_(url)
                    notification.set_identityImage_(image)
                if contentImage:
                    url = NSURL.alloc().initWithString_(contentImage)
                    image = NSImage.alloc().initWithContentsOfURL_(url)
                    notification.setContentImage_(image)

                if sound:
                    notification.setSoundName_(
                        "NSUserNotificationDefaultSoundName")
                notification.setDeliveryDate_(
                    NSDate.dateWithTimeInterval_sinceDate_(delay, NSDate.date()))
                NSUserNotificationCenter.defaultUserNotificationCenter().scheduleNotification_(
                    notification)
开发者ID:felixonmars,项目名称:pyfm,代码行数:27,代码来源:notifier.py

示例2: notify

        def notify(self, title, subtitle, text):
            """Create a user notification and display it."""

             # if appImage:
             #    source_img = AppKit.NSImage.alloc().initByReferencingFile_(appImage)
             #    notification.set_identityImage_(source_img)
             # if contentImage:
             #    source_img = AppKit.NSImage.alloc().initBy
            #     notification.setContentImage_(source_img)

            notification = NSUserNotification.alloc().init()
            notification.setTitle_(str(title))
            notification.setSubtitle_(str(subtitle))
            notification.setInformativeText_(str(text))
            notification.setSoundName_("NSUserNotificationDefaultSoundName")

            # notification.set_showsButtons_(True)
            # notification.setHasActionButton_(True)
            # notification.setHasReplyButton_ (True) # this will allow the user to enter text to "reply"
            # notification.setActionButtonTitle_("View")
            # notification.setUserInfo_({"action":"open_url", "value":url})

            NSUserNotificationCenter.defaultUserNotificationCenter().setDelegate_(self)
            NSUserNotificationCenter.defaultUserNotificationCenter().scheduleNotification_(notification)

            # Note that the notification center saves a *copy* of our object.
            AppHelper.runConsoleEventLoop()
开发者ID:thehesiod,项目名称:511.org-driving-time,代码行数:27,代码来源:511_time.py

示例3: notification

def notification(title, subtitle, message, data=None, sound=True, image=None):
    """Send a notification to Notification Center (Mac OS X 10.8+). If running on a version of Mac OS X that does not
    support notifications, a ``RuntimeError`` will be raised. Apple says,

        "The userInfo content must be of reasonable serialized size (less than 1k) or an exception will be thrown."

    So don't do that!

    :param title: text in a larger font.
    :param subtitle: text in a smaller font below the `title`.
    :param message: text representing the body of the notification below the `subtitle`.
    :param data: will be passed to the application's "notification center" (see :func:`rumps.notifications`) when this
                 notification is clicked.
    :param sound: whether the notification should make a noise when it arrives.
    """
    if not _NOTIFICATIONS:
        raise RuntimeError('Mac OS X 10.8+ is required to send notifications')
    if data is not None and not isinstance(data, Mapping):
        raise TypeError('notification data must be a mapping')
    _require_string_or_none(title, subtitle, message)
    notification = NSUserNotification.alloc().init()
    notification.setTitle_(title)
    notification.setSubtitle_(subtitle)
    notification.setInformativeText_(message)
    notification.setUserInfo_({} if data is None else data)
    if sound:
        notification.setSoundName_("NSUserNotificationDefaultSoundName")
    if image != None:
        notification.setContentImage_(image)
    notification.setDeliveryDate_(NSDate.dateWithTimeInterval_sinceDate_(0, NSDate.date()))
    NSUserNotificationCenter.defaultUserNotificationCenter().scheduleNotification_(notification)
开发者ID:4m1g0,项目名称:duplicati,代码行数:31,代码来源:rumps.py

示例4: notify

def notify(
    title: str,
    subtitle: str,
    info_text: str,
    delay: int = 0,
    sound: bool = False,
    user_info: Dict[str, str] = None,
) -> None:
    """ 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)
    user_info = user_info or {}
    notification.setUserInfo_(user_info)
    if sound:
        notification.setSoundName_("NSUserNotificationDefaultSoundName")
    center = NSUserNotificationCenter.defaultUserNotificationCenter()
    if center is not None:
        center.deliverNotification_(notification)
开发者ID:nuxeo,项目名称:nuxeo-drive,代码行数:28,代码来源:pyNotificationCenter.py

示例5: alert

def alert(content, title=ALERT_TITLE, icon=None, sound=ALERT_SOUND):
    notification = NSUserNotification.alloc().init()
    notification.setTitle_('{0} @ {1}'.format(title, timestamp()))
    notification.setInformativeText_(content)
    if sound:
        notification.setSoundName_('NSUserNotificationDefaultSoundName')
    NOTIFICATION_CENTER.deliverNotification_(notification)
开发者ID:MediaPreneur,项目名称:security-growler,代码行数:7,代码来源:osxnotifications.py

示例6: notify

def notify(title, subtitle, text):
    notification = NSUserNotification.alloc().init()
    notification.setTitle_(str(title))
    notification.setSubtitle_(str(subtitle))
    notification.setInformativeText_(str(text))
    notification.setSoundName_("NSUserNotificationDefaultSoundName")
    NSUserNotificationCenter.defaultUserNotificationCenter().scheduleNotification_(notification)
开发者ID:answerware,项目名称:scriptingosx-recipes,代码行数:7,代码来源:Notification.py

示例7: notify

def notify(text):

    notification = NSUserNotification.alloc().init()
    notification.setTitle_('Clipbox')
    notification.setInformativeText_(text)
    center = NSUserNotificationCenter.defaultUserNotificationCenter()
    center.deliverNotification_(notification)
开发者ID:emeth-,项目名称:Clipbox,代码行数:7,代码来源:clipbox.py

示例8: send_OS_X_notify

def send_OS_X_notify(title, content, img_path):
    '''发送Mac桌面通知'''
    def swizzle(cls, SEL, func):
        old_IMP = cls.instanceMethodForSelector_(SEL)

        def wrapper(self, *args, **kwargs):
            return func(self, old_IMP, *args, **kwargs)
        new_IMP = objc.selector(wrapper, selector=old_IMP.selector,
                                signature=old_IMP.signature)
        objc.classAddMethod(cls, SEL, new_IMP)

    def swizzled_bundleIdentifier(self, original):
        # Use iTunes icon for notification
        return 'com.apple.itunes'

    swizzle(objc.lookUpClass('NSBundle'),
            b'bundleIdentifier',
            swizzled_bundleIdentifier)
    notification = NSUserNotification.alloc().init()
    notification.setInformativeText_('')
    notification.setTitle_(title.decode('utf-8'))
    notification.setSubtitle_(content.decode('utf-8'))

    notification.setInformativeText_('')
    notification.setUserInfo_({})
    if img_path is not None:
        image = NSImage.alloc().initWithContentsOfFile_(img_path)
        # notification.setContentImage_(image)
        notification.set_identityImage_(image)
    notification.setDeliveryDate_(
            NSDate.dateWithTimeInterval_sinceDate_(0, NSDate.date())
    )
    NSUserNotificationCenter.defaultUserNotificationCenter().\
        scheduleNotification_(notification)
开发者ID:cckiss,项目名称:douban.fm-1,代码行数:34,代码来源:notification.py

示例9: notify

 def notify(content="", title="Security Notification", icon=None, sound=None):
     if content:
         log("[>] secnotify[%s]: %s" % (title, content))
         notification = NSUserNotification.alloc().init()
         notification.setTitle_(title)
         notification.setInformativeText_(content)
         center = NSUserNotificationCenter.defaultUserNotificationCenter()
         center.deliverNotification_(notification)
开发者ID:cudevops,项目名称:security-growler,代码行数:8,代码来源:growler.py

示例10: alert

 def alert(content="", title="SECURITY ALERT", icon=None, sound=None):
     if content:
         log("[>] secalert[%s]: %s" % (title, content))
         notification = NSUserNotification.alloc().init()
         notification.setTitle_(title)
         notification.setInformativeText_(content)
         center = NSUserNotificationCenter.defaultUserNotificationCenter()
         center.deliverNotification_(notification)
开发者ID:cudevops,项目名称:security-growler,代码行数:8,代码来源:growler.py

示例11: notify

 def notify(self, title, subtitle, text, url):
     notification = NSUserNotification.alloc().init()
     notification.setTitle_(str(title))
     notification.setSubtitle_(str(subtitle))
     notification.setInformativeText_(str(text))
     notification.setSoundName_("NSUserNotificationDefaultSoundName")
     notification.setUserInfo_({"action": "open_url", "value": url})
     NSUserNotificationCenter.defaultUserNotificationCenter().setDelegate_(self)
     NSUserNotificationCenter.defaultUserNotificationCenter().scheduleNotification_(notification)
开发者ID:rvpradeep,项目名称:Python-UI,代码行数:9,代码来源:native.py

示例12: osx_message

    def osx_message(self, title, message):
        # based on:
        # https://gist.github.com/baliw/4020619
        # http://stackoverflow.com/questions/17651017/python-post-osx-notification
        notification = NSUserNotification.alloc().init()
        notification.setTitle_(title)
        notification.setInformativeText_(message)

        center = NSUserNotificationCenter.defaultUserNotificationCenter()
        center.deliverNotification_(notification)
开发者ID:8cylinder,项目名称:tv-overlord,代码行数:10,代码来源:notify.py

示例13: notify

    def notify(self, title, message, sound):

        notification = NSUserNotification.alloc().init()
        notification.setTitle_(title)
        notification.setInformativeText_(message)
        if sound:
            notification.setSoundName_(NSUserNotificationDefaultSoundName)

        center = NSUserNotificationCenter.defaultUserNotificationCenter()
        center.deliverNotification_(notification)
开发者ID:ravikumarrvit,项目名称:cric-highlights-notifier,代码行数:10,代码来源:MacNotifier.py

示例14: alert

def alert(title,message):
    ''' Send the desktop notification. '''

    notification = NSUserNotification.alloc().init()
    notification.setTitle_(title)
    notification.setInformativeText_(message)
    notification.setSoundName_(NSUserNotificationDefaultSoundName)

    center = NSUserNotificationCenter.defaultUserNotificationCenter()
    center.deliverNotification_(notification)
开发者ID:dcarrollno,项目名称:Ganglia-Modules,代码行数:10,代码来源:osx_notify.py

示例15: notify

def notify(title, subtitle, text, fileType = None):
    notification = NSUserNotification.alloc().init()
    notification.setTitle_(str(title))
    notification.setSubtitle_(str(subtitle))
    notification.setInformativeText_(str(text))
    notification.setSoundName_("NSUserNotificationDefaultSoundName")
    if fileType is not None:
        file_icon = NSWorkspace.sharedWorkspace().iconForFileType_(fileType)
        notification.setContentImage_(file_icon)
    NSUserNotificationCenter.defaultUserNotificationCenter().scheduleNotification_(notification)
开发者ID:autopkg,项目名称:scriptingosx-recipes,代码行数:10,代码来源:Notification.py


注:本文中的Foundation.NSUserNotification类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。