1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | from datetime import datetime |
---|
4 | import dbus |
---|
5 | import gobject |
---|
6 | from dbus.mainloop.glib import DBusGMainLoop |
---|
7 | |
---|
8 | def handle_sleep(*args): |
---|
9 | print "%s PrepareForSleep%s" % (datetime.now().ctime(), args) |
---|
10 | |
---|
11 | DBusGMainLoop(set_as_default=True) # integrate into gobject main loop |
---|
12 | bus = dbus.SystemBus() # connect to system wide dbus |
---|
13 | bus.add_signal_receiver( # define the signal to listen to |
---|
14 | handle_sleep, # callback function |
---|
15 | 'PrepareForSleep', # signal name |
---|
16 | 'org.freedesktop.login1.Manager', # interface |
---|
17 | 'org.freedesktop.login1' # bus name |
---|
18 | ) |
---|
19 | |
---|
20 | loop = gobject.MainLoop() |
---|
21 | loop.run() |
---|