1 | #!/usr/bin/env python
|
---|
2 | # -*- coding: utf-8 -*-
|
---|
3 |
|
---|
4 | usage = """Usage:
|
---|
5 | knotify-recipient.py
|
---|
6 |
|
---|
7 | listens to knotify signals and prints them
|
---|
8 | """
|
---|
9 |
|
---|
10 | import sys
|
---|
11 | import traceback
|
---|
12 |
|
---|
13 | import gobject
|
---|
14 |
|
---|
15 | import dbus
|
---|
16 | import dbus.mainloop.glib
|
---|
17 | #import dbus.mainloop.qt
|
---|
18 |
|
---|
19 | def handle_reply(msg):
|
---|
20 | print msg
|
---|
21 |
|
---|
22 | def handle_error(e):
|
---|
23 | print str(e)
|
---|
24 |
|
---|
25 | def signal_handler_notificationClosed(id):
|
---|
26 | print "handler_notificationClosed ", str(id)
|
---|
27 |
|
---|
28 | def 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 |
|
---|
38 | def 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 |
|
---|
45 | if __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()
|
---|