Commits

Ronald Oussoren committed 8dc0292

Make example py3k safe and add a summary.txt file for the website

  • Participants
  • Parent commits 30b5ce7

Comments (0)

Files changed (5)

pyobjc-framework-InstantMessage/Examples/ABPresence/ABPersonDisplayNameAdditions.py

     # Pull first and last name, organization, and record flags
     # If the entry is a company, display the organization name instead
     def displayName(self):
-	firstName = self.valueForProperty_(kABFirstNameProperty)
-	lastName = self.valueForProperty_(kABLastNameProperty)
-	companyName = self.valueForProperty_(kABOrganizationProperty)
-	flags = self.valueForProperty_(kABPersonFlags)
+        firstName = self.valueForProperty_(kABFirstNameProperty)
+        lastName = self.valueForProperty_(kABLastNameProperty)
+        companyName = self.valueForProperty_(kABOrganizationProperty)
+        flags = self.valueForProperty_(kABPersonFlags)
         if flags is None:
             flags = 0
-	
+        
         if (flags & kABShowAsMask) == kABShowAsCompany:
             if len(companyName):
                 return companyName;
-	
-	lastNameFirst = (flags & kABNameOrderingMask) == kABLastNameFirst
-	hasFirstName = firstName is not None
-	hasLastName = lastName is not None
-	
+        
+        lastNameFirst = (flags & kABNameOrderingMask) == kABLastNameFirst
+        hasFirstName = firstName is not None
+        hasLastName = lastName is not None
+        
         if hasLastName and hasFirstName:
             if lastNameFirst:
-                return NSString.stringWithString_(u"%s %s"%(lastName, firstName))
+                return NSString.stringWithString_("%s %s"%(lastName, firstName))
             else:
-                return NSString.stringWithString_(u"%s %s"%(firstName, lastName))
-	
+                return NSString.stringWithString_("%s %s"%(firstName, lastName))
+        
         if hasLastName:
             return lastName
-	
-	return firstName
+        
+        return firstName
 
     def compareDisplayNames_(self, person):
-	return self.displayName().localizedCaseInsensitiveCompare_(
+        return self.displayName().localizedCaseInsensitiveCompare_(
                 person.displayName())

pyobjc-framework-InstantMessage/Examples/ABPresence/English.lproj/MainMenu.nib/keyedobjects.nib

Binary file modified.

pyobjc-framework-InstantMessage/Examples/ABPresence/PeopleDataSource.py

     _table = objc.IBOutlet()
 
     def awakeFromNib(self):
-	self._imPersonStatus = NSMutableArray.alloc().init()
+        self._imPersonStatus = NSMutableArray.alloc().init()
 
-	# We don't need to query the staus of everyone, we will wait for 
+        # We don't need to query the staus of everyone, we will wait for 
         # notifications of their status to arrive, so we just set them all up 
         # as offline.
-	self.setupABPeople()
+        self.setupABPeople()
 
-	NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(
+        NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(
                 self, 'abDatabaseChangedExternallyNotification:',
                 kABDatabaseChangedExternallyNotification, None)
 
-	NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(
+        NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(
                 self, 'addressBookPersonStatusChanged:',
                 kAddressBookPersonStatusChanged, None)
 
-	NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(
+        NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(
                 self, 'statusImagesChanged:', 
                 kStatusImagesChanged, None)
 
     # the current _abPeople
     # Fairly expensive, so this is only done when necessary
     def rebuildStatusInformation(self):
-	# Now scan through all the people, adding their status to the status 
+        # Now scan through all the people, adding their status to the status 
         # cache array
         for i, person in enumerate(self._abPeople):
                 # Let's assume they're offline to start
-		bestStatus = IMPersonStatusOffline 
+                bestStatus = IMPersonStatusOffline 
 
                 for service in IMService.allServices():
-			screenNames = service.screenNamesForPerson_(person)
-			
+                        screenNames = service.screenNamesForPerson_(person)
+                        
                         for screenName in screenNames:
-				dictionary = service.infoForScreenName_(
+                                dictionary = service.infoForScreenName_(
                                         screenName)
-				status = dictionary.get(IMPersonStatusKey)
+                                status = dictionary.get(IMPersonStatusKey)
                                 if status is not None:
-					thisStatus = status
+                                        thisStatus = status
                                         if IMComparePersonStatus(bestStatus, thisStatus) != NSOrderedAscending:
-						bestStatus = thisStatus;
-		
-		self._imPersonStatus[i] = bestStatus
+                                                bestStatus = thisStatus;
+                
+                self._imPersonStatus[i] = bestStatus
 
-	self._table.reloadData()
+        self._table.reloadData()
 
     # Rebuild status information for a given person, much faster than a full 
     # rebuild
         for i, person in enumerate(self._abPeople):
             if person is forPerson:
                 bestStatus = IMPersonStatusOffline
-			
+                        
                 # Scan through all the services, taking the 'best' status we 
                 # can find
                 for service in IMService.allServices():
                             thisStatus = status
                             if IMComparePersonStatus(bestStatus, thisStatus) != NSOrderedAscending:
                                 bestStatus = thisStatus
-			
+                        
                 self._imPersonStatus[i] = bestStatus
                 self._table.reloadData()
                 break
 
     # Sets up all our internal data
     def setupABPeople(self):
-	# Keep around a copy of all the people in the AB now
-	self._abPeople = ABAddressBook.sharedAddressBook().people().mutableCopy()
-	
-	# Sort them by display name
+        # Keep around a copy of all the people in the AB now
+        self._abPeople = ABAddressBook.sharedAddressBook().people().mutableCopy()
+        
+        # Sort them by display name
         self._abPeople.sortUsingSelector_('compareDisplayNames:')
 
-	# Assume everyone is offline.
-	self._imPersonStatus.removeAllObjects()
-	offlineNumber =  IMPersonStatusOffline
+        # Assume everyone is offline.
+        self._imPersonStatus.removeAllObjects()
+        offlineNumber =  IMPersonStatusOffline
         for i in range(len(self._abPeople)):
             self._imPersonStatus.append(offlineNumber)
 
     # This will do a full flush of people in our AB Cache, along with 
     # rebuilding their status */
     def reloadABPeople(self):
-	self.setupABPeople()
-	
-	# Now recache all the status info, this will spawn a reload of the table
-	self.rebuildStatusInformation()
+        self.setupABPeople()
+        
+        # Now recache all the status info, this will spawn a reload of the table
+        self.rebuildStatusInformation()
 
     def numberOfRowsInTableView_(self, tableView):
         if self._abPeople is None:
         return len(self._abPeople)
 
     def tableView_objectValueForTableColumn_row_(self, tableView, tableColumn, row):
-	identifier = tableColumn.identifier()
+        identifier = tableColumn.identifier()
         if identifier == u"image":
             status = self._imPersonStatus[row]
             return NSImage.imageNamed_(IMService.imageNameForStatus_(status))
-		
+                
         elif identifier == u"name":
             return self._abPeople[row].displayName()
 
-	return None
+        return None
 
 
     # Posted from ServiceWatcher
     # The object of this notification is an ABPerson who's status has
     # Changed
     def addressBookPersonStatusChanged_(self, notification):
-	self.rebuildStatusInformationForPerson_(notification.object())
+        self.rebuildStatusInformationForPerson_(notification.object())
 
     # Posted from ServiceWatcher
     # We should reload the tableview, because the user has changed the
     # status images that iChat is using.
     def statusImagesChanged_(self, notification):
-	self._table.reloadData()
+        self._table.reloadData()
 
     # If the AB database changes, force a reload of everyone
     # We could look in the notification to catch differential updates, but 
     # for now this is fine.
     def abDatabaseChangedExternallyNotification_(self, notification):
-	self.reloadABPeople()
+        self.reloadABPeople()

pyobjc-framework-InstantMessage/Examples/ABPresence/ServiceWatcher.py

 
 class ServiceWatcher (NSObject):
     def startMonitoring(self):
-	nCenter = IMService.notificationCenter()
+        nCenter = IMService.notificationCenter()
 
-	nCenter.addObserver_selector_name_object_(
+        nCenter.addObserver_selector_name_object_(
                 self, 'imPersonStatusChangedNotification:',
                 IMPersonStatusChangedNotification, None)
-	
-	nCenter.addObserver_selector_name_object_(
+        
+        nCenter.addObserver_selector_name_object_(
                 self, 'imStatusImagesChangedAppearanceNotification:',
                 IMStatusImagesChangedAppearanceNotification, None)
 
     def stopMonitoring(self):
-	nCenter = IMService.notificationCenter()
-	nCenter.removeObserver_(self)
+        nCenter = IMService.notificationCenter()
+        nCenter.removeObserver_(self)
 
     def awakeFromNib(self):
         self.startMonitoring()
     # information dictionary will always contain an 
     # IMPersonScreenNameKey and an IMPersonStatusKey, and no others.
     def imPersonStatusChangedNotification_(self, notification):
-	service = notification.object()
-	userInfo = notification.userInfo()
-	screenName = userInfo[IMPersonScreenNameKey]
-	abPersons = service.peopleWithScreenName_(screenName)
+        service = notification.object()
+        userInfo = notification.userInfo()
+        screenName = userInfo[IMPersonScreenNameKey]
+        abPersons = service.peopleWithScreenName_(screenName)
 
         center = NSNotificationCenter.defaultCenter()
         for person in abPersons:

pyobjc-framework-InstantMessage/Examples/ABPresence/summary.txt

+Simple example that uses the InstantMessage framework
+to show the connection status of persons in your
+address book.