4
from optparse import OptionParser
9
ICON_ONLY_HINT = "x-canonical-private-icon-only"
10
APPEND_HINT = "x-canonical-append"
11
SYNCHRONOUS_HINT = "x-canonical-private-synchronous"
14
def create_gauge_notification(title, icon, value):
15
n = pynotify.Notification(title, "", icon)
16
n.set_hint_string(SYNCHRONOUS_HINT, "")
17
n.set_hint_int32(VALUE_HINT, value)
20
def create_icon_only_notification(title, icon):
21
n = pynotify.Notification(title, "", icon)
22
n.set_hint_string(ICON_ONLY_HINT, "")
26
"""%prog [options] <title> [<body-text>]
28
If body-text is "-" %prog will display the content of stdin.
32
if not pynotify.init("notifyosd"):
35
parser = OptionParser()
38
parser.add_option("-i", "--icon", dest="icon",
39
help = "Name of the icon to show")
41
parser.add_option("--icon-data", dest="icon_data",
42
help = "Load icon data from a custom file")
44
parser.add_option("-v", "--value", dest="value",
45
help = "Start in value mode and display the percentage VALUE in a gauge")
47
parser.add_option("--icon-only", dest="icon_only",
48
help = "Only show icon, ignoring body",
49
action="store_true", default=False)
51
(options, args) = parser.parse_args()
60
body = sys.stdin.read()
62
body = " ".join(args[1:])
68
print "Note: ignoring body in value mode"
69
n = create_gauge_notification(title, options.icon, int(options.value))
70
elif options.icon_only:
72
print "Note: ignoring body in icon_only mode"
74
print "Error: icon name is missing"
76
n = create_icon_only_notification(title, options.icon)
78
n = pynotify.Notification(title, body, options.icon)
81
pixbuf = gtk.gdk.pixbuf_new_from_file(options.icon_data)
82
n.set_icon_from_pixbuf(pixbuf)
86
if __name__ == "__main__":