1 | #!/usr/bin/env python
|
---|
2 | # -*- coding: utf-8 -*-
|
---|
3 |
|
---|
4 | import sys
|
---|
5 | import dbus
|
---|
6 | from pprint import pprint
|
---|
7 | from time import sleep
|
---|
8 |
|
---|
9 | # since python 2.7
|
---|
10 | #import argparse
|
---|
11 | from optparse import OptionParser
|
---|
12 |
|
---|
13 | parser = OptionParser()
|
---|
14 | #parser.add_argument('message', type=string, nargs='+',
|
---|
15 | # help='message text to send')
|
---|
16 | parser.add_option('--event', dest='event', default="notification",
|
---|
17 | help='event')
|
---|
18 | parser.add_option('--app', dest='app', default="kde",
|
---|
19 | help='fromApp')
|
---|
20 | parser.add_option('--title', dest='title', default=sys.argv[0],
|
---|
21 | help='event')
|
---|
22 | parser.add_option('--timeout', dest='timeout', type=int, default=0,
|
---|
23 | help='timeout in seconds. Without timeout, message will stay until it is confirmed, but ' + sys.argv[0] + ' will return immedialy')
|
---|
24 | (options, args) = parser.parse_args()
|
---|
25 |
|
---|
26 | print "options:"
|
---|
27 | pprint(options)
|
---|
28 |
|
---|
29 | message = " ".join( args )
|
---|
30 |
|
---|
31 | print "message: ", message
|
---|
32 |
|
---|
33 | knotify = dbus.SessionBus().get_object("org.kde.knotify", "/Notify")
|
---|
34 |
|
---|
35 |
|
---|
36 | # predefined notify settings, see
|
---|
37 | # find /usr/share/kde4/apps -name *.notifyrc
|
---|
38 | # grep -v '[a-z]\[' /usr/share/kde4/apps/kde/kde.notifyrc
|
---|
39 |
|
---|
40 | # interface for knotify,
|
---|
41 | # taken from knotify.h
|
---|
42 | # int event(
|
---|
43 | # const QString &event,
|
---|
44 | # const QString &fromApp,
|
---|
45 | # const QVariantList& contexts,
|
---|
46 | # const QString &title,
|
---|
47 | # const QString &text,
|
---|
48 | # const QByteArray& pixmap,
|
---|
49 | # const QStringList& actions,
|
---|
50 | # int timeout,
|
---|
51 | # qlonglong winId );
|
---|
52 |
|
---|
53 | # specifiing timeout as parameter does not show a effect,
|
---|
54 | # therefore notification is closed manually after timeout
|
---|
55 | id = knotify.event( options.event, options.app, [], options.title, message, [], [], options.timeout, dbus_interface="org.kde.KNotify")
|
---|
56 |
|
---|
57 | if options.timeout > 0:
|
---|
58 | print "Knotify-ID: ", id
|
---|
59 |
|
---|
60 | sleep(options.timeout)
|
---|
61 |
|
---|
62 | # void update(int id, const QString &title, const QString &text, const KNotifyImage& image, const QStringList& actions);
|
---|
63 | #knotify.update( id, "knotify-client", "finished", [], [], dbus_interface="org.kde.KNotify")
|
---|
64 |
|
---|
65 | #sleep( 1 )
|
---|
66 |
|
---|
67 | #for i in range(3):
|
---|
68 | #print i
|
---|
69 | #knotify.update( id, "knotify-client", str(i), [], [], dbus_interface="org.kde.KNotify")
|
---|
70 | ## void reemit(int id, const ContextList& contexts);
|
---|
71 | #knotify.reemit( id, [], dbus_interface="org.kde.KNotify" )
|
---|
72 | #sleep(3)
|
---|
73 |
|
---|
74 | knotify.closeNotification(id, dbus_interface="org.kde.KNotify");
|
---|
75 |
|
---|
76 | exit(0)
|
---|