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

Last change on this file since 1118 was 943, checked in by joergs, on Dec 9, 2010 at 10:20:27 PM

added comment

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