GrowlNotifier class (Python)
Growl developer documentation
About
GrowlNotifier is a Python class that provides an interface to registering and posting notifications to Growl.
Usage
There are three different ways to use GrowlNotifier:
- Pass the relevant information to the initializer with keyed arguments.
- Pass no (or at least not all) of the relevant information to the initializer, and then assign the values to the object's attributes.
- Create a subclass and override some or all of the special class-level attributes.
The initializer keys and special class-level attributes are:
- applicationName
- The application name to register with
- notifications
- A list of notification names to register with
- defaultNotifications
- A list of notification names to enable by default
- applicationIcon
- An instance of Growl.Image to use as the icon for notifications that don't specify one
If defaultNotifications is omitted, it defaults to the value for notifications.
Any information passed in the initializer overrides any defined class-level attributes.
After you create an instance of GrowlNotifier or your custom subclass, but before posting any notifications, you must call the instance's register method. This will register your application and its notifications with Growl.
After you've registered with Growl, you can call the notify method to send a notification. This method takes three required arguments and two optional arguments. The required arguments are:
- noteType
- The name of the notification type
- title
- The title of the notification
- description
- The main text of the notification
The optional arguments are:
- icon
- An instance of Growl.Image to use as the icon for the notifications
- sticky
- A Boolean that controls the sticky state of the notification
If icon is omitted, applicationIcon is used.
Growl.Image
A Growl.Image instance represents an icon that will be used for a notification. Instances have no methods, and should be created using one of the following class methods:
- imageFromPath
- Return an image loaded from the specified file path.
- imageWithData
- Return an image loaded from the provided data. The data should be passed as a string, and may be in any format that Cocoa's NSImage understands. This includes PNG, TIFF, JPEG, GIF, PICT, PDF, BMP, and .icns.
- imageWithIconForFile
- Return an image initialized with the icon for the specified file.
- imageWithIconForFileType
- Return an image initialized with the icon for the specified type of file. The type may be given as a filename extension or an HFS file type (for example, text files can have a filename extension of 'txt' or an HFS file type of 'TEXT').
- imageWithIconForCurrentApplication
- Return an image initialized with the icon of the currently executing application.
- imageWithIconForApplication
- Return an image initialized with the icon for the specified application. Raises RuntimeError if the application cannot be found.
Note: Growl.Image requires access to the Window Server to function. Because of this requirement it should not be used in situations where access is not available, such as from system daemons or startup scripts.