[Pythonmac-SIG] question about Carbon.AE and AppleEvents

Jack Jansen Jack.Jansen at cwi.nl
Sat Feb 28 16:02:27 EST 2004


On 28 Feb 2004, at 01:21, Bob Ippolito wrote:
>> Not sure if this is the right forum, but I'm all Googled out and have
>> nothing working to show for it.....
>>
>> I'm working on a application (written in Python, packaged as a proper
>> .app) that runs on OS X under X11 and I
>> would like it to respond to AppleEvents (i.e. opening up its 
>> registered
>> file types).
>>
>> I got as far as to find the Carbon.AE and associated modules, and 
>> write a
>> bit of code which supposedly installs 'odoc' AE handlers, but with no
>> luck. So I had a couple questions I was hoping someone would be able 
>> to
>> help me with....
>>
>> 1 - Is there any way to track what AppleEvents an application is 
>> sending
>> and/or receiving?
>> 2 - Does using Tkinter and X11 cause any interference in the 
>> AppleEvent
>> handling mechanisms? I.e. do the events ever get to the Python layer?
>> 3 - Can anyone point me to some [preferably working!] sample code that
>> installs event handlers, etc...
>
> I don't think it's possible.  X11 isn't tightly coupled with Apple's 
> WindowServer.  The X11 app itself could be running on a linux box 
> somewhere, for example...

That was my first thought too, but thinking about it a bit longer there 
is no reason it shouldn't be possible to get this to work. At least, if 
the app is running on your mac and displaying to your mac.

The only thing that is required is that your application is both an X11 
application (for its normal GUI interaction) and a Carbon application 
(for its interaction with AppleEvents). I can't think of any reason why 
there would be adverse interaction between the two.

But: there is no magic that makes your AppleEvent handlers be called, 
so you will have to create a Carbon event loop yourself that waits for 
the events to come in. You can use argvemulator.py (in Lib/plat-mac) as 
an example, but that won't be good enough, if I understand correctly 
what you want to do, because you want to continue listening for 
aevt/odoc events for the whole lifetime of your program. You could 
either call something similar to 
argvemulator.ArgvCollector.dooneevent() once in a while in your 
program, or use a separate thread for it.

If you do the latter I think it's best to let this be handled by the 
main thread, and let your real main program run in a second thread. I 
have a vague memory that talking to the window server should be done in 
the main thread. And as X11 communication all goes via sockets and such 
there's no such restriction for that.
--
Jack Jansen, <Jack.Jansen at cwi.nl>, http://www.cwi.nl/~jack
If I can't dance I don't want to be part of your revolution -- Emma 
Goldman




More information about the Pythonmac-SIG mailing list