[Pythonmac-SIG] newbie questions about Mac APIs in Python

Jack Jansen Jack.Jansen at cwi.nl
Tue Oct 14 23:39:12 CEST 2008


On  14-Oct-2008, at 19:36 , Joe Strout wrote:

> On Oct 13, 2008, at 10:49 AM, Chris.Barker wrote:
>
>>> But what if we want to do some of them from a wxPython app (only  
>>> when we detect we're running on a Mac, of course)?
>>
>> Good question -- can pyObjC play well with wx? Anyone know?
>
> Or more generally: can you invoke some Cocoa functionality from any  
> generic Python app, or does it have to be a PyObjC app through and  
> through?
>
> For example: suppose we wanted to take the clean but Windows-only  
> "speech" package:
>
> 	<http://pypi.python.org/pypi/speech/0.5.1>
>
> ...and add Mac OS X support to it.  The speech facilities in Cocoa  
> (or Carbon, for that matter) are pretty easy to use; but this is a  
> generic module, that ought to work in any Python app, whether it's  
> got a wx GUI or even no GUI at all.  Is this possible, and how would  
> we go about it?

Some simple things "just work", also in command line tools. These are  
usually the CoreFoundation things that are pretty passive objects  
(CFDictionaries and such).

Some things work fine in a command line tool, as long as you make your  
command line tool have a run loop by allocating an NSRunLoop and  
calling one of it's run methods. But this wil require restructuring  
your app a bit. You may get away with running the runloop in a  
separate thread, but I have no experience with this (does anyone  
else?). I wouldn't be surprised if your speech stuff would fall in  
this category.

Some things will contact the window server, and this is not only  
obviously gui-related things like dialogs and such but also more  
subtle ones like some AppleEvents stuff. These will still work from a  
command line app, but they will probably not work from, say, a CGI  
script (as there's no window server). Hmm, maybe the speech stuff  
falls in this category after all, Apple may not want you to access the  
speaker if you're not the owner of the screen (the "you" here being  
the person running the script).


--
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


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pythonmac-sig/attachments/20081014/14077b91/attachment.htm>


More information about the Pythonmac-SIG mailing list