コード例 #1
0
def _process_Nav_args(dftflags, **args):
    import aepack
    import Carbon.AE
    import Carbon.File
    for k in args.keys():
        if args[k] is None:
            del args[k]
    # Set some defaults, and modify some arguments
    if not args.has_key('dialogOptionFlags'):
        args['dialogOptionFlags'] = dftflags
    if args.has_key('defaultLocation') and \
            not isinstance(args['defaultLocation'], Carbon.AE.AEDesc):
        defaultLocation = args['defaultLocation']
        if isinstance(defaultLocation, (Carbon.File.FSSpec, Carbon.File.FSRef)):
            args['defaultLocation'] = aepack.pack(defaultLocation)
        else:
            defaultLocation = Carbon.File.FSRef(defaultLocation)
            args['defaultLocation'] = aepack.pack(defaultLocation)
    if args.has_key('typeList') and not isinstance(args['typeList'], Carbon.Res.ResourceType):
        typeList = args['typeList'][:]
        # Workaround for OSX typeless files:
        if 'TEXT' in typeList and not '\0\0\0\0' in typeList:
            typeList = typeList + ('\0\0\0\0',)
        data = 'Pyth' + struct.pack("hh", 0, len(typeList))
        for type in typeList:
            data = data+type
        args['typeList'] = Carbon.Res.Handle(data)
    tpwanted = str
    if args.has_key('wanted'):
        tpwanted = args['wanted']
        del args['wanted']
    return args, tpwanted
コード例 #2
0
 def __aepack__(self):
     return pack(
         {
             keyAEScriptTag: self.script,
             keyAEStyles: self.style,
             keyAEText: self.text
         }, typeAEText)
コード例 #3
0
 def __aepack__(self):
     return pack(
         {
             'obj1': self.obj1,
             'relo': mkenum(self.relo),
             'obj2': self.obj2
         }, 'cmpd')
コード例 #4
0
 def __aepack__(self):
     return pack(
         {
             'want': mktype(self.want),
             'form': mkenum(self.form),
             'seld': self.seld,
             'from': self.fr
         }, 'obj ')
コード例 #5
0
 def test_roundtrip_FSSpec(self):
     try:
         import Carbon.File
     except:
         return
     o = Carbon.File.FSSpec(os.curdir)
     packed = aepack.pack(o)
     unpacked = aepack.unpack(packed)
     self.assertEqual(o.as_pathname(), unpacked.as_pathname())
コード例 #6
0
 def test_roundtrip_Alias(self):
     try:
         import Carbon.File
     except:
         return
     o = Carbon.File.FSSpec(os.curdir).NewAliasMinimal()
     packed = aepack.pack(o)
     unpacked = aepack.unpack(packed)
     self.assertEqual(o.FSResolveAlias(None)[0].as_pathname(),
         unpacked.FSResolveAlias(None)[0].as_pathname())
コード例 #7
0
    def main(self):
        pool = NSAutoreleasePool.alloc().init()
        NSLog("editing thread started for %s" % self.path)
        NSLog("shell command: %@", EDITOR_COMMAND % {'linenum': self.linenum, 'filename': self.path.replace("'","'\"'\"'")})

        stdin = open('/dev/null','r')
        stdout = open('/dev/null','w')
        subprocess.call(EDITOR_COMMAND % {'linenum': self.linenum, 'filename': self.path.replace("'","'\"'\"'")},
                        shell=True, stdin=stdin, stdout=stdout, stderr=stdout)
        #os.system(EDITOR_COMMAND % {'linenum':self.linenum, 'filename':self.path})

        # Send the "file closed" ODB event.
        if self.odb_app:
            NSLog("sending file closed event to %s, %s" % (self.odb_app, type(self.odb_app)))

            target = AE.AECreateDesc(AppleEvents.typeApplSignature, self.odb_app[::-1])  # For strange endianness reasons, have to reverse this
            event = AE.AECreateAppleEvent(kODBEditorSuite, kAEClosedFile, target, AppleEvents.kAutoGenerateReturnID, AppleEvents.kAnyTransactionID)

            if self.odb_token:
                event.AEPutParamDesc(keySenderToken, pack(self.odb_token, typeWildcard))

            fsr = Carbon.File.FSPathMakeRef(self.path)[0].encode('utf-8')
            event.AEPutParamDesc(AppleEvents.keyDirectObject, pack(fsr))

            event.AESend(AppleEvents.kAENoReply, AppleEvents.kAENormalPriority, AppleEvents.kAEDefaultTimeout)

            #evt_app = NSAppleEventDescriptor.descriptorWithTypeCode_(fourcc(self.odb_app))
            #evt = NSAppleEventDescriptor.appleEventWithEventClass_eventID_targetDescriptor_returnID_transactionID_(fourcc(kODBEditorSuite),
            #                                                                                                       fourcc(kAEClosedFile),
            #                                                                                                       evt_app,
            #                                                                                                       -1, # kAutoGenerateReturnID
            #                                                                                                       0) # kAnyTransactionID
            #if self.odb_token:
            #    evt_tok = NSAppleEventDescriptor.descriptorWithDescriptorType_data_(fourcc('****'), self.odb_token)
            #    evt.setParamDescriptor_forKeyword_(evt_tok, fourcc(keySenderToken))
            #
            #fsr = objc.FSRef.from_pathname(self.path).data
            #evt_path = NSAppleEventDescriptor.descriptorWithDescriptorType_bytes_length_(fourcc('fsrf'),fsr,len(fsr))
            #evt.setParamDescriptor_forKeyword_(evt_path, fourcc('----'))

        NSLog("editing thread finished for %s" % self.path)
        del pool
コード例 #8
0
    def main(self):
        pool = NSAutoreleasePool.alloc().init()
        NSLog("editing thread started for %s" % self.path)
        NSLog("shell command: %@", EDITOR_COMMAND % {'linenum': self.linenum, 'filename': self.path})

        stdin = open('/dev/null','r')
        stdout = open('/dev/null','w')
        subprocess.call(EDITOR_COMMAND % {'linenum': self.linenum, 'filename': self.path},
                        shell=True, stdin=stdin, stdout=stdout, stderr=stdout)
        #os.system(EDITOR_COMMAND % {'linenum':self.linenum, 'filename':self.path})

        # Send the "file closed" ODB event.
        if self.odb_app:
            NSLog("sending file closed event to %s, %s" % (self.odb_app, type(self.odb_app)))

            target = AE.AECreateDesc(AppleEvents.typeApplSignature, self.odb_app[::-1])  # For strange endianness reasons, have to reverse this
            event = AE.AECreateAppleEvent(kODBEditorSuite, kAEClosedFile, target, AppleEvents.kAutoGenerateReturnID, AppleEvents.kAnyTransactionID)

            if self.odb_token:
                event.AEPutParamDesc(keySenderToken, pack(self.odb_token, typeWildcard))

            fsr = Carbon.File.FSPathMakeRef(self.path)[0]
            event.AEPutParamDesc(AppleEvents.keyDirectObject, pack(fsr))

            event.AESend(AppleEvents.kAENoReply, AppleEvents.kAENormalPriority, AppleEvents.kAEDefaultTimeout)

            #evt_app = NSAppleEventDescriptor.descriptorWithTypeCode_(fourcc(self.odb_app))
            #evt = NSAppleEventDescriptor.appleEventWithEventClass_eventID_targetDescriptor_returnID_transactionID_(fourcc(kODBEditorSuite),
            #                                                                                                       fourcc(kAEClosedFile),
            #                                                                                                       evt_app,
            #                                                                                                       -1, # kAutoGenerateReturnID
            #                                                                                                       0) # kAnyTransactionID
            #if self.odb_token:
            #    evt_tok = NSAppleEventDescriptor.descriptorWithDescriptorType_data_(fourcc('****'), self.odb_token)
            #    evt.setParamDescriptor_forKeyword_(evt_tok, fourcc(keySenderToken))
            #
            #fsr = objc.FSRef.from_pathname(self.path).data
            #evt_path = NSAppleEventDescriptor.descriptorWithDescriptorType_bytes_length_(fourcc('fsrf'),fsr,len(fsr))
            #evt.setParamDescriptor_forKeyword_(evt_path, fourcc('----'))

        NSLog("editing thread finished for %s" % self.path)
        del pool
コード例 #9
0
 def __aepack__(self):
     return pack(struct.pack('hhhh', self.v0, self.h0, self.v1, self.h1),
                 typeQDRectangle)
コード例 #10
0
 def __aepack__(self):
     return pack(self.data, self.type)
コード例 #11
0
 def __aepack__(self):
     return pack(
         struct.pack('hh', self.script, self.language) + self.text,
         typeIntlText)
コード例 #12
0
 def __aepack__(self):
     return pack({'ksty': self.style, 'ktxt': self.text}, 'STXT')
コード例 #13
0
ファイル: aetypes.py プロジェクト: 1310701102/sl4a
 def __aepack__(self):
     return pack({'obj1': self.obj1,
              'relo': mkenum(self.relo),
              'obj2': self.obj2},
             'cmpd')
コード例 #14
0
 def test_roundtrip_None(self):
     o = None
     packed = aepack.pack(o)
     unpacked = aepack.unpack(packed)
     self.assertEqual(o, unpacked)
コード例 #15
0
ファイル: aetools.py プロジェクト: 5l1v3r1/python-10
"""Tools for use in AppleEvent clients and servers.

pack(x) converts a Python object to an AEDesc object
unpack(desc) does the reverse

packevent(event, parameters, attributes) sets params and attrs in an AEAppleEvent record
unpackevent(event) returns the parameters and attributes from an AEAppleEvent record

Plus...  Lots of classes and routines that help representing AE objects,
ranges, conditionals, logicals, etc., so you can write, e.g.:

    x = Character(1, Document("foobar"))

and pack(x) will create an AE object reference equivalent to AppleScript's

    character 1 of document "foobar"

Some of the stuff that appears to be exported from this module comes from other
files: the pack stuff from aepack, the objects from aetypes.

"""


from warnings import warnpy3k
warnpy3k("In 3.x, the aetools module is removed.", stacklevel=2)

from types import *
from Carbon import AE
from Carbon import Evt
from Carbon import AppleEvents
コード例 #16
0
ファイル: aetypes.py プロジェクト: 1310701102/sl4a
 def __aepack__(self):
     return pack(struct.pack('hh', self.script, self.language),
         typeIntlWritingCode)
コード例 #17
0
ファイル: aetypes.py プロジェクト: 1310701102/sl4a
 def __aepack__(self):
     return pack(struct.pack('hh', self.script, self.language)+self.text,
         typeIntlText)
コード例 #18
0
ファイル: aetypes.py プロジェクト: 1310701102/sl4a
 def __aepack__(self):
     return pack({keyAEScriptTag: self.script, keyAEStyles: self.style,
              keyAEText: self.text}, typeAEText)
コード例 #19
0
ファイル: aetypes.py プロジェクト: 1310701102/sl4a
 def __aepack__(self):
     return pack({'ksty': self.style, 'ktxt': self.text}, 'STXT')
コード例 #20
0
ファイル: aetypes.py プロジェクト: 1310701102/sl4a
 def __aepack__(self):
     return pack({'logc': mkenum(self.logc), 'term': self.term}, 'logi')
コード例 #21
0
ファイル: aetypes.py プロジェクト: 1310701102/sl4a
 def __aepack__(self):
     return pack(self.abso, 'abso')
コード例 #22
0
ファイル: aetypes.py プロジェクト: 1310701102/sl4a
 def __aepack__(self):
     return pack(self.type, typeType)
コード例 #23
0
 def __aepack__(self):
     rec = {'kobj': self.of, 'kpos': self.pos}
     return pack(rec, forcetype='insl')
コード例 #24
0
ファイル: aetypes.py プロジェクト: 1310701102/sl4a
 def __aepack__(self):
     return pack(self.data, self.type)
コード例 #25
0
 def test_roundtrip_string(self):
     o = 'a string'
     packed = aepack.pack(o)
     unpacked = aepack.unpack(packed)
     self.assertEqual(o, unpacked)
コード例 #26
0
ファイル: aetypes.py プロジェクト: 1310701102/sl4a
 def __aepack__(self):
     return pack(struct.pack('hh', self.v, self.h),
         typeQDPoint)
コード例 #27
0
ファイル: aetools.py プロジェクト: mcyril/ravel-ftn
"""Tools for use in AppleEvent clients and servers.
コード例 #28
0
ファイル: aetypes.py プロジェクト: 1310701102/sl4a
 def __aepack__(self):
     return pack(struct.pack('hhhh', self.v0, self.h0, self.v1, self.h1),
         typeQDRectangle)
コード例 #29
0
 def __aepack__(self):
     return pack({'logc': mkenum(self.logc), 'term': self.term}, 'logi')
コード例 #30
0
ファイル: aetypes.py プロジェクト: 1310701102/sl4a
 def __aepack__(self):
     return pack(struct.pack('hhh', self.r, self.g, self.b),
         typeRGBColor)
コード例 #31
0
ファイル: aetypes.py プロジェクト: 1310701102/sl4a
 def __aepack__(self):
     return pack(self.keyword, typeKeyword)
コード例 #32
0
ファイル: aetypes.py プロジェクト: 1310701102/sl4a
 def __aepack__(self):
     return pack({'want': mktype(self.want),
              'form': mkenum(self.form),
              'seld': self.seld,
              'from': self.fr},
             'obj ')
コード例 #33
0
 def __aepack__(self):
     return pack(struct.pack('hh', self.script, self.language),
                 typeIntlWritingCode)
コード例 #34
0
ファイル: aetypes.py プロジェクト: 1310701102/sl4a
 def __aepack__(self):
     return pack(self.enum, typeEnumeration)
コード例 #35
0
 def __aepack__(self):
     return pack(struct.pack('hh', self.v, self.h), typeQDPoint)
コード例 #36
0
ファイル: aetypes.py プロジェクト: 1310701102/sl4a
 def __aepack__(self):
     rec = {'kobj': self.of, 'kpos': self.pos}
     return pack(rec, forcetype='insl')
コード例 #37
0
 def __aepack__(self):
     return pack(struct.pack('hhh', self.r, self.g, self.b), typeRGBColor)
コード例 #38
0
ファイル: aetypes.py プロジェクト: 1310701102/sl4a
 def __aepack__(self):
     return pack(struct.pack('b', self.bool), 'bool')
コード例 #39
0
 def __aepack__(self):
     return pack(self.enum, typeEnumeration)
コード例 #40
0
def pack(*args, **kwargs):
    from aepack import pack
    return pack(*args, **kwargs)
コード例 #41
0
 def __aepack__(self):
     return pack(struct.pack('b', self.bool), 'bool')
コード例 #42
0
 def __aepack__(self):
     return pack(self.type, typeType)
コード例 #43
0
ファイル: aetools.py プロジェクト: 5l1v3r1/python-10
def packevent(ae, parameters = {}, attributes = {}):
    for key, value in parameters.items():
        packkey(ae, key, value)
    for key, value in attributes.items():
        ae.AEPutAttributeDesc(key, pack(value))
コード例 #44
0
 def __aepack__(self):
     return pack({'star': self.start, 'stop': self.stop}, 'rang')
コード例 #45
0
 def test_roundtrip_float(self):
     o = 12.1
     packed = aepack.pack(o)
     unpacked = aepack.unpack(packed)
     self.assertEqual(o, unpacked)
コード例 #46
0
ファイル: aetypes.py プロジェクト: 1310701102/sl4a
def pack(*args, **kwargs):
    from aepack import pack
    return pack( *args, **kwargs)
コード例 #47
0
 def test_roundtrip_aeobjects(self):
     for o in self.OBJECTS:
         packed = aepack.pack(o)
         unpacked = aepack.unpack(packed)
         self.assertEqual(repr(o), repr(unpacked))
コード例 #48
0
 def __aepack__(self):
     return pack(self.abso, 'abso')
コード例 #49
0
 def __aepack__(self):
     return pack(self.keyword, typeKeyword)
コード例 #50
0
ファイル: aetypes.py プロジェクト: 1310701102/sl4a
 def __aepack__(self):
     return pack({'star': self.start, 'stop': self.stop}, 'rang')