• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /macosx-10.9.5/pyobjc-42/2.5/pyobjc/pyobjc-framework-SystemConfiguration/Examples/CallbackDemo/
1#!/usr/bin/env
2"""
3This is a simple tool that exercises the some callback functions in the
4SystemConfiguration framework.
5
6In an ideal world this would be a nice GUI.
7
8Usage:
9    python callbacks.py
10"""
11from Cocoa import *
12from SystemConfiguration import *
13
14import signal
15
16def sigint(*args):
17    print "SIGINT: bailing out"
18    loop = CFRunLoopGetCurrent()
19    CFRunLoopStop(loop)
20
21
22def dynamicStoreChanged(store, changedKeys, info):
23    print "Dynamic Store: keys changed", changedKeys
24
25def prefsChanged(prefs, notificationType, info):
26    print "Prefs changed, type:", notificationType
27
28
29
30def main():
31
32    # Setup a dynamic store controller that monitors all keys:
33    store = SCDynamicStoreCreate(None, "demo.controller",
34                dynamicStoreChanged, None)
35    SCDynamicStoreSetNotificationKeys(store, None, [ '.*' ])
36    source = SCDynamicStoreCreateRunLoopSource(None, store, 0)
37
38    # Setup a preferences controller
39    prefs = SCPreferencesCreate(None, "demo.prefs", None)
40    SCPreferencesSetCallback(prefs, prefsChanged, None)
41
42
43    # Set up a run loop and add all controllers to that.
44    loop = CFRunLoopGetCurrent()
45    CFRunLoopAddSource(loop, source, kCFRunLoopCommonModes)
46    SCPreferencesScheduleWithRunLoop(prefs, loop, kCFRunLoopCommonModes)
47
48    signal.signal(signal.SIGINT, sigint)
49    CFRunLoopRun()
50
51
52if __name__ == "__main__":
53    main()
54