[Pythonmac-SIG] Carbon.AE - AEInstallCoercionHandler ?

has hengist.podd at virgin.net
Tue Aug 31 10:01:52 CEST 2004


Hey,

>>Really a question for Jack I suppose, but I'm wondering if there's 
>>a reason why Carbon.AE doesn't include functions for installing and 
>>removing coercion handlers?
>
>Probably because either (a) I didn't understand what they were, (b) 
>I was too lazy, or (c) both of the above.

See IM:IAC 4-41 for a description, and the Carbon Apple Event Manager 
Reference 
(/Developer/Documentation/Carbon/interapplicationcomm/AppleEventManager/Apple_Event_Manager/Apple_Event__er_Reference/index.html, 
or whatever it is in 10.3) lists the API.

I've attached a hacked (i.e. cut-n-paste coding), semi-working 
_AEModule.c FYI. I've found and fixed a bug with AEReplaceDescData 
(should be an AEDesc method), added code for installing and removing 
coercion handlers, and a generic coercion handler that calls a Python 
function. I've screwed something up so that it crashes the Python 
interpreter when you try to use it, but you know this stuff much 
better than I do so I expect you can figure it out - prolly dangled a 
pointer some place or something stupid like that.

Thanks,

has

---------
# TEST CODE

#!/usr/local/bin/pythonw

from Carbon.File import FSSpec
from Carbon import AE
from aem.types import Codecs

c = Codecs()

def unicodeToAlias(fromDesc, toType, toDesc):
	print 'FROM DESC %r' % fromDesc
	print 'type %r' % fromDesc.type
	print 'data %r' % fromDesc.data
	print 'DESIRED TYPE %r' % toType
	print 'TO DESC %r' % toDesc
	print 'type %r' % toDesc.type
	# print 'data %r' % toDesc.data # !!! something's not right here

	# insert test data into toDesc; Python interpreter crashes on 
this line when uncommented
	#toDesc.AEReplaceDescData('alis', 
'\x00\x00\x00\x00\x01B\x00\x02\x00\x00\x0cMacintosh 
HD\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbdER\xbbH+\x00\x00\x00\x02\x00\x95\nReadMe.txt\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04#\xac\xbdRwuWAFFMSIE\xff\xff\xff\xff\x00\x00\x01 
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03has\x00\x00\x10\x00\x08\x00\x00\xbdED\xab\x00\x00\x00\x11\x00\x08\x00\x00\xbdRie\x00\x00\x00\x01\x00\x08\x00\x02\x00\x95\x00\x00"*\x00\x02\x00!Macintosh 
HD:Users:has:ReadMe.txt\x00\x00\x0e\x00\x16\x00\n\x00R\x00e\x00a\x00d\x00M\x00e\x00.\x00t\x00x\x00t\x00\x0f\x00\x1a\x00\x0c\x00M\x00a\x00c\x00i\x00n\x00t\x00o\x00s\x00h\x00 
\x00H\x00D\x00\x12\x00\x14Users/has/ReadMe.txt\x00\x13\x00\x01/\x00\xff\xff\x00\x00')

# installing and removing handlers _seems_ to work ok
AE.AEInstallCoercionHandler('utxt', 'alis', unicodeToAlias)
print AE.AEGetCoercionHandler('utxt', 'alis')
AE.AERemoveCoercionHandler('utxt', 'alis')

# as does fixed AEReplaceDescData
desc = c.pack(u'/Users/has/ReadMe.txt')
desc.AEReplaceDescData('TEXT', 'hello world')
print 'Replaced type %r, data %r' % (desc.type, desc.data)

# actually invoking coercion is all kinds of buggy, however
AE.AEInstallCoercionHandler('utxt', 'alis', unicodeToAlias)
desc = c.pack(u'/Users/has/ReadMe.txt')
print desc.AECoerceDesc('alis')
-- 
http://freespace.virgin.net/hamish.sanderson/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: _AEmodule.c
Type: application/mac-binhex40
Size: 64439 bytes
Desc: not available
Url : http://mail.python.org/pipermail/pythonmac-sig/attachments/20040831/19363b4d/_AEmodule-0001.hqx


More information about the Pythonmac-SIG mailing list