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
def __aepack__(self): return pack( { keyAEScriptTag: self.script, keyAEStyles: self.style, keyAEText: self.text }, typeAEText)
def __aepack__(self): return pack( { 'obj1': self.obj1, 'relo': mkenum(self.relo), 'obj2': self.obj2 }, 'cmpd')
def __aepack__(self): return pack( { 'want': mktype(self.want), 'form': mkenum(self.form), 'seld': self.seld, 'from': self.fr }, 'obj ')
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())
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())
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
def __aepack__(self): return pack(struct.pack('hhhh', self.v0, self.h0, self.v1, self.h1), typeQDRectangle)
def __aepack__(self): return pack(self.data, self.type)
def __aepack__(self): return pack( struct.pack('hh', self.script, self.language) + self.text, typeIntlText)
def __aepack__(self): return pack({'ksty': self.style, 'ktxt': self.text}, 'STXT')
def __aepack__(self): return pack({'obj1': self.obj1, 'relo': mkenum(self.relo), 'obj2': self.obj2}, 'cmpd')
def test_roundtrip_None(self): o = None packed = aepack.pack(o) unpacked = aepack.unpack(packed) self.assertEqual(o, unpacked)
"""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
def __aepack__(self): return pack(struct.pack('hh', self.script, self.language), typeIntlWritingCode)
def __aepack__(self): return pack(struct.pack('hh', self.script, self.language)+self.text, typeIntlText)
def __aepack__(self): return pack({keyAEScriptTag: self.script, keyAEStyles: self.style, keyAEText: self.text}, typeAEText)
def __aepack__(self): return pack({'logc': mkenum(self.logc), 'term': self.term}, 'logi')
def __aepack__(self): return pack(self.abso, 'abso')
def __aepack__(self): return pack(self.type, typeType)
def __aepack__(self): rec = {'kobj': self.of, 'kpos': self.pos} return pack(rec, forcetype='insl')
def test_roundtrip_string(self): o = 'a string' packed = aepack.pack(o) unpacked = aepack.unpack(packed) self.assertEqual(o, unpacked)
def __aepack__(self): return pack(struct.pack('hh', self.v, self.h), typeQDPoint)
"""Tools for use in AppleEvent clients and servers.
def __aepack__(self): return pack(struct.pack('hhh', self.r, self.g, self.b), typeRGBColor)
def __aepack__(self): return pack(self.keyword, typeKeyword)
def __aepack__(self): return pack({'want': mktype(self.want), 'form': mkenum(self.form), 'seld': self.seld, 'from': self.fr}, 'obj ')
def __aepack__(self): return pack(self.enum, typeEnumeration)
def __aepack__(self): return pack(struct.pack('b', self.bool), 'bool')
def pack(*args, **kwargs): from aepack import pack return pack(*args, **kwargs)
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))
def __aepack__(self): return pack({'star': self.start, 'stop': self.stop}, 'rang')
def test_roundtrip_float(self): o = 12.1 packed = aepack.pack(o) unpacked = aepack.unpack(packed) self.assertEqual(o, unpacked)
def pack(*args, **kwargs): from aepack import pack return pack( *args, **kwargs)
def test_roundtrip_aeobjects(self): for o in self.OBJECTS: packed = aepack.pack(o) unpacked = aepack.unpack(packed) self.assertEqual(repr(o), repr(unpacked))