Stories
Slash Boxes
Comments

News for nerds, stuff that matters

Write Pure Python Cocoa Apps

Posted by pudge on Sun Oct 13, 2002 06:40 PM
from the cuckoo-for-cocoa-apps dept.
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?
This discussion has been archived. No new comments can be posted.
Display Options Threshold:
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
  • When.. (Score:2, Funny)

    by zulux (112259) on Sunday October 13 2002, @06:47PM (#4442502) Homepage Journal
    ...is sombody going to let me do this with Forth?
    • Re:When.. by Raskolnk (Score:2) Sunday October 13 2002, @07:43PM
    • 1 reply beneath your current threshold.
  • Perl-Cocoa... (Score:2)

    by 3-State Bit (225583) on Sunday October 13 2002, @06:48PM (#4442504)
    Sorry, I'm not very up on my Mac development...Does this mean TK apps will magically be sourcelevel cocoa-fied?
  • Yeah, good, but ... (Score:3, Insightful)

    by Trusty Penfold (615679) <jon_edwards@spanners4us.com> on Sunday October 13 2002, @06:49PM (#4442509) Journal
    ... why couldn't you write apps in Python before?

    What on earth is the point of a programming language that you can't write apps in???

    There are lots of these "WoW! Now you can use Programming Language X to do Y", but isn't the whole point of programming languages that you can do anything you want with them?
    • Re:Yeah, good, but ... (Score:5, Informative)

      by Raskolnk (26414) on Sunday October 13 2002, @07:41PM (#4442744)
      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. :-)
      [ Parent ]
    • Re:Yeah, good, but ... by Ster (Score:2) Sunday October 13 2002, @08:07PM
    • Re:Yeah, good, but ... by bdash (Score:2) Monday October 14 2002, @12:18AM
    • 1 reply beneath your current threshold.
  • by rfsayre (255559) on Sunday October 13 2002, @07:43PM (#4442758) Homepage
    PySoulseek must be made to run this way.
  • Clarification (Score:5, Informative)

    by bbum (28021) on Sunday October 13 2002, @07:58PM (#4442817) Homepage
    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!].
    • Re:Clarification by rfsayre (Score:2) Sunday October 13 2002, @08:25PM
      • Re:Clarification (Score:5, Informative)

        by bbum (28021) on Sunday October 13 2002, @08:50PM (#4443024) Homepage
        Well, sure, you have always been able to subclass ObjC classes from ObjC... :-)

        The key difference is that doing so in Python doesn't require recompilation and relinking the app (it currently requires relaunching the app, but that is an artificial barrier).

        The key advantage is that one can often implement functionality in Python much more rapidly than pure ObjC simply because of the reduction in number of lines of code and the greater degree of abstraction offered by Python.

        Even with a pure ObjC Cocoa app, PyObjC can be mixed in to provide a level of scriptability that isn't available in other solutions. Specifically, because Python provides a completely transparent interface between ObjC and Python, an entire application becomes scriptable simply by including PyObjC.
        [ Parent ]
        • Re:Clarification by rfsayre (Score:2) Sunday October 13 2002, @09:12PM
          • Re:Clarification (Score:4, Interesting)

            by bbum (28021) on Sunday October 13 2002, @09:43PM (#4443194) Homepage
            See, I thought you could even add Objective-C classes while the program was running, as it's totally dynamic.

            Oh -- certainly -- you can always load a bundle. However, redefining existing classes has always been somewhat limited because of the way ObjC is implemented. Not a criticism of the language-- just the nature of its implementation.

            With the Python stuff, it is much easier to effectively redefine everything about a class. This isn't 100% considered within the current implementation, but the potential is there.
            [ Parent ]
          • 1 reply beneath your current threshold.
    • Re:Clarification by anarkhos (Score:2) Monday October 14 2002, @03:07AM
  • RubyCocoa (Score:2, Informative)

    by Canyon Rat (103953) on Sunday October 13 2002, @11:48PM (#4443631)
    What other scripting frameworks for Mac OS X are out there? Well there is a very nice one here [imasy.or.jp].
  • great news! (Score:5, Interesting)

    by Panix (2408) on Monday October 14 2002, @01:05AM (#4443932) Homepage
    This is absolutely excellent news! I downloaded this the second I read the article, and I have been playing with it for a few hours now. It works almost flawlessly. The only thing that could really make this better is if Apple picked it up and integrated Python as a first class citizen along with Java and Objective-C in Interface Builder and Project Builder.

    People may ask "what's the point?" Well, for starters, Python is absolutely fantastic for building things quickly, especially for complex object or data structures that would take much more time to implement in Objective-C or Java.

    On top of this, Python is much better suited for Cocoa than Java! Apple implemented the Java-Cocoa bridge mostly for the sake of having Java be a "supported language." But, since Java is inflexible and strongly typed, it doesn't really fit into the Objective-C model that Cocoa relies on. Python on the other hand is perfectly suited for Cocoa. Python is weakly typed and can handle the dynamic runtime of Cocoa a lot better than a language like Java.

    In addition to this, Python's runtime is much more compact than Javas, and manages to load much more quickly. Just fire up Terminal.app and type "python" ... you will see the interactive Python interpreter fire up within a second. Its an amazing little language =)

    I am very excited about the potential of this Python/Cocoa implementation! In the first hour or so since I installed this, I was able to take an existing Python backend and add a quick Cocoa frontend, using nothing but the standard OS X Development Tools.

    Kudos to the great people who developed this!
    • Re:great news! by anarkhos (Score:1) Monday October 14 2002, @03:10AM
      • Re:great news! (Score:4, Informative)

        by Panix (2408) on Monday October 14 2002, @09:35AM (#4445419) Homepage
        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.
        [ Parent ]
  • Re:Who cares? (Score:2, Interesting)

    by sco08y (615665) on Sunday October 13 2002, @08:02PM (#4442835)
    Actually, you can use that as an advantage. Often times employers will ask you to write a "prototype" and then when it's done, they fire you and hire some monkeys to do upgrades.

    If you do prototyping in python and Cocoa, you can be sure that won't happen.
    [ Parent ]
    • Re:Who cares? by occam (Score:3) Monday October 14 2002, @12:17AM
  • 4 replies beneath your current threshold.