source: kde/dbus/knotify-recipient.py@ 942

Last change on this file since 942 was 941, checked in by joergs, on Dec 9, 2010 at 10:15:26 PM

listener to knotify signals

  • Property svn:executable set to *
File size: 2.2 KB
RevLine 
[941]1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4usage = """Usage:
5knotify-recipient.py
6
7listens to knotify signals and prints them
8"""
9
10import sys
11import traceback
12
13import gobject
14
15import dbus
16import dbus.mainloop.glib
17#import dbus.mainloop.qt
18
19def handle_reply(msg):
20 print msg
21
22def handle_error(e):
23 print str(e)
24
25def signal_handler_notificationClosed(id):
26 print "handler_notificationClosed ", str(id)
27
28def signal_handler_actionInvoked(id,action):
29 print "handler_actionInvoked: ", str(id), ", ", str(action)
30
31
32#def catchall_signal_handler(*args, **kwargs):
33 #print ("Caught signal (in catchall handler) "
34 #+ kwargs['dbus_interface'] + "." + kwargs['member'])
35 #for arg in args:
36 #print " " + str(arg)
37
38def catchall_hello_signals_handler(hello_string):
39 print "Received a hello signal and it says ", hello_string
40
41#def catchall_testservice_interface_handler(hello_string, dbus_message):
42 #print "com.example.TestService interface says " + hello_string + " when it sent signal " + dbus_message.get_member()
43
44
45if __name__ == '__main__':
46 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
47 #dbus.mainloop.qt.DBusQtMainLoop(set_as_default=True)
48
49 bus = dbus.SessionBus()
50 try:
51 object = bus.get_object("org.kde.knotify", "/Notify")
52
53 #object.connect_to_signal("notificationClosed", hello_signal_handler, dbus_interface="org.kde.knotify", arg0="Hello")
54 object.connect_to_signal("notificationClosed", signal_handler_notificationClosed, dbus_interface="org.kde.KNotify")
55 object.connect_to_signal("actionInvoked", signal_handler_actionInvoked, dbus_interface="org.kde.KNotify")
56 except dbus.DBusException:
57 traceback.print_exc()
58 print usage
59 sys.exit(1)
60
61 #lets make a catchall
62 #bus.add_signal_receiver(catchall_signal_handler, interface_keyword='dbus_interface', member_keyword='member')
63
64 bus.add_signal_receiver(catchall_hello_signals_handler, dbus_interface = "org.kde.KNotify", signal_name = "notificationClosed")
65
66 #bus.add_signal_receiver(catchall_testservice_interface_handler, dbus_interface = "com.example.TestService", message_keyword='dbus_message')
67
68 loop = gobject.MainLoop()
69 loop.run()
Note: See TracBrowser for help on using the repository browser.