• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /macosx-10.10.1/pyobjc-45/2.5/pyobjc/pyobjc-framework-Cocoa/Examples/AppKit/PredicateEditorSample/
1PredicateEditorSample
2=====================
3
4"PredicateEditorSample" is a Cocoa application that demonstrates how to use 
5the ``NSPredicateEditor`` class.  The ``NSPredicateEditor`` class is a 
6subclass of ``NSRuleEditor`` that is specialized for editing ``NSPredicate`` 
7objects.  This sample is intended to show how to use the many different 
8features and aspects of this control and leverages Spotlight to search your 
9Address Book.
10
11It shows how to manage this control inside your window along with an 
12``NSTableView``, build Spotlight friendly queries based on ``NSPredicate`` and 
13``NSCompountPredicate``, build search results based on ``NSMetadataQuery`` object.
14
15Using the Sample
16----------------
17
18Simply build the example using the supplied ``setup.py`` file.  Enter 
19query information pertaining to your Address Book.  The application will 
20display matches in its table view.
21
22Note that this sample uses Interface Builder 3.0 to build the 
23``NSPredicateEditorRowTemplates`` that make up the control's interface.
24
25AddressBook searches are achieved by specifically requesting the "kind" of data to search via the ``kMDItemKind`` key constant.  This is the metadata attribute key that tells Spotlight to search for address book data only.  Together along with the other predicates from the ``NSPredicateEditor`` class we form a "compound predicate" and start the query.  The code snippet below found in this sample shows how this is done::
26
27   # always search for items in the Address Book
28   addrBookPredicate = NSPredicate.predicateWithFormat_("(kMDItemKind = 'Address Book Person Data')")
29   predicate = NSCompoundPredicate.andPredicateWithSubpredicates_([addrBookPredicate, predicate])
30
31   query.setPredicate_(predicate)
32   query.startQuery()
33