[Pythonmac-SIG] Python RAD tools
bill fancher
bfancher@mac.com
Sun, 13 Jan 2002 15:30:06 -0800
On Sunday, January 13, 2002, at 05:27 AM, Adam Eijdenberg wrote:
> But my question is, would a tool like this be welcomed? Is it a
> duplication of existing effort or could it find a niche? What do you
> all think?
I believe such a tool would be welcomed. Whether it's a duplication of
effort is debatable...
I have an OSA component for Python that enables Python scripting in
Script Editor and other OSA compliant applications. After a few tweaks,
it can now be used to create Python applications in AppleScript Studio.
Here's the complete script for a very simple calendar application with a
text entry field, a button, and a text display field:
from calendar import calendar
def will_finish_launching():
showYear()
def action(theObject):
showYear()
def clicked(theObject):
showYear()
def showYear():
w = app().window['main']
year = w.text_field['dateEntry'].contents
w.scroll_view['display'].text_view['calendar'].contents =
calendar(year)
The application comes up displaying a calendar for 2002 (in blue text).
Entering a different year in the text entry field and hitting return or
pressing the button puts the appropriate calendar in the calendar
display field. The application has all the features you'd expect with a
Cocoa app: field validation, copy/paste, a scrolling resizable window,
working "Hide" and "Minimize" menu items, an "About Calendar" dialog,
services, etc.
The interface is constructed and linked to the Python handlers in
Interface Builder. All AppleScriptKit interface objects are supported.
Script editing and application building are done with Project Builder.
During compilation, syntax errors are reported by Project Builder and
clicking the error report selects the correct line in the script.
Debugging (single step, breakpoints, variable display, etc.) is not yet
working, but runtime errors are reported in a dialog giving the error
message and line number.
One advantage of this approach is that you can write part or all of your
application in C, OjbC, C++, or Java, making it easy to progress from a
scripted prototype to a fully optimized application with only minor
changes in IB. I reimplemented the ASS Outline example in Python with NO
changes in IB.
It's far from a finished solution, and, as it stands, it's not ready for
production use: it requires hacking a ProjectBuilderJambase rule that's
hard coded for AppleScript, PB will muck with your script files in
various annoying ways, and you can't mix Python and AppleScript in the
same application. But it's a start.
I'll be sending this latest version of OSA Python (1.0a5) to testers
shortly. (Anyone else interested in helping out should contact me off
list.)
Apple has hinted that future versions of PB/IB will fully support OSA
languages other than AppleScript. I'm hoping they deliver and looking at
alternatives in the meanwhile.
Let a thousand flowers bloom...
--
bill