source: kde/dbus/knotify-client@ 1165

Last change on this file since 1165 was 940, checked in by joergs, on Dec 9, 2010 at 8:25:47 PM

cleanup, added comments, get list of events

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 3.2 KB
RevLine 
[935]1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
[940]4"""
5knotify-client sends messages to the KDE knotify daemon.
6KDE applications can define different types of messages
7and theses types define different actions
8(display message, play sound, start program, ...)
9
10tested on KDE 4.3.5 (openSUSE 11.2)
11"""
12
13# $Id: knotify-client 940 2010-12-09 19:25:47Z joergs $
14
15
[935]16import sys
17import dbus
[940]18from os import system
[938]19from pprint import pprint
20from time import sleep
[935]21
[938]22# since python 2.7
23#import argparse
24from optparse import OptionParser
[935]25
[940]26
27parser = OptionParser(usage = "\n %prog [options] 'text message to send to knotify'\n %prog --appevents APPLICATION")
[938]28#parser.add_argument('message', type=string, nargs='+',
29# help='message text to send')
30parser.add_option('--event', dest='event', default="notification",
[940]31 help='event (default: %default). Use --appevents to get list of events')
32parser.add_option('--app', dest='application', default="kde",
33 help='event from application (default: %default)')
[938]34parser.add_option('--title', dest='title', default=sys.argv[0],
[940]35 help='text in title of knotify message')
[938]36parser.add_option('--timeout', dest='timeout', type=int, default=0,
37 help='timeout in seconds. Without timeout, message will stay until it is confirmed, but ' + sys.argv[0] + ' will return immedialy')
[940]38parser.add_option('--appevents', metavar='APPLICATION', dest='appevents',
39 help='print list of events for application')
[938]40(options, args) = parser.parse_args()
41
42print "options:"
43pprint(options)
44
[940]45if options.appevents:
46 ressource = options.appevents + "/" + options.appevents + ".notifyrc"
47 system("kread-ressource.py --type data " + ressource )
48 exit(0)
49
[938]50message = " ".join( args )
51
52print "message: ", message
53
[935]54knotify = dbus.SessionBus().get_object("org.kde.knotify", "/Notify")
55
[938]56
57# predefined notify settings, see
58# find /usr/share/kde4/apps -name *.notifyrc
59# grep -v '[a-z]\[' /usr/share/kde4/apps/kde/kde.notifyrc
60
[935]61# interface for knotify,
62# taken from knotify.h
63# int event(
64# const QString &event,
65# const QString &fromApp,
[938]66# const QVariantList& contexts,
[935]67# const QString &title,
68# const QString &text,
69# const QByteArray& pixmap,
70# const QStringList& actions,
71# int timeout,
72# qlonglong winId );
73
[938]74# specifiing timeout as parameter does not show a effect,
75# therefore notification is closed manually after timeout
[940]76id = knotify.event( options.event, options.application, [], options.title, message, [], [], options.timeout, dbus_interface="org.kde.KNotify")
[935]77
[938]78if options.timeout > 0:
79 print "Knotify-ID: ", id
[935]80
[938]81 sleep(options.timeout)
[935]82
[938]83 # void update(int id, const QString &title, const QString &text, const KNotifyImage& image, const QStringList& actions);
84 #knotify.update( id, "knotify-client", "finished", [], [], dbus_interface="org.kde.KNotify")
85
86 #sleep( 1 )
87
88 #for i in range(3):
89 #print i
90 #knotify.update( id, "knotify-client", str(i), [], [], dbus_interface="org.kde.KNotify")
91 ## void reemit(int id, const ContextList& contexts);
92 #knotify.reemit( id, [], dbus_interface="org.kde.KNotify" )
93 #sleep(3)
94
95 knotify.closeNotification(id, dbus_interface="org.kde.KNotify");
96
97exit(0)
Note: See TracBrowser for help on using the repository browser.