Write Pure Python Cocoa Apps
bbum writes "Today, Ronald Oussoren and I patched the PyObjC (PythonObj-C) bridge to allow for completely standalone Cocoa applications that are implemented in Python. My 11-Oct-2002 weblog entries provide more detail and includes a link to a PyObjC Cocoa app that can be downloaded and hacked upon (with the app, you can actually create other apps without using the dev tools at all!). As the days pass, I'll be updating the 'blog with new software, updates, etc. A Fink package will be submitted shortly. (In reality -- Ronald did the hard stuff in that he figured out how to subclass ObjC classes in Python!!)" Nifty. Note there is also a PerlObjCBridge module included with Jaguar, and there's also CamelBones for Perl-Cocoa; what other scripting frameworks for Mac OS X are out there?
Sheesh, for a minute I thought you were kidding, but I guess not.
:-)
Yes, many languages are very powerful and allow you to do many things, but just because a language exists doesn't mean it magically includes support for everything -- including things that didn't exist at the time the language was created.
Generally, a language has a core set functionality that only provides a framework to build applications. Most languages then have a standard set of libraries implementing common functionality, and extended libraries implementing features outside the spec of the core and common APIs.
Anyway, Cocoa isn't written in Python, so you can't just use it from Python without an interface into the Cocoa framework. So, someone has provided an interface to Cocoa. Its not that Python was semantically unable to work with Cocoa, but that the mechanism didn't exist.
You should try something other than Visual Basic, maybe you'd learn about how software really works.
Don't blame me, I get all my opinions from my Ouija board.
From reading the threads, let me respond with a bit of clarification.
This is really only of interest to Python programmers that want to leverage Cocoa or ObjC [including Cocoa] programmers that want to leverage the power of Python.
It is not intended to be used as a cross platform solution.
In context, it happens to be extremely powerful. The ability to subclass and extend ObjC classes with Python means that one can build Cocoa applications that can have their classes reloaded and redefined on the fly. I.e. it can greatly reduce the "run-compile" part of the "run-compile-edit" loop that developers tend to be stuck in.
Furthermore, having access to the power of Python from Cocoa greatly reduces the # of lines of code necessary to perform certain tasks. The Python libraries provide great, easy to use, HTTP client/server solutions, excellent XML-RPC support and a slew of other features that are damned handy to have around.
The real value of the PyObjC module-- and credit largely goes to Ronald for this-- is the transparency with which one can interact between languages. This isn't just a messaging solution (like CamelBones). PyObjC provides the developer with the ability to subclass ObjC classes from Python and-- if one really wanted to go there-- subclass Python subclasses of ObjC classes in ObjC.
As well, PyObjC tends to be a bit more straightforward in terms of integration than AppleScript Studio.
Think of it this way: PyObjC allows the developer to quickly and easily prototype applications in a scripting language [Python] while not sacrificing any of the awesome power of Cocoa [and awesome it is!].
You could write apps in Python, but they wouldn't be able to access the Cocoa frameworks. Now Python can be used to create apps that can have native GUIs, use Cocoa classes and collections, use OS X Services, etc.
Programing languages CAN be used to do (almost) anything, but they're not all DESIGNED to to everything. If you really want to, you can create a complete GUI app with just assembly language. But it would be infinitely easier to use a higher-level language like Python, Objective C, Java, etc. FORTRAN was designed for mathematically intense code, while Perl was designed for extraction and reporting; you wouldn't want to write (for example) engineering simulation code in Perl, or Slashcode in FORTRAN.
-Ster
What other scripting frameworks for Mac OS X are out there? Well there is a very nice one here.
Yep, you can code everything inside Project Builder. You create your interface, connections, and outlets in Interface Builder.
There is no syntax highlighting for Python in project builder just yet, but I am sure that some creative person can make that happen soon enough. Apple might even implement it if they like the idea of a Python/Cocoa integration.
Can you mix with 3rd Party ObjC classes? I am pretty sure that you can, since this is a Python/Obj-C bridge. I haven't tried it myself, but I am pretty sure that its possible.
The best thing is actually interfacing your Objective-C objects with native Python objects. Create a complex Python data structure, full of lists, objects, tuples, and dictionaries, and then you can use it as the model (MVC) for your application in Cocoa!
You've had no interest in Python? Well, head over to http://www.python.org, and click on the tutorial. Its a great little language, its shipped by default with OS X 10.2, and its trivially easy to learn.