Ignore:
Timestamp:
Dec 8, 2010, 4:08:14 PM (14 years ago)
Author:
joergs
Message:

usable knotify handling

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kde/dbus/knotify-client

    r936 r938  
    44import sys
    55import dbus
    6 import pprint
     6from pprint import pprint
     7from time import sleep
    78
    8 try:
    9     message = sys.argv[1]
    10 except:
    11     message = sys.argv[0]
     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
    1232
    1333knotify = 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
    1439
    1540# interface for knotify,
     
    1843#       const QString &event,
    1944#       const QString &fromApp,
    20 #       const QVariantList& contexts ,
     45#       const QVariantList& contexts,
    2146#       const QString &title,
    2247#       const QString &text,
     
    2651#       qlonglong winId );
    2752
     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")
    2856
    29 # predefined notify settings, see
    30 # find /usr/share/kde4/apps -name *.notifyrc
    31 # grep -v '[a-z]\[' /usr/share/kde4/apps/kde/kde.notifyrc
     57if options.timeout > 0:
     58    print "Knotify-ID: ", id
    3259
    33 #i = knotify.event( "warning", "mettenmeier_batteriemanagement", [], "Batteriemanagement", m, [0,0,0,0], [], 0, dbus_interface="org.kde.KNotify")
     60    sleep(options.timeout)
    3461
    35 # use notify settings from powerdevil
    36 #i = knotify.event( "criticalbattery", "powerdevil", [], "Batteriemanagement", m, [], [], 0, dbus_interface="org.kde.KNotify")
    37 i = knotify.event( "notification", "kde", [], "knotify-client", message, [], [], 5, dbus_interface="org.kde.KNotify")
    38 #pprint.pprint(i)
    39 print i
     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 TracChangeset for help on using the changeset viewer.