• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /macosx-10.10/pyobjc-45/2.6/pyobjc/pyobjc-framework-InstantMessage/Examples/ABPresence/
1from Cocoa import *
2from InstantMessage import *
3from AddressBook import *
4
5kAddressBookPersonStatusChanged = u"AddressBookPersonStatusChanged"
6kStatusImagesChanged = u"StatusImagesChanged"
7
8class ServiceWatcher (NSObject):
9    def startMonitoring(self):
10	nCenter = IMService.notificationCenter()
11
12	nCenter.addObserver_selector_name_object_(
13                self, 'imPersonStatusChangedNotification:',
14                IMPersonStatusChangedNotification, None)
15
16	nCenter.addObserver_selector_name_object_(
17                self, 'imStatusImagesChangedAppearanceNotification:',
18                IMStatusImagesChangedAppearanceNotification, None)
19
20    def stopMonitoring(self):
21	nCenter = IMService.notificationCenter()
22	nCenter.removeObserver_(self)
23
24    def awakeFromNib(self):
25        self.startMonitoring()
26
27    # Received from IMService's custom notification center. Posted when a
28    # different user (screenName) logs in, logs off, goes away,
29    # and so on. This notification is for the IMService object. The user
30    # information dictionary will always contain an
31    # IMPersonScreenNameKey and an IMPersonStatusKey, and no others.
32    def imPersonStatusChangedNotification_(self, notification):
33	service = notification.object()
34	userInfo = notification.userInfo()
35	screenName = userInfo[IMPersonScreenNameKey]
36	abPersons = service.peopleWithScreenName_(screenName)
37
38        center = NSNotificationCenter.defaultCenter()
39        for person in abPersons:
40            center.postNotificationName_object_(
41                    kAddressBookPersonStatusChanged, person)
42
43    # Received from IMService's custom notification center. Posted when the
44    # user changes their preferred images for displaying status.
45    # This notification is relevant to no particular object. The user
46    # information dictionary will not contain keys. Clients that display
47    # status information graphically (using the green/yellow/red dots) should
48    # call <tt>imageURLForStatus:</tt> to get the new image.
49    # See "Class Methods" for IMService in this document.
50    def imStatusImagesChangedAppearanceNotification_(self, notification):
51        NSNotificationCenter.defaultCenter().postNotificationName_object_(
52                kStatusImagesChanged, self)
53