• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /macosx-10.10.1/pyobjc-45/2.5/pyobjc/pyobjc-framework-InstantMessage/Examples/ABPresence/
1from Cocoa import *
2from AddressBook import *
3
4class ABPerson (objc.Category(ABPerson)):
5    # Pull first and last name, organization, and record flags
6    # If the entry is a company, display the organization name instead
7    def displayName(self):
8	firstName = self.valueForProperty_(kABFirstNameProperty)
9	lastName = self.valueForProperty_(kABLastNameProperty)
10	companyName = self.valueForProperty_(kABOrganizationProperty)
11	flags = self.valueForProperty_(kABPersonFlags)
12        if flags is None:
13            flags = 0
14
15        if (flags & kABShowAsMask) == kABShowAsCompany:
16            if len(companyName):
17                return companyName;
18
19	lastNameFirst = (flags & kABNameOrderingMask) == kABLastNameFirst
20	hasFirstName = firstName is not None
21	hasLastName = lastName is not None
22
23        if hasLastName and hasFirstName:
24            if lastNameFirst:
25                return NSString.stringWithString_(u"%s %s"%(lastName, firstName))
26            else:
27                return NSString.stringWithString_(u"%s %s"%(firstName, lastName))
28
29        if hasLastName:
30            return lastName
31
32	return firstName
33
34    def compareDisplayNames_(self, person):
35	return self.displayName().localizedCaseInsensitiveCompare_(
36                person.displayName())
37