source: kde/dbus/knotify-client@ 939

Last change on this file since 939 was 938, checked in by joergs, on Dec 8, 2010 at 4:08:14 PM

usable knotify handling

  • Property svn:executable set to *
File size: 2.4 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4import sys
5import dbus
6from pprint import pprint
7from time import sleep
8
9# since python 2.7
10#import argparse
11from optparse import OptionParser
12
13parser = OptionParser()
14#parser.add_argument('message', type=string, nargs='+',
15# help='message text to send')
16parser.add_option('--event', dest='event', default="notification",
17 help='event')
18parser.add_option('--app', dest='app', default="kde",
19 help='fromApp')
20parser.add_option('--title', dest='title', default=sys.argv[0],
21 help='event')
22parser.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
26print "options:"
27pprint(options)
28
29message = " ".join( args )
30
31print "message: ", message
32
33knotify = 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
55id = knotify.event( options.event, options.app, [], options.title, message, [], [], options.timeout, dbus_interface="org.kde.KNotify")
56
57if 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
76exit(0)
Note: See TracBrowser for help on using the repository browser.