NotificationCenter

Direct creation of and interation with these objects will most likely be rare as they are automatically handled by BaseObject.

NotificationCenter

class defcon.tools.notifications.NotificationCenter
addObserver(observer, methodName, notification=None, observable=None, identifier=None)

Add an observer to this notification dispatcher.

  • observer An object that can be referenced with weakref.
  • methodName A string representing the method to be called when the notification is posted.
  • notification The notification that the observer should be notified of. If this is None, all notifications for the observable will be posted to observer.
  • observable The object to observe. If this is None, all notifications with the name provided as notification will be posted to the observer.
  • identifier None or a string identifying the observation. There is no requirement that the string be unique. A reverse domain naming scheme is recommended, but there are no requirements for the structure of the string.

If None is given for both notification and observable all notifications posted will be sent to the given method of the observer.

The method that will be called as a result of the action must accept a single notification argument. This will be a Notification object.

areNotificationsDisabled(observable=None, notification=None, observer=None)

Returns a boolean indicating if notifications posted to all objects observing notification in observable are disabled.

  • observable The object that the notification belongs to. This is optional.
  • notification The name of the notification. This is optional.
  • observer The observer. This is optional.
areNotificationsHeld(observable=None, notification=None, observer=None)

Returns a boolean indicating if notifications posted to all objects observing notification in observable are being held.

  • observable The object that the notification belongs to. This is optional.
  • notification The name of the notification. This is optional.
  • observer The observer. This is optional.
disableNotifications(observable=None, notification=None, observer=None)

Disable all posts of notification from observable posted to observer observing.

  • observable The object that the notification belongs to. This is optional. If no observable is given, all notifications will be disabled for observer.
  • notification The name of the notification. This is optional. If no notification is given, all notifications for observable will be disabled for observer.
  • observer The specific observer to not send posts to. If no observer is given, the appropriate notifications will not be posted to any observers.

This object will retain a count of how many times it has been told to disable notifications for notification and observable. It will not enable new notifications until the notification and observable have been released the same number of times.

enableNotifications(observable=None, notification=None, observer=None)

Enable notifications posted to all objects observing notification in observable.

  • observable The object that the notification belongs to. This is optional.
  • notification The name of the notification. This is optional.
  • observer The observer. This is optional.
findObservations(observer=None, notification=None, observable=None, identifier=None)

Find observations matching the given arguments based on the values that were passed during addObserver. A value of None for any of these indicates that all should be considered to match the value. In the case of identifier, strings will be matched using fnmatch.fnmatchcase. The returned value will be a list of dictionaries with this format:

[
{
observer=<…> observable=<…> methodName=”…” notification=”…” identifier=”…”

}

]

getHeldNotificationNotes(observable=None, notification=None, observer=None)

Returns a list of notes defined for notification holds observing notification in observable are being held.

  • observable The object that the notification belongs to. This is optional.
  • notification The name of the notification. This is optional.
  • observer The observer. This is optional.
getHeldNotifications()

Returns a list of all held notifications. This will be a tuple of the form:

(notification, observable, observer)

hasObserver(observer, notification, observable)

Returns a boolean indicating if the observer is registered for notification posted by observable. Either observable or notification may be None.

holdNotifications(observable=None, notification=None, observer=None, note=None)

Hold all notifications posted to all objects observing notification in observable.

  • observable The object that the notification belongs to. This is optional. If no observable is given, all notifications will be held.
  • notification The name of the notification. This is optional. If no notification is given, all notifications for observable will be held.
  • observer The specific observer to not hold notifications for. If no observer is given, the appropriate notifications will be held for all observers.
  • note An arbitrary string containing information about why the hold has been requested, the requester, etc. This is used for reference only.

Held notifications will be posted after the matching notification and observable have been passed to Notification.releaseHeldNotifications(). This object will retain a count of how many times it has been told to hold notifications for notification and observable. It will not post the notifications until the notification and observable have been released the same number of times.

releaseHeldNotifications(observable=None, notification=None, observer=None)

Release all held notifications posted to all objects observing notification in observable.

  • observable The object that the notification belongs to. This is optional.
  • notification The name of the notification. This is optional.
  • observer The observer. This is optional.
removeObserver(observer, notification, observable=None)

Remove an observer from this notification dispatcher.

  • observer A registered object.
  • notification The notification that the observer was registered to be notified of. If this is “all”, all notifications for the observable will be removed for observer.
  • observable The object being observed.

Notification

class defcon.tools.notifications.Notification(name, objRef, data)

An object that wraps notification data.

data

Arbitrary data passed along with the notification. There is no set format for this data and there is not requirement that any data be present. Refer to the documentation for methods that are responsible for generating notifications for information about this data.

name

The notification name. A string.

object

The observable object the notification belongs to.