• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /macosx-10.10/pyobjc-45/2.6/pyobjc/pyobjc-framework-AddressBook/Examples/Plugins/Python Address Label/
1"""
2This plugin adds an 'Python Address Label' action to "Adress" properties in
3the AddressBook application.
4
5To install this plugin you have to build it (using 'python setup.py py2app')
6and then copy it to  '~/Library/Address\ Book\ Plug-Ins' (this folder may
7not exist yet.
8"""
9from AddressBook import *
10from AppKit import *
11
12class PyAddressLabelDelegate (NSObject):
13    def actionProperty(self):
14        return kABAddressProperty
15
16    def titleForPerson_identifier_(self, person, identifier):
17        return u"Python Address Label"
18
19    def shouldEnableActionForPerson_identifier_(self, person, identifier):
20        return len(person.address()) > 0
21
22    def performActionForPerson_identifier_(self, person, identifier):
23        text = person.name()
24        if person.department() is not NSNull.null():
25            text += '\n' + person.department()
26
27        if person.organization() is not NSNull.null():
28            text += '\n' + person.organization()
29
30        address = person.address()[0]
31        text += '\n' + address.street()
32        text += '\n' + address.zip() + ' ' + address.city()
33
34        if address.country() is not NSNull.null():
35            text += '\n' + address.country()
36
37        pboard = NSPasteboard.generalPasteboard()
38        pboard.declareTypes_owner_([NSStringPboardType], None)
39        pboard.setString_forType_(text, NSStringPboardType)
40