Beispiel #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
Beispiel #2
0
 def __aepack__(self):
     return pack(
         {
             keyAEScriptTag: self.script,
             keyAEStyles: self.style,
             keyAEText: self.text
         }, typeAEText)
Beispiel #3
0
 def __aepack__(self):
     return pack(
         {
             'obj1': self.obj1,
             'relo': mkenum(self.relo),
             'obj2': self.obj2
         }, 'cmpd')
Beispiel #4
0
 def __aepack__(self):
     return pack(
         {
             'want': mktype(self.want),
             'form': mkenum(self.form),
             'seld': self.seld,
             'from': self.fr
         }, 'obj ')
Beispiel #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())
Beispiel #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())
Beispiel #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
    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
Beispiel #9
0
 def __aepack__(self):
     return pack(struct.pack('hhhh', self.v0, self.h0, self.v1, self.h1),
                 typeQDRectangle)
Beispiel #10
0
 def __aepack__(self):
     return pack(self.data, self.type)
Beispiel #11
0
 def __aepack__(self):
     return pack(
         struct.pack('hh', self.script, self.language) + self.text,
         typeIntlText)
Beispiel #12
0
 def __aepack__(self):
     return pack({'ksty': self.style, 'ktxt': self.text}, 'STXT')
Beispiel #13
0
 def __aepack__(self):
     return pack({'obj1': self.obj1,
              'relo': mkenum(self.relo),
              'obj2': self.obj2},
             'cmpd')
Beispiel #14
0
 def test_roundtrip_None(self):
     o = None
     packed = aepack.pack(o)
     unpacked = aepack.unpack(packed)
     self.assertEqual(o, unpacked)
Beispiel #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
Beispiel #16
0
 def __aepack__(self):
     return pack(struct.pack('hh', self.script, self.language),
         typeIntlWritingCode)
Beispiel #17
0
 def __aepack__(self):
     return pack(struct.pack('hh', self.script, self.language)+self.text,
         typeIntlText)
Beispiel #18
0
 def __aepack__(self):
     return pack({keyAEScriptTag: self.script, keyAEStyles: self.style,
              keyAEText: self.text}, typeAEText)
Beispiel #19
0
 def __aepack__(self):
     return pack({'ksty': self.style, 'ktxt': self.text}, 'STXT')
Beispiel #20
0
 def __aepack__(self):
     return pack({'logc': mkenum(self.logc), 'term': self.term}, 'logi')
Beispiel #21
0
 def __aepack__(self):
     return pack(self.abso, 'abso')
Beispiel #22
0
 def __aepack__(self):
     return pack(self.type, typeType)
Beispiel #23
0
 def __aepack__(self):
     rec = {'kobj': self.of, 'kpos': self.pos}
     return pack(rec, forcetype='insl')
Beispiel #24
0
 def __aepack__(self):
     return pack(self.data, self.type)
Beispiel #25
0
 def test_roundtrip_string(self):
     o = 'a string'
     packed = aepack.pack(o)
     unpacked = aepack.unpack(packed)
     self.assertEqual(o, unpacked)
Beispiel #26
0
 def __aepack__(self):
     return pack(struct.pack('hh', self.v, self.h),
         typeQDPoint)
Beispiel #27
0
"""Tools for use in AppleEvent clients and servers.
Beispiel #28
0
 def __aepack__(self):
     return pack(struct.pack('hhhh', self.v0, self.h0, self.v1, self.h1),
         typeQDRectangle)
Beispiel #29
0
 def __aepack__(self):
     return pack({'logc': mkenum(self.logc), 'term': self.term}, 'logi')
Beispiel #30
0
 def __aepack__(self):
     return pack(struct.pack('hhh', self.r, self.g, self.b),
         typeRGBColor)
Beispiel #31
0
 def __aepack__(self):
     return pack(self.keyword, typeKeyword)
Beispiel #32
0
 def __aepack__(self):
     return pack({'want': mktype(self.want),
              'form': mkenum(self.form),
              'seld': self.seld,
              'from': self.fr},
             'obj ')
Beispiel #33
0
 def __aepack__(self):
     return pack(struct.pack('hh', self.script, self.language),
                 typeIntlWritingCode)
Beispiel #34
0
 def __aepack__(self):
     return pack(self.enum, typeEnumeration)
Beispiel #35
0
 def __aepack__(self):
     return pack(struct.pack('hh', self.v, self.h), typeQDPoint)
Beispiel #36
0
 def __aepack__(self):
     rec = {'kobj': self.of, 'kpos': self.pos}
     return pack(rec, forcetype='insl')
Beispiel #37
0
 def __aepack__(self):
     return pack(struct.pack('hhh', self.r, self.g, self.b), typeRGBColor)
Beispiel #38
0
 def __aepack__(self):
     return pack(struct.pack('b', self.bool), 'bool')
Beispiel #39
0
 def __aepack__(self):
     return pack(self.enum, typeEnumeration)
Beispiel #40
0
def pack(*args, **kwargs):
    from aepack import pack
    return pack(*args, **kwargs)
Beispiel #41
0
 def __aepack__(self):
     return pack(struct.pack('b', self.bool), 'bool')
Beispiel #42
0
 def __aepack__(self):
     return pack(self.type, typeType)
Beispiel #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))
Beispiel #44
0
 def __aepack__(self):
     return pack({'star': self.start, 'stop': self.stop}, 'rang')
Beispiel #45
0
 def test_roundtrip_float(self):
     o = 12.1
     packed = aepack.pack(o)
     unpacked = aepack.unpack(packed)
     self.assertEqual(o, unpacked)
Beispiel #46
0
def pack(*args, **kwargs):
    from aepack import pack
    return pack( *args, **kwargs)
Beispiel #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))
Beispiel #48
0
 def __aepack__(self):
     return pack(self.abso, 'abso')
Beispiel #49
0
 def __aepack__(self):
     return pack(self.keyword, typeKeyword)
Beispiel #50
0
 def __aepack__(self):
     return pack({'star': self.start, 'stop': self.stop}, 'rang')