[Pythonmac-SIG] problem trying to use aemreceive with Tkinter app

Nicholas Riley njriley at uiuc.edu
Fri Dec 2 19:34:24 CET 2005


On Thu, Dec 01, 2005 at 02:45:10PM -0600, Kennedy, Andrew (GE Healthcare) wrote:

> I'm trying to use aemreceive to process AppleEvents in a
> Tkinter-GUI'd Python app.  I have been able to use argvemulator.py
> from plat-mac to handle double clicking on a file and having it open
> in the application automatically.  I'm now trying to catch 'ocon'
> and 'odoc' AppleEvents within the application to handle dragging
> files onto the icon and double clicking on files while the
> application is running.
> 
> I can add the event handler per the code below:
> 
>     if sys.platform == 'darwin':
>         import aemreceive
>         aemreceive.installeventhandler(AEOpenFile, 'aevtodoc',
>                                        ('----','AliasList', aemreceive.ArgListOf(aemreceive.kAE.typeAlias)))
>
> What am I missing?  Do I need to modify my main loop to handle the
> events?  I never seem to get into the event handler code this way,
> so there must be something else at work here.  Is my event handler
> at the wrong level of the stack?
>
> The crash log is included after my signature.  Any assistance anyone
> can offer would be greatly appreciated.

It's trying to execute your event handler; it looks like the Python
thread state (PyThreadState) passed to PyFrame_New is null.  I imagine
this happens because the Python code is being dispatched when it
doesn't expect to be running Python code at all.  There might be a way
to wrap your event handler but I'm not familiar enough with the
internals of aemreceive to say how.

The only Python AE receive stuff I've done has been using
aemreceive.sfba.  I was able to use aemreceive.sfba.starteventloop()
for that.  It seems from the stack trace that Tk still removes and
dispatches an event at a time, so it doesn't play well with other
event consumers.  Maybe you can run your own event loop and dispatch
events to Tk yourself?

Or you could try using Tk's event handler instead.  You can try
evaluating a definition of ::tk::mac::OpenDocument, which according to
the TkAqua FAQ should be called on an aevt/odoc event.

-- 
Nicholas Riley <njriley at uiuc.edu> | <http://www.uiuc.edu/ph/www/njriley>


More information about the Pythonmac-SIG mailing list