Пример #1
0
def OSX_get_a_certificate():
    # This function is @#$@#@#$ retarded. Its only point is to extract a single
    # cert from the OSX trusted cert store, so I can put it in a file, so I give
    # that file to Python's SSL module (which gives it to OpenSSL), which then
    # basically ignores that I'm explicitly telling it to only trust that one
    # certificate, and uses all the certificates in OSX's trusted cert store,
    # anyways. But it forces me to give it a file with a cert in it regardless
    # of the fact that it's planning to use the **entire cert store**
    # regardless of what I actually ask for...sigh. Why???
    import objc, tempfile
    global OSX_cert_tempfile

    # ALSO, wtf doesn't Security.framework already have python wrappers like the
    # rest of OSX's frameworks?? Just make up a minimal wrapper here...
    Security=types.ModuleType('Security')
    objc.loadBundle(Security.__name__, Security.__dict__,
                    bundle_identifier="com.apple.security")
    objc.parseBridgeSupport('''<signatures version="0.9"><depends_on path="/System/Library/Frameworks/CoreFoundation.framework"/><enum name="kSecFormatX509Cert" value="9"/><enum name="kSecItemPemArmour" value="1"/><function name="SecTrustCopyAnchorCertificates"><arg type="o^@"/><retval type="l"/></function><function name="SecKeychainItemExport"><arg type="@"/><arg type="I"/><arg type="I"/><arg type="^{?=II^v@@@II}"/><arg type="o^@"/><retval type="l"/></function></signatures>''', Security.__dict__, Security.__name__)

    res, certs = Security.SecTrustCopyAnchorCertificates(None)

    if res == 0:
        for cert in certs:
            res, data = Security.SecKeychainItemExport(
                cert,
                Security.kSecFormatX509Cert, Security.kSecItemPemArmour, None, None)
            if res == 0:
                OSX_cert_tempfile = tempfile.NamedTemporaryFile()
                OSX_cert_tempfile.write(str(buffer(data)))
                OSX_cert_tempfile.flush()
                return OSX_cert_tempfile.name

    return None
Пример #2
0
def OSX_get_a_certificate():
    # This function is @#$@#@#$ retarded. Its only point is to extract a single
    # cert from the OSX trusted cert store, so I can put it in a file, so I give
    # that file to Python's SSL module (which gives it to OpenSSL), which then
    # basically ignores that I'm explicitly telling it to only trust that one
    # certificate, and uses all the certificates in OSX's trusted cert store,
    # anyways. But it forces me to give it a file with a cert in it regardless
    # of the fact that it's planning to use the **entire cert store**
    # regardless of what I actually ask for...sigh. Why???
    import objc, tempfile
    global OSX_cert_tempfile

    # ALSO, wtf doesn't Security.framework already have python wrappers like the
    # rest of OSX's frameworks?? Just make up a minimal wrapper here...
    Security=types.ModuleType('Security')
    objc.loadBundle(Security.__name__, Security.__dict__,
                    bundle_identifier="com.apple.security")
    objc.parseBridgeSupport('''<signatures version="0.9"><depends_on path="/System/Library/Frameworks/CoreFoundation.framework"/><enum name="kSecFormatX509Cert" value="9"/><enum name="kSecItemPemArmour" value="1"/><function name="SecTrustCopyAnchorCertificates"><arg type="o^@"/><retval type="l"/></function><function name="SecKeychainItemExport"><arg type="@"/><arg type="I"/><arg type="I"/><arg type="^{?=II^v@@@II}"/><arg type="o^@"/><retval type="l"/></function></signatures>''', Security.__dict__, Security.__name__)

    res, certs = Security.SecTrustCopyAnchorCertificates(None)

    if res == 0:
        for cert in certs:
            res, data = Security.SecKeychainItemExport(
                cert,
                Security.kSecFormatX509Cert, Security.kSecItemPemArmour, None, None)
            if res == 0:
                OSX_cert_tempfile = tempfile.NamedTemporaryFile()
                OSX_cert_tempfile.write(str(buffer(data)))
                OSX_cert_tempfile.flush()
                return OSX_cert_tempfile.name

    return None
Пример #3
0
def _parseBridgeSupport(data, globals, frameworkName, *args, **kwds):
    try:
        objc.parseBridgeSupport(data, globals, frameworkName, *args, **kwds)
    except objc.internal_error as e:
        import warnings
        warnings.warn(
            "Error parsing BridgeSupport data for %s: %s" % (frameworkName, e),
            RuntimeWarning)
Пример #4
0
def _parseBridgeSupport(data, globals, frameworkName, *args, **kwds):
    try:
        try:
            objc.parseBridgeSupport(data, globals, frameworkName, *args, **kwds)
        except objc.internal_error, e:
            import warnings
            warnings.warn("Error parsing BridgeSupport data for %s: %s" % (frameworkName, e), RuntimeWarning)
    finally:
        # Add formal protocols to the protocols submodule, for backward
        # compatibility with earlier versions of PyObjC
        if 'protocols' in globals:
            for p in objc.protocolsForProcess():
                setattr(globals['protocols'], p.__name__, p)
Пример #5
0
def _parseBridgeSupport(data, globals, frameworkName, *args, **kwds):
    try:
        try:
            objc.parseBridgeSupport(data, globals, frameworkName, *args,
                                    **kwds)
        except objc.internal_error, e:
            import warnings
            warnings.warn(
                "Error parsing BridgeSupport data for %s: %s" %
                (frameworkName, e), RuntimeWarning)
    finally:
        # Add formal protocols to the protocols submodule, for backward
        # compatibility with earlier versions of PyObjC
        if 'protocols' in globals:
            for p in objc.protocolsForProcess():
                setattr(globals['protocols'], p.__name__, p)
Пример #6
0
def get_pixel_color_init():
    global mainID
    objc.parseBridgeSupport(
        """<?xml version='1.0'?>
<!DOCTYPE signatures SYSTEM "file://localhost/System/Library/DTDs/BridgeSupport.dtd">
<signatures version='1.0'>
  <depends_on path='/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation' />
  <depends_on path='/System/Library/Frameworks/IOKit.framework/IOKit' />
  <depends_on path='/System/Library/Frameworks/CoreServices.framework/CoreServices' />
  <function name='CGDisplayCreateImageForRect'>
    <retval already_cfretained='true' type='^{CGImage=}' />
    <arg type='I' />
    <arg type='{CGRect={CGPoint=ff}{CGSize=ff}}' type64='{CGRect={CGPoint=dd}{CGSize=dd}}' />
  </function>
</signatures>
""", globals(),
        '/System/Library/Frameworks/ApplicationServices.framework/Frameworks/CoreGraphics.framework'
    )
    mainID = CGMainDisplayID()
Пример #7
0
objc.parseBridgeSupport("""<?xml version='1.0'?>
<!DOCTYPE signatures SYSTEM "file://localhost/System/Library/DTDs/BridgeSupport.dtd">
<signatures version='0.9'>
<depends_on path='/System/Library/Frameworks/DiskArbitration.framework'/>
<depends_on path='/System/Library/Frameworks/IOKit.framework'/>
<depends_on path='/System/Library/Frameworks/Security.framework'/>
<depends_on path='/System/Library/Frameworks/SystemConfiguration.framework'/>
<depends_on path='/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CarbonCore.framework'/>
<depends_on path='/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CFNetwork.framework'/>
<depends_on path='/System/Library/Frameworks/CoreFoundation.framework'/>
<depends_on path='/System/Library/Frameworks/NetFS.framework'/>
<enum name='kCSIdentityAuthorityNotAccessibleErr' value='-2'/>
<enum name='kCSIdentityClassGroup' value='2'/>
<enum name='kCSIdentityClassUser' value='1'/>
<enum name='kCSIdentityCommitCompleted' value='1'/>
<enum name='kCSIdentityDeletedErr' value='-4'/>
<enum name='kCSIdentityDuplicateFullNameErr' value='-6'/>
<enum name='kCSIdentityDuplicatePosixNameErr' value='-8'/>
<enum name='kCSIdentityFlagHidden' value='1'/>
<enum name='kCSIdentityFlagNone' value='0'/>
<enum name='kCSIdentityInvalidFullNameErr' value='-5'/>
<enum name='kCSIdentityInvalidPosixNameErr' value='-7'/>
<enum name='kCSIdentityPermissionErr' value='-3'/>
<enum name='kCSIdentityQueryEventErrorOccurred' value='5'/>
<enum name='kCSIdentityQueryEventResultsAdded' value='2'/>
<enum name='kCSIdentityQueryEventResultsChanged' value='3'/>
<enum name='kCSIdentityQueryEventResultsRemoved' value='4'/>
<enum name='kCSIdentityQueryEventSearchPhaseFinished' value='1'/>
<enum name='kCSIdentityQueryGenerateUpdateEvents' value='1'/>
<enum name='kCSIdentityQueryIncludeHiddenIdentities' value='2'/>
<enum name='kCSIdentityQueryStringBeginsWith' value='2'/>
<enum name='kCSIdentityQueryStringEquals' value='1'/>
<enum name='kCSIdentityUnknownAuthorityErr' value='-1'/>
<function name='CSIdentityCreateGroupMembershipQuery'>
<arg type='^{__CFAllocator=}'/>
<arg type='^{__CSIdentity=}'/>
<retval type='^{__CSIdentityQuery=}'/>
</function>
<function name='CSIdentityGetClass'>
<arg type='^{__CSIdentity=}'/>
<retval type64='q' type='l'/>
</function>
<function name='CSIdentityGetPosixID'>
<arg type='^{__CSIdentity=}'/>
<retval type='I'/>
</function>
<function name='CSIdentityGetPosixName'>
<arg type='^{__CSIdentity=}'/>
<retval type='^{__CFString=}'/>
</function>
<function name='CSIdentityGetTypeID'>
<retval type64='Q' type='L'/>
</function>
<function name='CSIdentityGetUUID'>
<arg type='^{__CSIdentity=}'/>
<retval type='^{__CFUUID=}'/>
</function>
<function name='CSIdentityIsEnabled'>
<arg type='^{__CSIdentity=}'/>
<retval type='B'/>
</function>
<function name='CSIdentityIsHidden'>
<arg type='^{__CSIdentity=}'/>
<retval type='B'/>
</function>
<function name='CSIdentityIsMemberOfGroup'>
<arg type='^{__CSIdentity=}'/>
<arg type='^{__CSIdentity=}'/>
<retval type='B'/>
</function>
<function name='CSIdentityQueryCopyResults'>
<arg type='^{__CSIdentityQuery=}'/>
<retval already_retained='true' type='^{__CFArray=}'/>
</function>
<function name='CSIdentityQueryCreate'>
<arg type='^{__CFAllocator=}'/>
<arg type64='q' type='l'/>
<arg type='^{__CSIdentityAuthority=}'/>
<retval type='^{__CSIdentityQuery=}'/>
</function>
<function name='CSIdentityQueryCreateForCurrentUser'>
<arg type='^{__CFAllocator=}'/>
<retval type='^{__CSIdentityQuery=}'/>
</function>
<function name='CSIdentityQueryCreateForName'>
<arg type='^{__CFAllocator=}'/>
<arg type='^{__CFString=}'/>
<arg type64='q' type='l'/>
<arg type64='q' type='l'/>
<arg type='^{__CSIdentityAuthority=}'/>
<retval type='^{__CSIdentityQuery=}'/>
</function>
<function name='CSIdentityQueryCreateForPersistentReference'>
<arg type='^{__CFAllocator=}'/>
<arg type='^{__CFData=}'/>
<retval type='^{__CSIdentityQuery=}'/>
</function>
<function name='CSIdentityQueryCreateForPosixID'>
<arg type='^{__CFAllocator=}'/>
<arg type='I'/>
<arg type64='q' type='l'/>
<arg type='^{__CSIdentityAuthority=}'/>
<retval type='^{__CSIdentityQuery=}'/>
</function>
<function name='CSIdentityQueryCreateForUUID'>
<arg type='^{__CFAllocator=}'/>
<arg type='^{__CFUUID=}'/>
<arg type='^{__CSIdentityAuthority=}'/>
<retval type='^{__CSIdentityQuery=}'/>
</function>
<function name='CSIdentityQueryExecute'>
<arg type='^{__CSIdentityQuery=}'/>
<arg type64='Q' type='L'/>
<arg type='^^{__CFError}'/>
<retval type='B'/>
</function>
<function name='CSGetDefaultIdentityAuthority'>
<retval type='^{__CSIdentityAuthority=}'/>
</function>
<function name='CSGetLocalIdentityAuthority'>
<retval type='^{__CSIdentityAuthority=}'/>
</function>
<function name='CSGetManagedIdentityAuthority'>
<retval type='^{__CSIdentityAuthority=}'/>
</function>
</signatures>
""", globals(), '/System/Library/Frameworks/CoreServices.framework/Frameworks/OSServices.framework')
Пример #8
0
objc.parseBridgeSupport('''\
    <?xml version='1.0'?>
    <!DOCTYPE signatures SYSTEM "file://localhost/System/Library/DTDs/BridgeSupport.dtd">
    <signatures version='1.0'>
      <class name='OCTestBlock'>
        <method selector='getStructBlock'>
          <retval block='true' >
              <retval type='%(NSRect_tp)s' />
              <arg type='d' />
              <arg type='d' />
              <arg type='d' />
              <arg type='d' />
          </retval>
        </method>
        <method selector='getIntBlock'>
          <retval block='true' >
              <retval type='i' />
          </retval>
        </method>
        <method selector='getFloatBlock'>
          <retval block='true' >
              <retval type='d' />
              <arg type='d' />
              <arg type='d' />
          </retval>
        </method>
        <method selector='callOptionalBlock:withValue:'>
          <arg index='0' block='true'>
            <retval type='@'/>
            <arg type='@' />
          </arg>
        </method>
        <method selector='callIntBlock:withValue:'>
          <arg index='0' block='true' >
              <retval type='v' />
              <arg type='i' />
          </arg>
        </method>
        <method selector='callDoubleBlock:withValue:andValue:'>
          <arg index='0' block='true' >
              <retval type='d' />
              <arg type='d' />
              <arg type='d' />
          </arg>
        </method>
        <method selector='callStructBlock:withA:b:c:d:'>
          <arg index='0' block='true' >
              <retval type='%(NSRect_tp)s' />
              <arg type='d' />
              <arg type='d' />
              <arg type='d' />
              <arg type='d' />
          </arg>
        </method>
      </class>
      <class name='NSObject'>
        <method selector='processBlock:'>
          <retval type='d' />
          <arg index='0' block='true' type='@?'>
            <retval type='d'/>
            <arg type='d' />
            <arg type='d' />
          </arg>
        </method>
        <method selector='optionalBlock:'>
          <retval type='@' />
          <arg index='0' block='true' type='@?'>
            <retval type='@'/>
            <arg type='@' />
          </arg>
        </method>
      </class>
    </signatures>
    ''' % dict(NSRect_tp=NSRect_tp if sys.version_info[0] == 2 else NSRect_tp.decode('ascii')),
    globals(), 'PyObjCTest')
def _parseBridgeSupport(data, globals, frameworkName, *args, **kwds):
    try:
        objc.parseBridgeSupport(data, globals, frameworkName, *args, **kwds)
    except objc.internal_error as e:
        import warnings
        warnings.warn("Error parsing BridgeSupport data for %s: %s" % (frameworkName, e), RuntimeWarning)
Пример #10
0
# coding=utf-8

import SegmentsPen
reload(SegmentsPen)
from fontTools.misc.arrayTools import pointInRect

from fontTools.misc.arrayTools import offsetRect, sectRect
from Foundation import NSBundle
import objc
_path = NSBundle.mainBundle().bundlePath()
_path = _path+"/Contents/Frameworks/GlyphsCore.framework/Versions/A/Resources/BridgeSupport/GlyphsCore.bridgesupport"
f = open(_path)
objc.parseBridgeSupport(f.read(), globals(), _path)
f.close()

def segmentInBound(segment, bounds):
    minX, minY, maxX, maxY = bounds
    for point in segment:
        if pointInRect(point, bounds):
            return True
        found = minX <= point[0] <= maxX
        if found:
            return True
    return False
    
class Touche(object):
    """Checks a font for touching glyphs.
    
        font = CurrentFont()
        a, b = font['a'], font['b']
        touche = Touche(font)
Пример #11
0
<arg type='^{__CFDictionary=}'/>
<arg type='^{CFArrayRefRef=}'/>
<retval type='i'/>
</function>
</signatures>"""


# This is fun - lets you refer dict keys like dict.keyname
class attrdict(dict):
    __getattr__ = dict.__getitem__
    __setattr__ = dict.__setitem__


# Create 'NetFS' framework object from XML above
NetFS = attrdict()
objc.parseBridgeSupport(NetFS_bridgesupport, NetFS,
                        objc.pathForFramework('NetFS.framework'))


class ArrayPair(object):
    def __init__(self):
        super(type(self), self).__init__()
        # Build a pointer to a null array (which OS X will replace anyways)
        self.cArray = pointer(c_void_p(None))
        # Now we cast it to our custom opaque type
        self.oArray = NetFS.CFArrayRefRef(c_void_p=cast(self.cArray, c_void_p))

    def contents(self):
        # Cast the pointer cArray now points to into a objc object (CFArray/NSArray here)
        return [
            str(x) for x in objc.objc_object(c_void_p=self.cArray.contents)
        ]
    </function>
    <function name="IOBluetoothPreferenceSetControllerPowerState">
        <arg type="i"></arg>
        <retval type="i"></retval>
    </function>
</signatures>'''

objc.initFrameworkWrapper(
    frameworkName="IOBluetooth",
    frameworkIdentifier="com.apple.Bluetooth",
    frameworkPath=objc.pathForFramework('/System/Library/Frameworks/IOBluetooth.framework'),
    globals=globals()
)
objc.parseBridgeSupport(
    IOBT_BRIDGESUPPORT, 
    globals(), 
    objc.pathForFramework('/System/Library/Frameworks/IOBluetooth.framework')
)

def set_ioblpstate(s):
    #   int s : 0 = off, 1 = on
    IOBluetoothPreferenceSetControllerPowerState(s)
    s1 = -1
    for i in range(50):
        s1 = get_ioblpstate()
        if s1 == s:
            break
        time.sleep(0.1)
    if s1 != s:
        sys.stderr.write('Unable to set bluetooth power state to %s\n' % ('off' if s == 0 else 'on').encode('utf-8'))
        sys.exit(1)
Пример #13
0
    <arg type='^I'/>
    <retval type='I'/>
  </function>
  <function name='IORegisterForSystemPower'>
    <arg type='^v'/>
    <arg type='^^{IONotificationPort}'/>
    <arg function_pointer='true' type='^?'>
      <arg type='^v'/>
      <arg type='I'/>
      <arg type='I'/>
      <arg type='^v'/>
      <retval type='v'/>
    </arg>
    <arg type='^I'/>
    <retval type='I'/>
  </function>
</signatures>
"""

# __bundle__ = objc.initFrameworkWrapper("IOKit",
#                                        frameworkIdentifier="com.apple.framework.IOKit",
#                                        frameworkPath=objc.pathForFramework("/System/Library/Frameworks/IOKit.framework"),
#                                        globals=globals())

__bundle__ = objc.parseBridgeSupport(
    GEN_BRIDGE_METADATA,
    globals(),
    objc.pathForFramework("/System/Library/Frameworks/IOKit.framework"))

objc.loadBundleFunctions(__bundle__, globals(), [("IOPMAssertionCreateWithName", b"i@I@o^I")])
Пример #14
0
# encoding: utf-8
from __future__ import division, print_function, unicode_literals

import SegmentsPen
#reload(SegmentsPen)
from fontTools.misc.arrayTools import pointInRect

from fontTools.misc.arrayTools import offsetRect, sectRect
from Foundation import NSBundle
import objc
_path = NSBundle.mainBundle().bundlePath()
_path = _path + "/Contents/Frameworks/GlyphsCore.framework/Versions/A/Resources/BridgeSupport/GlyphsCore.bridgesupport"
f = open(_path)
objc.parseBridgeSupport(f.read(), globals(), _path)
f.close()


def segmentInBound(segment, bounds):
    minX, minY, maxX, maxY = bounds
    for point in segment:
        if pointInRect(point, bounds):
            return True
        found = minX <= point[0] <= maxX
        if found:
            return True
    return False


class Touche(object):
    """Checks a font for touching glyphs.
    
Пример #15
0
        <arg type='I'/>
        <retval already_retained='true' type='^{__CFUUID=}'/>
      </function>
      <function name='ColorSyncDeviceCopyDeviceInfo'>
        <arg type='^{__CFString=}'/>
        <arg type='^{__CFUUID=}'/>
        <retval already_retained='true' type='^{__CFDictionary=}'/>
      </function>
      <function name='ColorSyncDeviceSetCustomProfiles'>
        <arg type='^{__CFString=}'/>
        <arg type='^{__CFUUID=}'/>
        <arg type='^{__CFDictionary=}'/>
        <retval type='B'/>
      </function>
    </signatures>"""
  objc.parseBridgeSupport(color_sync_bridge_string, globals(),
                          color_sync_framework)


# Set |display_id| to use the color profile specified in |profile_url|. If
# |profile_url| is None, then use the factor default.
def SetDisplayCustomProfile(device_id, profile_url):
  if profile_url == None:
    profile_url = Foundation.kCFNull
  profile_info = {
      kColorSyncDeviceDefaultProfileID: profile_url,
      kColorSyncProfileUserScope: Foundation.kCFPreferencesCurrentUser
  }
  result = ColorSyncDeviceSetCustomProfiles(kColorSyncDisplayDeviceClass,
                                            device_id, profile_info)
  if result != True:
    raise Exception('Failed to set display custom profile')
Пример #16
0
    <arg type='^I'/>
    <retval type='I'/>
  </function>
  <function name='IORegisterForSystemPower'>
    <arg type='^v'/>
    <arg type='^^{IONotificationPort}'/>
    <arg function_pointer='true' type='^?'>
      <arg type='^v'/>
      <arg type='I'/>
      <arg type='I'/>
      <arg type='^v'/>
      <retval type='v'/>
    </arg>
    <arg type='^I'/>
    <retval type='I'/>
  </function>
</signatures>
"""

# __bundle__ = objc.initFrameworkWrapper("IOKit",
#                                        frameworkIdentifier="com.apple.framework.IOKit",
#                                        frameworkPath=objc.pathForFramework("/System/Library/Frameworks/IOKit.framework"),
#                                        globals=globals())

__bundle__ = objc.parseBridgeSupport(
    GEN_BRIDGE_METADATA, globals(),
    objc.pathForFramework("/System/Library/Frameworks/IOKit.framework"))

objc.loadBundleFunctions(__bundle__, globals(),
                         [("IOPMAssertionCreateWithName", b"i@I@o^I")])
Пример #17
0
objc.parseBridgeSupport('''\
    <?xml version='1.0'?>
    <!DOCTYPE signatures SYSTEM "file://localhost/System/Library/DTDs/BridgeSupport.dtd">
    <signatures version='1.0'>
      <class name='OCTestBlock'>
        <method selector='getIntBlock'>
          <retval block='true' >
              <retval type='i' />
          </retval>
        </method>
        <method selector='getFloatBlock'>
          <retval block='true' >
              <retval type='d' />
              <arg type='d' />
              <arg type='d' />
          </retval>
        </method>
        <method selector='callIntBlock:withValue:'>
          <arg index='0' block='true' >
              <retval type='v' />
              <arg type='i' />
          </arg>
        </method>
        <method selector='callDoubleBlock:withValue:andValue:'>
          <arg index='0' block='true' >
              <retval type='d' />
              <arg type='d' />
              <arg type='d' />
          </arg>
        </method>
      </class>
    </signatures>
    ''', globals(), 'PyObjCTest')
Пример #18
0
objc.parseBridgeSupport(
    """\
    <?xml version='1.0'?>
    <!DOCTYPE signatures SYSTEM "file://localhost/System/Library/DTDs/BridgeSupport.dtd">
    <signatures version='1.0'>
      <class name='OCTestBlock'>
        <method selector='getStructBlock'>
          <retval block='true' >
              <retval type='%(NSRect_tp)s' />
              <arg type='d' />
              <arg type='d' />
              <arg type='d' />
              <arg type='d' />
          </retval>
        </method>
        <method selector='getIntBlock'>
          <retval block='true' >
              <retval type='i' />
          </retval>
        </method>
        <method selector='getFloatBlock'>
          <retval block='true' >
              <retval type='d' />
              <arg type='d' />
              <arg type='d' />
          </retval>
        </method>
        <method selector='callOptionalBlock:withValue:'>
          <arg index='0' block='true'>
            <retval type='@'/>
            <arg type='@' />
          </arg>
        </method>
        <method selector='callIntBlock:withValue:'>
          <arg index='0' block='true' >
              <retval type='v' />
              <arg type='i' />
          </arg>
        </method>
        <method selector='callDoubleBlock:withValue:andValue:'>
          <arg index='0' block='true' >
              <retval type='d' />
              <arg type='d' />
              <arg type='d' />
          </arg>
        </method>
        <method selector='callStructBlock:withA:b:c:d:'>
          <arg index='0' block='true' >
              <retval type='%(NSRect_tp)s' />
              <arg type='d' />
              <arg type='d' />
              <arg type='d' />
              <arg type='d' />
          </arg>
        </method>
        <method selector='signatureForBlock1:'>
          <arg index='0' block='true'>
           <retval type='d' />
           <arg type='d' />
           <arg type='d' />
          </arg>
        </method>
        <method selector='signatureForBlock2:'>
          <arg index='0' block='true'>
           <retval type='@' />
           <arg type='@' />
          </arg>
        </method>
        <method selector='signatureForBlock3:'>
          <arg index='0' block='true'>
           <retval type='@' />
           <arg type='s' />
          </arg>
        </method>
        <method selector='signatureForBlock4:'>
          <arg index='0' block='true'>
           <retval type='c' />
           <arg type='i' />
           <arg type='i' />
           <arg type='f' />
          </arg>
        </method>
      </class>
      <class name='NSObject'>
        <method selector='processBlock:'>
          <retval type='d' />
          <arg index='0' block='true' type='@?'>
            <retval type='d'/>
            <arg type='d' />
            <arg type='d' />
          </arg>
        </method>
        <method selector='callWithCompletion:'>
          <arg index='0' block='true' type='@?'>
            <retval type='v'/>
            <arg type='@' />
          </arg>
        </method>
        <method selector='optionalBlock:'>
          <retval type='@' />
          <arg index='0' block='true' type='@?'>
            <retval type='@'/>
            <arg type='@' />
          </arg>
        </method>
      </class>
    </signatures>
    """ % {"NSRect_tp": NSRect_tp.decode("ascii")},
    globals(),
    "PyObjCTest",
)
Пример #19
0
    </function>
    <function name='IOPSGetTimeRemainingEstimate'>
        <retval type='d'/>
    </function>
    <function name='IOPSNotificationCreateRunLoopSource'>
        <arg type='^?' function_pointer='true'>
            <arg type='^v'/>
            <retval type='v'/>
        </arg>
        <arg type='^v'/>
        <retval type='^{__CFRunLoopSource=}' already_retained='true'/>
    </function>
</signatures>"""

objc.parseBridgeSupport(
    IO_POWER_SOURCES_BRIDGESUPPORT, globals(),
    objc.pathForFramework("/System/Library/Frameworks/IOKit.framework"))

POWER_TYPE_MAP = {
    kIOPMACPowerKey: common.POWER_TYPE_AC,
    kIOPMBatteryPowerKey: common.POWER_TYPE_BATTERY,
    kIOPMUPSPowerKey: common.POWER_TYPE_UPS
}

WARNING_LEVEL_MAP = {
    kIOPSLowBatteryWarningNone: common.LOW_BATTERY_WARNING_NONE,
    kIOPSLowBatteryWarningEarly: common.LOW_BATTERY_WARNING_EARLY,
    kIOPSLowBatteryWarningFinal: common.LOW_BATTERY_WARNING_FINAL
}

Пример #20
0
    <function name='IOPSGetTimeRemainingEstimate'>
        <retval type='d'/>
    </function>
    <function name='IOPSNotificationCreateRunLoopSource'>
        <arg type='^?' function_pointer='true'>
            <arg type='^v'/>
            <retval type='v'/>
        </arg>
        <arg type='^v'/>
        <retval type='^{__CFRunLoopSource=}' already_retained='true'/>
    </function>
</signatures>"""

objc.parseBridgeSupport(
    IO_POWER_SOURCES_BRIDGESUPPORT,
    globals(),
    objc.pathForFramework("/System/Library/Frameworks/IOKit.framework")
)


POWER_TYPE_MAP = {
    kIOPMACPowerKey: common.POWER_TYPE_AC,
    kIOPMBatteryPowerKey: common.POWER_TYPE_BATTERY,
    kIOPMUPSPowerKey: common.POWER_TYPE_UPS
}


WARNING_LEVEL_MAP = {
    kIOPSLowBatteryWarningNone: common.LOW_BATTERY_WARNING_NONE,
    kIOPSLowBatteryWarningEarly: common.LOW_BATTERY_WARNING_EARLY,
    kIOPSLowBatteryWarningFinal: common.LOW_BATTERY_WARNING_FINAL
Пример #21
0
objc.parseBridgeSupport(
    '''\
    <?xml version='1.0'?>
    <!DOCTYPE signatures SYSTEM "file://localhost/System/Library/DTDs/BridgeSupport.dtd">
    <signatures version='1.0'>
      <class name='OCTestBlock'>
        <method selector='getIntBlock'>
          <retval block='true' >
              <retval type='i' />
          </retval>
        </method>
        <method selector='getFloatBlock'>
          <retval block='true' >
              <retval type='d' />
              <arg type='d' />
              <arg type='d' />
          </retval>
        </method>
        <method selector='callIntBlock:withValue:'>
          <arg index='0' block='true' >
              <retval type='v' />
              <arg type='i' />
          </arg>
        </method>
        <method selector='callDoubleBlock:withValue:andValue:'>
          <arg index='0' block='true' >
              <retval type='d' />
              <arg type='d' />
              <arg type='d' />
          </arg>
        </method>
      </class>
    </signatures>
    ''', globals(), 'PyObjCTest')
Пример #22
0
objc.parseBridgeSupport("""<?xml version='1.0'?>
<!DOCTYPE signatures SYSTEM "file://localhost/System/Library/DTDs/BridgeSupport.dtd">
<signatures version='1.0'>
    <cftype name='ColorSyncProfileRef' type='^{ColorSyncProfile=}' tollfree='__NSCFType' gettypeid_func='ColorSyncProfileGetTypeID'/>
    <constant name='kColorSyncDeviceDefaultProfileID' type='^{__CFString=}'/>
    <constant name='kColorSyncDisplayDeviceClass' type='^{__CFString=}'/>
    <constant name='kColorSyncProfile' type='^{__CFString=}'/>
    <constant name='kColorSyncProfileUserScope' type='^{__CFString=}'/>
    <function name='CGDisplayCreateUUIDFromDisplayID'>
    <arg type='I'/>
    <retval already_retained='true' type='^{__CFUUID=}'/>
    </function>
    <function name='ColorSyncDeviceCopyDeviceInfo'>
    <arg type='^{__CFString=}'/>
    <arg type='^{__CFUUID=}'/>
    <retval already_retained='true' type='^{__CFDictionary=}'/>
    </function>
    <function name='ColorSyncDeviceSetCustomProfiles'>
    <arg type='^{__CFString=}'/>
    <arg type='^{__CFUUID=}'/>
    <arg type='^{__CFDictionary=}'/>
    <retval type='B'/>
    </function>
    <function name='ColorSyncProfileCreateWithURL'>
    <arg type='^{__CFURL=}'/>
    <arg type='^^{_CFError}' type_modifier='o'/>
    <retval already_retained='true' type='^{ColorSyncProfile=}'/>
    </function>
    <function name='ColorSyncProfileVerify'>
    <arg type='^{ColorSyncProfile=}'/>
    <arg type='^^{_CFError}' type_modifier='o'/>
    <arg type='^^{_CFError}' type_modifier='o'/>
    <retval type='B'/>
    </function>
</signatures>
""", globals(), '/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ColorSync.framework')
Пример #23
0
import objc, Quartz
from AppKit import NSBitmapImageRep
from Quartz.CoreGraphics import CGMainDisplayID

# Big big thanks to https://bitbucket.org/ronaldoussoren/pyobjc/ for updated .bridgesupport files
# And also this particular message that showed how to use them:
# http://www.mail-archive.com/[email protected]/msg09749.html

# Import the definition for CGDisplayCreateImageForRect
objc.parseBridgeSupport( """<?xml version='1.0'?>
<!DOCTYPE signatures SYSTEM "file://localhost/System/Library/DTDs/BridgeSupport.dtd">
<signatures version='1.0'>
  <depends_on path='/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation' />
  <depends_on path='/System/Library/Frameworks/IOKit.framework/IOKit' />
  <depends_on path='/System/Library/Frameworks/CoreServices.framework/CoreServices' />
  <function name='CGDisplayCreateImageForRect'>
    <retval already_cfretained='true' type='^{CGImage=}' />
    <arg type='I' />
    <arg type='{CGRect={CGPoint=ff}{CGSize=ff}}' type64='{CGRect={CGPoint=dd}{CGSize=dd}}' />
  </function>
</signatures>
""", globals(), '/System/Library/Frameworks/ApplicationServices.framework/Frameworks/CoreGraphics.framework')

mainID = CGMainDisplayID()
# Grab a chunk of the screen from 0,0 to 100,100 from top left
image = CGDisplayCreateImageForRect(mainID, ((0,0), (100,100)))
bitmap = NSBitmapImageRep.alloc()
bitmap.initWithCGImage_(image)
# Get the RGB color (float values from 0 to 1 per color, plus alpha) at a particular point
bitmap.colorAtX_y_(93.484375, 60.4921875)