#!/usr/bin/env python # -*- coding: utf-8 -*- """ knotify-client sends messages to the KDE knotify daemon. KDE applications can define different types of messages and theses types define different actions (display message, play sound, start program, ...) tested on KDE 4.3.5 (openSUSE 11.2) """ # $Id: knotify-client 940 2010-12-09 19:25:47Z joergs $ import sys import dbus from os import system from pprint import pprint from time import sleep # since python 2.7 #import argparse from optparse import OptionParser parser = OptionParser(usage = "\n %prog [options] 'text message to send to knotify'\n %prog --appevents APPLICATION") #parser.add_argument('message', type=string, nargs='+', # help='message text to send') parser.add_option('--event', dest='event', default="notification", help='event (default: %default). Use --appevents to get list of events') parser.add_option('--app', dest='application', default="kde", help='event from application (default: %default)') parser.add_option('--title', dest='title', default=sys.argv[0], help='text in title of knotify message') parser.add_option('--timeout', dest='timeout', type=int, default=0, help='timeout in seconds. Without timeout, message will stay until it is confirmed, but ' + sys.argv[0] + ' will return immedialy') parser.add_option('--appevents', metavar='APPLICATION', dest='appevents', help='print list of events for application') (options, args) = parser.parse_args() print "options:" pprint(options) if options.appevents: ressource = options.appevents + "/" + options.appevents + ".notifyrc" system("kread-ressource.py --type data " + ressource ) exit(0) message = " ".join( args ) print "message: ", message knotify = dbus.SessionBus().get_object("org.kde.knotify", "/Notify") # predefined notify settings, see # find /usr/share/kde4/apps -name *.notifyrc # grep -v '[a-z]\[' /usr/share/kde4/apps/kde/kde.notifyrc # interface for knotify, # taken from knotify.h # int event( # const QString &event, # const QString &fromApp, # const QVariantList& contexts, # const QString &title, # const QString &text, # const QByteArray& pixmap, # const QStringList& actions, # int timeout, # qlonglong winId ); # specifiing timeout as parameter does not show a effect, # therefore notification is closed manually after timeout id = knotify.event( options.event, options.application, [], options.title, message, [], [], options.timeout, dbus_interface="org.kde.KNotify") if options.timeout > 0: print "Knotify-ID: ", id sleep(options.timeout) # void update(int id, const QString &title, const QString &text, const KNotifyImage& image, const QStringList& actions); #knotify.update( id, "knotify-client", "finished", [], [], dbus_interface="org.kde.KNotify") #sleep( 1 ) #for i in range(3): #print i #knotify.update( id, "knotify-client", str(i), [], [], dbus_interface="org.kde.KNotify") ## void reemit(int id, const ContextList& contexts); #knotify.reemit( id, [], dbus_interface="org.kde.KNotify" ) #sleep(3) knotify.closeNotification(id, dbus_interface="org.kde.KNotify"); exit(0)