當前位置: 首頁>>代碼示例>>Python>>正文


Python NSUserNotificationCenter.defaultUserNotificationCenter方法代碼示例

本文整理匯總了Python中Foundation.NSUserNotificationCenter.defaultUserNotificationCenter方法的典型用法代碼示例。如果您正苦於以下問題:Python NSUserNotificationCenter.defaultUserNotificationCenter方法的具體用法?Python NSUserNotificationCenter.defaultUserNotificationCenter怎麽用?Python NSUserNotificationCenter.defaultUserNotificationCenter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Foundation.NSUserNotificationCenter的用法示例。


在下文中一共展示了NSUserNotificationCenter.defaultUserNotificationCenter方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: run

# 需要導入模塊: from Foundation import NSUserNotificationCenter [as 別名]
# 或者: from Foundation.NSUserNotificationCenter import defaultUserNotificationCenter [as 別名]
    def run(self, **options):
        """Performs various setup tasks including creating the underlying Objective-C application, starting the timers,
        and registering callback functions for click events. Then starts the application run loop.

        .. versionchanged:: 0.2.1
            Accepts `debug` keyword argument.

        :param debug: determines if application should log information useful for debugging. Same effect as calling
                      :func:`rumps.debug_mode`.

        """
        dont_change = object()
        debug = options.get('debug', dont_change)
        if debug is not dont_change:
            debug_mode(debug)

        nsapplication = NSApplication.sharedApplication()
        nsapplication.activateIgnoringOtherApps_(True)  # NSAlerts in front
        self._nsapp = NSApp.alloc().init()
        self._nsapp._app = self.__dict__  # allow for dynamic modification based on this App instance
        nsapplication.setDelegate_(self._nsapp)
        if _NOTIFICATIONS:
            NSUserNotificationCenter.defaultUserNotificationCenter().setDelegate_(self._nsapp)

        setattr(App, '*app_instance', self)  # class level ref to running instance (for passing self to App subclasses)
        t = b = None
        for t in getattr(timer, '*timers', []):
            t.start()
        for b in getattr(clicked, '*buttons', []):
            b(self)  # we waited on registering clicks so we could pass self to access _menu attribute
        del t, b

        self._nsapp.initializeStatusBar()

        AppHelper.runEventLoop()
開發者ID:4m1g0,項目名稱:duplicati,代碼行數:37,代碼來源:rumps.py

示例2: notify

# 需要導入模塊: from Foundation import NSUserNotificationCenter [as 別名]
# 或者: from Foundation.NSUserNotificationCenter import defaultUserNotificationCenter [as 別名]
        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,代碼行數:29,代碼來源:511_time.py

示例3: _pyobjc_notify

# 需要導入模塊: from Foundation import NSUserNotificationCenter [as 別名]
# 或者: from Foundation.NSUserNotificationCenter import defaultUserNotificationCenter [as 別名]
            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,代碼行數:29,代碼來源:notifier.py

示例4: notification

# 需要導入模塊: from Foundation import NSUserNotificationCenter [as 別名]
# 或者: from Foundation.NSUserNotificationCenter import defaultUserNotificationCenter [as 別名]
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,代碼行數:33,代碼來源:rumps.py

示例5: notify

# 需要導入模塊: from Foundation import NSUserNotificationCenter [as 別名]
# 或者: from Foundation.NSUserNotificationCenter import defaultUserNotificationCenter [as 別名]
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,代碼行數:9,代碼來源:Notification.py

示例6: send_OS_X_notify

# 需要導入模塊: from Foundation import NSUserNotificationCenter [as 別名]
# 或者: from Foundation.NSUserNotificationCenter import defaultUserNotificationCenter [as 別名]
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,代碼行數:36,代碼來源:notification.py

示例7: notify

# 需要導入模塊: from Foundation import NSUserNotificationCenter [as 別名]
# 或者: from Foundation.NSUserNotificationCenter import defaultUserNotificationCenter [as 別名]
 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,代碼行數:11,代碼來源:native.py

示例8: alert

# 需要導入模塊: from Foundation import NSUserNotificationCenter [as 別名]
# 或者: from Foundation.NSUserNotificationCenter import defaultUserNotificationCenter [as 別名]
    def alert(self, title, subtitle, message, delay=0, sound=False, userInfo={}):
        self.notification.setTitle_(title)
        self.notification.setSubtitle_(subtitle)
        self.notification.setInformativeText_(message)
        self.notification.setDeliveryDate_(NSDate.dateWithTimeInterval_sinceDate_(delay, NSDate.date()))
#        self.notification.setUserInfo_(userInfo)
        if sound:
            self.notification.setSoundName_("NSUserNotificationDefaultSoundName")
        NSUserNotificationCenter.defaultUserNotificationCenter().scheduleNotification_(self.notification)
開發者ID:chilcote,項目名稱:pylab,代碼行數:11,代碼來源:pynotify.py

示例9: notify

# 需要導入模塊: from Foundation import NSUserNotificationCenter [as 別名]
# 或者: from Foundation.NSUserNotificationCenter import defaultUserNotificationCenter [as 別名]
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,代碼行數:12,代碼來源:Notification.py

示例10: writeFont_error_

# 需要導入模塊: from Foundation import NSUserNotificationCenter [as 別名]
# 或者: from Foundation.NSUserNotificationCenter import defaultUserNotificationCenter [as 別名]
	def writeFont_error_(self, font, error):
		"""
		EXPORT dialog

		This method is called when the Next button is pressed in the Export dialog,
		and should ask the user for the place to store the font (not necessarily, you could choose to hard-wire the destination in the code).

		Parameters:
		- font: The font object to export
		- error: PyObjc-Requirement. It is required here in order to return the error object upon export failure. Ignore its existence here.

		return (True, None) if the export was successful
		return (False, NSError) if the export failed
		"""
		try:

			returnStatus, returnMessage = [False, 'export() is not implemented in the plugin.']
			if hasattr(self, 'export'):
				returnStatus, returnMessage = self.export(font)

			# Export successful
			# Change the condition (True) to your own assessment on whether or not the export succeeded
			if returnStatus:
				# Use Mac Notification Center
				notification = NSUserNotification.alloc().init()
				notification.setTitle_(self.title())
				notification.setInformativeText_(returnMessage)
				NSUserNotificationCenter.defaultUserNotificationCenter().scheduleNotification_(notification)

				return (True, None)

			# Export failed, give reason
			else:
				error = NSError.errorWithDomain_code_userInfo_(self.title(), -57, {
					NSLocalizedDescriptionKey: NSLocalizedString('Export failed', None),
					NSLocalizedRecoverySuggestionErrorKey: returnMessage
				})
				return (False, error)

		# Python exception, return error message
		except Exception as e:
			self.logError(traceback.format_exc())
			error = NSError.errorWithDomain_code_userInfo_(self.title(), -57, {
				NSLocalizedDescriptionKey: NSLocalizedString('Python exception', None),
				NSLocalizedRecoverySuggestionErrorKey: str(e) + '\nCheck Macro window output.'
			})
			return (False, error)
		return True
開發者ID:schriftgestalt,項目名稱:GlyphsSDK,代碼行數:50,代碼來源:plugins.py

示例11: notify

# 需要導入模塊: from Foundation import NSUserNotificationCenter [as 別名]
# 或者: from Foundation.NSUserNotificationCenter import defaultUserNotificationCenter [as 別名]
def notify(text):

    notification = NSUserNotification.alloc().init()
    notification.setTitle_('Clipbox')
    notification.setInformativeText_(text)
    center = NSUserNotificationCenter.defaultUserNotificationCenter()
    center.deliverNotification_(notification)
開發者ID:emeth-,項目名稱:Clipbox,代碼行數:9,代碼來源:clipbox.py

示例12: notification

# 需要導入模塊: from Foundation import NSUserNotificationCenter [as 別名]
# 或者: from Foundation.NSUserNotificationCenter import defaultUserNotificationCenter [as 別名]
def notification(title, subtitle, message, data=None, sound=True):
    """
    Notification sender. 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!
    """
    if data is not None and not isinstance(data, Mapping):
        raise TypeError('notification data must be a mapping')
    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")
    notification.setDeliveryDate_(NSDate.dateWithTimeInterval_sinceDate_(0, NSDate.date()))
    NSUserNotificationCenter.defaultUserNotificationCenter().scheduleNotification_(notification)
開發者ID:philippeowagner,項目名稱:rumps,代碼行數:18,代碼來源:rumps.py

示例13: notify

# 需要導入模塊: from Foundation import NSUserNotificationCenter [as 別名]
# 或者: from Foundation.NSUserNotificationCenter import defaultUserNotificationCenter [as 別名]
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,代碼行數:30,代碼來源:pyNotificationCenter.py

示例14: notify

# 需要導入模塊: from Foundation import NSUserNotificationCenter [as 別名]
# 或者: from Foundation.NSUserNotificationCenter import defaultUserNotificationCenter [as 別名]
 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,代碼行數:10,代碼來源:growler.py

示例15: send_OS_X_notify

# 需要導入模塊: from Foundation import NSUserNotificationCenter [as 別名]
# 或者: from Foundation.NSUserNotificationCenter import defaultUserNotificationCenter [as 別名]
def send_OS_X_notify(title, content, img_path):
    '''發送Mac桌麵通知'''
    try:
        from Foundation import (
            NSDate, NSUserNotification, NSUserNotificationCenter)
        from AppKit import NSImage
        import objc
    except ImportError:
        logger.info('failed to init OSX notify!')
        return

    def swizzle(cls, SEL, func):
        old_IMP = getattr(cls, SEL, None)

        if old_IMP is None:
            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.encode(), new_IMP)

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

    swizzle(objc.lookUpClass('NSBundle'),
            'bundleIdentifier',
            swizzled_bundleIdentifier)
    notification = NSUserNotification.alloc().init()

    notification.setTitle_(title)
    notification.setSubtitle_(content)
    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)
    logger.info('send notify success!')
開發者ID:PDonin,項目名稱:douban.fm,代碼行數:48,代碼來源:notification.py


注:本文中的Foundation.NSUserNotificationCenter.defaultUserNotificationCenter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。