예제 #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
"""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
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')