3/27/2002

Linebreaks and Advanced Editor.py in the Mach-O MacPython IDE

I finally got some time and energy to pick up on the Mach-O MacPython project again today. I had been poking around in aetools, writing some code that will allow me to control Mac applications with Python, and was using the Mach-O MacPython IDE basically for it's "Run all" button. Since the underlying Python that is running the Mach-O IDE is really UNIX Python, it expects to see \n as the line ending character, but WASTE doesn't do a linebreak when it sees \n. So basically, you end up with one really, really long line. But, happily, the "Run all" button would faithfully tell UNIX Python to run the file, \n line endings and all, so it was at least of some utility.

After I had finished poking around with the ae* modules and gensuitemodule.py, I made a diff and applied it to a fresh CVS checkout on my Boss' laptop, since he was eager to play with the code I have been generating. (Side note: I figured out how to use diff and patch; "cvs diff | mydiff.diff" on one machine and "patch -p0
The patch applied quite easily, and soon enough I was controlling InDesign from Python. I thought to myself, "if only you could actually use the editor in the IDE..." Jack is working the political machinery on Python-dev trying to get his universal newlines patch accepted, and once he does, none of this will be required, but meanwhile, how about this hack...

When you open a file in the IDE, it gets read into a string. Check to see what kind of newlines the file has, and keep a record of it. Then, convert every newline in the string to \r.

When you save to disk, convert \r to the original newline character.

Ugly as hell, but it works! And isn't that really all that matters to most people?

While I was at it, I added the Advanced Editor from here, as well. All I needed to do was add "from Carbon " in front of all of the toolbox import statements.

Good things are happening in the world of UNIX/MacPython integration...

Here's a screenshot of the MacPython IDE opening and editing files with UNIX line endings, with the Advanced Editor patch applied.

12/19/2001

Mach-O MacPython IDE!!!

Well, since I noticed Jack had gotten the WASTE module compiling and linking under command-line Mach-O Python in the CVS, I decided to take another stab at getting the IDE up and running as a Mach-O bundle.

After downloading WASTE, putting it in the right place (as mentioned in the comment in setup.py in CVS) and running ranlib on the libWASTE.a file, I was able to get the WASTE module to compile and link. So far so good.

Then, I dropped PythonIDEMain.py on the Python.app. Error on MacOS.EnableAppSwitch. No problem, just comment it out. I was able to get as far as macresource.need before having tough problems.

It turns out that while os.path.join and the like create '/asdf/zxcv/wqr' slash delimited strings, the code that converts a python string into a C FSRef (? or FSSpec?) needs ':' delimited strings. Or the Carbon library itself needs colon delimited strings. I didn't look into it too much except to determine that slash delimited path strings were the problem. Anyway, I wrote an awful hack in macresource.py that converts any slash delimited paths to colon delimited and allows the IDE to get up and running!!!

There are caveats, however. I had to comment out quite a few more MacOS.EnableAppSwitch calls as well as the call that installs the Console and Output windows in the IDE. But I only worked on it for about an hour, and already, I can create new python files, execute them (output goes to the Console application), use the module browser, see nice traceback windows, and bring up a post-mortem debugger! Awesome.

Here are some screenshots:


12/05/2001

Apple just released AppleScript Studio

Apple just released AppleScript Studio in the December 2001 Developer Tools update! Get it from Apple.

If you haven't heard of it, AppleScript Studio is Apple's integration of a few technologies. First, they extended Project Builder to edit, format, color, and debug AppleScripts. Then, they wrote a terminology dictionary to give AppleScript the ability to manipulate Cocoa objects. Finally, they modified Interface Builder to allow the developer to hook up a Cocoa widget with an AppleScript "handler".

Several of us at my company have been eagerly awaiting this release. It's an interesting hybrid application of all the technologies Apple now controls -- some Apple projects, and some NeXT projects. Also, it seems to revive a lot of the missing rapid development possibilities left untapped by the demise of HyperCard -- all that is missing is an Object Database.

More to come as I explore the possibilities embodied in this exiting new release.