|
1 # |
|
2 # Wake/sleep detection for scheduling adjustments |
|
3 # |
|
4 |
|
5 import Foundation |
|
6 import AppKit |
|
7 import borgend |
|
8 |
|
9 logger=borgend.logger.getChild(__name__) |
|
10 |
|
11 class SleepHandler(Foundation.NSObject): |
|
12 """ Handle wake/sleep notifications """ |
|
13 |
|
14 def handleSleepNotification(self, aNotification): |
|
15 logger.info("System going to sleep") |
|
16 |
|
17 def handleWakeNotification(self, aNotification): |
|
18 logger.info("System waking up from sleep") |
|
19 |
|
20 if platform.system()=='Darwin': |
|
21 workspace = AppKit.NSWorkspace.sharedWorkspace() |
|
22 notification_center = workspace.notificationCenter() |
|
23 sleep_handler = SleepHandler.new() |
|
24 |
|
25 notification_center.addObserver_selector_name_object_( |
|
26 sleep_handler, |
|
27 "handleSleepNotification", |
|
28 AppKit.NSWorkspaceWillSleepNotification, |
|
29 None) |
|
30 |
|
31 notification_center.addObserver_selector_name_object_( |
|
32 sleep_handler, |
|
33 "handleWakeNotification", |
|
34 AppKit.NSWorkspaceDidWakeNotification, |
|
35 None) |
|
36 |