Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scripting Bridge vs PyObjC vs py2app

I am just starting to learn about integrating Python and Mac OS apps. (I want to call some methods from Cocoa to Python.) I've ran into these terminologies -- Scripting Bridge, PyObjC, and py2app. What's the difference? Is PyObjC an example of a scripting bridge? And when does py2app come into play?

like image 718
janeh Avatar asked Jun 05 '12 18:06

janeh


1 Answers

The short version: PyObjC is the way you call Mac OS X APIs, Scripting Bridge is the way you talk to other apps' scripting interfaces. In more detail:

PyObjC is a bridge between the Python language and the Objective C runtime (and the set of Cocoa wrappers built trivially on top of that bridge, and some nice convenience stuff). If you want to call Cocoa methods, you use PyObjC, typically by importing either Cocoa or Foundation.

Scripting Bridge is a bridge between the Python language and the Apple Event-based scripting system. If you want to call another app's scripting interface, you use Scripting Bridge. (In most cases, if you're using Scripting Bridge, you'll also want to import Foundation, because Scripting Bridge deals with things like NSArrays, etc.)

So, PyObjC is not an example of a scripting bridge. An example of a scripting bridge is, well, Scripting Bridge, or Appscript (which is better, but not from Apple, and no longer maintained).

py2app has nothing much to do with either of these; it's a way to wrap up a Python application, together with all of the extension modules it requires, and as much of the Python interpreter as necessary, into a single .app bundle that you can distribute to users so they can just double-click to run it. Of course most such apps will have GUIs, and many of them will use PyObjC to create those GUIs directly in Cocoa (rather than using, e.g., PyQt or wxPython), but beyond that, there's no real connection.

like image 58
abarnert Avatar answered Sep 18 '22 23:09

abarnert