__init__.py :  » Development » PyObjC » trunk » pyobjc » pyobjc-framework-SearchKit » Lib » SearchKit » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Development » PyObjC 
PyObjC » trunk » pyobjc » pyobjc framework SearchKit » Lib » SearchKit » __init__.py
'''
Python mapping for the SearchKit framework.

This module does not contain docstrings for the wrapped code, check Apple's
documentation for details on how to use these functions and classes. 
'''

import objc as _objc
from CoreFoundation import *

__bundle__ = _objc.initFrameworkWrapper("SearchKit",
    frameworkIdentifier="com.apple.SearchKit",
    frameworkPath=_objc.pathForFramework(
        "/System/Library/Frameworks/CoreServices.framework/Frameworks/SearchKit.framework"),
    globals=globals())

try:
    SKIndexGetTypeID

except NameError:
    # SKIndexGetTypeID is documented, but not actually exported by Leopard. Try to
    # emulate the missing functionality. 
    #
    # See also radar:6525606.
    #
    def workaround():
        from Foundation import NSMutableData,NSAutoreleasePool

        pool = NSAutoreleasePool.alloc().init()
        try:
            rI = SKIndexCreateWithMutableData(NSMutableData.data(),
                    None, kSKIndexInverted, None)

            indexID = CFGetTypeID(rI)

            r = SKIndexDocumentIteratorCreate(rI, None)
            iterID = CFGetTypeID(r)
            del r

            r = SKSearchGroupCreate([rI])
            groupID = CFGetTypeID(r)

            r = SKSearchResultsCreateWithQuery(r, ".*", kSKSearchRanked, 1, None, None)
            resultID = CFGetTypeID(r)

            if SKSearchGetTypeID() == 0:
                # Type doesn't get registered unless you try to use it.
                # That's no good for PyObjC, therefore forcefully create
                # a SKSearch object
                SKSearchCreate(rI, "q", 0)
                searchref = objc.registerCFSignature(
                        "SKSearchRef", "^{__SKSearch=}", SKSearchGetTypeID())
            else:
                searchref = SKSearchRef

            del r
            del rI

            r = SKSummaryCreateWithString("foo")
            summaryID = CFGetTypeID(r)
            del r

        finally:
            del pool

        def SKIndexGetTypeID():
            return indexID

        def SKIndexDocumentIteratorGetTypeID():
            return iterID

        def SKSearchGroupGetTypeID():
            return groupID

        def SKSearchResultsGetTypeID():
            return resultID

        def SKSummaryGetTypeID():
            return summaryID

        indexType = objc.registerCFSignature(
                "SKIndexRef", "^{__SKIndex=}", indexID)
        iterType = objc.registerCFSignature(
                "SKIndexDocumentIteratorRef", "^{__SKIndexDocumentIterator=}", indexID)
        groupType = objc.registerCFSignature(
                "SKSearchGroupRef", "^{__SKSearchGroup=}", groupID)
        resultType = objc.registerCFSignature(
                "SKSearchResultsRef", "^{__SKSearchResults=}", resultID)
        summaryType = objc.registerCFSignature(
                "SKSummaryRef", "^{__SKSummary=}", summaryID)

        # For some reason SKDocumentGetTypeID doesn't return the right value
        # when the framework loader calls it the first time around,
        # by this time the framework is fully initialized and we get
        # the correct result.
        SKDocumentRef = objc.registerCFSignature(
                "SKDocumentRef", "@", SKDocumentGetTypeID())


        return (SKIndexGetTypeID, indexType, SKIndexDocumentIteratorGetTypeID, iterType, 
                SKSearchGroupGetTypeID, groupType, SKSearchResultsGetTypeID, resultType,
                SKSummaryGetTypeID, summaryType,
                SKDocumentRef, searchref)

    (SKIndexGetTypeID, SKIndexRef, 
        SKIndexDocumentIteratorGetTypeID, SKIndexDocumentRef, 
        SKSearchGroupGetTypeID, SKSearchGroupRef,
        SKSearchResultsGetTypeID, SKSearchResultsRef,
        SKSummaryGetTypeID, SKSummaryRef,
        SKDocumentRef, SKSearchRef,
    ) = workaround()

    del workaround
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.